Skip to content

Commit

Permalink
[INTERNAL] Add tests for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Mar 9, 2022
1 parent d1d9b9f commit d61655e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
49 changes: 46 additions & 3 deletions test/lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ test.beforeEach((t) => {
t.context.dependencies = {};
t.context.comboByGlob = sinon.stub().resolves([]);

t.context.combo = {
byGlob: t.context.comboByGlob,
};
t.context.combo.filter = sinon.stub().returns(t.context.combo);

t.context.ReaderCollectionPrioritizedStub = sinon.stub();
t.context.ReaderCollectionPrioritizedStub.returns({
byGlob: t.context.comboByGlob
});
t.context.ReaderCollectionPrioritizedStub.returns(t.context.combo);
mock("@ui5/fs", {
ReaderCollectionPrioritized: t.context.ReaderCollectionPrioritizedStub
});
Expand Down Expand Up @@ -1367,6 +1370,46 @@ test.serial("generateLibraryPreload for sap.ui.core with own bundle configuratio
"ReaderCollectionPrioritized should have been called with 'new'");
});

test.serial("Error: Failed to resolve non-debug name", async (t) => {
const {
generateLibraryPreload,
workspace, dependencies, comboByGlob
} = t.context;
const resources = [
{getPath: sinon.stub().returns("/resources/resource-tagged-as-debug-variant.js")}
];
comboByGlob.resolves(resources);

workspace.byGlob.resolves([
{getPath: sinon.stub().returns("/resources/sap/ui/core/.library")}
]);

const taskUtil = {
getTag: sinon.stub().returns(false),
STANDARD_TAGS: {
HasDebugVariant: "<HasDebugVariant>",
IsDebugVariant: "<IsDebugVariant>",
OmitFromBuildResult: "<OmitFromBuildResult>"
}
};
taskUtil.getTag
.withArgs("/resources/resource-tagged-as-debug-variant.js", taskUtil.STANDARD_TAGS.IsDebugVariant)
.returns(true);

await t.throwsAsync(generateLibraryPreload({
workspace,
dependencies,
taskUtil,
options: {
projectName: "sap.ui.core",
// Should be ignored for hardcoded sap.ui.core bundle configuration
excludes: ["sap/ui/core/**"]
}
}), {
message: "Failed to resolve non-debug name for /resources/resource-tagged-as-debug-variant.js"
});
});

test.serial("generateLibraryPreload with excludes", async (t) => {
const {
generateLibraryPreload, moduleBundlerStub, ReaderCollectionPrioritizedStub,
Expand Down
32 changes: 32 additions & 0 deletions test/lib/tasks/bundlers/generateStandaloneAppBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,35 @@ test.serial("execute module bundler with taskUtil", async (t) => {
}
});
});

test.serial("Error: Failed to resolve non-debug name", async (t) => {
// NOTE: This scenario is not expected to happen as the "minify" task sets the IsDebugVariant tag
// only for resources that adhere to the debug file name pattern

const {taskUtil} = t.context;
const dummyResource1 = createDummyResource("1.js");
taskUtil.getTag.withArgs(dummyResource1.getPath(), taskUtil.STANDARD_TAGS.IsDebugVariant).returns(true);

const dummyReaderWriter = {
_byGlob: async function() {
return [
dummyResource1,
];
},
write: function() {}
};
sinon.stub(dummyReaderWriter, "write").resolves();
const params = {
workspace: dummyReaderWriter,
dependencies: dummyReaderWriter,
taskUtil,
options: {
projectName: "some.project.name",
namespace: "some/project/namespace"
}
};

await t.throwsAsync(generateStandaloneAppBundle(params), {
message: "Failed to resolve non-debug name for /resources/ponyPath1.js"
});
});

0 comments on commit d61655e

Please sign in to comment.