@rspack/test-tools 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/dist/helper/setup-env.js +6 -1
- package/dist/helper/setup-wasm.d.ts +1 -0
- package/dist/helper/setup-wasm.js +19 -0
- package/dist/processor/hot-step.js +6 -1
- package/dist/processor/snapshot.js +5 -1
- package/dist/test/creator.js +3 -1
- package/dist/type.d.ts +1 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<picture>
|
|
2
|
-
<img alt="Rspack Banner" src="https://assets.rspack.
|
|
2
|
+
<img alt="Rspack Banner" src="https://assets.rspack.rs/rspack/rspack-banner.png">
|
|
3
3
|
</picture>
|
|
4
4
|
|
|
5
5
|
# @rspack/test-tools
|
|
@@ -8,6 +8,19 @@
|
|
|
8
8
|
|
|
9
9
|
Test tools for rspack.
|
|
10
10
|
|
|
11
|
+
## Wasm Tests
|
|
12
|
+
|
|
13
|
+
We expect to reuse the tests for Rspack wasm target as many as possible and we have managed to do it partially. Currently wasm tests should be run with an environment variable `WASM=1` under the following limitations:
|
|
14
|
+
|
|
15
|
+
1. Node 20 is required, which is consistent with the Node version in StackBlitz.
|
|
16
|
+
2. Set `maxWorkers` to `1`, `maxConcurrency` to `1` and disable concurrent mode to avoid flaky failures.
|
|
17
|
+
3. `forceExit` is needed.
|
|
18
|
+
|
|
19
|
+
Also check all the skipped testcases with `!process.env.WASM` in `test.filter.js`s and the skipped testsuits in `jest.config.js`s. They are divided into two categories:
|
|
20
|
+
|
|
21
|
+
1. Skip due to lacks of api support, such as tests related to swc wasm plugins, pnp and profiling. We skip them to avoid obsolete snapshot errors.
|
|
22
|
+
2. Skip temporarily and should be investigate in the future. There could be something wrong with test harness and rspack wasm itself. Since it could be time-consuming to figure out all of them so in this stage we use the wasm test ci to avoid the regression rather than improve its stability.
|
|
23
|
+
|
|
11
24
|
## Documentation
|
|
12
25
|
|
|
13
26
|
See [https://rspack.rs](https://rspack.rs) for details.
|
package/dist/helper/setup-env.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// @ts-nocheck
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
// Setup environment variable for binding testing
|
|
6
|
+
if (process.env.RSPACK_BINDING_BUILDER_TESTING) {
|
|
7
|
+
process.env.RSPACK_BINDING = path.resolve(__dirname, "../../node_modules/@rspack/binding-testing");
|
|
8
|
+
}
|
|
4
9
|
if (process.env.ALTERNATIVE_SORT) {
|
|
5
10
|
const oldSort = Array.prototype.sort;
|
|
6
11
|
Array.prototype.sort = function (cmp) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Skip all snapshot tests for wasm because:
|
|
3
|
+
// 1. The wasm error backtrace bypasses emnapi.
|
|
4
|
+
// 2. Wasm target is a 32-bit platform, where all hash results are diffeference from the native targets.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
function toMatchSnapshot() {
|
|
7
|
+
return { pass: true, message: () => "" };
|
|
8
|
+
}
|
|
9
|
+
function toMatchInlineSnapshot() {
|
|
10
|
+
return { pass: true, message: () => "" };
|
|
11
|
+
}
|
|
12
|
+
function toMatchFileSnapshot() {
|
|
13
|
+
return { pass: true, message: () => "" };
|
|
14
|
+
}
|
|
15
|
+
expect.extend({
|
|
16
|
+
toMatchSnapshot,
|
|
17
|
+
toMatchInlineSnapshot,
|
|
18
|
+
toMatchFileSnapshot
|
|
19
|
+
});
|
|
@@ -136,7 +136,12 @@ class HotSnapshotProcessor extends hot_1.HotProcessor {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
-
const replaceContent = (
|
|
139
|
+
const replaceContent = (rawStr) => {
|
|
140
|
+
let str = rawStr;
|
|
141
|
+
const replaceContentConfig = context.getTestConfig().snapshotContent;
|
|
142
|
+
if (replaceContentConfig) {
|
|
143
|
+
str = replaceContentConfig(str);
|
|
144
|
+
}
|
|
140
145
|
return (0, placeholder_1.normalizePlaceholder)(Object.entries(hashes)
|
|
141
146
|
.reduce((str, [raw, replacement]) => {
|
|
142
147
|
return str.split(raw).join(replacement);
|
|
@@ -45,7 +45,11 @@ class SnapshotProcessor extends basic_1.BasicProcessor {
|
|
|
45
45
|
.filter(([file]) => snapshotFileFilter(file))
|
|
46
46
|
.map(([file, source]) => {
|
|
47
47
|
const tag = node_path_1.default.extname(file).slice(1) || "txt";
|
|
48
|
-
|
|
48
|
+
let content = this.serializeEachFile(source.source().toString());
|
|
49
|
+
const testConfig = context.getTestConfig();
|
|
50
|
+
if (testConfig.snapshotContent) {
|
|
51
|
+
content = testConfig.snapshotContent(content);
|
|
52
|
+
}
|
|
49
53
|
return `\`\`\`${tag} title=${file}\n${content}\n\`\`\``;
|
|
50
54
|
});
|
|
51
55
|
fileContents.sort();
|
package/dist/test/creator.js
CHANGED
|
@@ -31,7 +31,9 @@ class BasicCaseCreator {
|
|
|
31
31
|
}
|
|
32
32
|
const run = this.shouldRun(name);
|
|
33
33
|
const tester = this.createTester(name, src, dist, temp, testConfig);
|
|
34
|
-
const concurrent =
|
|
34
|
+
const concurrent = process.env.WASM
|
|
35
|
+
? false
|
|
36
|
+
: testConfig.concurrent || this._options.concurrent;
|
|
35
37
|
if (this._options.describe) {
|
|
36
38
|
if (run) {
|
|
37
39
|
if (concurrent) {
|
package/dist/type.d.ts
CHANGED
|
@@ -148,6 +148,7 @@ export type TTestConfig<T extends ECompilerType> = {
|
|
|
148
148
|
modules?: Record<string, Object>;
|
|
149
149
|
timeout?: number;
|
|
150
150
|
concurrent?: boolean;
|
|
151
|
+
snapshotContent?(content: string): string;
|
|
151
152
|
checkSteps?: boolean;
|
|
152
153
|
};
|
|
153
154
|
export type TTestFilter<T extends ECompilerType> = (creatorConfig: Record<string, unknown>, testConfig: TTestConfig<T>) => boolean | string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"./setup-expect": "./dist/helper/setup-expect.js",
|
|
13
13
|
"./setup-env": "./dist/helper/setup-env.js",
|
|
14
|
+
"./setup-wasm": "./dist/helper/setup-wasm.js",
|
|
14
15
|
"./package.json": "./package.json"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
@@ -95,9 +96,10 @@
|
|
|
95
96
|
"typescript": "^5.8.3",
|
|
96
97
|
"wast-loader": "^1.14.1",
|
|
97
98
|
"worker-rspack-loader": "^3.1.2",
|
|
98
|
-
"@rspack/
|
|
99
|
-
"@rspack/cli": "1.4.
|
|
100
|
-
"@rspack/
|
|
99
|
+
"@rspack/core": "1.4.3",
|
|
100
|
+
"@rspack/cli": "1.4.3",
|
|
101
|
+
"@rspack/binding-testing": "1.4.1",
|
|
102
|
+
"@rspack/test-tools": "1.4.3"
|
|
101
103
|
},
|
|
102
104
|
"peerDependencies": {
|
|
103
105
|
"@rspack/core": ">=1.0.0"
|