Skip to content

Commit b4ea5a7

Browse files
test: update target flag tests for webpack 5.108 (#4797)
webpack 5.108 introduces the universal, deno and bun targets and supports combining targets like node and web via universal ESM output, which broke the target flag tests: - update the "Unknown target" stderr snapshots to include the new universal, deno and bun entries - replace the "should throw an error for incompatible multiple targets" test with "should allow multiple different targets", since node + web now builds successfully - bump webpack to 5.108.3 in the lockfile so the snapshots match the installed version Fixes the failing CI on #4792 and unblocks #4795. Claude-Session: https://claude.ai/code/session_012iKSSr35Ue6UtyA6rcw6UA Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9a5fef9 commit b4ea5a7

3 files changed

Lines changed: 112 additions & 125 deletions

File tree

package-lock.json

Lines changed: 102 additions & 110 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/build/target/flag-test/__snapshots__/target-flag.test.js.snap.webpack5

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,15 @@ exports[`--target flag should reset the \`target\` option when the \`--target-re
44

55
exports[`--target flag should reset the \`target\` option when the \`--target-reset\` is used: stderr 1`] = `""`;
66

7-
exports[`--target flag should throw an error for incompatible multiple targets: stderr 1`] = `
8-
"[webpack-cli] ✖ Error: For the selected environment is no default script chunk format available:
9-
10-
JSONP Array push ('array-push') can be chosen when 'document' or 'importScripts' is available.
11-
CommonJs exports ('commonjs') can be chosen when 'require' or node builtins are available.
12-
Select an appropriate 'target' to allow selecting one by default, or specify the 'output.chunkFormat' directly.
13-
at stack"
14-
`;
15-
16-
exports[`--target flag should throw an error for incompatible multiple targets: stdout 1`] = `""`;
17-
187
exports[`--target flag should throw an error for invalid target in multiple syntax: stderr 1`] = `
198
"[webpack-cli] ✖ Error: Unknown target 'invalid'. The following targets are supported:
209
* browserslist / browserslist:env / browserslist:query / browserslist:path-to-config / browserslist:path-to-config:env: Resolve features from browserslist. Will resolve browserslist config automatically. Only browser or node queries are supported (electron is not supported). Examples: 'browserslist:modern' to use 'modern' environment from browserslist config
2110
* web: Web browser.
2211
* webworker: Web Worker, SharedWorker or Service Worker.
12+
* universal: Universal target running in browser, web worker, Node.js, Electron and NW.js. Output is always ECMAScript modules.
2313
* [async-]node[X[.Y]]: Node.js in version X.Y. The 'async-' prefix will load chunks asynchronously via 'fs' and 'vm' instead of 'require()'. Examples: node14.5, async-node10.
14+
* deno[X[.Y]]: Deno in version X.Y. Emits ESM output; node.js built-ins are available via the required 'node:' specifier and web APIs (fetch, WebAssembly, ...) are available too. Examples: deno2, deno1.40.
15+
* bun[X[.Y]]: Bun in version X.Y. Output is always ECMAScript modules. Examples: bun, bun1.1.
2416
* electron[X[.Y]]-main/preload/renderer: Electron in version X.Y. Script is running in main, preload resp. renderer context.
2517
* nwjs[X[.Y]] / node-webkit[X[.Y]]: NW.js in version X.Y.
2618
* esX: EcmaScript in this version. Examples: es2020, es5.
@@ -41,7 +33,10 @@ exports[`--target flag should throw error with invalid value for --target: stder
4133
* browserslist / browserslist:env / browserslist:query / browserslist:path-to-config / browserslist:path-to-config:env: Resolve features from browserslist. Will resolve browserslist config automatically. Only browser or node queries are supported (electron is not supported). Examples: 'browserslist:modern' to use 'modern' environment from browserslist config
4234
* web: Web browser.
4335
* webworker: Web Worker, SharedWorker or Service Worker.
36+
* universal: Universal target running in browser, web worker, Node.js, Electron and NW.js. Output is always ECMAScript modules.
4437
* [async-]node[X[.Y]]: Node.js in version X.Y. The 'async-' prefix will load chunks asynchronously via 'fs' and 'vm' instead of 'require()'. Examples: node14.5, async-node10.
38+
* deno[X[.Y]]: Deno in version X.Y. Emits ESM output; node.js built-ins are available via the required 'node:' specifier and web APIs (fetch, WebAssembly, ...) are available too. Examples: deno2, deno1.40.
39+
* bun[X[.Y]]: Bun in version X.Y. Output is always ECMAScript modules. Examples: bun, bun1.1.
4540
* electron[X[.Y]]-main/preload/renderer: Electron in version X.Y. Script is running in main, preload resp. renderer context.
4641
* nwjs[X[.Y]] / node-webkit[X[.Y]]: NW.js in version X.Y.
4742
* esX: EcmaScript in this version. Examples: es2020, es5.

test/build/target/flag-test/target-flag.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ describe("--target flag", () => {
6666
expect(normalizeStdout(stdout)).toMatchSnapshot("stdout");
6767
});
6868

69-
it("should throw an error for incompatible multiple targets", async () => {
69+
it("should allow multiple different targets", async () => {
7070
const { exitCode, stderr, stdout } = await run(__dirname, [
7171
"--target",
7272
"node",
7373
"--target",
7474
"web",
7575
]);
7676

77-
expect(exitCode).toBe(2);
78-
expect(normalizeStderr(stderr)).toMatchSnapshot("stderr");
79-
expect(normalizeStdout(stdout)).toMatchSnapshot("stdout");
77+
expect(exitCode).toBe(0);
78+
expect(stderr).toBeFalsy();
79+
expect(stdout).toContain("target: [ 'node', 'web' ]");
8080
});
8181

8282
it("should reset the `target` option when the `--target-reset` is used", async () => {

0 commit comments

Comments
 (0)