Repository navigation
refactor(builder): Tag debug variants pairs skipped by minify
#1694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -242,7 +242,7 @@ test("minify: No taskUtil", async (t) => { | |
| }); | ||
| }); | ||
|
|
||
| test("minify: Skips and warns for an existing -dbg.js next to its .js", async (t) => { | ||
| test("minify: Skips, tags and warns for an existing -dbg.js next to its .js", async (t) => { | ||
| const {minify, workspace, taskUtil, minifierStub, log} = t.context; | ||
| // A .js with an existing -dbg.js sibling (broken input state), plus a plain .js without a sibling. | ||
| const normal = {getPath: () => "/resources/normal.js"}; | ||
|
|
@@ -278,9 +278,58 @@ test("minify: Skips and warns for an existing -dbg.js next to its .js", async (t | |
| t.true(log.warn.firstCall.firstArg.includes("builder.minification.excludes"), | ||
| "Warning hints at the minification excludes configuration"); | ||
|
|
||
| t.true(taskUtil.setTag.calledWithExactly(withDbg, taskUtil.STANDARD_TAGS.HasDebugVariant), | ||
| "Skipped .js is tagged as having a debug variant"); | ||
| t.true(taskUtil.setTag.calledWithExactly(existingDbg, taskUtil.STANDARD_TAGS.IsDebugVariant), | ||
|
Comment on lines
+281
to
+283
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @matz3 is testing setTag() enough? (testing getTag() would be cleaner?)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, for a unit test, I think checking for an expected setTag call is sufficient.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for taking the time :) Yeah good idea regarding tests with caching. I'll look into this once I'm initially done with these PRs. |
||
| "Existing -dbg.js is tagged as a debug variant"); | ||
|
|
||
| // Neither the skipped .js nor its -dbg.js got written back. | ||
| t.is(workspace.write.callCount, 3, "workspace#write got called only for the plain .js and its derived resources"); | ||
| ["resource normal", "dbgResource normal", "sourceMapResource normal"].forEach((resName, idx) => { | ||
| t.is(workspace.write.getCall(idx).firstArg, resName, "workspace#write got called for expected resource"); | ||
| }); | ||
| }); | ||
|
|
||
| test("minify: Processes a standalone -dbg.js without a .js sibling", async (t) => { | ||
| // This test covers a scenario where a -dbg.js file exists WITHOUT a corresponding normal .js sibling. | ||
| // This could happen e.g. if (for whatever reason) the resource was simply named "..-dbg.js" | ||
| // (-> valid case) | ||
| const {minify, workspace, taskUtil, minifierStub, log} = t.context; | ||
| const standalone = {getPath: () => "/resources/standalone-dbg.js"}; | ||
| workspace.byGlob.resolves([standalone]); | ||
|
|
||
| const processedByInput = new Map([ | ||
| [standalone, { | ||
| resource: "resource standalone", | ||
| dbgResource: "dbgResource standalone", | ||
| sourceMapResource: "sourceMapResource standalone", | ||
| }] | ||
| ]); | ||
| minifierStub.callsFake(({resources}) => Promise.resolve([processedByInput.get(resources[0])])); | ||
|
|
||
| await runTask(minify, { | ||
| workspace, | ||
| taskUtil, | ||
| options: { | ||
| pattern: "**" | ||
| } | ||
| }); | ||
|
|
||
| t.is(minifierStub.callCount, 1, "minifier got called once - for the standalone -dbg.js"); | ||
| t.deepEqual(minifierStub.firstCall.firstArg.resources, [standalone], | ||
| "minifier processed the standalone -dbg.js"); | ||
|
|
||
| t.is(log.warn.callCount, 0, "No warning got logged for the standalone -dbg.js"); | ||
|
|
||
| t.true(taskUtil.setTag.calledWithExactly("resource standalone", taskUtil.STANDARD_TAGS.HasDebugVariant), | ||
| "The standalone file is tagged as having a generated debug variant"); | ||
| t.false(taskUtil.setTag.calledWith(standalone, taskUtil.STANDARD_TAGS.IsDebugVariant), | ||
| "The standalone file is not tagged as a debug variant based on its name"); | ||
| t.true(taskUtil.setTag.calledWithExactly("dbgResource standalone", taskUtil.STANDARD_TAGS.IsDebugVariant), | ||
| "The generated debug variant receives its debug tag"); | ||
|
|
||
| t.is(workspace.write.callCount, 3, "workspace#write got called for the standalone file and its derived resources"); | ||
| ["resource standalone", "dbgResource standalone", "sourceMapResource standalone"].forEach((resName, idx) => { | ||
| t.is(workspace.write.getCall(idx).firstArg, resName, "workspace#write got called for expected resource"); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.