Skip to content

Commit

Permalink
Enhance tests / minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Dec 22, 2021
1 parent 37452a4 commit 42ea767
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
1 change: 0 additions & 1 deletion lib/processors/resourceListCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ module.exports = async function({resources, dependencyResources = [], options})
}

await collector.determineResourceDetails({
pool,
debugResources: options.debugResources,
mergedResources: options.mergedResources,
designtimeResources: options.designtimeResources,
Expand Down
43 changes: 40 additions & 3 deletions test/lib/lbt/resources/ResourceCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,60 @@ test.serial("determineResourceDetails: view.xml", async (t) => {
t.is(enrichWithDependencyInfoStub.getCall(0).args[0].name, "mylib/my.view.xml", "is called with view");
});

test.serial("determineResourceDetails: Debug bundle", async (t) => {
test.serial("determineResourceDetails: Debug bundle (without non-debug variant)", async (t) => {
const resourceCollector = new ResourceCollector();

const enrichWithDependencyInfoStub = sinon.stub(resourceCollector, "enrichWithDependencyInfo").resolves();
await resourceCollector.visitResource({getPath: () => "/resources/MyBundle-dbg.js", getSize: async () => 13});

await resourceCollector.determineResourceDetails({});
await resourceCollector.determineResourceDetails({
debugResources: ["**/*-dbg.js"], // MyBundle-dbg.js should be marked as "isDebug"
});

t.is(enrichWithDependencyInfoStub.callCount, 1, "enrichWithDependencyInfo is called once");
t.is(enrichWithDependencyInfoStub.getCall(0).args[0].name, "MyBundle-dbg.js",
"enrichWithDependencyInfo is called with debug bundle");
});

test.serial("determineResourceDetails: Debug bundle (with non-debug variant)", async (t) => {
const resourceCollector = new ResourceCollector();

const enrichWithDependencyInfoStub = sinon.stub(resourceCollector, "enrichWithDependencyInfo")
.onFirstCall().callsFake(async (resourceInfo) => {
resourceInfo.included = new Set(["SomeModule.js"]);
resourceInfo.required = new Set(["Boot.js"]);
})
.onSecondCall().callsFake(async (resourceInfo) => {
resourceInfo.required = new Set(["Boot.js"]);
});
await resourceCollector.visitResource({getPath: () => "/resources/MyBundle-dbg.js", getSize: async () => 13});
await resourceCollector.visitResource({getPath: () => "/resources/MyBundle.js", getSize: async () => 13});

await resourceCollector.determineResourceDetails({
debugResources: ["**/*-dbg.js"], // MyBundle-dbg.js should be marked as "isDebug"
});
t.is(enrichWithDependencyInfoStub.callCount, 2, "enrichWithDependencyInfo is called twice");
t.is(enrichWithDependencyInfoStub.getCall(0).args[0].name, "MyBundle.js",
"enrichWithDependencyInfo is called with non-debug bundle first");
t.is(enrichWithDependencyInfoStub.getCall(1).args[0].name, "MyBundle-dbg.js",
"enrichWithDependencyInfo is called with debug bundle on second run");

const bundleInfo = resourceCollector._resources.get("MyBundle.js");
t.deepEqual(bundleInfo.included, new Set(["SomeModule.js"]));
t.deepEqual(bundleInfo.required, new Set(["Boot.js"]));
t.is(bundleInfo.isDebug, false);

const debugBundleInfo = resourceCollector._resources.get("MyBundle-dbg.js");
t.is(debugBundleInfo.included, null);
t.deepEqual(debugBundleInfo.required, new Set(["Boot.js"]));
t.is(debugBundleInfo.isDebug, true);
});

test.serial("determineResourceDetails: Debug files and non-debug files", async (t) => {
const resourceCollector = new ResourceCollector();

const enrichWithDependencyInfoStub = sinon.stub(resourceCollector, "enrichWithDependencyInfo")
.callsFake((resourceInfo) => {
.callsFake(async (resourceInfo) => {
// Simulate enriching resource info with dependency info to test whether it gets shared
// with the dbg resource later on
resourceInfo.dynRequired = true;
Expand Down

0 comments on commit 42ea767

Please sign in to comment.