Skip to content

Commit 26ec980

Browse files
authored
test: improve cli test performance (#9494)
1 parent c705e1e commit 26ec980

File tree

14 files changed

+116
-92
lines changed

14 files changed

+116
-92
lines changed

packages/rspack-cli/tests/api/type/js-api-cjs.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type IsFunction<T> = T extends (...args: any[]) => any ? true : false;
77

88
// https://github.com/web-infra-dev/rspack/issues/8095
99
describe("js-api-type should be correct when requiring from @rspack/core", () => {
10-
it("cjs default require", async () => {
10+
it.concurrent("cjs default require", async () => {
1111
// const rspack = require('@rspack/core')
1212
type Truthy = IsFunction<typeof rspackCjsRequire>;
1313
const truthy: Truthy = true;
@@ -18,7 +18,7 @@ describe("js-api-type should be correct when requiring from @rspack/core", () =>
1818
assert(compiler);
1919
});
2020

21-
it("cjs named require", async () => {
21+
it.concurrent("cjs named require", async () => {
2222
// const { rspack } = require('@rspack/core')
2323
type Truthy = IsFunction<typeof rspackCjsNamedRequire>;
2424
const truthy: Truthy = true;
@@ -29,7 +29,7 @@ describe("js-api-type should be correct when requiring from @rspack/core", () =>
2929
assert(compiler);
3030
});
3131

32-
it("rspack.default should not exist in cjs require", async () => {
32+
it.concurrent("rspack.default should not exist in cjs require", async () => {
3333
assert(!(rspackCjsNamedRequire as any).default);
3434
assert(!(rspackCjsRequire as any).default);
3535
});

packages/rspack-cli/tests/api/type/js-api-esm.test.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ type IsFunction<T> = T extends (...args: any[]) => any ? true : false;
77

88
// https://github.com/web-infra-dev/rspack/issues/8095
99
describe("js-api-type should be correct when importing from @rspack/core", () => {
10-
it("esm default import", async () => {
10+
it.concurrent("esm default import", async () => {
1111
// rspack has no default export now
1212
type Falsy = IsFunction<typeof rspackEsmDefaultImport>;
1313
const falsy: Falsy = false;
1414
falsy;
1515
assert(rspackEsmDefaultImport.BannerPlugin);
1616
});
1717

18-
it("esm named import", async () => {
18+
it.concurrent("esm named import", async () => {
1919
type Truthy = IsFunction<typeof rspackEsmNamedImport>;
2020
const truthy: Truthy = true;
2121
truthy;
@@ -25,7 +25,7 @@ describe("js-api-type should be correct when importing from @rspack/core", () =>
2525
assert(compiler);
2626
});
2727

28-
it("rspack.default should not exist in esm import", async () => {
28+
it.concurrent("rspack.default should not exist in esm import", async () => {
2929
assert(!(rspackEsmNamedImport as any).default);
3030
assert(!(rspackEsmDefaultImport as any).default);
3131
});

packages/rspack-cli/tests/build/basic/basic.test.ts

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@ import { resolve } from "path";
22
import { readFile, run, runWatch } from "../../utils/test-utils";
33

44
describe("build command", () => {
5-
it("it should work ", async () => {
5+
it.concurrent("it should work ", async () => {
66
const { exitCode, stderr, stdout } = await run(__dirname, []);
77
expect(exitCode).toBe(0);
88
expect(stderr).toBeFalsy();
99
expect(stdout).toBeTruthy();
1010
});
11-
it("should work without command and options (default command)", async () => {
12-
const { exitCode, stderr, stdout } = await run(__dirname, [
13-
"--mode",
14-
"development"
15-
]);
11+
it.concurrent(
12+
"should work without command and options (default command)",
13+
async () => {
14+
const { exitCode, stderr, stdout } = await run(__dirname, [
15+
"--mode",
16+
"development"
17+
]);
1618

17-
expect(exitCode).toBe(0);
18-
expect(stderr).toBeFalsy();
19-
expect(stdout).toBeTruthy();
20-
});
21-
it("should work with configuration return function", async () => {
19+
expect(exitCode).toBe(0);
20+
expect(stderr).toBeFalsy();
21+
expect(stdout).toBeTruthy();
22+
}
23+
);
24+
it.concurrent("should work with configuration return function", async () => {
2225
const { exitCode, stderr, stdout } = await run(__dirname, [
2326
"--config",
2427
"./entry.function.js"
@@ -27,27 +30,33 @@ describe("build command", () => {
2730
expect(stderr).toBeFalsy();
2831
expect(stdout).toBeTruthy();
2932
});
30-
it("should pass env.RSPACK_BUILD and env.RSPACK_BUNDLE for function configuration on build mode", async () => {
31-
const { stdout } = await run(__dirname, ["--config", "./entry.env.js"]);
32-
expect(stdout).toContain("RSPACK_BUILD=true");
33-
expect(stdout).toContain("RSPACK_BUNDLE=true");
34-
expect(stdout).not.toContain("RSPACK_WATCH=true");
35-
});
33+
it.concurrent(
34+
"should pass env.RSPACK_BUILD and env.RSPACK_BUNDLE for function configuration on build mode",
35+
async () => {
36+
const { stdout } = await run(__dirname, ["--config", "./entry.env.js"]);
37+
expect(stdout).toContain("RSPACK_BUILD=true");
38+
expect(stdout).toContain("RSPACK_BUNDLE=true");
39+
expect(stdout).not.toContain("RSPACK_WATCH=true");
40+
}
41+
);
3642

37-
it("should pass env.RSPACK_WATCH for function configuration on watch mode", async () => {
38-
const { stdout } = await runWatch(
39-
__dirname,
40-
["--watch", "--config", "./entry.env.js"],
41-
{
42-
// `Rspack compiled successfully` or `Rspack compiled with 1 error`
43-
killString: /rspack compiled/i
44-
}
45-
);
46-
expect(stdout).not.toContain("RSPACK_BUILD=true");
47-
expect(stdout).not.toContain("RSPACK_BUNDLE=true");
48-
expect(stdout).toContain("RSPACK_WATCH=true");
49-
});
50-
it("should work with configuration return promise", async () => {
43+
it.concurrent(
44+
"should pass env.RSPACK_WATCH for function configuration on watch mode",
45+
async () => {
46+
const { stdout } = await runWatch(
47+
__dirname,
48+
["--watch", "--config", "./entry.env.js"],
49+
{
50+
// `Rspack compiled successfully` or `Rspack compiled with 1 error`
51+
killString: /rspack compiled/i
52+
}
53+
);
54+
expect(stdout).not.toContain("RSPACK_BUILD=true");
55+
expect(stdout).not.toContain("RSPACK_BUNDLE=true");
56+
expect(stdout).toContain("RSPACK_WATCH=true");
57+
}
58+
);
59+
it.concurrent("should work with configuration return promise", async () => {
5160
const { exitCode, stderr, stdout } = await run(__dirname, [
5261
"--config",
5362
"./entry.promise.js"
@@ -56,7 +65,7 @@ describe("build command", () => {
5665
expect(stderr).toBeFalsy();
5766
expect(stdout).toBeTruthy();
5867
});
59-
it("should work with mjs configuration ", async () => {
68+
it.concurrent("should work with mjs configuration ", async () => {
6069
const { exitCode, stderr, stdout } = await run(__dirname, [
6170
"--config",
6271
"./entry.config.mjs"
@@ -65,21 +74,27 @@ describe("build command", () => {
6574
expect(stderr).toBeFalsy();
6675
expect(stdout).toBeTruthy();
6776
});
68-
it("entry option should have higher priority than config", async () => {
69-
const { exitCode, stderr, stdout } = await run(__dirname, [
70-
"--entry",
71-
"./src/other.js",
72-
"--config",
73-
"./entry.config.js"
74-
]);
75-
const mainJs = await readFile(resolve(__dirname, "dist/main.js"), "utf-8");
77+
it.concurrent(
78+
"entry option should have higher priority than config",
79+
async () => {
80+
const { exitCode, stderr, stdout } = await run(__dirname, [
81+
"--entry",
82+
"./src/other.js",
83+
"--config",
84+
"./entry.config.js"
85+
]);
86+
const mainJs = await readFile(
87+
resolve(__dirname, "dist/main.js"),
88+
"utf-8"
89+
);
7690

77-
expect(exitCode).toBe(0);
78-
expect(stderr).toBeFalsy();
79-
expect(stdout).toBeTruthy();
80-
expect(mainJs).toContain("other");
81-
expect(mainJs).not.toContain("CONFIG");
82-
});
91+
expect(exitCode).toBe(0);
92+
expect(stderr).toBeFalsy();
93+
expect(stdout).toBeTruthy();
94+
expect(mainJs).toContain("other");
95+
expect(mainJs).not.toContain("CONFIG");
96+
}
97+
);
8398

8499
it.each(["-o", "--output-path", "--outputPath"])(
85100
"output-path option %p should have higher priority than config",

packages/rspack-cli/tests/build/config/config.test.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import { run } from "../../utils/test-utils";
44

55
describe("rspack cli", () => {
66
describe("should config not found", () => {
7-
it("should throw an error when config file does not found", async () => {
8-
const { stderr } = await run(__dirname, ["-c", "not-found-config.js"]);
9-
expect(stderr).toMatch(/not found/);
10-
});
7+
it.concurrent(
8+
"should throw an error when config file does not found",
9+
async () => {
10+
const { stderr } = await run(__dirname, ["-c", "not-found-config.js"]);
11+
expect(stderr).toMatch(/not found/);
12+
}
13+
);
1114
});
1215
describe("should respect cjs in esm folder", () => {
1316
const cwd = resolve(__dirname, "./cjs_in_esm");
14-
it("should load config.cjs file", async () => {
17+
it.concurrent("should load config.cjs file", async () => {
1518
const { exitCode, stderr, stdout } = await run(cwd, [
1619
"-c",
1720
"rspack.config.cjs"
@@ -24,7 +27,7 @@ describe("rspack cli", () => {
2427
).resolves.toMatch(/Main cjs file/);
2528
});
2629

27-
it("should load config.cts file", async () => {
30+
it.concurrent("should load config.cts file", async () => {
2831
const { exitCode, stderr, stdout } = await run(cwd, [
2932
"-c",
3033
"rspack.config.cts"
@@ -40,7 +43,7 @@ describe("rspack cli", () => {
4043
describe("should load cjs config", () => {
4144
const cwd = resolve(__dirname, "./cjs");
4245

43-
it("should load default config.js file", async () => {
46+
it.concurrent("should load default config.js file", async () => {
4447
const { exitCode, stderr, stdout } = await run(cwd, []);
4548
expect(stderr).toBeFalsy();
4649
expect(stdout).toBeTruthy();
@@ -50,7 +53,7 @@ describe("rspack cli", () => {
5053
).resolves.toMatch(/Main cjs file/);
5154
});
5255

53-
it("should load config.ts file", async () => {
56+
it.concurrent("should load config.ts file", async () => {
5457
const { exitCode, stderr, stdout } = await run(cwd, [
5558
"-c",
5659
"rspack.config.ts"
@@ -62,7 +65,7 @@ describe("rspack cli", () => {
6265
readFile(resolve(cwd, "./dist/ts.bundle.js"), { encoding: "utf-8" })
6366
).resolves.toMatch(/Main cjs file/);
6467
});
65-
it("should load config.export.ts file", async () => {
68+
it.concurrent("should load config.export.ts file", async () => {
6669
const { exitCode, stderr, stdout } = await run(cwd, [
6770
"-c",
6871
"rspack.config.export.ts"
@@ -75,7 +78,7 @@ describe("rspack cli", () => {
7578
).resolves.toMatch(/Main cjs file/);
7679
});
7780

78-
it("should load config.cjs file", async () => {
81+
it.concurrent("should load config.cjs file", async () => {
7982
const { exitCode, stderr, stdout } = await run(cwd, [
8083
"-c",
8184
"rspack.config.cjs"
@@ -88,7 +91,7 @@ describe("rspack cli", () => {
8891
).resolves.toMatch(/Main cjs file/);
8992
});
9093

91-
it("should load config.cts file", async () => {
94+
it.concurrent("should load config.cts file", async () => {
9295
const { exitCode, stderr, stdout } = await run(cwd, [
9396
"-c",
9497
"rspack.config.cts"
@@ -105,7 +108,7 @@ describe("rspack cli", () => {
105108
describe("should load esm config", () => {
106109
const cwd = resolve(__dirname, "./esm");
107110

108-
it("should load default config.js file", async () => {
111+
it.concurrent("should load default config.js file", async () => {
109112
const { exitCode, stderr, stdout } = await run(cwd, []);
110113
expect(stderr).toBeFalsy();
111114
expect(stdout).toBeTruthy();
@@ -115,7 +118,7 @@ describe("rspack cli", () => {
115118
).resolves.toMatch(/Main esm file/);
116119
});
117120

118-
it("should load config.ts file", async () => {
121+
it.concurrent("should load config.ts file", async () => {
119122
const { exitCode, stdout } = await run(cwd, ["-c", "rspack.config.ts"], {
120123
nodeOptions: ["--experimental-loader=ts-node/esm"]
121124
});
@@ -126,7 +129,7 @@ describe("rspack cli", () => {
126129
).resolves.toMatch(/Main esm file/);
127130
});
128131

129-
it("should load config.mjs file", async () => {
132+
it.concurrent("should load config.mjs file", async () => {
130133
const { exitCode, stderr, stdout } = await run(cwd, [
131134
"-c",
132135
"rspack.config.mjs"
@@ -139,7 +142,7 @@ describe("rspack cli", () => {
139142
).resolves.toMatch(/Main esm file/);
140143
});
141144

142-
it("should load config.mts file", async () => {
145+
it.concurrent("should load config.mts file", async () => {
143146
const { exitCode, stdout } = await run(cwd, ["-c", "rspack.config.mts"], {
144147
nodeOptions: ["--experimental-loader=ts-node/esm"]
145148
});
@@ -155,7 +158,7 @@ describe("rspack cli", () => {
155158
describe("should load config with defineConfig helper", () => {
156159
const cwd = resolve(__dirname, "./esm");
157160

158-
it("should load config.ts file", async () => {
161+
it.concurrent("should load config.ts file", async () => {
159162
const { exitCode, stdout } = await run(cwd, ["-c", "rspack.config.ts"], {
160163
nodeOptions: ["--experimental-loader=ts-node/esm"]
161164
});
@@ -166,7 +169,7 @@ describe("rspack cli", () => {
166169
).resolves.toMatch(/Main esm file/);
167170
});
168171

169-
it("should load config.mts file", async () => {
172+
it.concurrent("should load config.mts file", async () => {
170173
const { exitCode, stdout } = await run(cwd, ["-c", "rspack.config.mts"], {
171174
nodeOptions: ["--experimental-loader=ts-node/esm"]
172175
});
@@ -181,7 +184,7 @@ describe("rspack cli", () => {
181184

182185
describe("should load monorepo config", () => {
183186
const cwd = resolve(__dirname, "./monorepo");
184-
it("should load monorepo config.ts file", async () => {
187+
it.concurrent("should load monorepo config.ts file", async () => {
185188
const { exitCode, stdout } = await run(cwd, ["-c", "rspack.config.ts"], {
186189
nodeOptions: ["--experimental-loader=ts-node/esm"]
187190
});
@@ -198,7 +201,7 @@ describe("rspack cli", () => {
198201

199202
// describe("loose-unrecognized-keys (default)", () => {
200203
// const cwd = resolve(__dirname, "./loose-unrecognized-keys");
201-
// it("should report unrecognized keys", async () => {
204+
// it.concurrent("should report unrecognized keys", async () => {
202205
// const { stderr, exitCode } = await run(cwd, []);
203206
// expect(stderr).toMatchInlineSnapshot(`
204207
// "Configuration error:
@@ -211,7 +214,7 @@ describe("rspack cli", () => {
211214

212215
// describe("loose-unrecognized-keys 2 (default)", () => {
213216
// const cwd = resolve(__dirname, "./loose-unrecognized-keys-other-error");
214-
// it("should fail on other error", async () => {
217+
// it.concurrent("should fail on other error", async () => {
215218
// const { stderr, exitCode } = await run(cwd, []);
216219
// expect(stderr).toMatch("ValidationError");
217220
// expect(stderr).toMatch(

packages/rspack-cli/tests/build/issue-4467/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from "path";
22
import { run } from "../../utils/test-utils";
33

4-
it("should not print the warning for child compiler", async () => {
4+
it.concurrent("should not print the warning for child compiler", async () => {
55
const cwd = path.resolve(__dirname, "./child");
66
const { exitCode, stderr } = await run(
77
cwd,
@@ -15,7 +15,7 @@ it("should not print the warning for child compiler", async () => {
1515
expect(stderr).not.toContain("deprecated");
1616
});
1717

18-
it("should print the warning for root compiler", async () => {
18+
it.concurrent("should print the warning for root compiler", async () => {
1919
const cwd = path.resolve(__dirname, "./root");
2020
const { exitCode } = await run(
2121
cwd,
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { resolve } from "path";
22
import { readFile, run } from "../../utils/test-utils";
33

4-
it("should not have `process.env.NODE_ENV` when optimization.nodeEnv has been set", async () => {
5-
await run(__dirname, ["--mode", "production"]);
6-
const mainJs = await readFile(resolve(__dirname, "dist/main.js"), "utf-8");
7-
expect(mainJs).toContain("process.env.NODE_ENV");
8-
expect(mainJs).not.toContain("long_name_should_be_minified");
9-
});
4+
it.concurrent(
5+
"should not have `process.env.NODE_ENV` when optimization.nodeEnv has been set",
6+
async () => {
7+
await run(__dirname, ["--mode", "production"]);
8+
const mainJs = await readFile(resolve(__dirname, "dist/main.js"), "utf-8");
9+
expect(mainJs).toContain("process.env.NODE_ENV");
10+
expect(mainJs).not.toContain("long_name_should_be_minified");
11+
}
12+
);

0 commit comments

Comments
 (0)