Skip to content

Commit deb8843

Browse files
snitin315alexander-akait
authored andcommitted
test: add case for --target-reset with multiple targets (#3347)
1 parent a9ce5d0 commit deb8843

File tree

4 files changed

+48
-12
lines changed

4 files changed

+48
-12
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`--target flag should reset target from node to async-node with --target-reset: stderr 1`] = `""`;
3+
exports[`--target flag should reset the \`target\` option when the \`--target-reset\` is used for multiple targets: stderr 1`] = `""`;
4+
5+
exports[`--target flag should reset the \`target\` option when the \`--target-reset\` is used: stderr 1`] = `""`;
46

57
exports[`--target flag should throw an error for incompatible multiple targets: stderr 1`] = `
68
"[webpack-cli] Error: For the selected environment is no default script chunk format available:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin");
2+
3+
module.exports = {
4+
entry: "./index.js",
5+
mode: "development",
6+
target: ["web", "es5"],
7+
plugins: [new WebpackCLITestPlugin()],
8+
};

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

+29-11
Original file line numberDiff line numberDiff line change
@@ -91,42 +91,60 @@ describe("--target flag", () => {
9191
expect(stdout).toContain(`target: [ 'node', 'async-node' ]`);
9292
});
9393

94-
it("should throw an error for invalid target in multiple syntax", async () => {
94+
it("should reset the `target` option when the `--target-reset` is used", async () => {
95+
const { exitCode, stderr, stdout } = await run(__dirname, [
96+
"--config",
97+
"target.web.config.js",
98+
"--target-reset",
99+
"--target",
100+
"node",
101+
]);
102+
103+
expect(exitCode).toBe(0);
104+
expect(normalizeStderr(stderr)).toMatchSnapshot("stderr");
105+
expect(stdout).toContain(`target: [ 'node' ]`);
106+
});
107+
108+
it("should reset the `target` option when the `--target-reset` is used for multiple targets", async () => {
95109
const { exitCode, stderr, stdout } = await run(__dirname, [
110+
"--config",
111+
"multiple-target.config.js",
112+
"--target-reset",
96113
"--target",
97114
"node",
98115
"--target",
99-
"invalid",
116+
"async-node",
100117
]);
101118

102-
expect(exitCode).toBe(2);
119+
expect(exitCode).toBe(0);
103120
expect(normalizeStderr(stderr)).toMatchSnapshot("stderr");
104-
expect(normalizeStdout(stdout)).toMatchSnapshot("stdout");
121+
expect(stdout).toContain(`target: [ 'node', 'async-node' ]`);
105122
});
106123

107-
it("should throw an error for incompatible multiple targets", async () => {
124+
it("should throw an error for invalid target in multiple syntax", async () => {
108125
const { exitCode, stderr, stdout } = await run(__dirname, [
109126
"--target",
110127
"node",
111128
"--target",
112-
"web",
129+
"invalid",
113130
]);
114131

115132
expect(exitCode).toBe(2);
116133
expect(normalizeStderr(stderr)).toMatchSnapshot("stderr");
117134
expect(normalizeStdout(stdout)).toMatchSnapshot("stdout");
118135
});
119136

120-
it("should reset target from node to async-node with --target-reset", async () => {
137+
it("should throw an error for incompatible multiple targets", async () => {
121138
const { exitCode, stderr, stdout } = await run(__dirname, [
122-
"--target-reset",
123139
"--target",
124-
"async-node",
140+
"node",
141+
"--target",
142+
"web",
125143
]);
126144

127-
expect(exitCode).toBe(0);
145+
expect(exitCode).toBe(2);
128146
expect(normalizeStderr(stderr)).toMatchSnapshot("stderr");
129-
expect(stdout).toContain(`target: [ 'async-node' ]`);
147+
expect(normalizeStdout(stdout)).toMatchSnapshot("stdout");
130148
});
131149

132150
it("should throw error if target is an empty array", async () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin");
2+
3+
module.exports = {
4+
entry: "./index.js",
5+
mode: "development",
6+
target: "web",
7+
plugins: [new WebpackCLITestPlugin()],
8+
};

0 commit comments

Comments
 (0)