Skip to content

Commit

Permalink
Fixes and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Dec 6, 2021
1 parent cfc79a7 commit 8934088
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/lbt/resources/ResourceCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ class ResourceCollector {

// FIXME: "merged" property is only calculated in ResourceInfo#copyFrom
// Therefore using the same logic here to compute it.
if (nonDbgInfo.included != null && nonDbgInfo.included.size > 0) {
// We need to analyze the dbg resource if the non-dbg variant is a bundle
// because we will (usually) have different content.
if (!nonDbgInfo || (nonDbgInfo.included != null && nonDbgInfo.included.size > 0)) {
// We need to analyze the dbg resource if there is no non-dbg variant or
// it is a bundle because we will (usually) have different content.
debugBundlePromises.push(
this.enrichWithDependencyInfo(dbgInfo)
);
Expand Down
17 changes: 7 additions & 10 deletions test/lib/lbt/resources/ResourceCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test.serial("visitResource: ensure proper matching of indicator files", async (t
t.is(resourceCollector.components.size, 0, "No prefixes should be added");
});

test.serial("groupResourcesByComponents: debugBundles", async (t) => {
test.serial("groupResourcesByComponents: external resources", async (t) => {
const resourceCollector = new ResourceCollector();
resourceCollector.setExternalResources({
"testcomp": ["my/file.js"]
Expand Down Expand Up @@ -155,9 +155,7 @@ test.serial("determineResourceDetails: Debug bundle", async (t) => {
const enrichWithDependencyInfoStub = sinon.stub(resourceCollector, "enrichWithDependencyInfo").resolves();
await resourceCollector.visitResource({getPath: () => "/resources/MyBundle-dbg.js", getSize: async () => 13});

await resourceCollector.determineResourceDetails({
debugBundles: ["MyBundle-dbg.js"]
});
await resourceCollector.determineResourceDetails({});
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");
Expand All @@ -183,16 +181,15 @@ test.serial("determineResourceDetails: Debug files and non-debug files", async (
}));

await resourceCollector.determineResourceDetails({
debugResources: ["**/*-dbg.js"],
debugBundles: ["MyBundle-dbg.js"]
debugResources: ["**/*-dbg.js"]
});
t.is(enrichWithDependencyInfoStub.callCount, 3, "enrichWithDependencyInfo is called three times");
t.is(enrichWithDependencyInfoStub.getCall(0).args[0].name, "MyBundle-dbg.js",
"enrichWithDependencyInfo called with debug bundle");
t.is(enrichWithDependencyInfoStub.getCall(1).args[0].name, "mylib/MyControlA.js",
t.is(enrichWithDependencyInfoStub.getCall(0).args[0].name, "mylib/MyControlA.js",
"enrichWithDependencyInfo called with non-debug control A");
t.is(enrichWithDependencyInfoStub.getCall(2).args[0].name, "mylib/MyControlB.js",
t.is(enrichWithDependencyInfoStub.getCall(1).args[0].name, "mylib/MyControlB.js",
"enrichWithDependencyInfo called with non-debug control B");
t.is(enrichWithDependencyInfoStub.getCall(2).args[0].name, "MyBundle-dbg.js",
"enrichWithDependencyInfo called with debug bundle");

t.is(resourceCollector._resources.get("MyBundle-dbg.js").isDebug, true, "MyBundle-dbg is a debug file");
t.is(resourceCollector._resources.get("MyBundle-dbg.js").dynRequired, true,
Expand Down

0 comments on commit 8934088

Please sign in to comment.