@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/case/hot-step.js
CHANGED
|
@@ -8,8 +8,9 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const helper_1 = require("../helper");
|
|
10
10
|
const placeholder_1 = require("../helper/expect/placeholder");
|
|
11
|
-
const runner_1 = require("../runner");
|
|
12
11
|
const creator_1 = require("../test/creator");
|
|
12
|
+
const type_1 = require("../type");
|
|
13
|
+
const common_1 = require("./common");
|
|
13
14
|
const hot_1 = require("./hot");
|
|
14
15
|
const NOOP_SET = new Set();
|
|
15
16
|
const escapeLocalName = (str) => str.split(/[-<>:"/|?*.]/).join("_");
|
|
@@ -261,7 +262,7 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
|
|
|
261
262
|
: Array.from(entry.runtime);
|
|
262
263
|
}
|
|
263
264
|
}
|
|
264
|
-
const compiler =
|
|
265
|
+
const compiler = context.getCompiler(name, type_1.ECompilerType.Rspack);
|
|
265
266
|
const compilerOptions = compiler.getOptions();
|
|
266
267
|
matchStepSnapshot(env, context, hotUpdateContext.updateIndex, compilerOptions, statsJson, runtime);
|
|
267
268
|
hashes.push(stats.hash);
|
|
@@ -269,10 +270,10 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
|
|
|
269
270
|
context.setValue(name, "hotUpdateStepErrorChecker", (_, stats, runtime) => {
|
|
270
271
|
hashes.push(stats.hash);
|
|
271
272
|
});
|
|
272
|
-
await originRun
|
|
273
|
+
await originRun(env, context);
|
|
273
274
|
};
|
|
274
275
|
processor.check = async function (env, context) {
|
|
275
|
-
const compiler =
|
|
276
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
276
277
|
const stats = compiler.getStats();
|
|
277
278
|
if (!stats || !stats.hash) {
|
|
278
279
|
env.expect(false);
|
|
@@ -314,7 +315,10 @@ function getCreator(target) {
|
|
|
314
315
|
steps: ({ name, target }) => [
|
|
315
316
|
createHotStepProcessor(name, target)
|
|
316
317
|
],
|
|
317
|
-
runner:
|
|
318
|
+
runner: {
|
|
319
|
+
key: (context, name, file) => name,
|
|
320
|
+
runner: hot_1.createHotRunner
|
|
321
|
+
},
|
|
318
322
|
concurrent: true
|
|
319
323
|
}));
|
|
320
324
|
}
|
package/dist/case/hot.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ECompilerType, type TCompilerOptions, type THotUpdateContext } from "../type";
|
|
1
|
+
import { type ECompilerType, type ITestContext, type ITestEnv, type ITestProcessor, type ITestRunner, type TCompilerOptions, type THotUpdateContext } from "../type";
|
|
3
2
|
type TTarget = TCompilerOptions<ECompilerType.Rspack>["target"];
|
|
4
|
-
type THotProcessor = BasicProcessor<ECompilerType.Rspack> & {
|
|
5
|
-
hotUpdateContext: THotUpdateContext;
|
|
6
|
-
};
|
|
7
3
|
export declare function createHotProcessor(name: string, target: TTarget, incremental?: boolean): THotProcessor;
|
|
8
4
|
export declare function createHotCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
|
5
|
+
type THotProcessor = ITestProcessor & {
|
|
6
|
+
hotUpdateContext: THotUpdateContext;
|
|
7
|
+
};
|
|
8
|
+
export declare function createHotRunner<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
|
|
9
9
|
export {};
|
package/dist/case/hot.js
CHANGED
|
@@ -5,16 +5,84 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createHotProcessor = createHotProcessor;
|
|
7
7
|
exports.createHotCase = createHotCase;
|
|
8
|
+
exports.createHotRunner = createHotRunner;
|
|
8
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
10
|
const core_1 = __importDefault(require("@rspack/core"));
|
|
10
11
|
const helper_1 = require("../helper");
|
|
12
|
+
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
11
13
|
const plugins_1 = require("../helper/plugins");
|
|
12
14
|
const plugin_1 = require("../plugin");
|
|
13
|
-
const processor_1 = require("../processor");
|
|
14
15
|
const runner_1 = require("../runner");
|
|
15
16
|
const creator_1 = require("../test/creator");
|
|
16
17
|
const type_1 = require("../type");
|
|
18
|
+
const common_1 = require("./common");
|
|
19
|
+
const runner_2 = require("./runner");
|
|
17
20
|
const creators = new Map();
|
|
21
|
+
function createHotProcessor(name, target, incremental = false) {
|
|
22
|
+
const hotUpdateContext = {
|
|
23
|
+
updateIndex: 0,
|
|
24
|
+
totalUpdates: 1,
|
|
25
|
+
changedFiles: []
|
|
26
|
+
};
|
|
27
|
+
const processor = {
|
|
28
|
+
config: async (context) => {
|
|
29
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
30
|
+
let options = defaultOptions(context, target, hotUpdateContext);
|
|
31
|
+
options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"], options);
|
|
32
|
+
overrideOptions(context, options, target, hotUpdateContext);
|
|
33
|
+
if (incremental) {
|
|
34
|
+
options.experiments ??= {};
|
|
35
|
+
options.experiments.incremental ??= "advance-silent";
|
|
36
|
+
}
|
|
37
|
+
compiler.setOptions(options);
|
|
38
|
+
},
|
|
39
|
+
compiler: async (context) => {
|
|
40
|
+
await (0, common_1.compiler)(context, name);
|
|
41
|
+
},
|
|
42
|
+
build: async (context) => {
|
|
43
|
+
await (0, common_1.build)(context, name);
|
|
44
|
+
},
|
|
45
|
+
run: async (env, context) => {
|
|
46
|
+
context.setValue(name, "hotUpdateContext", hotUpdateContext);
|
|
47
|
+
await (0, common_1.run)(env, context, name, context => findBundle(context, name, target, hotUpdateContext));
|
|
48
|
+
},
|
|
49
|
+
check: async (env, context) => {
|
|
50
|
+
await (0, common_1.check)(env, context, name);
|
|
51
|
+
},
|
|
52
|
+
afterAll: async (context) => {
|
|
53
|
+
if (context.getTestConfig().checkSteps === false) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (hotUpdateContext.updateIndex + 1 !== hotUpdateContext.totalUpdates) {
|
|
57
|
+
throw new Error(`Should run all hot steps (${hotUpdateContext.updateIndex + 1} / ${hotUpdateContext.totalUpdates}): ${name}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
processor.hotUpdateContext = hotUpdateContext;
|
|
62
|
+
return processor;
|
|
63
|
+
}
|
|
64
|
+
function getCreator(target) {
|
|
65
|
+
if (!creators.has(target)) {
|
|
66
|
+
creators.set(target, new creator_1.BasicCaseCreator({
|
|
67
|
+
clean: true,
|
|
68
|
+
describe: true,
|
|
69
|
+
target,
|
|
70
|
+
steps: ({ name, target }) => [
|
|
71
|
+
createHotProcessor(name, target)
|
|
72
|
+
],
|
|
73
|
+
runner: {
|
|
74
|
+
key: (context, name, file) => name,
|
|
75
|
+
runner: createHotRunner
|
|
76
|
+
},
|
|
77
|
+
concurrent: true
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
return creators.get(target);
|
|
81
|
+
}
|
|
82
|
+
function createHotCase(name, src, dist, target) {
|
|
83
|
+
const creator = getCreator(target);
|
|
84
|
+
creator.create(name, src, dist);
|
|
85
|
+
}
|
|
18
86
|
function defaultOptions(context, target, updateOptions) {
|
|
19
87
|
const options = {
|
|
20
88
|
context: context.getSource(),
|
|
@@ -110,63 +178,82 @@ function findBundle(context, name, target, updateOptions) {
|
|
|
110
178
|
}
|
|
111
179
|
return [...prefiles, ...files];
|
|
112
180
|
}
|
|
113
|
-
function
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
181
|
+
function createHotRunner(context, name, file, env) {
|
|
182
|
+
const compiler = context.getCompiler(name);
|
|
183
|
+
const compilerOptions = compiler.getOptions();
|
|
184
|
+
const testConfig = context.getTestConfig();
|
|
185
|
+
const source = context.getSource();
|
|
186
|
+
const dist = context.getDist();
|
|
187
|
+
const hotUpdateContext = context.getValue(name, "hotUpdateContext");
|
|
188
|
+
const next = async (callback) => {
|
|
189
|
+
const usePromise = typeof callback === "function";
|
|
190
|
+
try {
|
|
191
|
+
hotUpdateContext.updateIndex++;
|
|
192
|
+
const stats = await compiler.build();
|
|
193
|
+
if (!stats) {
|
|
194
|
+
throw new Error("Should generate stats during build");
|
|
195
|
+
}
|
|
196
|
+
const jsonStats = stats.toJson({
|
|
197
|
+
// errorDetails: true
|
|
198
|
+
});
|
|
199
|
+
const compilerOptions = compiler.getOptions();
|
|
200
|
+
const checker = context.getValue(name, jsonStats.errors?.length
|
|
201
|
+
? "hotUpdateStepErrorChecker"
|
|
202
|
+
: "hotUpdateStepChecker");
|
|
203
|
+
if (checker) {
|
|
204
|
+
checker(hotUpdateContext, stats, runner.getGlobal("__HMR_UPDATED_RUNTIME__"));
|
|
205
|
+
}
|
|
206
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${hotUpdateContext.updateIndex}`, "Error", compilerOptions);
|
|
207
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${hotUpdateContext.updateIndex}`, "Warning", compilerOptions);
|
|
208
|
+
if (usePromise) {
|
|
209
|
+
// old callback style hmr cases
|
|
210
|
+
callback(null, jsonStats);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
// new promise style hmr cases
|
|
214
|
+
return jsonStats;
|
|
132
215
|
}
|
|
133
|
-
},
|
|
134
|
-
findBundle(context, options) {
|
|
135
|
-
return findBundle(context, name, target, hotUpdateContext);
|
|
136
|
-
},
|
|
137
|
-
async compiler(context, compiler) {
|
|
138
|
-
context.setValue(name, "hotUpdateContext", hotUpdateContext);
|
|
139
216
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
217
|
+
catch (e) {
|
|
218
|
+
if (usePromise) {
|
|
219
|
+
callback(e);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
throw e;
|
|
223
|
+
}
|
|
147
224
|
}
|
|
148
|
-
|
|
149
|
-
|
|
225
|
+
};
|
|
226
|
+
const nextHMR = async (m, options) => {
|
|
227
|
+
const jsonStats = await next();
|
|
228
|
+
const updatedModules = await m.hot.check(options || true);
|
|
229
|
+
if (!updatedModules) {
|
|
230
|
+
throw new Error("No update available");
|
|
150
231
|
}
|
|
232
|
+
return jsonStats;
|
|
151
233
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
234
|
+
const runner = new runner_1.WebRunner({
|
|
235
|
+
dom: context.getValue(name, "documentType") || type_1.EDocumentType.JSDOM,
|
|
236
|
+
env,
|
|
237
|
+
stats: (0, runner_2.cachedStats)(context, name),
|
|
238
|
+
name: name,
|
|
239
|
+
runInNewContext: false,
|
|
240
|
+
testConfig: {
|
|
241
|
+
documentType: testConfig.documentType || type_1.EDocumentType.Fake,
|
|
242
|
+
...testConfig,
|
|
243
|
+
moduleScope(ms, stats, options) {
|
|
244
|
+
const moduleScope = ms;
|
|
245
|
+
if (typeof testConfig.moduleScope === "function") {
|
|
246
|
+
testConfig.moduleScope(moduleScope, stats, compilerOptions);
|
|
247
|
+
}
|
|
248
|
+
moduleScope.NEXT = next;
|
|
249
|
+
moduleScope.NEXT_HMR = nextHMR;
|
|
250
|
+
return moduleScope;
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
cachable: true,
|
|
254
|
+
source,
|
|
255
|
+
dist,
|
|
256
|
+
compilerOptions
|
|
257
|
+
});
|
|
258
|
+
return runner;
|
|
172
259
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ECompilerType, type TCompilerOptions } from "../type";
|
|
1
|
+
import { type ECompilerType, type TCompilerOptions } from "../type";
|
|
2
2
|
export declare function createHotIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], webpackCases: boolean): void;
|
|
3
3
|
export type WatchIncrementalOptions = {
|
|
4
4
|
ignoreNotFriendlyForIncrementalWarnings?: boolean;
|
package/dist/case/incremental.js
CHANGED
|
@@ -7,11 +7,10 @@ exports.createHotIncrementalCase = createHotIncrementalCase;
|
|
|
7
7
|
exports.createWatchIncrementalCase = createWatchIncrementalCase;
|
|
8
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
-
const watch_1 = require("../processor/watch");
|
|
11
|
-
const runner_1 = require("../runner");
|
|
12
10
|
const creator_1 = require("../test/creator");
|
|
13
11
|
const type_1 = require("../type");
|
|
14
12
|
const hot_1 = require("./hot");
|
|
13
|
+
const watch_1 = require("./watch");
|
|
15
14
|
const hotCreators = new Map();
|
|
16
15
|
function createHotIncrementalProcessor(name, target, webpackCases) {
|
|
17
16
|
const processor = (0, hot_1.createHotProcessor)(name, target, true);
|
|
@@ -21,7 +20,7 @@ function createHotIncrementalProcessor(name, target, webpackCases) {
|
|
|
21
20
|
const originalAfterAll = processor.afterAll;
|
|
22
21
|
processor.afterAll = async function (context) {
|
|
23
22
|
try {
|
|
24
|
-
await originalAfterAll
|
|
23
|
+
await originalAfterAll?.(context);
|
|
25
24
|
}
|
|
26
25
|
catch (e) {
|
|
27
26
|
const isFake = context.getValue(name, "documentType") === type_1.EDocumentType.Fake;
|
|
@@ -42,7 +41,10 @@ function getHotCreator(target, webpackCases) {
|
|
|
42
41
|
steps: ({ name, target }) => [
|
|
43
42
|
createHotIncrementalProcessor(name, target, webpackCases)
|
|
44
43
|
],
|
|
45
|
-
runner:
|
|
44
|
+
runner: {
|
|
45
|
+
key: (context, name, file) => name,
|
|
46
|
+
runner: hot_1.createHotRunner
|
|
47
|
+
},
|
|
46
48
|
concurrent: true
|
|
47
49
|
}));
|
|
48
50
|
}
|
|
@@ -58,7 +60,10 @@ function getWatchCreator(options) {
|
|
|
58
60
|
if (!watchCreators.has(key)) {
|
|
59
61
|
watchCreators.set(key, new creator_1.BasicCaseCreator({
|
|
60
62
|
clean: true,
|
|
61
|
-
runner:
|
|
63
|
+
runner: {
|
|
64
|
+
key: watch_1.getWatchRunnerKey,
|
|
65
|
+
runner: watch_1.createWatchRunner
|
|
66
|
+
},
|
|
62
67
|
description: (name, index) => {
|
|
63
68
|
return index === 0
|
|
64
69
|
? `${name} should compile`
|
|
@@ -70,37 +75,17 @@ function getWatchCreator(options) {
|
|
|
70
75
|
const runs = node_fs_1.default
|
|
71
76
|
.readdirSync(src)
|
|
72
77
|
.sort()
|
|
73
|
-
.filter(name =>
|
|
74
|
-
return node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory();
|
|
75
|
-
})
|
|
78
|
+
.filter(name => node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory())
|
|
76
79
|
.map(name => ({ name }));
|
|
77
80
|
return runs.map((run, index) => index === 0
|
|
78
|
-
?
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
experiments: {
|
|
88
|
-
incremental: "advance"
|
|
89
|
-
},
|
|
90
|
-
ignoreWarnings: options.ignoreNotFriendlyForIncrementalWarnings
|
|
91
|
-
? [/is not friendly for incremental/]
|
|
92
|
-
: undefined
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}, watchState)
|
|
96
|
-
: new watch_1.WatchStepProcessor({
|
|
97
|
-
name,
|
|
98
|
-
stepName: run.name,
|
|
99
|
-
tempDir: temp,
|
|
100
|
-
runable: true,
|
|
101
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
102
|
-
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
103
|
-
}, watchState));
|
|
81
|
+
? (0, watch_1.createWatchInitialProcessor)(name, temp, run.name, watchState, {
|
|
82
|
+
incremental: true,
|
|
83
|
+
ignoreNotFriendlyForIncrementalWarnings: options.ignoreNotFriendlyForIncrementalWarnings
|
|
84
|
+
})
|
|
85
|
+
: (0, watch_1.createWatchStepProcessor)(name, temp, run.name, watchState, {
|
|
86
|
+
incremental: true,
|
|
87
|
+
ignoreNotFriendlyForIncrementalWarnings: options.ignoreNotFriendlyForIncrementalWarnings
|
|
88
|
+
}));
|
|
104
89
|
},
|
|
105
90
|
concurrent: true
|
|
106
91
|
}));
|
|
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createNativeWatcher = createNativeWatcher;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const watch_1 = require("../processor/watch");
|
|
10
|
-
const runner_1 = require("../runner");
|
|
11
9
|
const creator_1 = require("../test/creator");
|
|
12
|
-
const
|
|
10
|
+
const watch_1 = require("./watch");
|
|
13
11
|
const creator = new creator_1.BasicCaseCreator({
|
|
14
12
|
clean: true,
|
|
15
|
-
runner:
|
|
13
|
+
runner: {
|
|
14
|
+
key: watch_1.getWatchRunnerKey,
|
|
15
|
+
runner: watch_1.createWatchRunner
|
|
16
|
+
},
|
|
16
17
|
description: (name, index) => {
|
|
17
18
|
return index === 0
|
|
18
19
|
? `${name} should compile`
|
|
@@ -24,29 +25,15 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
24
25
|
const runs = node_fs_1.default
|
|
25
26
|
.readdirSync(src)
|
|
26
27
|
.sort()
|
|
27
|
-
.filter(name =>
|
|
28
|
-
return node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory();
|
|
29
|
-
})
|
|
28
|
+
.filter(name => node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory())
|
|
30
29
|
.map(name => ({ name }));
|
|
31
30
|
return runs.map((run, index) => index === 0
|
|
32
|
-
?
|
|
33
|
-
name,
|
|
34
|
-
stepName: run.name,
|
|
35
|
-
tempDir: temp,
|
|
36
|
-
runable: true,
|
|
37
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
38
|
-
configFiles: ["rspack.config.js", "webpack.config.js"],
|
|
31
|
+
? (0, watch_1.createWatchInitialProcessor)(name, temp, run.name, watchState, {
|
|
39
32
|
nativeWatcher: true
|
|
40
|
-
}
|
|
41
|
-
:
|
|
42
|
-
name,
|
|
43
|
-
stepName: run.name,
|
|
44
|
-
tempDir: temp,
|
|
45
|
-
runable: true,
|
|
46
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
47
|
-
configFiles: ["rspack.config.js", "webpack.config.js"],
|
|
33
|
+
})
|
|
34
|
+
: (0, watch_1.createWatchStepProcessor)(name, temp, run.name, watchState, {
|
|
48
35
|
nativeWatcher: true
|
|
49
|
-
}
|
|
36
|
+
}));
|
|
50
37
|
},
|
|
51
38
|
concurrent: true
|
|
52
39
|
});
|
package/dist/case/normal.js
CHANGED
|
@@ -8,11 +8,54 @@ exports.createHotNormalCase = createHotNormalCase;
|
|
|
8
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const core_1 = require("@rspack/core");
|
|
11
|
-
const processor_1 = require("../processor");
|
|
12
|
-
const runner_1 = require("../runner");
|
|
13
11
|
const creator_1 = require("../test/creator");
|
|
14
|
-
const
|
|
12
|
+
const common_1 = require("./common");
|
|
13
|
+
const runner_1 = require("./runner");
|
|
15
14
|
const NORMAL_CASES_ROOT = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/normalCases");
|
|
15
|
+
const createCaseOptions = (hot) => {
|
|
16
|
+
return {
|
|
17
|
+
clean: true,
|
|
18
|
+
describe: false,
|
|
19
|
+
steps: ({ name }) => [
|
|
20
|
+
{
|
|
21
|
+
config: async (context) => {
|
|
22
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
23
|
+
let options = defaultOptions(context, {
|
|
24
|
+
plugins: hot ? [new core_1.HotModuleReplacementPlugin()] : []
|
|
25
|
+
});
|
|
26
|
+
options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"], options);
|
|
27
|
+
overrideOptions(context, options);
|
|
28
|
+
compiler.setOptions(options);
|
|
29
|
+
},
|
|
30
|
+
compiler: async (context) => {
|
|
31
|
+
await (0, common_1.compiler)(context, name);
|
|
32
|
+
},
|
|
33
|
+
build: async (context) => {
|
|
34
|
+
await (0, common_1.build)(context, name);
|
|
35
|
+
},
|
|
36
|
+
run: async (env, context) => {
|
|
37
|
+
await (0, common_1.run)(env, context, name, findBundle);
|
|
38
|
+
},
|
|
39
|
+
check: async (env, context) => {
|
|
40
|
+
await (0, common_1.check)(env, context, name);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
runner: {
|
|
45
|
+
key: (context, name, file) => name,
|
|
46
|
+
runner: runner_1.createRunner
|
|
47
|
+
},
|
|
48
|
+
concurrent: true
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const creator = new creator_1.BasicCaseCreator(createCaseOptions(false));
|
|
52
|
+
function createNormalCase(name, src, dist) {
|
|
53
|
+
creator.create(name, src, dist);
|
|
54
|
+
}
|
|
55
|
+
const hotCreator = new creator_1.BasicCaseCreator(createCaseOptions(true));
|
|
56
|
+
function createHotNormalCase(name, src, dist) {
|
|
57
|
+
hotCreator.create(name, src, dist);
|
|
58
|
+
}
|
|
16
59
|
function findBundle(context, options) {
|
|
17
60
|
const testConfig = context.getTestConfig();
|
|
18
61
|
if (typeof testConfig.findBundle === "function") {
|
|
@@ -158,31 +201,3 @@ function overrideOptions(context, options) {
|
|
|
158
201
|
};
|
|
159
202
|
}
|
|
160
203
|
}
|
|
161
|
-
const createCaseOptions = (hot) => {
|
|
162
|
-
return {
|
|
163
|
-
clean: true,
|
|
164
|
-
describe: false,
|
|
165
|
-
steps: ({ name }) => [
|
|
166
|
-
new processor_1.BasicProcessor({
|
|
167
|
-
name,
|
|
168
|
-
findBundle,
|
|
169
|
-
defaultOptions: context => defaultOptions(context, {
|
|
170
|
-
plugins: hot ? [new core_1.HotModuleReplacementPlugin()] : []
|
|
171
|
-
}),
|
|
172
|
-
overrideOptions,
|
|
173
|
-
runable: true,
|
|
174
|
-
compilerType: type_1.ECompilerType.Rspack
|
|
175
|
-
})
|
|
176
|
-
],
|
|
177
|
-
runner: runner_1.BasicRunnerFactory,
|
|
178
|
-
concurrent: true
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
const creator = new creator_1.BasicCaseCreator(createCaseOptions(false));
|
|
182
|
-
function createNormalCase(name, src, dist) {
|
|
183
|
-
creator.create(name, src, dist);
|
|
184
|
-
}
|
|
185
|
-
const hotCreator = new creator_1.BasicCaseCreator(createCaseOptions(true));
|
|
186
|
-
function createHotNormalCase(name, src, dist) {
|
|
187
|
-
hotCreator.create(name, src, dist);
|
|
188
|
-
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ECompilerType, type ITestContext, type ITestEnv, type ITestRunner, type TCompilerStatsCompilation } from "../type";
|
|
2
|
+
export type THotStepRuntimeLangData = {
|
|
3
|
+
outdatedModules: string[];
|
|
4
|
+
outdatedDependencies: Record<string, string[]>;
|
|
5
|
+
updatedModules: string[];
|
|
6
|
+
updatedRuntime: string[];
|
|
7
|
+
acceptedModules: string[];
|
|
8
|
+
disposedModules: string[];
|
|
9
|
+
};
|
|
10
|
+
export type THotStepRuntimeData = {
|
|
11
|
+
javascript: THotStepRuntimeLangData;
|
|
12
|
+
css: THotStepRuntimeLangData;
|
|
13
|
+
statusPath: string[];
|
|
14
|
+
};
|
|
15
|
+
export declare function cachedStats<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string): () => TCompilerStatsCompilation<T>;
|
|
16
|
+
export declare function createRunner<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
|
|
17
|
+
export declare function getMultiCompilerRunnerKey(context: ITestContext, name: string, file: string): string;
|
|
18
|
+
export declare function createMultiCompilerRunner<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cachedStats = cachedStats;
|
|
4
|
+
exports.createRunner = createRunner;
|
|
5
|
+
exports.getMultiCompilerRunnerKey = getMultiCompilerRunnerKey;
|
|
6
|
+
exports.createMultiCompilerRunner = createMultiCompilerRunner;
|
|
7
|
+
const runner_1 = require("../runner");
|
|
8
|
+
const type_1 = require("../type");
|
|
9
|
+
const common_1 = require("./common");
|
|
10
|
+
function cachedStats(context, name) {
|
|
11
|
+
const compiler = context.getCompiler(name);
|
|
12
|
+
const statsGetter = (() => {
|
|
13
|
+
let cached = null;
|
|
14
|
+
return () => {
|
|
15
|
+
if (cached) {
|
|
16
|
+
return cached;
|
|
17
|
+
}
|
|
18
|
+
cached = compiler.getStats().toJson({
|
|
19
|
+
errorDetails: true
|
|
20
|
+
});
|
|
21
|
+
return cached;
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
return statsGetter;
|
|
25
|
+
}
|
|
26
|
+
function createRunner(context, name, file, env) {
|
|
27
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
28
|
+
const compilerOptions = compiler.getOptions();
|
|
29
|
+
const runnerOptions = {
|
|
30
|
+
runInNewContext: false,
|
|
31
|
+
cachable: true,
|
|
32
|
+
env,
|
|
33
|
+
stats: cachedStats(context, name),
|
|
34
|
+
name,
|
|
35
|
+
testConfig: context.getTestConfig(),
|
|
36
|
+
source: context.getSource(),
|
|
37
|
+
dist: context.getDist(),
|
|
38
|
+
compilerOptions
|
|
39
|
+
};
|
|
40
|
+
if (compilerOptions.target === "web" ||
|
|
41
|
+
compilerOptions.target === "webworker") {
|
|
42
|
+
return new runner_1.WebRunner({
|
|
43
|
+
...runnerOptions,
|
|
44
|
+
runInNewContext: true,
|
|
45
|
+
dom: context.getValue(name, "documentType") || type_1.EDocumentType.Fake
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return new runner_1.NodeRunner(runnerOptions);
|
|
49
|
+
}
|
|
50
|
+
function getFileIndexHandler(context, name, file) {
|
|
51
|
+
const multiFileIndexMap = context.getValue(name, "multiFileIndexMap") || {};
|
|
52
|
+
const runned = context.getValue(name, "runned") || new Set();
|
|
53
|
+
if (typeof multiFileIndexMap[file] === "undefined") {
|
|
54
|
+
throw new Error("Unexpect file in multiple runner");
|
|
55
|
+
}
|
|
56
|
+
const indexList = multiFileIndexMap[file];
|
|
57
|
+
const seq = indexList.findIndex((index, n) => !runned.has(`${name}:${file}[${n}]`));
|
|
58
|
+
if (seq === -1) {
|
|
59
|
+
throw new Error(`File ${file} should run only ${indexList.length} times`);
|
|
60
|
+
}
|
|
61
|
+
const getIndex = () => [indexList[seq], seq];
|
|
62
|
+
const flagIndex = () => runned.add(`${name}:${file}[${seq}]`);
|
|
63
|
+
context.setValue(name, "runned", runned);
|
|
64
|
+
return { getIndex, flagIndex };
|
|
65
|
+
}
|
|
66
|
+
function getMultiCompilerRunnerKey(context, name, file) {
|
|
67
|
+
const { getIndex } = getFileIndexHandler(context, name, file);
|
|
68
|
+
const [index, seq] = getIndex();
|
|
69
|
+
return `${name}-${index}[${seq}]`;
|
|
70
|
+
}
|
|
71
|
+
function createMultiCompilerRunner(context, name, file, env) {
|
|
72
|
+
const { getIndex, flagIndex } = getFileIndexHandler(context, name, file);
|
|
73
|
+
const multiCompilerOptions = context.getValue(name, "multiCompilerOptions") || [];
|
|
74
|
+
const [index] = getIndex();
|
|
75
|
+
const compilerOptions = multiCompilerOptions[index];
|
|
76
|
+
let runner;
|
|
77
|
+
const runnerOptions = {
|
|
78
|
+
runInNewContext: false,
|
|
79
|
+
cachable: true,
|
|
80
|
+
env,
|
|
81
|
+
stats: () => {
|
|
82
|
+
const s = cachedStats(context, name)();
|
|
83
|
+
if (s.children?.length && s.children.length > 1) {
|
|
84
|
+
s.__index__ = index;
|
|
85
|
+
return s;
|
|
86
|
+
}
|
|
87
|
+
return s.children[index];
|
|
88
|
+
},
|
|
89
|
+
name,
|
|
90
|
+
testConfig: context.getTestConfig(),
|
|
91
|
+
source: context.getSource(),
|
|
92
|
+
dist: context.getDist(),
|
|
93
|
+
compilerOptions
|
|
94
|
+
};
|
|
95
|
+
if (compilerOptions.target === "web" ||
|
|
96
|
+
compilerOptions.target === "webworker") {
|
|
97
|
+
runner = new runner_1.WebRunner({
|
|
98
|
+
...runnerOptions,
|
|
99
|
+
runInNewContext: true,
|
|
100
|
+
dom: context.getValue(name, "documentType") || type_1.EDocumentType.Fake
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
runner = new runner_1.NodeRunner(runnerOptions);
|
|
105
|
+
}
|
|
106
|
+
flagIndex();
|
|
107
|
+
return runner;
|
|
108
|
+
}
|
package/dist/case/serial.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ECompilerType,
|
|
1
|
+
import type { ECompilerType, TTestConfig } from "../type";
|
|
2
2
|
export type TSerialCaseConfig = Omit<TTestConfig<ECompilerType.Rspack>, "validate">;
|
|
3
3
|
export declare function createSerialCase(name: string, src: string, dist: string): void;
|