@rspack/test-tools 1.3.12 → 1.3.13
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 +2 -2
- package/dist/case/diagnostic.js +2 -0
- package/dist/helper/expect/to-match-file-snapshot.js +11 -2
- package/dist/helper/serializers.d.ts +2 -0
- package/dist/helper/serializers.js +52 -0
- package/dist/helper/setup-expect.js +4 -47
- package/dist/processor/diagnostic.d.ts +2 -0
- package/dist/processor/diagnostic.js +29 -0
- package/dist/processor/normal.js +1 -1
- package/package.json +12 -11
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
|
|
@@ -10,7 +10,7 @@ Test tools for rspack.
|
|
|
10
10
|
|
|
11
11
|
## Documentation
|
|
12
12
|
|
|
13
|
-
See [https://rspack.
|
|
13
|
+
See [https://rspack.rs](https://rspack.rs) for details.
|
|
14
14
|
|
|
15
15
|
## License
|
|
16
16
|
|
package/dist/case/diagnostic.js
CHANGED
|
@@ -11,6 +11,8 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
11
11
|
new processor_1.DiagnosticProcessor({
|
|
12
12
|
name,
|
|
13
13
|
snapshot: "./stats.err",
|
|
14
|
+
snapshotErrors: "./raw-error.err",
|
|
15
|
+
snapshotWarning: "./raw-warning.err",
|
|
14
16
|
configFiles: ["rspack.config.js", "webpack.config.js"],
|
|
15
17
|
compilerType: type_1.ECompilerType.Rspack,
|
|
16
18
|
format: (output) => {
|
|
@@ -11,7 +11,10 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
11
11
|
const chalk_1 = __importDefault(require("chalk"));
|
|
12
12
|
const filenamify_1 = __importDefault(require("filenamify"));
|
|
13
13
|
const jest_diff_1 = require("jest-diff");
|
|
14
|
+
const serializers_1 = require("../serializers");
|
|
14
15
|
const { serialize } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve("jest-snapshot")), "./utils.js"));
|
|
16
|
+
// get jest builtin serializers
|
|
17
|
+
const { getSerializers } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve("jest-snapshot")), "./plugins.js"));
|
|
15
18
|
/**
|
|
16
19
|
* Check if 2 strings or buffer are equal
|
|
17
20
|
*/
|
|
@@ -27,9 +30,15 @@ const isEqual = (a, b) => {
|
|
|
27
30
|
* @param options Additional options for matching
|
|
28
31
|
*/
|
|
29
32
|
function toMatchFileSnapshot(rawContent, filepath, options = {}) {
|
|
30
|
-
const content = Buffer.isBuffer(rawContent)
|
|
33
|
+
const content = Buffer.isBuffer(rawContent)
|
|
31
34
|
? rawContent
|
|
32
|
-
: serialize(rawContent
|
|
35
|
+
: serialize(rawContent, /* ident */ 2, {
|
|
36
|
+
plugins: [
|
|
37
|
+
...getSerializers(),
|
|
38
|
+
// Rspack serializers
|
|
39
|
+
...serializers_1.serializers
|
|
40
|
+
]
|
|
41
|
+
});
|
|
33
42
|
const { isNot, snapshotState } = this;
|
|
34
43
|
const filename = filepath === undefined
|
|
35
44
|
? // If file name is not specified, generate one from the test title
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializers = void 0;
|
|
4
|
+
const diff_1 = require("./expect/diff");
|
|
5
|
+
const error_1 = require("./expect/error");
|
|
6
|
+
const placeholder_1 = require("./expect/placeholder");
|
|
7
|
+
const rspack_1 = require("./expect/rspack");
|
|
8
|
+
exports.serializers = [
|
|
9
|
+
{
|
|
10
|
+
test(received) {
|
|
11
|
+
return typeof received === "string";
|
|
12
|
+
},
|
|
13
|
+
print(received) {
|
|
14
|
+
return (0, placeholder_1.normalizePlaceholder)(received.trim());
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
// for diff
|
|
18
|
+
{
|
|
19
|
+
test(received) {
|
|
20
|
+
return received?.constructor?.name === "RspackTestDiff";
|
|
21
|
+
},
|
|
22
|
+
print(received, next) {
|
|
23
|
+
return next((0, diff_1.normalizeDiff)(received));
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
// for errors
|
|
27
|
+
{
|
|
28
|
+
test(received) {
|
|
29
|
+
return received?.constructor?.name === "RspackStatsDiagnostics";
|
|
30
|
+
},
|
|
31
|
+
print(received, next) {
|
|
32
|
+
return next((0, error_1.normalizeDignostics)(received));
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
test(received) {
|
|
37
|
+
return typeof received?.message === "string";
|
|
38
|
+
},
|
|
39
|
+
print(received, next) {
|
|
40
|
+
return next((0, error_1.normalizeError)(received));
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
// for stats
|
|
44
|
+
{
|
|
45
|
+
test(received) {
|
|
46
|
+
return received?.constructor?.name === "RspackStats";
|
|
47
|
+
},
|
|
48
|
+
print(received, next) {
|
|
49
|
+
return next((0, rspack_1.normalizeStats)(received));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
];
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const diff_1 = require("./expect/diff");
|
|
4
|
-
const error_1 = require("./expect/error");
|
|
5
|
-
const placeholder_1 = require("./expect/placeholder");
|
|
6
|
-
const rspack_1 = require("./expect/rspack");
|
|
7
3
|
const to_be_typeof_1 = require("./expect/to-be-typeof");
|
|
8
4
|
const to_end_with_1 = require("./expect/to-end-with");
|
|
9
5
|
const to_match_file_snapshot_1 = require("./expect/to-match-file-snapshot");
|
|
6
|
+
const serializers_1 = require("./serializers");
|
|
10
7
|
expect.extend({
|
|
11
8
|
// CHANGE: new test matcher for `rspack-test-tools`
|
|
12
9
|
// @ts-ignore
|
|
@@ -14,46 +11,6 @@ expect.extend({
|
|
|
14
11
|
toBeTypeOf: to_be_typeof_1.toBeTypeOf,
|
|
15
12
|
toEndWith: to_end_with_1.toEndWith
|
|
16
13
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
print(received) {
|
|
22
|
-
return (0, placeholder_1.normalizePlaceholder)(received.trim());
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
// for diff
|
|
26
|
-
expect.addSnapshotSerializer({
|
|
27
|
-
test(received) {
|
|
28
|
-
return received?.constructor?.name === "RspackTestDiff";
|
|
29
|
-
},
|
|
30
|
-
print(received, next) {
|
|
31
|
-
return next((0, diff_1.normalizeDiff)(received));
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
// for errors
|
|
35
|
-
expect.addSnapshotSerializer({
|
|
36
|
-
test(received) {
|
|
37
|
-
return received?.constructor?.name === "RspackStatsDiagnostics";
|
|
38
|
-
},
|
|
39
|
-
print(received, next) {
|
|
40
|
-
return next((0, error_1.normalizeDignostics)(received));
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
expect.addSnapshotSerializer({
|
|
44
|
-
test(received) {
|
|
45
|
-
return typeof received?.message === "string";
|
|
46
|
-
},
|
|
47
|
-
print(received, next) {
|
|
48
|
-
return next((0, error_1.normalizeError)(received));
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
// for stats
|
|
52
|
-
expect.addSnapshotSerializer({
|
|
53
|
-
test(received) {
|
|
54
|
-
return received?.constructor?.name === "RspackStats";
|
|
55
|
-
},
|
|
56
|
-
print(received, next) {
|
|
57
|
-
return next((0, rspack_1.normalizeStats)(received));
|
|
58
|
-
}
|
|
59
|
-
});
|
|
14
|
+
for (const serializer of serializers_1.serializers) {
|
|
15
|
+
expect.addSnapshotSerializer(serializer);
|
|
16
|
+
}
|
|
@@ -2,6 +2,8 @@ import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "..
|
|
|
2
2
|
import { BasicProcessor, type IBasicProcessorOptions } from "./basic";
|
|
3
3
|
export interface IDiagnosticProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
|
|
4
4
|
snapshot: string;
|
|
5
|
+
snapshotErrors: string;
|
|
6
|
+
snapshotWarning: string;
|
|
5
7
|
format?: (output: string) => string;
|
|
6
8
|
}
|
|
7
9
|
export declare class DiagnosticProcessor<T extends ECompilerType> extends BasicProcessor<T> {
|
|
@@ -29,11 +29,40 @@ class DiagnosticProcessor extends basic_1.BasicProcessor {
|
|
|
29
29
|
errors: true,
|
|
30
30
|
warnings: true
|
|
31
31
|
})).replaceAll("\\", "/"); // stats has some win32 paths that path-serializer can not handle
|
|
32
|
+
const statsJson = stats.toJson({
|
|
33
|
+
all: false,
|
|
34
|
+
errors: true,
|
|
35
|
+
warnings: true
|
|
36
|
+
});
|
|
37
|
+
const errors = (statsJson.errors || []).map(e => {
|
|
38
|
+
// @ts-expect-error error message is already serialized in `stats.err`
|
|
39
|
+
delete e.message;
|
|
40
|
+
delete e.stack;
|
|
41
|
+
return e;
|
|
42
|
+
});
|
|
43
|
+
const warnings = (statsJson.warnings || []).map(e => {
|
|
44
|
+
// @ts-expect-error error message is already serialized in `stats.err`
|
|
45
|
+
delete e.message;
|
|
46
|
+
delete e.stack;
|
|
47
|
+
return e;
|
|
48
|
+
});
|
|
32
49
|
if (typeof this._diagnosticOptions.format === "function") {
|
|
33
50
|
output = this._diagnosticOptions.format(output);
|
|
34
51
|
}
|
|
52
|
+
env.expect.addSnapshotSerializer({
|
|
53
|
+
test(received) {
|
|
54
|
+
return typeof received === "string";
|
|
55
|
+
},
|
|
56
|
+
serialize(received) {
|
|
57
|
+
return (0, placeholder_1.normalizePlaceholder)(received.trim());
|
|
58
|
+
}
|
|
59
|
+
});
|
|
35
60
|
const errorOutputPath = node_path_1.default.resolve(context.getSource(this._diagnosticOptions.snapshot));
|
|
61
|
+
const errorStatsOutputPath = node_path_1.default.resolve(context.getSource(this._diagnosticOptions.snapshotErrors));
|
|
62
|
+
const warningStatsOutputPath = node_path_1.default.resolve(context.getSource(this._diagnosticOptions.snapshotWarning));
|
|
36
63
|
env.expect(output).toMatchFileSnapshot(errorOutputPath);
|
|
64
|
+
env.expect(errors).toMatchFileSnapshot(errorStatsOutputPath);
|
|
65
|
+
env.expect(warnings).toMatchFileSnapshot(warningStatsOutputPath);
|
|
37
66
|
}
|
|
38
67
|
static defaultOptions(context) {
|
|
39
68
|
return {
|
package/dist/processor/normal.js
CHANGED
|
@@ -106,7 +106,7 @@ class NormalProcessor extends basic_1.BasicProcessor {
|
|
|
106
106
|
.concat(function () {
|
|
107
107
|
this.hooks.compilation.tap("TestCasesTest", compilation => {
|
|
108
108
|
const hooks = [
|
|
109
|
-
// CHANGE: the
|
|
109
|
+
// CHANGE: the following hooks are not supported yet, so comment it out
|
|
110
110
|
// "optimize",
|
|
111
111
|
// "optimizeModules",
|
|
112
112
|
// "optimizeChunks",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"access": "public",
|
|
24
24
|
"provenance": true
|
|
25
25
|
},
|
|
26
|
-
"homepage": "https://rspack.
|
|
26
|
+
"homepage": "https://rspack.rs",
|
|
27
27
|
"bugs": "https://github.com/web-infra-dev/rspack/issues",
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"directory": "packages/rspack-test-tools"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@babel/generator": "7.27.
|
|
35
|
-
"@babel/parser": "7.27.
|
|
36
|
-
"@babel/traverse": "7.27.
|
|
37
|
-
"@babel/types": "7.27.
|
|
34
|
+
"@babel/generator": "7.27.3",
|
|
35
|
+
"@babel/parser": "7.27.3",
|
|
36
|
+
"@babel/traverse": "7.27.3",
|
|
37
|
+
"@babel/types": "7.27.3",
|
|
38
38
|
"cross-env": "^7.0.3",
|
|
39
39
|
"csv-to-markdown-table": "^1.5.0",
|
|
40
40
|
"deepmerge": "^4.3.1",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"jest-snapshot": "29.7.0",
|
|
48
48
|
"jsdom": "^26.1.0",
|
|
49
49
|
"memfs": "4.17.2",
|
|
50
|
+
"loader-utils": "^2.0.4",
|
|
50
51
|
"path-serializer": "0.4.0",
|
|
51
52
|
"pretty-format": "29.7.0",
|
|
52
53
|
"rimraf": "^5.0.10",
|
|
@@ -65,7 +66,7 @@
|
|
|
65
66
|
"@types/babel__traverse": "7.20.7",
|
|
66
67
|
"@types/fs-extra": "11.0.4",
|
|
67
68
|
"@types/jsdom": "^21.1.7",
|
|
68
|
-
"@types/react": "^19.1.
|
|
69
|
+
"@types/react": "^19.1.6",
|
|
69
70
|
"@types/react-dom": "^19.1.5",
|
|
70
71
|
"@webdiscus/pug-loader": "^2.11.1",
|
|
71
72
|
"acorn": "^8.14.1",
|
|
@@ -90,13 +91,13 @@
|
|
|
90
91
|
"source-map": "^0.7.4",
|
|
91
92
|
"source-map-loader": "^5.0.0",
|
|
92
93
|
"style-loader": "^4.0.0",
|
|
93
|
-
"terser": "5.
|
|
94
|
+
"terser": "5.40.0",
|
|
94
95
|
"typescript": "^5.8.3",
|
|
95
96
|
"wast-loader": "^1.14.1",
|
|
96
97
|
"worker-rspack-loader": "^3.1.2",
|
|
97
|
-
"@rspack/
|
|
98
|
-
"@rspack/
|
|
99
|
-
"@rspack/
|
|
98
|
+
"@rspack/cli": "1.3.13",
|
|
99
|
+
"@rspack/core": "1.3.13",
|
|
100
|
+
"@rspack/test-tools": "1.3.13"
|
|
100
101
|
},
|
|
101
102
|
"peerDependencies": {
|
|
102
103
|
"@rspack/core": ">=1.0.0"
|