Skip to content

Commit 2c12f2a

Browse files
authored
test: migrate rspack wasm test to rstest (#11990)
* migrate rspack wasm test to rstest
1 parent 4506d64 commit 2c12f2a

File tree

11 files changed

+131
-30
lines changed

11 files changed

+131
-30
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"cross-env": "^10.1.0",
7575
"husky": "^9.1.7",
7676
"is-ci": "4.1.0",
77-
"@rstest/core": "^0.6.1",
77+
"@rstest/core": "^0.6.3",
7878
"jest": "29.7.0",
7979
"jest-cli": "29.7.0",
8080
"lint-staged": "^16.2.6",

packages/rspack-test-tools/src/case/hash.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,13 @@ async function check(env: ITestEnv, context: ITestContext, name: string) {
9898
const stats = compiler.getStats();
9999
const testConfig = context.getTestConfig();
100100
if (!stats) {
101-
env.expect(false);
102-
return;
101+
throw new Error(
102+
"No stats found\n" +
103+
context
104+
.getError()
105+
.map(e => e.stack)
106+
.join("\n")
107+
);
103108
}
104109
if (REG_ERROR_CASE.test(name)) {
105110
env.expect(stats.hasErrors());

packages/rspack-test-tools/src/helper/setup-env.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ if (process.env.RSTEST) {
2020
global.__RSPACK_PATH__ ??= process.env.__RSPACK_PATH__;
2121
global.__RSPACK_TEST_TOOLS_PATH__ ??= process.env.__RSPACK_TEST_TOOLS_PATH__;
2222
global.__DEBUG__ ??= process.env.DEBUG === "test";
23-
} else {
24-
// Compatible with wasm tests (lazyTestEnv)
25-
global.rstest = jest;
2623
}
2724

2825
if (process.env.ALTERNATIVE_SORT) {

packages/rspack-test-tools/src/test/creator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface IBasicCaseCreatorOptions {
4444
[key: string]: unknown;
4545
}
4646

47-
const DEFAULT_MAX_CONCURRENT = 5;
47+
const DEFAULT_MAX_CONCURRENT = process.env.WASM ? 1 : 5;
4848

4949
export class BasicCaseCreator {
5050
protected currentConcurrent = 0;
@@ -88,7 +88,7 @@ export class BasicCaseCreator {
8888
options
8989
);
9090
const concurrent = process.env.WASM
91-
? false
91+
? 1
9292
: testConfig.concurrent || options.concurrent;
9393
if (options.describe) {
9494
if (run) {

packages/rspack/src/ChunkGraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Object.defineProperty(ChunkGraph.prototype, "getOrderedChunkModulesIterable", {
1010
value(
1111
this: ChunkGraph,
1212
chunk: Chunk,
13-
compareFn: (a: Module, b: Module) => number
13+
compareFn: (_a: Module, _b: Module) => number
1414
): Iterable<Module> {
1515
const modules = this.getChunkModules(chunk);
1616
modules.sort(compareFn);

pnpm-lock.yaml

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

tests/rspack-test/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const setupFilesAfterEnv = [
1010
const wasmConfig = process.env.WASM && {
1111
setupFilesAfterEnv: [...setupFilesAfterEnv, "@rspack/test-tools/setup-wasm"],
1212
testPathIgnorePatterns: [
13-
// Skip because they reply on snapshots
13+
// Skip because they rely on snapshots
1414
"Diagnostics.test.js",
1515
"Error.test.js",
1616
"StatsAPI.test.js",

tests/rspack-test/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"test": "cross-env RUST_BACKTRACE=full pnpm run --stream /^test:.*/",
1111
"testu": "pnpm run --stream /^test:.*/ -u",
1212
"test:rstest": "rstest",
13-
"test:base": "cross-env node --no-warnings --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --colors --config ./jest.config.js --passWithNoTests",
1413
"test:hot": "cross-env RSPACK_HOT_TEST=true node --no-warnings --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/@rstest/core/bin/rstest --config ./rstest.config.hot.ts --passWithNoTests"
1514
},
1615
"devDependencies": {
@@ -20,7 +19,7 @@
2019
"@rspack/plugin-preact-refresh": "1.1.4",
2120
"@rspack/plugin-react-refresh": "^1.5.2",
2221
"@rspack/test-tools": "workspace:*",
23-
"@rstest/core": "^0.6.1",
22+
"@rstest/core": "^0.6.3",
2423
"@swc/helpers": "0.5.17",
2524
"@swc/plugin-remove-console": "^10.0.0",
2625
"@types/babel__generator": "7.27.0",
@@ -45,6 +44,7 @@
4544
"lodash": "^4.17.21",
4645
"memfs": "4.48.1",
4746
"mini-svg-data-uri": "^1.4.4",
47+
"node-polyfill-webpack-plugin": "^4.1.0",
4848
"postcss-loader": "^8.2.0",
4949
"postcss-pxtorem": "^6.1.0",
5050
"raw-loader": "^4.0.2",

tests/rspack-test/rstest.config.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,39 @@ const setupFilesAfterEnv = [
77
"@rspack/test-tools/setup-expect",
88
];
99

10+
const wasmConfig = process.env.WASM && defineConfig({
11+
setupFiles: [...setupFilesAfterEnv, "@rspack/test-tools/setup-wasm"],
12+
exclude: [
13+
// Skip because they rely on snapshots
14+
"Diagnostics.test.js",
15+
"Error.test.js",
16+
"StatsAPI.test.js",
17+
"StatsOutput.test.js",
18+
// Skip because the loader can not be loaded in CI
19+
"Hot*.test.js",
20+
21+
// Skip temporarily and should investigate in the future
22+
"Cache.test.js",
23+
"Compiler.test.js",
24+
"MultiCompiler.test.js",
25+
"Serial.test.js",
26+
"Defaults.test.js",
27+
"Example.test.js",
28+
"Incremental-*.test.js",
29+
"NativeWatcher*.test.js",
30+
],
31+
maxConcurrency: 1,
32+
pool: {
33+
maxWorkers: 1,
34+
execArgv: ['--no-warnings', '--expose-gc', '--max-old-space-size=6144', '--experimental-vm-modules'],
35+
}
36+
});
37+
38+
1039
export default defineConfig({
1140
setupFiles: setupFilesAfterEnv,
1241
testTimeout: process.env.CI ? 60000 : 30000,
13-
include: process.env.WASM ? [] : [
42+
include: [
1443
"*.test.js",
1544
],
1645
slowTestThreshold: 5000,
@@ -25,6 +54,7 @@ export default defineConfig({
2554
source: {
2655
exclude: [root],
2756
},
57+
disableConsoleIntercept: true,
2858
globals: true,
2959
output: {
3060
externals: [/.*/],
@@ -62,5 +92,6 @@ export default defineConfig({
6292
__DEBUG__: process.env.DEBUG === "test" ? 'true' : 'false',
6393
},
6494
hideSkippedTests: true,
95+
...(wasmConfig || {}),
6596
});
6697

website/docs/en/plugins/webpack/entry-plugin.mdx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,5 @@ When the plugin's `name` option is set to `undefined`, the entry is treated as a
5151
This allows you to inject global runtime code, such as the dev server's HMR runtime or the initialization logic for module federation.
5252

5353
```js
54-
new rspack.EntryPlugin(
55-
context,
56-
'./global-runtime.js',
57-
{ name: undefined }
58-
);
54+
new rspack.EntryPlugin(context, './global-runtime.js', { name: undefined });
5955
```

0 commit comments

Comments
 (0)