@rspack-canary/test-tools 1.5.7-canary-a3406c0a-20250922173625 → 1.5.8-canary-e350b761-20250924173613
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/builtin.d.ts +2 -2
- package/dist/case/builtin.js +37 -28
- package/dist/case/cache.d.ts +1 -1
- package/dist/case/cache.js +135 -42
- package/dist/case/common.d.ts +10 -0
- package/dist/case/common.js +237 -0
- package/dist/case/compiler.d.ts +7 -4
- package/dist/case/compiler.js +144 -109
- package/dist/case/config.d.ts +3 -2
- package/dist/case/config.js +47 -39
- package/dist/case/defaults.d.ts +2 -2
- package/dist/case/defaults.js +28 -18
- package/dist/case/diagnostic.d.ts +1 -1
- package/dist/case/diagnostic.js +52 -43
- package/dist/case/diff.d.ts +17 -1
- package/dist/case/diff.js +170 -22
- package/dist/case/error.d.ts +14 -4
- package/dist/case/error.js +51 -21
- package/dist/case/hash.d.ts +1 -1
- package/dist/case/hash.js +41 -34
- package/dist/case/hook.d.ts +4 -5
- package/dist/case/hook.js +78 -70
- package/dist/case/hot-step.d.ts +1 -1
- package/dist/case/hot-step.js +9 -5
- package/dist/case/hot.d.ts +5 -5
- package/dist/case/hot.js +142 -55
- package/dist/case/incremental.d.ts +1 -1
- package/dist/case/incremental.js +19 -34
- package/dist/case/native-watcher.js +10 -23
- package/dist/case/normal.js +46 -31
- package/dist/case/runner.d.ts +18 -0
- package/dist/case/runner.js +108 -0
- package/dist/case/serial.d.ts +1 -1
- package/dist/case/serial.js +7 -15
- package/dist/case/stats-api.js +52 -22
- package/dist/case/stats-output.js +133 -137
- package/dist/case/treeshaking.js +33 -22
- package/dist/case/watch.d.ts +27 -0
- package/dist/case/watch.js +321 -21
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/runner/index.d.ts +2 -7
- package/dist/runner/index.js +2 -7
- package/dist/runner/{runner/node → node}/index.d.ts +1 -2
- package/dist/runner/{runner/node → node}/index.js +2 -2
- package/dist/runner/{runner/web → web}/fake.d.ts +1 -2
- package/dist/runner/{runner/web → web}/fake.js +7 -7
- package/dist/runner/{runner/web → web}/index.d.ts +2 -2
- package/dist/runner/{runner/web → web}/index.js +1 -1
- package/dist/runner/{runner/web → web}/jsdom.d.ts +1 -2
- package/dist/runner/{runner/web → web}/jsdom.js +4 -4
- package/dist/test/context.d.ts +3 -5
- package/dist/test/context.js +22 -12
- package/dist/test/creator.d.ts +13 -12
- package/dist/test/creator.js +52 -43
- package/dist/test/tester.js +4 -1
- package/dist/type.d.ts +41 -10
- package/dist/type.js +7 -1
- package/package.json +5 -5
- package/dist/processor/basic.d.ts +0 -27
- package/dist/processor/basic.js +0 -157
- package/dist/processor/diff.d.ts +0 -30
- package/dist/processor/diff.js +0 -140
- package/dist/processor/index.d.ts +0 -6
- package/dist/processor/index.js +0 -22
- package/dist/processor/multi.d.ts +0 -19
- package/dist/processor/multi.js +0 -75
- package/dist/processor/simple.d.ts +0 -24
- package/dist/processor/simple.js +0 -51
- package/dist/processor/snapshot.d.ts +0 -12
- package/dist/processor/snapshot.js +0 -67
- package/dist/processor/watch.d.ts +0 -30
- package/dist/processor/watch.js +0 -252
- package/dist/runner/basic.d.ts +0 -10
- package/dist/runner/basic.js +0 -64
- package/dist/runner/cache.d.ts +0 -5
- package/dist/runner/cache.js +0 -92
- package/dist/runner/hot.d.ts +0 -5
- package/dist/runner/hot.js +0 -91
- package/dist/runner/multiple.d.ts +0 -11
- package/dist/runner/multiple.js +0 -52
- package/dist/runner/runner/index.d.ts +0 -2
- package/dist/runner/runner/index.js +0 -18
- package/dist/runner/type.d.ts +0 -42
- package/dist/runner/type.js +0 -9
- package/dist/runner/watch.d.ts +0 -7
- package/dist/runner/watch.js +0 -71
- package/dist/test/simple.d.ts +0 -5
- package/dist/test/simple.js +0 -43
package/dist/test/creator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ECompilerType, ITestContext, ITestEnv, ITester,
|
|
1
|
+
import type { ECompilerType, ITestContext, ITestEnv, ITester, ITesterConfig, ITestProcessor, TTestConfig, TTestRunnerCreator } from "../type";
|
|
2
2
|
declare global {
|
|
3
3
|
var testFilter: string | undefined;
|
|
4
4
|
}
|
|
@@ -19,28 +19,29 @@ export interface IBasicCaseCreatorOptions<T extends ECompilerType> {
|
|
|
19
19
|
}) => ITestProcessor[];
|
|
20
20
|
testConfig?: (testConfig: TTestConfig<T>) => void;
|
|
21
21
|
description?: (name: string, step: number) => string;
|
|
22
|
-
runner?:
|
|
23
|
-
|
|
22
|
+
runner?: TTestRunnerCreator;
|
|
23
|
+
createContext?: (config: ITesterConfig) => ITestContext;
|
|
24
24
|
concurrent?: boolean | number;
|
|
25
|
+
[key: string]: unknown;
|
|
25
26
|
}
|
|
26
27
|
export declare class BasicCaseCreator<T extends ECompilerType> {
|
|
27
28
|
protected _options: IBasicCaseCreatorOptions<T>;
|
|
28
29
|
protected currentConcurrent: number;
|
|
29
30
|
protected tasks: [string, () => void][];
|
|
30
31
|
constructor(_options: IBasicCaseCreatorOptions<T>);
|
|
31
|
-
create(name: string, src: string, dist: string, temp?: string): ITester | undefined;
|
|
32
|
+
create(name: string, src: string, dist: string, temp?: string, caseOptions?: Partial<IBasicCaseCreatorOptions<T>>): ITester | undefined;
|
|
32
33
|
protected shouldRun(name: string): boolean;
|
|
33
|
-
protected describeConcurrent(name: string, tester: ITester, testConfig: TTestConfig<T>): void;
|
|
34
|
-
protected describe(name: string, tester: ITester, testConfig: TTestConfig<T>): void;
|
|
34
|
+
protected describeConcurrent(name: string, tester: ITester, testConfig: TTestConfig<T>, options: IBasicCaseCreatorOptions<T>): void;
|
|
35
|
+
protected describe(name: string, tester: ITester, testConfig: TTestConfig<T>, options: IBasicCaseCreatorOptions<T>): void;
|
|
35
36
|
protected createConcurrentEnv(): ITestEnv & IConcurrentTestEnv;
|
|
36
|
-
protected createEnv(testConfig: TTestConfig<T>): ITestEnv;
|
|
37
|
+
protected createEnv(testConfig: TTestConfig<T>, options: IBasicCaseCreatorOptions<T>): ITestEnv;
|
|
37
38
|
protected clean(folders: string[]): void;
|
|
38
39
|
protected skip(name: string, reason: string | boolean): void;
|
|
39
40
|
protected readTestConfig(src: string): TTestConfig<T>;
|
|
40
|
-
protected checkSkipped(src: string, testConfig: TTestConfig<T>): boolean | string;
|
|
41
|
-
protected createTester(name: string, src: string, dist: string, temp: string | undefined, testConfig: TTestConfig<T>): ITester;
|
|
42
|
-
protected tryRunTask(): void;
|
|
43
|
-
protected getMaxConcurrent(): number;
|
|
44
|
-
protected registerConcurrentTask(name: string, starter: () => void): () => void;
|
|
41
|
+
protected checkSkipped(src: string, testConfig: TTestConfig<T>, options: IBasicCaseCreatorOptions<T>): boolean | string;
|
|
42
|
+
protected createTester(name: string, src: string, dist: string, temp: string | undefined, testConfig: TTestConfig<T>, options: IBasicCaseCreatorOptions<T>): ITester;
|
|
43
|
+
protected tryRunTask(concurrent?: number): void;
|
|
44
|
+
protected getMaxConcurrent(concurrent?: number): number;
|
|
45
|
+
protected registerConcurrentTask(name: string, starter: () => void, concurrent?: number): () => void;
|
|
45
46
|
}
|
|
46
47
|
export {};
|
package/dist/test/creator.js
CHANGED
|
@@ -16,31 +16,35 @@ class BasicCaseCreator {
|
|
|
16
16
|
this.currentConcurrent = 0;
|
|
17
17
|
this.tasks = [];
|
|
18
18
|
}
|
|
19
|
-
create(name, src, dist, temp) {
|
|
19
|
+
create(name, src, dist, temp, caseOptions) {
|
|
20
|
+
const options = {
|
|
21
|
+
...this._options,
|
|
22
|
+
...caseOptions
|
|
23
|
+
};
|
|
20
24
|
const testConfig = this.readTestConfig(src);
|
|
21
|
-
if (typeof
|
|
22
|
-
|
|
25
|
+
if (typeof options.testConfig === "function") {
|
|
26
|
+
options.testConfig(testConfig);
|
|
23
27
|
}
|
|
24
|
-
const skipped = this.checkSkipped(src, testConfig);
|
|
28
|
+
const skipped = this.checkSkipped(src, testConfig, options);
|
|
25
29
|
if (skipped) {
|
|
26
30
|
this.skip(name, skipped);
|
|
27
31
|
return;
|
|
28
32
|
}
|
|
29
|
-
if (
|
|
33
|
+
if (options.clean) {
|
|
30
34
|
this.clean([dist, temp || ""].filter(Boolean));
|
|
31
35
|
}
|
|
32
36
|
const run = this.shouldRun(name);
|
|
33
|
-
const tester = this.createTester(name, src, dist, temp, testConfig);
|
|
37
|
+
const tester = this.createTester(name, src, dist, temp, testConfig, options);
|
|
34
38
|
const concurrent = process.env.WASM
|
|
35
39
|
? false
|
|
36
|
-
: testConfig.concurrent ||
|
|
37
|
-
if (
|
|
40
|
+
: testConfig.concurrent || options.concurrent;
|
|
41
|
+
if (options.describe) {
|
|
38
42
|
if (run) {
|
|
39
43
|
if (concurrent) {
|
|
40
|
-
describe(name, () => this.describeConcurrent(name, tester, testConfig));
|
|
44
|
+
describe(name, () => this.describeConcurrent(name, tester, testConfig, options));
|
|
41
45
|
}
|
|
42
46
|
else {
|
|
43
|
-
describe(name, () => this.describe(name, tester, testConfig));
|
|
47
|
+
describe(name, () => this.describe(name, tester, testConfig, options));
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
else {
|
|
@@ -52,10 +56,10 @@ class BasicCaseCreator {
|
|
|
52
56
|
else {
|
|
53
57
|
if (run) {
|
|
54
58
|
if (concurrent) {
|
|
55
|
-
this.describeConcurrent(name, tester, testConfig);
|
|
59
|
+
this.describeConcurrent(name, tester, testConfig, options);
|
|
56
60
|
}
|
|
57
61
|
else {
|
|
58
|
-
this.describe(name, tester, testConfig);
|
|
62
|
+
this.describe(name, tester, testConfig, options);
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
else {
|
|
@@ -71,7 +75,7 @@ class BasicCaseCreator {
|
|
|
71
75
|
}
|
|
72
76
|
return name.includes(global.testFilter);
|
|
73
77
|
}
|
|
74
|
-
describeConcurrent(name, tester, testConfig) {
|
|
78
|
+
describeConcurrent(name, tester, testConfig, options) {
|
|
75
79
|
beforeAll(async () => {
|
|
76
80
|
await tester.prepare();
|
|
77
81
|
});
|
|
@@ -79,7 +83,7 @@ class BasicCaseCreator {
|
|
|
79
83
|
let chain = new Promise((resolve, reject) => {
|
|
80
84
|
starter = resolve;
|
|
81
85
|
});
|
|
82
|
-
const ender = this.registerConcurrentTask(name, starter);
|
|
86
|
+
const ender = this.registerConcurrentTask(name, starter, options.concurrent);
|
|
83
87
|
const env = this.createConcurrentEnv();
|
|
84
88
|
for (let index = 0; index < tester.total; index++) {
|
|
85
89
|
let stepSignalResolve = null;
|
|
@@ -88,8 +92,8 @@ class BasicCaseCreator {
|
|
|
88
92
|
}).catch(() => {
|
|
89
93
|
// prevent unhandled rejection
|
|
90
94
|
});
|
|
91
|
-
const description = typeof
|
|
92
|
-
?
|
|
95
|
+
const description = typeof options.description === "function"
|
|
96
|
+
? options.description(name, index)
|
|
93
97
|
: index
|
|
94
98
|
? `step [${index}] should pass`
|
|
95
99
|
: "should pass";
|
|
@@ -97,7 +101,7 @@ class BasicCaseCreator {
|
|
|
97
101
|
stepSignal.then((e) => {
|
|
98
102
|
cb(e);
|
|
99
103
|
});
|
|
100
|
-
},
|
|
104
|
+
}, options.timeout || 180000);
|
|
101
105
|
chain = chain.then(async () => {
|
|
102
106
|
try {
|
|
103
107
|
env.clear();
|
|
@@ -136,22 +140,28 @@ class BasicCaseCreator {
|
|
|
136
140
|
await tester.resume();
|
|
137
141
|
});
|
|
138
142
|
}
|
|
139
|
-
describe(name, tester, testConfig) {
|
|
143
|
+
describe(name, tester, testConfig, options) {
|
|
140
144
|
beforeAll(async () => {
|
|
141
145
|
await tester.prepare();
|
|
142
146
|
});
|
|
143
147
|
let bailout = false;
|
|
144
148
|
for (let index = 0; index < tester.total; index++) {
|
|
145
|
-
const description = typeof
|
|
146
|
-
?
|
|
147
|
-
: `step
|
|
149
|
+
const description = typeof options.description === "function"
|
|
150
|
+
? options.description(name, index)
|
|
151
|
+
: `step [${index}] should pass`;
|
|
148
152
|
it(description, async () => {
|
|
149
153
|
if (bailout) {
|
|
150
154
|
throw `Case "${name}" step ${index + 1} bailout because ${tester.step + 1} failed`;
|
|
151
155
|
}
|
|
152
|
-
await tester.compile();
|
|
153
|
-
await tester.check(env);
|
|
154
156
|
const context = tester.getContext();
|
|
157
|
+
try {
|
|
158
|
+
await tester.compile();
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
bailout = true;
|
|
162
|
+
context.emitError(name, e);
|
|
163
|
+
}
|
|
164
|
+
await tester.check(env);
|
|
155
165
|
if (!tester.next() && context.hasError()) {
|
|
156
166
|
bailout = true;
|
|
157
167
|
const errors = context
|
|
@@ -160,8 +170,8 @@ class BasicCaseCreator {
|
|
|
160
170
|
.join("\n\n");
|
|
161
171
|
throw new Error(`Case "${name}" failed at step ${tester.step + 1}:\n${errors}`);
|
|
162
172
|
}
|
|
163
|
-
},
|
|
164
|
-
const env = this.createEnv(testConfig);
|
|
173
|
+
}, options.timeout || 30000);
|
|
174
|
+
const env = this.createEnv(testConfig, options);
|
|
165
175
|
}
|
|
166
176
|
afterAll(async () => {
|
|
167
177
|
await tester.resume();
|
|
@@ -230,8 +240,8 @@ class BasicCaseCreator {
|
|
|
230
240
|
jest
|
|
231
241
|
};
|
|
232
242
|
}
|
|
233
|
-
createEnv(testConfig) {
|
|
234
|
-
if (
|
|
243
|
+
createEnv(testConfig, options) {
|
|
244
|
+
if (options.runner && !testConfig.noTests) {
|
|
235
245
|
return (0, createLazyTestEnv_1.default)(10000);
|
|
236
246
|
}
|
|
237
247
|
return {
|
|
@@ -257,30 +267,31 @@ class BasicCaseCreator {
|
|
|
257
267
|
const testConfigFile = node_path_1.default.join(src, "test.config.js");
|
|
258
268
|
return node_fs_1.default.existsSync(testConfigFile) ? require(testConfigFile) : {};
|
|
259
269
|
}
|
|
260
|
-
checkSkipped(src, testConfig) {
|
|
270
|
+
checkSkipped(src, testConfig, options) {
|
|
261
271
|
const filterPath = node_path_1.default.join(src, "test.filter.js");
|
|
262
272
|
// no test.filter.js, should not skip
|
|
263
273
|
if (!node_fs_1.default.existsSync(filterPath)) {
|
|
264
274
|
return false;
|
|
265
275
|
}
|
|
266
276
|
// test.filter.js exists, skip if it returns false|string|array
|
|
267
|
-
const filtered = require(filterPath)(
|
|
277
|
+
const filtered = require(filterPath)(options, testConfig);
|
|
268
278
|
if (typeof filtered === "string" || Array.isArray(filtered)) {
|
|
269
279
|
return true;
|
|
270
280
|
}
|
|
271
281
|
return !filtered;
|
|
272
282
|
}
|
|
273
|
-
createTester(name, src, dist, temp, testConfig) {
|
|
283
|
+
createTester(name, src, dist, temp, testConfig, options) {
|
|
274
284
|
return new tester_1.Tester({
|
|
275
285
|
name,
|
|
276
286
|
src,
|
|
277
287
|
dist,
|
|
278
288
|
temp,
|
|
279
289
|
testConfig,
|
|
280
|
-
contextValue:
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
290
|
+
contextValue: options.contextValue,
|
|
291
|
+
runnerCreator: options.runner,
|
|
292
|
+
createContext: options.createContext,
|
|
293
|
+
steps: options.steps({
|
|
294
|
+
...options,
|
|
284
295
|
name,
|
|
285
296
|
src,
|
|
286
297
|
dist,
|
|
@@ -288,25 +299,23 @@ class BasicCaseCreator {
|
|
|
288
299
|
})
|
|
289
300
|
});
|
|
290
301
|
}
|
|
291
|
-
tryRunTask() {
|
|
302
|
+
tryRunTask(concurrent) {
|
|
292
303
|
while (this.tasks.length !== 0 &&
|
|
293
|
-
this.currentConcurrent < this.getMaxConcurrent()) {
|
|
304
|
+
this.currentConcurrent < this.getMaxConcurrent(concurrent)) {
|
|
294
305
|
const [_name, starter] = this.tasks.shift();
|
|
295
306
|
this.currentConcurrent++;
|
|
296
307
|
starter();
|
|
297
308
|
}
|
|
298
309
|
}
|
|
299
|
-
getMaxConcurrent() {
|
|
300
|
-
return typeof
|
|
301
|
-
? this._options.concurrent
|
|
302
|
-
: DEFAULT_MAX_CONCURRENT;
|
|
310
|
+
getMaxConcurrent(concurrent) {
|
|
311
|
+
return typeof concurrent === "number" ? concurrent : DEFAULT_MAX_CONCURRENT;
|
|
303
312
|
}
|
|
304
|
-
registerConcurrentTask(name, starter) {
|
|
313
|
+
registerConcurrentTask(name, starter, concurrent) {
|
|
305
314
|
this.tasks.push([name, starter]);
|
|
306
|
-
this.tryRunTask();
|
|
315
|
+
this.tryRunTask(concurrent);
|
|
307
316
|
return () => {
|
|
308
317
|
this.currentConcurrent--;
|
|
309
|
-
this.tryRunTask();
|
|
318
|
+
this.tryRunTask(concurrent);
|
|
310
319
|
};
|
|
311
320
|
}
|
|
312
321
|
}
|
package/dist/test/tester.js
CHANGED
|
@@ -12,7 +12,9 @@ class Tester {
|
|
|
12
12
|
this.steps = [];
|
|
13
13
|
this.step = 0;
|
|
14
14
|
this.total = 0;
|
|
15
|
-
this.context =
|
|
15
|
+
this.context = config.createContext
|
|
16
|
+
? config.createContext(config)
|
|
17
|
+
: new context_1.TestContext(config);
|
|
16
18
|
this.steps = config.steps || [];
|
|
17
19
|
this.step = 0;
|
|
18
20
|
this.total = config.steps?.length || 0;
|
|
@@ -69,6 +71,7 @@ class Tester {
|
|
|
69
71
|
for (const i of this.steps) {
|
|
70
72
|
if (typeof i.afterAll === "function") {
|
|
71
73
|
await i.afterAll(this.context);
|
|
74
|
+
await this.context.closeCompiler(this.config.name);
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
}
|
package/dist/type.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type EventEmitter from "node:events";
|
|
2
2
|
import type { Compilation as RspackCompilation, Compiler as RspackCompiler, MultiStats as RspackMultiStats, RspackOptions, Stats as RspackStats, StatsCompilation as RspackStatsCompilation } from "@rspack/core";
|
|
3
3
|
import type { Compilation as WebpackCompilation, Compiler as WebpackCompiler, MultiStats as WebpackMultiStats, Configuration as WebpackOptions, Stats as WebpackStats, StatsCompilation as WebpackStatsCompilation } from "webpack";
|
|
4
|
-
import type { IModuleScope, TRunnerRequirer } from "./runner/type";
|
|
5
4
|
export interface ITestContext {
|
|
6
5
|
getSource(sub?: string): string;
|
|
7
6
|
getDist(sub?: string): string;
|
|
8
7
|
getTemp(sub?: string): string | null;
|
|
9
8
|
getCompiler<T extends ECompilerType>(name: string, type: T | void): ITestCompilerManager<T>;
|
|
9
|
+
closeCompiler(name: string): Promise<void>;
|
|
10
10
|
getTestConfig<T extends ECompilerType>(): TTestConfig<T>;
|
|
11
|
-
|
|
12
|
-
getRunner(key: string): ITestRunner | null;
|
|
13
|
-
setRunner(key: string, runner: ITestRunner): void;
|
|
11
|
+
getRunner(name: string, file: string, env: ITestEnv): ITestRunner;
|
|
14
12
|
setValue<T>(name: string, key: string, value: T): void;
|
|
15
13
|
getValue<T>(name: string, key: string): T | void;
|
|
16
14
|
getNames(): string[];
|
|
@@ -55,7 +53,8 @@ export interface ITesterConfig {
|
|
|
55
53
|
testConfig?: TTestConfig<ECompilerType>;
|
|
56
54
|
compilerFactories?: TCompilerFactories<ECompilerType>;
|
|
57
55
|
contextValue?: Record<string, unknown>;
|
|
58
|
-
|
|
56
|
+
runnerCreator?: TTestRunnerCreator;
|
|
57
|
+
createContext?: (config: ITesterConfig) => ITestContext;
|
|
59
58
|
}
|
|
60
59
|
export interface ITester {
|
|
61
60
|
step: number;
|
|
@@ -72,11 +71,11 @@ export interface ITestProcessor {
|
|
|
72
71
|
afterAll?(context: ITestContext): Promise<void>;
|
|
73
72
|
before?(context: ITestContext): Promise<void>;
|
|
74
73
|
after?(context: ITestContext): Promise<void>;
|
|
75
|
-
config
|
|
76
|
-
compiler
|
|
77
|
-
build
|
|
78
|
-
run
|
|
79
|
-
check
|
|
74
|
+
config(context: ITestContext): Promise<void>;
|
|
75
|
+
compiler(context: ITestContext): Promise<void>;
|
|
76
|
+
build(context: ITestContext): Promise<void>;
|
|
77
|
+
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
78
|
+
check(env: ITestEnv, context: ITestContext): Promise<unknown>;
|
|
80
79
|
}
|
|
81
80
|
export interface ITestReporter<T> {
|
|
82
81
|
init(data?: T): Promise<void>;
|
|
@@ -169,3 +168,35 @@ export type THotUpdateContext = {
|
|
|
169
168
|
changedFiles: string[];
|
|
170
169
|
};
|
|
171
170
|
export type TCompilerFactories<T extends ECompilerType> = Record<T, TCompilerFactory<T>>;
|
|
171
|
+
export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] | string, context?: {
|
|
172
|
+
file?: TRunnerFile;
|
|
173
|
+
esmMode?: EEsmMode;
|
|
174
|
+
}) => Object | Promise<Object>;
|
|
175
|
+
export type TRunnerFile = {
|
|
176
|
+
path: string;
|
|
177
|
+
content: string;
|
|
178
|
+
subPath: string;
|
|
179
|
+
};
|
|
180
|
+
export declare enum EEsmMode {
|
|
181
|
+
Unknown = 0,
|
|
182
|
+
Evaluated = 1,
|
|
183
|
+
Unlinked = 2
|
|
184
|
+
}
|
|
185
|
+
export interface IModuleScope extends ITestEnv {
|
|
186
|
+
console: Record<string, (...args: any[]) => void>;
|
|
187
|
+
expect: jest.Expect;
|
|
188
|
+
[key: string]: any;
|
|
189
|
+
}
|
|
190
|
+
export interface IGlobalContext {
|
|
191
|
+
console: Record<string, (...args: any[]) => void>;
|
|
192
|
+
setTimeout: typeof setTimeout;
|
|
193
|
+
clearTimeout: typeof clearTimeout;
|
|
194
|
+
[key: string]: any;
|
|
195
|
+
}
|
|
196
|
+
export type TModuleObject = {
|
|
197
|
+
exports: unknown;
|
|
198
|
+
};
|
|
199
|
+
export type TTestRunnerCreator = {
|
|
200
|
+
key: (context: ITestContext, name: string, file: string) => string;
|
|
201
|
+
runner: (context: ITestContext, name: string, file: string, env: ITestEnv) => ITestRunner;
|
|
202
|
+
};
|
package/dist/type.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/// <reference types="../jest.d.ts" />
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.EDocumentType = exports.ECompareResultType = exports.ECompilerType = void 0;
|
|
4
|
+
exports.EEsmMode = exports.EDocumentType = exports.ECompareResultType = exports.ECompilerType = void 0;
|
|
5
5
|
var ECompilerType;
|
|
6
6
|
(function (ECompilerType) {
|
|
7
7
|
ECompilerType["Rspack"] = "rspack";
|
|
@@ -20,3 +20,9 @@ var EDocumentType;
|
|
|
20
20
|
EDocumentType["Fake"] = "fake";
|
|
21
21
|
EDocumentType["JSDOM"] = "jsdom";
|
|
22
22
|
})(EDocumentType || (exports.EDocumentType = EDocumentType = {}));
|
|
23
|
+
var EEsmMode;
|
|
24
|
+
(function (EEsmMode) {
|
|
25
|
+
EEsmMode[EEsmMode["Unknown"] = 0] = "Unknown";
|
|
26
|
+
EEsmMode[EEsmMode["Evaluated"] = 1] = "Evaluated";
|
|
27
|
+
EEsmMode[EEsmMode["Unlinked"] = 2] = "Unlinked";
|
|
28
|
+
})(EEsmMode || (exports.EEsmMode = EEsmMode = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack-canary/test-tools",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8-canary-e350b761-20250924173613",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -100,10 +100,10 @@
|
|
|
100
100
|
"wast-loader": "^1.14.1",
|
|
101
101
|
"worker-rspack-loader": "^3.1.2",
|
|
102
102
|
"exports-loader": "^5.0.0",
|
|
103
|
-
"@rspack/cli": "npm:@rspack-canary/cli@1.5.
|
|
104
|
-
"@rspack/core": "npm:@rspack-canary/core@1.5.
|
|
105
|
-
"@rspack/
|
|
106
|
-
"@rspack/
|
|
103
|
+
"@rspack/cli": "npm:@rspack-canary/cli@1.5.8-canary-e350b761-20250924173613",
|
|
104
|
+
"@rspack/core": "npm:@rspack-canary/core@1.5.8-canary-e350b761-20250924173613",
|
|
105
|
+
"@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.8-canary-e350b761-20250924173613",
|
|
106
|
+
"@rspack/binding-testing": "1.4.1"
|
|
107
107
|
},
|
|
108
108
|
"peerDependencies": {
|
|
109
109
|
"@rspack/core": ">=1.0.0"
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, TCompiler, TCompilerMultiStats, TCompilerOptions, TCompilerStats } from "../type";
|
|
2
|
-
export interface IBasicProcessorOptions<T extends ECompilerType> {
|
|
3
|
-
defaultOptions?: (context: ITestContext) => TCompilerOptions<T>;
|
|
4
|
-
configFiles?: string[];
|
|
5
|
-
overrideOptions?: (context: ITestContext, options: TCompilerOptions<T>) => void;
|
|
6
|
-
findBundle?: (context: ITestContext, options: TCompilerOptions<T>) => string[] | string | void;
|
|
7
|
-
compilerType: T;
|
|
8
|
-
runable: boolean;
|
|
9
|
-
name: string;
|
|
10
|
-
compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
11
|
-
build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
12
|
-
check?: (env: ITestEnv, context: ITestContext, compiler: TCompiler<T>, stats: TCompilerStats<T> | TCompilerMultiStats<T> | null) => Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
export declare class BasicProcessor<T extends ECompilerType> implements ITestProcessor {
|
|
15
|
-
protected _options: IBasicProcessorOptions<T>;
|
|
16
|
-
constructor(_options: IBasicProcessorOptions<T>);
|
|
17
|
-
config(context: ITestContext): Promise<void>;
|
|
18
|
-
compiler(context: ITestContext): Promise<void>;
|
|
19
|
-
build(context: ITestContext): Promise<void>;
|
|
20
|
-
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
21
|
-
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
22
|
-
before(context: ITestContext): Promise<void>;
|
|
23
|
-
after(context: ITestContext): Promise<void>;
|
|
24
|
-
beforeAll(context: ITestContext): Promise<void>;
|
|
25
|
-
afterAll(context: ITestContext): Promise<void>;
|
|
26
|
-
protected getCompiler(context: ITestContext): import("../type").ITestCompilerManager<T>;
|
|
27
|
-
}
|
package/dist/processor/basic.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BasicProcessor = void 0;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const helper_1 = require("../helper");
|
|
10
|
-
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
11
|
-
class BasicProcessor {
|
|
12
|
-
constructor(_options) {
|
|
13
|
-
this._options = _options;
|
|
14
|
-
}
|
|
15
|
-
async config(context) {
|
|
16
|
-
const compiler = this.getCompiler(context);
|
|
17
|
-
if (typeof this._options.defaultOptions === "function") {
|
|
18
|
-
compiler.setOptions(this._options.defaultOptions.call(this, context));
|
|
19
|
-
}
|
|
20
|
-
if (Array.isArray(this._options.configFiles)) {
|
|
21
|
-
const fileOptions = (0, helper_1.readConfigFile)(this._options.configFiles.map(i => context.getSource(i)))[0];
|
|
22
|
-
compiler.mergeOptions(fileOptions);
|
|
23
|
-
}
|
|
24
|
-
if (typeof this._options.overrideOptions === "function") {
|
|
25
|
-
const compilerOptions = compiler.getOptions();
|
|
26
|
-
this._options.overrideOptions.call(this, context, compilerOptions);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
async compiler(context) {
|
|
30
|
-
const compiler = this.getCompiler(context);
|
|
31
|
-
compiler.createCompiler();
|
|
32
|
-
if (typeof this._options.compiler === "function") {
|
|
33
|
-
await this._options.compiler.call(this, context, compiler.getCompiler());
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async build(context) {
|
|
37
|
-
const compiler = this.getCompiler(context);
|
|
38
|
-
if (typeof this._options.build === "function") {
|
|
39
|
-
await this._options.build.call(this, context, compiler.getCompiler());
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
await compiler.build();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async run(env, context) {
|
|
46
|
-
if (!this._options.runable)
|
|
47
|
-
return;
|
|
48
|
-
const testConfig = context.getTestConfig();
|
|
49
|
-
if (testConfig.noTests)
|
|
50
|
-
return;
|
|
51
|
-
if (testConfig.documentType) {
|
|
52
|
-
context.setValue(this._options.name, "documentType", testConfig.documentType);
|
|
53
|
-
}
|
|
54
|
-
const compiler = this.getCompiler(context);
|
|
55
|
-
if (typeof testConfig.beforeExecute === "function") {
|
|
56
|
-
testConfig.beforeExecute.call(this, compiler.getOptions());
|
|
57
|
-
}
|
|
58
|
-
let bundles;
|
|
59
|
-
if (testConfig.bundlePath) {
|
|
60
|
-
bundles = testConfig.bundlePath;
|
|
61
|
-
}
|
|
62
|
-
else if (typeof this._options.findBundle === "function") {
|
|
63
|
-
bundles = this._options.findBundle.call(this, context, compiler.getOptions());
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
bundles = [];
|
|
67
|
-
}
|
|
68
|
-
if (typeof bundles === "string") {
|
|
69
|
-
bundles = [bundles];
|
|
70
|
-
}
|
|
71
|
-
if (!bundles || !bundles.length) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
for (const bundle of bundles) {
|
|
75
|
-
if (!bundle) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
const runnerFactory = context.getRunnerFactory(this._options.name);
|
|
79
|
-
if (!runnerFactory) {
|
|
80
|
-
throw new Error(`Test case ${this._options.name} is not runable`);
|
|
81
|
-
}
|
|
82
|
-
const runner = runnerFactory.create(bundle, compiler.getOptions(), env);
|
|
83
|
-
const mod = runner.run(bundle);
|
|
84
|
-
const result = context.getValue(this._options.name, "modules") || [];
|
|
85
|
-
result.push(mod);
|
|
86
|
-
context.setValue(this._options.name, "modules", result);
|
|
87
|
-
}
|
|
88
|
-
const results = context.getValue(this._options.name, "modules") || [];
|
|
89
|
-
await Promise.all(results);
|
|
90
|
-
if (typeof testConfig.afterExecute === "function") {
|
|
91
|
-
testConfig.afterExecute.call(this, compiler.getOptions());
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async check(env, context) {
|
|
95
|
-
const testConfig = context.getTestConfig();
|
|
96
|
-
if (testConfig.noTests)
|
|
97
|
-
return;
|
|
98
|
-
const compiler = this.getCompiler(context);
|
|
99
|
-
if (typeof this._options.check === "function") {
|
|
100
|
-
const stats = compiler.getStats();
|
|
101
|
-
await this._options.check.call(this, env, context, compiler.getCompiler(), stats);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const errors = (context.getError(this._options.name) || []).map(e => ({
|
|
105
|
-
message: e.message,
|
|
106
|
-
stack: e.stack
|
|
107
|
-
}));
|
|
108
|
-
const warnings = [];
|
|
109
|
-
const stats = compiler.getStats();
|
|
110
|
-
const options = compiler.getOptions();
|
|
111
|
-
if (stats) {
|
|
112
|
-
if (testConfig.writeStatsOuptut) {
|
|
113
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
|
|
114
|
-
preset: "verbose",
|
|
115
|
-
colors: false
|
|
116
|
-
}), "utf-8");
|
|
117
|
-
}
|
|
118
|
-
if (testConfig.writeStatsJson) {
|
|
119
|
-
const jsonStats = stats.toJson({
|
|
120
|
-
errorDetails: true
|
|
121
|
-
});
|
|
122
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.json"), JSON.stringify(jsonStats, null, 2), "utf-8");
|
|
123
|
-
}
|
|
124
|
-
if (node_fs_1.default.existsSync(context.getSource("errors.js")) ||
|
|
125
|
-
node_fs_1.default.existsSync(context.getSource("warnings.js")) ||
|
|
126
|
-
stats.hasErrors() ||
|
|
127
|
-
stats.hasWarnings()) {
|
|
128
|
-
const statsJson = stats.toJson({
|
|
129
|
-
errorDetails: true
|
|
130
|
-
});
|
|
131
|
-
if (statsJson.errors) {
|
|
132
|
-
errors.push(...statsJson.errors);
|
|
133
|
-
}
|
|
134
|
-
if (statsJson.warnings) {
|
|
135
|
-
warnings.push(...statsJson.warnings);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
await (0, checkArrayExpectation_1.default)(context.getSource(), { errors }, "error", "errors", "Error", options);
|
|
140
|
-
await (0, checkArrayExpectation_1.default)(context.getSource(), { warnings }, "warning", "warnings", "Warning", options);
|
|
141
|
-
// clear error if checked
|
|
142
|
-
if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
|
|
143
|
-
context.clearError(this._options.name);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
async before(context) { }
|
|
147
|
-
async after(context) { }
|
|
148
|
-
async beforeAll(context) { }
|
|
149
|
-
async afterAll(context) {
|
|
150
|
-
const compiler = this.getCompiler(context);
|
|
151
|
-
await compiler.close();
|
|
152
|
-
}
|
|
153
|
-
getCompiler(context) {
|
|
154
|
-
return context.getCompiler(this._options.name, this._options.compilerType);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.BasicProcessor = BasicProcessor;
|
package/dist/processor/diff.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { type IFormatCodeOptions, type IFormatCodeReplacement } from "../compare";
|
|
2
|
-
import { type ITestContext, type ITestEnv, type ITestProcessor, type TCompareModules, type TFileCompareResult, type TModuleCompareResult } from "../type";
|
|
3
|
-
export interface IDiffProcessorOptions extends IFormatCodeOptions {
|
|
4
|
-
webpackPath: string;
|
|
5
|
-
rspackPath: string;
|
|
6
|
-
files?: string[];
|
|
7
|
-
modules?: TCompareModules;
|
|
8
|
-
runtimeModules?: TCompareModules;
|
|
9
|
-
bootstrap?: boolean;
|
|
10
|
-
detail?: boolean;
|
|
11
|
-
errors?: boolean;
|
|
12
|
-
replacements?: IFormatCodeReplacement[];
|
|
13
|
-
renameModule?: (file: string) => string;
|
|
14
|
-
onCompareFile?: (file: string, result: TFileCompareResult) => void;
|
|
15
|
-
onCompareModules?: (file: string, results: TModuleCompareResult[]) => void;
|
|
16
|
-
onCompareRuntimeModules?: (file: string, results: TModuleCompareResult[]) => void;
|
|
17
|
-
}
|
|
18
|
-
export declare class DiffProcessor implements ITestProcessor {
|
|
19
|
-
private options;
|
|
20
|
-
private hashes;
|
|
21
|
-
private webpack;
|
|
22
|
-
private rspack;
|
|
23
|
-
constructor(options: IDiffProcessorOptions);
|
|
24
|
-
config(context: ITestContext): Promise<void>;
|
|
25
|
-
compiler(context: ITestContext): Promise<void>;
|
|
26
|
-
build(context: ITestContext): Promise<void>;
|
|
27
|
-
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
28
|
-
private getDefaultOptions;
|
|
29
|
-
private createFormatOptions;
|
|
30
|
-
}
|