@rspack-debug/test-tools 1.4.11 → 1.6.4
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 +1 -1
- package/dist/case/builtin.d.ts +3 -0
- package/dist/case/builtin.js +152 -14
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +214 -12
- package/dist/case/common.d.ts +11 -0
- package/dist/case/common.js +249 -0
- package/dist/case/compiler.d.ts +17 -4
- package/dist/case/compiler.js +149 -12
- package/dist/case/config.d.ts +7 -2
- package/dist/case/config.js +106 -18
- package/dist/case/defaults.d.ts +13 -4
- package/dist/case/defaults.js +73 -18
- package/dist/case/diagnostic.d.ts +6 -0
- package/dist/case/diagnostic.js +121 -14
- package/dist/case/error.d.ts +15 -4
- package/dist/case/error.js +137 -12
- package/dist/case/esm-output.d.ts +1 -0
- package/dist/case/esm-output.js +117 -0
- package/dist/case/example.d.ts +1 -0
- package/dist/case/example.js +57 -0
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +72 -9
- package/dist/case/hook.d.ts +36 -4
- package/dist/case/hook.js +209 -20
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +309 -13
- package/dist/case/hot.d.ts +11 -2
- package/dist/case/hot.js +217 -12
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +24 -45
- package/dist/case/index.d.ts +31 -20
- package/dist/case/index.js +50 -34
- package/dist/case/multi-compiler.d.ts +19 -0
- package/dist/case/multi-compiler.js +97 -0
- package/dist/case/{nativeWatcher.js → native-watcher.js} +11 -23
- package/dist/case/normal.d.ts +3 -0
- package/dist/case/normal.js +202 -18
- package/dist/case/runner.d.ts +19 -0
- package/dist/case/runner.js +113 -0
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +10 -14
- package/dist/case/stats-api.d.ts +8 -3
- package/dist/case/stats-api.js +69 -10
- package/dist/case/stats-output.d.ts +11 -0
- package/dist/case/stats-output.js +199 -8
- package/dist/case/treeshaking.js +34 -7
- package/dist/case/watch.d.ts +27 -0
- package/dist/case/watch.js +318 -22
- package/dist/compiler.d.ts +16 -16
- package/dist/compiler.js +120 -15
- package/dist/helper/directory.d.ts +1 -1
- package/dist/helper/directory.js +6 -2
- package/dist/helper/disable-iconv-lite-warning.d.ts +1 -0
- package/dist/helper/disable-iconv-lite-warning.js +12 -0
- package/dist/helper/expect/error.js +1 -1
- package/dist/helper/expect/placeholder.js +7 -7
- package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
- package/dist/helper/expect/to-match-file-snapshot.js +3 -3
- package/dist/helper/hot-update/loader.d.ts +2 -1
- package/dist/helper/hot-update/loader.js +5 -30
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +14 -13
- package/dist/helper/index.d.ts +2 -1
- package/dist/helper/index.js +2 -1
- package/dist/helper/is.d.ts +2 -0
- package/dist/helper/is.js +15 -0
- package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
- package/dist/helper/legacy/LogTestPlugin.js +35 -0
- package/dist/helper/legacy/asModule.js +0 -2
- package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
- package/dist/helper/legacy/checkArrayExpectation.js +8 -8
- package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
- package/dist/helper/legacy/createFakeWorker.js +44 -20
- package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
- package/dist/helper/legacy/createLazyTestEnv.js +3 -3
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
- package/dist/helper/legacy/deprecationTracking.js +41 -0
- package/dist/helper/legacy/expectSource.d.ts +10 -0
- package/dist/helper/legacy/expectSource.js +23 -0
- package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
- package/dist/helper/legacy/findOutputFiles.js +14 -0
- package/dist/helper/legacy/regexEscape.d.ts +2 -0
- package/dist/helper/legacy/regexEscape.js +5 -0
- package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
- package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
- package/dist/helper/legacy/supportsTextDecoder.js +9 -0
- package/dist/helper/legacy/supportsUsing.d.ts +2 -0
- package/dist/helper/legacy/supportsUsing.js +26 -0
- package/dist/helper/legacy/urlToRelativePath.js +5 -2
- package/dist/helper/read-config-file.d.ts +3 -2
- package/dist/helper/read-config-file.js +12 -2
- package/dist/helper/setup-env.js +26 -4
- package/dist/helper/setup-expect.js +2 -2
- package/dist/helper/setup-wasm.js +2 -2
- package/dist/helper/stringify-config.d.ts +2 -0
- package/dist/helper/stringify-config.js +43 -0
- package/dist/helper/util/checkStats.d.ts +0 -1
- package/dist/helper/util/checkStats.js +0 -18
- package/dist/helper/util/expectWarningFactory.js +2 -4
- package/dist/index.d.ts +0 -4
- package/dist/index.js +1 -4
- package/dist/plugin/index.d.ts +0 -3
- package/dist/plugin/index.js +0 -3
- package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
- package/dist/runner/index.d.ts +2 -9
- package/dist/runner/index.js +2 -9
- package/dist/runner/node/index.d.ts +41 -0
- package/dist/runner/node/index.js +450 -0
- package/dist/runner/web/index.d.ts +30 -0
- package/dist/runner/web/index.js +343 -0
- package/dist/test/context.d.ts +15 -18
- package/dist/test/context.js +52 -57
- package/dist/test/creator.d.ts +20 -19
- package/dist/test/creator.js +69 -57
- package/dist/test/debug.d.ts +15 -0
- package/dist/test/debug.js +205 -0
- package/dist/test/tester.d.ts +1 -0
- package/dist/test/tester.js +44 -6
- package/dist/type.d.ts +94 -64
- package/dist/type.js +8 -12
- package/package.json +22 -61
- package/rstest.d.ts +24 -0
- package/dist/case/diff.d.ts +0 -3
- package/dist/case/diff.js +0 -126
- package/dist/compare/comparator.d.ts +0 -17
- package/dist/compare/comparator.js +0 -52
- package/dist/compare/compare.d.ts +0 -17
- package/dist/compare/compare.js +0 -175
- package/dist/compare/format-code.d.ts +0 -16
- package/dist/compare/format-code.js +0 -239
- package/dist/compare/index.d.ts +0 -5
- package/dist/compare/index.js +0 -21
- package/dist/compare/replace-module-argument.d.ts +0 -1
- package/dist/compare/replace-module-argument.js +0 -8
- package/dist/compare/replace-runtime-module-name.d.ts +0 -1
- package/dist/compare/replace-runtime-module-name.js +0 -71
- package/dist/helper/legacy/FakeDocument.d.ts +0 -54
- package/dist/helper/legacy/FakeDocument.js +0 -278
- package/dist/helper/legacy/createLogger.d.ts +0 -23
- package/dist/helper/legacy/createLogger.js +0 -20
- package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
- package/dist/helper/legacy/supportsImportFn.js +0 -15
- package/dist/helper/legacy/supportsWorker.js +0 -17
- package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
- package/dist/helper/legacy/walkCssTokens.js +0 -761
- package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
- package/dist/helper/legacy/warmup-webpack.js +0 -26
- package/dist/helper/loaders/hot-update.d.ts +0 -1
- package/dist/helper/loaders/hot-update.js +0 -40
- package/dist/helper/plugins/hot-update.d.ts +0 -7
- package/dist/helper/plugins/hot-update.js +0 -40
- package/dist/helper/plugins/index.d.ts +0 -1
- package/dist/helper/plugins/index.js +0 -17
- package/dist/helper/util/currentWatchStep.d.ts +0 -1
- package/dist/helper/util/currentWatchStep.js +0 -2
- package/dist/helper/util/identifier.d.ts +0 -76
- package/dist/helper/util/identifier.js +0 -339
- package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
- package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
- package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/rspack-diff-config-plugin.js +0 -42
- package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/webpack-diff-config-plugin.js +0 -41
- package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
- package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
- package/dist/processor/basic.d.ts +0 -24
- package/dist/processor/basic.js +0 -146
- package/dist/processor/builtin.d.ts +0 -9
- package/dist/processor/builtin.js +0 -171
- package/dist/processor/cache.d.ts +0 -20
- package/dist/processor/cache.js +0 -128
- package/dist/processor/config.d.ts +0 -11
- package/dist/processor/config.js +0 -81
- package/dist/processor/defaults.d.ts +0 -30
- package/dist/processor/defaults.js +0 -72
- package/dist/processor/diagnostic.d.ts +0 -15
- package/dist/processor/diagnostic.js +0 -102
- package/dist/processor/diff.d.ts +0 -30
- package/dist/processor/diff.js +0 -140
- package/dist/processor/error.d.ts +0 -23
- package/dist/processor/error.js +0 -95
- package/dist/processor/hash.d.ts +0 -10
- package/dist/processor/hash.js +0 -63
- package/dist/processor/hook.d.ts +0 -44
- package/dist/processor/hook.js +0 -204
- package/dist/processor/hot-incremental.d.ts +0 -14
- package/dist/processor/hot-incremental.js +0 -43
- package/dist/processor/hot-step.d.ts +0 -18
- package/dist/processor/hot-step.js +0 -304
- package/dist/processor/hot.d.ts +0 -17
- package/dist/processor/hot.js +0 -140
- package/dist/processor/index.d.ts +0 -20
- package/dist/processor/index.js +0 -36
- package/dist/processor/multi.d.ts +0 -17
- package/dist/processor/multi.js +0 -73
- package/dist/processor/normal.d.ts +0 -12
- package/dist/processor/normal.js +0 -150
- package/dist/processor/simple.d.ts +0 -23
- package/dist/processor/simple.js +0 -49
- package/dist/processor/snapshot.d.ts +0 -12
- package/dist/processor/snapshot.js +0 -66
- package/dist/processor/stats-api.d.ts +0 -18
- package/dist/processor/stats-api.js +0 -48
- package/dist/processor/stats.d.ts +0 -18
- package/dist/processor/stats.js +0 -206
- package/dist/processor/treeshaking.d.ts +0 -10
- package/dist/processor/treeshaking.js +0 -33
- package/dist/processor/watch.d.ts +0 -30
- package/dist/processor/watch.js +0 -241
- package/dist/reporter/diff-html.d.ts +0 -15
- package/dist/reporter/diff-html.js +0 -69
- package/dist/reporter/diff-stats.d.ts +0 -24
- package/dist/reporter/diff-stats.js +0 -131
- package/dist/reporter/index.d.ts +0 -2
- package/dist/reporter/index.js +0 -18
- package/dist/runner/basic.d.ts +0 -10
- package/dist/runner/basic.js +0 -63
- package/dist/runner/cache.d.ts +0 -5
- package/dist/runner/cache.js +0 -90
- package/dist/runner/hot-step.d.ts +0 -5
- package/dist/runner/hot-step.js +0 -87
- package/dist/runner/hot.d.ts +0 -5
- package/dist/runner/hot.js +0 -83
- package/dist/runner/multiple.d.ts +0 -11
- package/dist/runner/multiple.js +0 -38
- package/dist/runner/normal.d.ts +0 -5
- package/dist/runner/normal.js +0 -20
- package/dist/runner/runner/basic.d.ts +0 -30
- package/dist/runner/runner/basic.js +0 -107
- package/dist/runner/runner/cjs.d.ts +0 -14
- package/dist/runner/runner/cjs.js +0 -151
- package/dist/runner/runner/esm.d.ts +0 -7
- package/dist/runner/runner/esm.js +0 -125
- package/dist/runner/runner/index.d.ts +0 -8
- package/dist/runner/runner/index.js +0 -24
- package/dist/runner/runner/normal.d.ts +0 -9
- package/dist/runner/runner/normal.js +0 -23
- package/dist/runner/runner/watch.d.ts +0 -16
- package/dist/runner/runner/watch.js +0 -27
- package/dist/runner/runner/web/fake.d.ts +0 -18
- package/dist/runner/runner/web/fake.js +0 -143
- package/dist/runner/runner/web/jsdom.d.ts +0 -26
- package/dist/runner/runner/web/jsdom.js +0 -219
- package/dist/runner/runner/web.d.ts +0 -15
- package/dist/runner/runner/web.js +0 -32
- 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 -60
- package/dist/test/simple.d.ts +0 -5
- package/dist/test/simple.js +0 -43
- package/jest.d.ts +0 -25
- package/template/diff.bundle.css +0 -1
- package/template/diff.bundle.js +0 -144
- package/template/diff.html +0 -14
- package/template/editor.worker.js +0 -1
- /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
- /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
package/dist/test/creator.js
CHANGED
|
@@ -9,38 +9,42 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
9
9
|
const rimraf_1 = require("rimraf");
|
|
10
10
|
const createLazyTestEnv_1 = __importDefault(require("../helper/legacy/createLazyTestEnv"));
|
|
11
11
|
const tester_1 = require("./tester");
|
|
12
|
-
const DEFAULT_MAX_CONCURRENT = 5;
|
|
12
|
+
const DEFAULT_MAX_CONCURRENT = process.env.WASM ? 1 : 5;
|
|
13
13
|
class BasicCaseCreator {
|
|
14
14
|
constructor(_options) {
|
|
15
15
|
this._options = _options;
|
|
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
|
-
?
|
|
36
|
-
: testConfig.concurrent ||
|
|
37
|
-
if (
|
|
39
|
+
? 1
|
|
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,22 +92,24 @@ 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";
|
|
96
|
-
it(description,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
it(description, async () => {
|
|
101
|
+
const e = await stepSignal;
|
|
102
|
+
if (e) {
|
|
103
|
+
throw e;
|
|
104
|
+
}
|
|
105
|
+
}, options.timeout || 300000);
|
|
101
106
|
chain = chain.then(async () => {
|
|
102
107
|
try {
|
|
103
108
|
env.clear();
|
|
104
109
|
await tester.compile();
|
|
105
110
|
await tester.check(env);
|
|
106
111
|
await env.run();
|
|
112
|
+
await tester.after();
|
|
107
113
|
const context = tester.getContext();
|
|
108
114
|
if (!tester.next() && context.hasError()) {
|
|
109
115
|
const errors = context
|
|
@@ -136,22 +142,28 @@ class BasicCaseCreator {
|
|
|
136
142
|
await tester.resume();
|
|
137
143
|
});
|
|
138
144
|
}
|
|
139
|
-
describe(name, tester, testConfig) {
|
|
145
|
+
describe(name, tester, testConfig, options) {
|
|
140
146
|
beforeAll(async () => {
|
|
141
147
|
await tester.prepare();
|
|
142
148
|
});
|
|
143
149
|
let bailout = false;
|
|
144
150
|
for (let index = 0; index < tester.total; index++) {
|
|
145
|
-
const description = typeof
|
|
146
|
-
?
|
|
147
|
-
: `step
|
|
151
|
+
const description = typeof options.description === "function"
|
|
152
|
+
? options.description(name, index)
|
|
153
|
+
: `step [${index}] should pass`;
|
|
148
154
|
it(description, async () => {
|
|
149
155
|
if (bailout) {
|
|
150
156
|
throw `Case "${name}" step ${index + 1} bailout because ${tester.step + 1} failed`;
|
|
151
157
|
}
|
|
152
|
-
await tester.compile();
|
|
153
|
-
await tester.check(env);
|
|
154
158
|
const context = tester.getContext();
|
|
159
|
+
try {
|
|
160
|
+
await tester.compile();
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
bailout = true;
|
|
164
|
+
context.emitError(e);
|
|
165
|
+
}
|
|
166
|
+
await tester.check(env);
|
|
155
167
|
if (!tester.next() && context.hasError()) {
|
|
156
168
|
bailout = true;
|
|
157
169
|
const errors = context
|
|
@@ -160,8 +172,8 @@ class BasicCaseCreator {
|
|
|
160
172
|
.join("\n\n");
|
|
161
173
|
throw new Error(`Case "${name}" failed at step ${tester.step + 1}:\n${errors}`);
|
|
162
174
|
}
|
|
163
|
-
},
|
|
164
|
-
const env = this.createEnv(testConfig);
|
|
175
|
+
}, options.timeout || 60000);
|
|
176
|
+
const env = this.createEnv(testConfig, options);
|
|
165
177
|
}
|
|
166
178
|
afterAll(async () => {
|
|
167
179
|
await tester.resume();
|
|
@@ -205,8 +217,11 @@ class BasicCaseCreator {
|
|
|
205
217
|
try {
|
|
206
218
|
await runFn(fn);
|
|
207
219
|
}
|
|
208
|
-
catch (
|
|
209
|
-
|
|
220
|
+
catch (err) {
|
|
221
|
+
const e = err;
|
|
222
|
+
const message = `Error: ${description} failed:\n${e.message}`;
|
|
223
|
+
e.message = message;
|
|
224
|
+
throw e;
|
|
210
225
|
}
|
|
211
226
|
for (const after of afterTasks) {
|
|
212
227
|
await runFn(after);
|
|
@@ -227,11 +242,11 @@ class BasicCaseCreator {
|
|
|
227
242
|
expect(typeof fn === "function");
|
|
228
243
|
afterTasks.push(fn);
|
|
229
244
|
},
|
|
230
|
-
|
|
245
|
+
rstest
|
|
231
246
|
};
|
|
232
247
|
}
|
|
233
|
-
createEnv(testConfig) {
|
|
234
|
-
if (
|
|
248
|
+
createEnv(testConfig, options) {
|
|
249
|
+
if (options.runner && !testConfig.noTests) {
|
|
235
250
|
return (0, createLazyTestEnv_1.default)(10000);
|
|
236
251
|
}
|
|
237
252
|
return {
|
|
@@ -239,47 +254,46 @@ class BasicCaseCreator {
|
|
|
239
254
|
it,
|
|
240
255
|
beforeEach,
|
|
241
256
|
afterEach,
|
|
242
|
-
|
|
257
|
+
rstest
|
|
243
258
|
};
|
|
244
259
|
}
|
|
245
260
|
clean(folders) {
|
|
246
261
|
for (const f of folders) {
|
|
247
262
|
(0, rimraf_1.rimrafSync)(f);
|
|
248
|
-
node_fs_1.default.mkdirSync(f, { recursive: true });
|
|
249
263
|
}
|
|
250
264
|
}
|
|
251
265
|
skip(name, reason) {
|
|
252
|
-
|
|
253
|
-
it(typeof reason === "string" ? `filtered by ${reason}` : "filtered", () => { });
|
|
254
|
-
});
|
|
266
|
+
it(typeof reason === "string" ? `filtered by ${reason}` : "filtered", () => { });
|
|
255
267
|
}
|
|
256
268
|
readTestConfig(src) {
|
|
257
269
|
const testConfigFile = node_path_1.default.join(src, "test.config.js");
|
|
258
270
|
return node_fs_1.default.existsSync(testConfigFile) ? require(testConfigFile) : {};
|
|
259
271
|
}
|
|
260
|
-
checkSkipped(src, testConfig) {
|
|
272
|
+
checkSkipped(src, testConfig, options) {
|
|
261
273
|
const filterPath = node_path_1.default.join(src, "test.filter.js");
|
|
262
274
|
// no test.filter.js, should not skip
|
|
263
275
|
if (!node_fs_1.default.existsSync(filterPath)) {
|
|
264
276
|
return false;
|
|
265
277
|
}
|
|
266
278
|
// test.filter.js exists, skip if it returns false|string|array
|
|
267
|
-
const filtered = require(filterPath)(
|
|
279
|
+
const filtered = require(filterPath)(options, testConfig);
|
|
268
280
|
if (typeof filtered === "string" || Array.isArray(filtered)) {
|
|
269
281
|
return true;
|
|
270
282
|
}
|
|
271
283
|
return !filtered;
|
|
272
284
|
}
|
|
273
|
-
createTester(name, src, dist, temp, testConfig) {
|
|
285
|
+
createTester(name, src, dist, temp, testConfig, options) {
|
|
274
286
|
return new tester_1.Tester({
|
|
275
287
|
name,
|
|
276
288
|
src,
|
|
277
289
|
dist,
|
|
290
|
+
temp,
|
|
278
291
|
testConfig,
|
|
279
|
-
contextValue:
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
292
|
+
contextValue: options.contextValue,
|
|
293
|
+
runnerCreator: options.runner,
|
|
294
|
+
createContext: options.createContext,
|
|
295
|
+
steps: options.steps({
|
|
296
|
+
...options,
|
|
283
297
|
name,
|
|
284
298
|
src,
|
|
285
299
|
dist,
|
|
@@ -287,25 +301,23 @@ class BasicCaseCreator {
|
|
|
287
301
|
})
|
|
288
302
|
});
|
|
289
303
|
}
|
|
290
|
-
tryRunTask() {
|
|
304
|
+
tryRunTask(concurrent) {
|
|
291
305
|
while (this.tasks.length !== 0 &&
|
|
292
|
-
this.currentConcurrent < this.getMaxConcurrent()) {
|
|
306
|
+
this.currentConcurrent < this.getMaxConcurrent(concurrent)) {
|
|
293
307
|
const [_name, starter] = this.tasks.shift();
|
|
294
308
|
this.currentConcurrent++;
|
|
295
309
|
starter();
|
|
296
310
|
}
|
|
297
311
|
}
|
|
298
|
-
getMaxConcurrent() {
|
|
299
|
-
return typeof
|
|
300
|
-
? this._options.concurrent
|
|
301
|
-
: DEFAULT_MAX_CONCURRENT;
|
|
312
|
+
getMaxConcurrent(concurrent) {
|
|
313
|
+
return typeof concurrent === "number" ? concurrent : DEFAULT_MAX_CONCURRENT;
|
|
302
314
|
}
|
|
303
|
-
registerConcurrentTask(name, starter) {
|
|
315
|
+
registerConcurrentTask(name, starter, concurrent) {
|
|
304
316
|
this.tasks.push([name, starter]);
|
|
305
|
-
this.tryRunTask();
|
|
317
|
+
this.tryRunTask(concurrent);
|
|
306
318
|
return () => {
|
|
307
319
|
this.currentConcurrent--;
|
|
308
|
-
this.tryRunTask();
|
|
320
|
+
this.tryRunTask(concurrent);
|
|
309
321
|
};
|
|
310
322
|
}
|
|
311
323
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ITestContext } from "../type";
|
|
2
|
+
export declare function generateDebugReport(context: ITestContext): void;
|
|
3
|
+
export declare const DEBUG_SCOPES: {
|
|
4
|
+
CompilerOptionsReadConfigFile: string;
|
|
5
|
+
CompilerOptionsFinalOptions: string;
|
|
6
|
+
CreateCompilerInstance: string;
|
|
7
|
+
CreateCompilerSetProperties: string;
|
|
8
|
+
BuildMethod: string;
|
|
9
|
+
BuildError: string;
|
|
10
|
+
BuildWarning: string;
|
|
11
|
+
RunFindBundle: string;
|
|
12
|
+
RunGetRunner: string;
|
|
13
|
+
RunLogs: string;
|
|
14
|
+
RunErrors: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,205 @@
|
|
|
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.DEBUG_SCOPES = void 0;
|
|
7
|
+
exports.generateDebugReport = generateDebugReport;
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const javascript_stringify_1 = require("javascript-stringify");
|
|
11
|
+
const stringify_config_1 = __importDefault(require("../helper/stringify-config"));
|
|
12
|
+
function generateDebugReport(context) {
|
|
13
|
+
const report = `
|
|
14
|
+
## Case Meta
|
|
15
|
+
|
|
16
|
+
${generateCaseMetaPathReport(context)}
|
|
17
|
+
|
|
18
|
+
${generateCaseMetaTestConfigReport(context)}
|
|
19
|
+
|
|
20
|
+
## Compiler Options
|
|
21
|
+
|
|
22
|
+
${generateReadConfigFileReport(context)}
|
|
23
|
+
|
|
24
|
+
${generateFinalOptionsReport(context)}
|
|
25
|
+
|
|
26
|
+
## Create Compiler
|
|
27
|
+
|
|
28
|
+
${generateCreateCompilerInstanceReport(context)}
|
|
29
|
+
|
|
30
|
+
${generateCreateCompilerSetPropertiesReport(context)}
|
|
31
|
+
|
|
32
|
+
## Build
|
|
33
|
+
|
|
34
|
+
${generateBuildMethodReport(context)}
|
|
35
|
+
|
|
36
|
+
${generateBuildErrorReport(context)}
|
|
37
|
+
|
|
38
|
+
${generateBuildWarningReport(context)}
|
|
39
|
+
|
|
40
|
+
## Run
|
|
41
|
+
|
|
42
|
+
${generateRunFindBundleReport(context)}
|
|
43
|
+
|
|
44
|
+
${generateRunGetRunnerReport(context)}
|
|
45
|
+
|
|
46
|
+
${generateRunLogsReport(context)}
|
|
47
|
+
|
|
48
|
+
${generateRunErrorsReport(context)}
|
|
49
|
+
|
|
50
|
+
`;
|
|
51
|
+
const dist = context.getDist("debug.md");
|
|
52
|
+
fs_extra_1.default.ensureDirSync(node_path_1.default.dirname(dist));
|
|
53
|
+
fs_extra_1.default.writeFileSync(dist, report);
|
|
54
|
+
}
|
|
55
|
+
function generateCaseMetaPathReport(context) {
|
|
56
|
+
return `
|
|
57
|
+
### Case Path
|
|
58
|
+
|
|
59
|
+
- Source: ${context.getSource()}
|
|
60
|
+
- Dist: ${context.getDist()}
|
|
61
|
+
- Temp: ${context.getTemp()}
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
function generateCaseMetaTestConfigReport(context) {
|
|
65
|
+
return `
|
|
66
|
+
### Test Config
|
|
67
|
+
|
|
68
|
+
\`\`\`js
|
|
69
|
+
// ${node_path_1.default.resolve(context.getSource(), "./test.config.js")}
|
|
70
|
+
${(0, javascript_stringify_1.stringify)(context.getTestConfig(), null, 2)}
|
|
71
|
+
\`\`\`
|
|
72
|
+
`;
|
|
73
|
+
}
|
|
74
|
+
function generateReadConfigFileReport(context) {
|
|
75
|
+
const configFileInfo = context.getValue(exports.DEBUG_SCOPES.CompilerOptionsReadConfigFile);
|
|
76
|
+
if (!configFileInfo)
|
|
77
|
+
return "";
|
|
78
|
+
return `
|
|
79
|
+
### Read Config File
|
|
80
|
+
|
|
81
|
+
\`\`\`js
|
|
82
|
+
// ${configFileInfo.file}
|
|
83
|
+
${(0, stringify_config_1.default)(configFileInfo.config)}
|
|
84
|
+
\`\`\`
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
function generateFinalOptionsReport(context) {
|
|
88
|
+
const finalOptions = context.getCompiler().getOptions();
|
|
89
|
+
return `
|
|
90
|
+
### Final Options
|
|
91
|
+
|
|
92
|
+
\`\`\`js
|
|
93
|
+
${(0, stringify_config_1.default)(finalOptions)}
|
|
94
|
+
\`\`\`
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
function generateCreateCompilerInstanceReport(context) {
|
|
98
|
+
const instanceInfo = context.getValue(exports.DEBUG_SCOPES.CreateCompilerInstance);
|
|
99
|
+
if (!instanceInfo)
|
|
100
|
+
return "";
|
|
101
|
+
return `
|
|
102
|
+
### Create Compiler Instance
|
|
103
|
+
|
|
104
|
+
- Rspack Path: ${instanceInfo.path}
|
|
105
|
+
- Callback Mode: ${instanceInfo.mode}
|
|
106
|
+
`;
|
|
107
|
+
}
|
|
108
|
+
function generateCreateCompilerSetPropertiesReport(context) {
|
|
109
|
+
const setPropertiesInfo = context.getValue(exports.DEBUG_SCOPES.CreateCompilerSetProperties);
|
|
110
|
+
if (!setPropertiesInfo || setPropertiesInfo.length === 0)
|
|
111
|
+
return "";
|
|
112
|
+
return `
|
|
113
|
+
### Set Properties
|
|
114
|
+
|
|
115
|
+
${setPropertiesInfo.map(p => `- ${p}`).join("\n")}
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
function generateBuildMethodReport(context) {
|
|
119
|
+
const buildMethod = context.getValue(exports.DEBUG_SCOPES.BuildMethod);
|
|
120
|
+
if (!buildMethod)
|
|
121
|
+
return "";
|
|
122
|
+
return `
|
|
123
|
+
### Build Method
|
|
124
|
+
|
|
125
|
+
- Method: \`compiler.${buildMethod.method}()\`
|
|
126
|
+
${buildMethod.options ? `- Options:\n\`\`\`js\n${(0, javascript_stringify_1.stringify)(buildMethod.options, null, 2)}\n\`\`\`` : ""}
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
function generateBuildErrorReport(context) {
|
|
130
|
+
const buildError = context.getValue(exports.DEBUG_SCOPES.BuildError);
|
|
131
|
+
if (!buildError)
|
|
132
|
+
return "";
|
|
133
|
+
return `
|
|
134
|
+
### Build Error
|
|
135
|
+
|
|
136
|
+
type: ${buildError.type}
|
|
137
|
+
|
|
138
|
+
${buildError.errors.map(e => `\`\`\`\n// message:\n${e.message}\n// stack:\n${e.stack}\n\`\`\``).join("\n\n")}
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
function generateBuildWarningReport(context) {
|
|
142
|
+
const buildWarning = context.getValue(exports.DEBUG_SCOPES.BuildWarning);
|
|
143
|
+
if (!buildWarning)
|
|
144
|
+
return "";
|
|
145
|
+
return `
|
|
146
|
+
### Build Warning
|
|
147
|
+
|
|
148
|
+
${buildWarning.map(w => `\`\`\`\n// message:\n${w.message}\n// stack:\n${w.stack}\n\`\`\``).join("\n\n")}
|
|
149
|
+
`;
|
|
150
|
+
}
|
|
151
|
+
function generateRunFindBundleReport(context) {
|
|
152
|
+
const runFindBundle = context.getValue(exports.DEBUG_SCOPES.RunFindBundle);
|
|
153
|
+
if (!runFindBundle)
|
|
154
|
+
return "";
|
|
155
|
+
return `
|
|
156
|
+
### Find Bundle
|
|
157
|
+
|
|
158
|
+
${runFindBundle.map(b => `- ${context.getDist(b)}`).join("\n")}
|
|
159
|
+
`;
|
|
160
|
+
}
|
|
161
|
+
function generateRunGetRunnerReport(context) {
|
|
162
|
+
const getRunnerInfo = context.getValue(exports.DEBUG_SCOPES.RunGetRunner);
|
|
163
|
+
if (!getRunnerInfo)
|
|
164
|
+
return "";
|
|
165
|
+
return `
|
|
166
|
+
### Get Runner
|
|
167
|
+
|
|
168
|
+
${Object.entries(getRunnerInfo)
|
|
169
|
+
.map(([file, info]) => `- ${file}: ${info.runnerKey} (Reused: ${info.reused}, Type: \`${info.runnerType}\`)`)
|
|
170
|
+
.join("\n")}
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
function generateRunLogsReport(context) {
|
|
174
|
+
const runLogs = context.getValue(exports.DEBUG_SCOPES.RunLogs);
|
|
175
|
+
if (!runLogs)
|
|
176
|
+
return "";
|
|
177
|
+
return `
|
|
178
|
+
### Run Logs
|
|
179
|
+
|
|
180
|
+
${runLogs.map(l => `- ${l}`).join("\n")}
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
function generateRunErrorsReport(context) {
|
|
184
|
+
const runErrors = context.getValue(exports.DEBUG_SCOPES.RunErrors);
|
|
185
|
+
if (!runErrors)
|
|
186
|
+
return "";
|
|
187
|
+
return `
|
|
188
|
+
### Run Errors
|
|
189
|
+
|
|
190
|
+
${runErrors.map(e => `\`\`\`\n// message:\n${e.message}\n// stack:\n${e.stack}\n\`\`\``).join("\n\n")}
|
|
191
|
+
`;
|
|
192
|
+
}
|
|
193
|
+
exports.DEBUG_SCOPES = {
|
|
194
|
+
CompilerOptionsReadConfigFile: "compiler-options:read-config-file",
|
|
195
|
+
CompilerOptionsFinalOptions: "compiler-options:final-options",
|
|
196
|
+
CreateCompilerInstance: "create-compiler:instance",
|
|
197
|
+
CreateCompilerSetProperties: "create-compiler:set-properties",
|
|
198
|
+
BuildMethod: "build:method",
|
|
199
|
+
BuildError: "build:error",
|
|
200
|
+
BuildWarning: "build:warning",
|
|
201
|
+
RunFindBundle: "run:find-bundle",
|
|
202
|
+
RunGetRunner: "run:get-runner",
|
|
203
|
+
RunLogs: "run:logs",
|
|
204
|
+
RunErrors: "run:errors"
|
|
205
|
+
};
|
package/dist/test/tester.d.ts
CHANGED
package/dist/test/tester.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Tester = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
4
8
|
const context_1 = require("./context");
|
|
9
|
+
const debug_1 = require("./debug");
|
|
5
10
|
class Tester {
|
|
6
11
|
constructor(config) {
|
|
7
12
|
this.config = config;
|
|
8
13
|
this.steps = [];
|
|
9
14
|
this.step = 0;
|
|
10
15
|
this.total = 0;
|
|
11
|
-
this.context =
|
|
16
|
+
this.context = config.createContext
|
|
17
|
+
? config.createContext(config)
|
|
18
|
+
: new context_1.TestContext(config);
|
|
12
19
|
this.steps = config.steps || [];
|
|
13
20
|
this.step = 0;
|
|
14
21
|
this.total = config.steps?.length || 0;
|
|
15
22
|
if (config.contextValue) {
|
|
16
23
|
for (const [key, value] of Array.from(Object.entries(config.contextValue))) {
|
|
17
|
-
this.context.setValue(
|
|
24
|
+
this.context.setValue(key, value);
|
|
18
25
|
}
|
|
19
26
|
}
|
|
20
27
|
}
|
|
@@ -22,6 +29,11 @@ class Tester {
|
|
|
22
29
|
return this.context;
|
|
23
30
|
}
|
|
24
31
|
async prepare() {
|
|
32
|
+
fs_extra_1.default.mkdirSync(this.context.getDist(), { recursive: true });
|
|
33
|
+
const tempDir = this.context.getTemp();
|
|
34
|
+
if (tempDir) {
|
|
35
|
+
fs_extra_1.default.mkdirSync(tempDir, { recursive: true });
|
|
36
|
+
}
|
|
25
37
|
for (const i of this.steps) {
|
|
26
38
|
if (typeof i.beforeAll === "function") {
|
|
27
39
|
await i.beforeAll(this.context);
|
|
@@ -44,6 +56,11 @@ class Tester {
|
|
|
44
56
|
if (!currentStep)
|
|
45
57
|
return;
|
|
46
58
|
await this.runCheckStepMethods(currentStep, env, this.context.hasError() ? ["check"] : ["run", "check"]);
|
|
59
|
+
}
|
|
60
|
+
async after() {
|
|
61
|
+
const currentStep = this.steps[this.step];
|
|
62
|
+
if (!currentStep)
|
|
63
|
+
return;
|
|
47
64
|
await this.runStepMethods(currentStep, ["after"], true);
|
|
48
65
|
}
|
|
49
66
|
next() {
|
|
@@ -62,6 +79,20 @@ class Tester {
|
|
|
62
79
|
await i.afterAll(this.context);
|
|
63
80
|
}
|
|
64
81
|
}
|
|
82
|
+
try {
|
|
83
|
+
await this.context.closeCompiler();
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
console.warn(`Error occured while closing compilers of '${this.config.name}':\n${e.stack}`);
|
|
87
|
+
}
|
|
88
|
+
if (__DEBUG__) {
|
|
89
|
+
try {
|
|
90
|
+
(0, debug_1.generateDebugReport)(this.context);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
console.warn(`Generate debug report failed: ${e.message}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
65
96
|
}
|
|
66
97
|
async runStepMethods(step, methods, force = false) {
|
|
67
98
|
for (const i of methods) {
|
|
@@ -72,17 +103,24 @@ class Tester {
|
|
|
72
103
|
await step[i](this.context);
|
|
73
104
|
}
|
|
74
105
|
catch (e) {
|
|
75
|
-
this.context.emitError(
|
|
106
|
+
this.context.emitError(e);
|
|
76
107
|
}
|
|
77
108
|
}
|
|
78
109
|
}
|
|
79
110
|
}
|
|
80
111
|
async runCheckStepMethods(step, env, methods) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
112
|
+
try {
|
|
113
|
+
for (const i of methods) {
|
|
114
|
+
if (typeof step[i] === "function") {
|
|
115
|
+
await step[i](env, this.context);
|
|
116
|
+
}
|
|
84
117
|
}
|
|
85
118
|
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
const errors = this.context.getError();
|
|
121
|
+
console.error(new Error([...errors, e].map(e => e.message).join("\n")));
|
|
122
|
+
throw e;
|
|
123
|
+
}
|
|
86
124
|
}
|
|
87
125
|
}
|
|
88
126
|
exports.Tester = Tester;
|