@rspack/test-tools 1.2.0-beta.0 → 1.2.1
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/dist/case/index.d.ts +1 -0
- package/dist/case/index.js +1 -0
- package/dist/case/new-code-splitting.d.ts +2 -0
- package/dist/case/new-code-splitting.js +77 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/processor/stats-api.d.ts +1 -0
- package/dist/processor/stats.d.ts +2 -0
- package/dist/processor/stats.js +7 -1
- package/package.json +4 -4
package/dist/case/index.d.ts
CHANGED
package/dist/case/index.js
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConfigNewCodeSplittingCase = createConfigNewCodeSplittingCase;
|
|
4
|
+
exports.createStatsAPINewCodeSplittingCase = createStatsAPINewCodeSplittingCase;
|
|
5
|
+
const processor_1 = require("../processor");
|
|
6
|
+
const runner_1 = require("../runner");
|
|
7
|
+
const creator_1 = require("../test/creator");
|
|
8
|
+
const simple_1 = require("../test/simple");
|
|
9
|
+
const type_1 = require("../type");
|
|
10
|
+
function createConfigNewCodeSplittingCase(name, src, dist) {
|
|
11
|
+
configCreator.create(name, src, dist);
|
|
12
|
+
}
|
|
13
|
+
const configCreator = new creator_1.BasicCaseCreator({
|
|
14
|
+
clean: true,
|
|
15
|
+
runner: runner_1.MultipleRunnerFactory,
|
|
16
|
+
describe: false,
|
|
17
|
+
testConfig: testConfig => {
|
|
18
|
+
const oldModuleScope = testConfig.moduleScope;
|
|
19
|
+
testConfig.moduleScope = (ms, stats) => {
|
|
20
|
+
let res = ms;
|
|
21
|
+
// TODO: modify runner module scope based on stats here
|
|
22
|
+
if (typeof oldModuleScope === "function") {
|
|
23
|
+
res = oldModuleScope(ms, stats);
|
|
24
|
+
}
|
|
25
|
+
return res;
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
steps: ({ name }) => {
|
|
29
|
+
const processor = new NewCodeSplittingProcessor({
|
|
30
|
+
name,
|
|
31
|
+
runable: true,
|
|
32
|
+
compilerType: type_1.ECompilerType.Rspack,
|
|
33
|
+
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
34
|
+
});
|
|
35
|
+
return [processor];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
class NewCodeSplittingProcessor extends processor_1.ConfigProcessor {
|
|
39
|
+
constructor(_configOptions) {
|
|
40
|
+
super({
|
|
41
|
+
..._configOptions,
|
|
42
|
+
overrideOptions: (NewCodeSplittingProcessor.overrideOptions)
|
|
43
|
+
});
|
|
44
|
+
this._configOptions = _configOptions;
|
|
45
|
+
}
|
|
46
|
+
static overrideOptions(index, context, options) {
|
|
47
|
+
processor_1.ConfigProcessor.overrideOptions(index, context, options);
|
|
48
|
+
options.experiments ??= {};
|
|
49
|
+
options.experiments.parallelCodeSplitting ??= true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function createStatsAPINewCodeSplittingCase(name, src, dist, testConfig) {
|
|
53
|
+
const caseConfig = require(testConfig);
|
|
54
|
+
const runner = (0, simple_1.getSimpleProcessorRunner)(src, dist);
|
|
55
|
+
it(caseConfig.description, async () => {
|
|
56
|
+
await runner(name, new NewCodeSplittingStatsAPIProcessor({
|
|
57
|
+
name: name,
|
|
58
|
+
snapshotName: "NewCodeSplittingStatsOutput",
|
|
59
|
+
compilerType: type_1.ECompilerType.Rspack,
|
|
60
|
+
...caseConfig
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
class NewCodeSplittingStatsAPIProcessor extends processor_1.StatsAPIProcessor {
|
|
65
|
+
constructor(_statsAPIOptions) {
|
|
66
|
+
super({
|
|
67
|
+
..._statsAPIOptions,
|
|
68
|
+
options: context => {
|
|
69
|
+
const res = _statsAPIOptions.options?.(context) || {};
|
|
70
|
+
res.experiments ??= {};
|
|
71
|
+
res.experiments.parallelCodeSplitting ??= true;
|
|
72
|
+
return res;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
this._statsAPIOptions = _statsAPIOptions;
|
|
76
|
+
}
|
|
77
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -24,4 +24,5 @@ __exportStar(require("./runner"), exports);
|
|
|
24
24
|
__exportStar(require("./test/context"), exports);
|
|
25
25
|
__exportStar(require("./test/simple"), exports);
|
|
26
26
|
__exportStar(require("./test/tester"), exports);
|
|
27
|
+
__exportStar(require("./test/creator"), exports);
|
|
27
28
|
__exportStar(require("./type"), exports);
|
|
@@ -4,6 +4,7 @@ export interface IStatsAPIProcessorOptions<T extends ECompilerType> {
|
|
|
4
4
|
options?: (context: ITestContext) => TCompilerOptions<T>;
|
|
5
5
|
name: string;
|
|
6
6
|
compilerType: T;
|
|
7
|
+
snapshotName?: string;
|
|
7
8
|
compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
8
9
|
build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
9
10
|
check?: (stats: TCompilerStats<T>, compiler: TCompiler<T>) => Promise<void>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
|
|
2
2
|
import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";
|
|
3
3
|
export interface IStatsProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {
|
|
4
|
+
snapshotName?: string;
|
|
4
5
|
}
|
|
5
6
|
export declare class StatsProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
|
|
6
7
|
private stderr;
|
|
8
|
+
private snapshotName?;
|
|
7
9
|
constructor(_statsOptions: IStatsProcessorOptions<T>);
|
|
8
10
|
before(context: ITestContext): Promise<void>;
|
|
9
11
|
after(context: ITestContext): Promise<void>;
|
package/dist/processor/stats.js
CHANGED
|
@@ -23,6 +23,7 @@ class StatsProcessor extends multi_1.MultiTaskProcessor {
|
|
|
23
23
|
runable: false,
|
|
24
24
|
..._statsOptions
|
|
25
25
|
});
|
|
26
|
+
this.snapshotName = _statsOptions.snapshotName;
|
|
26
27
|
}
|
|
27
28
|
async before(context) {
|
|
28
29
|
this.stderr = (0, captureStdio_1.default)(process.stderr, true);
|
|
@@ -133,7 +134,12 @@ class StatsProcessor extends multi_1.MultiTaskProcessor {
|
|
|
133
134
|
// CHANGE: The time unit display in Rspack is second
|
|
134
135
|
.replace(/[.0-9]+(\s?s)/g, "X$1");
|
|
135
136
|
}
|
|
136
|
-
|
|
137
|
+
if (this.snapshotName) {
|
|
138
|
+
env.expect(new RspackStats(actual)).toMatchSnapshot(this.snapshotName);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
env.expect(new RspackStats(actual)).toMatchSnapshot();
|
|
142
|
+
}
|
|
137
143
|
const testConfig = context.getTestConfig();
|
|
138
144
|
if (typeof testConfig?.validate === "function") {
|
|
139
145
|
testConfig.validate(stats, this.stderr.toString());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"glob": "^11.0.0",
|
|
46
46
|
"jest-diff": "^29.7.0",
|
|
47
47
|
"jest-snapshot": "29.7.0",
|
|
48
|
-
"jsdom": "^
|
|
48
|
+
"jsdom": "^26.0.0",
|
|
49
49
|
"memfs": "4.14.0",
|
|
50
50
|
"path-serializer": "0.3.4",
|
|
51
51
|
"pretty-format": "29.7.0",
|
|
@@ -101,8 +101,8 @@
|
|
|
101
101
|
"typescript": "^5.7.2",
|
|
102
102
|
"wast-loader": "^1.12.1",
|
|
103
103
|
"worker-rspack-loader": "^3.1.2",
|
|
104
|
-
"@rspack/cli": "1.2.
|
|
105
|
-
"@rspack/core": "1.2.
|
|
104
|
+
"@rspack/cli": "1.2.1",
|
|
105
|
+
"@rspack/core": "1.2.1"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
108
|
"@rspack/core": ">=1.0.0"
|