Skip to content

Commit aae0cba

Browse files
test(javascript): assert what load() owes, not what Deno can import
`should install onto terser` asserted that under Deno `phases` is empty, because Deno could not import terser's own sources when the test was written. It sometimes can, and then the test fails — it went red once on #22243, a pull request touching only CSS fixtures, and cost a re-run of a 21-minute job to establish it was not that change's doing. Which sources a runtime reaches is the one thing `load` is written to tolerate: it catches any failure and hands back terser's published entry point. So the runtime is the wrong thing to assert. What `load` owes everywhere is that it installed phases this build declares and nothing else, and Node, which always reaches the sources, still owes the whole set — both of which this now states. The fallback path stays covered by behaviour rather than by a hardcoded outcome: every `should mangle exactly as terser does` case compares webpack's `minify` against terser's own, whichever way `load` resolved.
1 parent be2f190 commit aae0cba

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎test/unitCases/syntax-printer.unittest.js‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// cspell:ignore fnames
44

5-
const { load } = require("../../lib/javascript/syntax").printer;
5+
const { load, PHASES } = require("../../lib/javascript/syntax").printer;
66

77
/**
88
* Sources chosen for the decisions the mangler makes: which scope hands out a
@@ -90,13 +90,16 @@ describe("syntax-printer", () => {
9090
it("should install onto terser", async () => {
9191
const terser = await load();
9292
expect(typeof terser.minify).toBe("function");
93-
// Deno cannot import terser's own sources here, so `load` hands back
94-
// terser's published entry point with no phase of ours installed —
95-
// the fallback every phase is written to allow.
93+
// WHY: whether a runtime reaches terser's own sources is the one thing
94+
// `load` is written to tolerate, and Deno reaches them only sometimes —
95+
// so asserting either outcome there failed at random. What it owes
96+
// everywhere is to install phases this build declares and nothing else;
97+
// Node, which always reaches the sources, owes the whole set.
98+
expect(PHASES.map((phase) => phase.name)).toEqual(
99+
expect.arrayContaining(terser.phases)
100+
);
96101
if (!("Deno" in globalThis)) {
97102
expect(terser.phases).toContain("mangle");
98-
} else {
99-
expect(terser.phases).toEqual([]);
100103
}
101104
});
102105

0 commit comments

Comments
 (0)