@rspack-canary/test-tools 1.5.6-canary-e598f284-20250921173624 → 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 -0
- package/dist/case/builtin.js +173 -13
- package/dist/case/cache.d.ts +1 -1
- package/dist/case/cache.js +210 -11
- 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 +5 -1
- package/dist/case/config.js +102 -16
- package/dist/case/defaults.d.ts +12 -4
- package/dist/case/defaults.js +67 -12
- package/dist/case/diagnostic.d.ts +6 -0
- package/dist/case/diagnostic.js +123 -14
- 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 +117 -10
- package/dist/case/hash.d.ts +1 -1
- package/dist/case/hash.js +70 -9
- package/dist/case/hook.d.ts +35 -4
- package/dist/case/hook.js +210 -21
- package/dist/case/hot-step.js +307 -9
- package/dist/case/hot.d.ts +8 -1
- package/dist/case/hot.js +235 -8
- package/dist/case/incremental.d.ts +1 -1
- package/dist/case/incremental.js +39 -41
- package/dist/case/index.d.ts +20 -20
- package/dist/case/index.js +44 -34
- package/dist/case/native-watcher.js +10 -23
- package/dist/case/normal.js +174 -12
- 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 +8 -12
- package/dist/case/stats-api.d.ts +0 -5
- package/dist/case/stats-api.js +71 -10
- package/dist/case/stats-output.js +197 -11
- package/dist/case/treeshaking.js +34 -7
- package/dist/case/watch.d.ts +27 -0
- package/dist/case/watch.js +321 -21
- package/dist/helper/plugins/hot-update.d.ts +2 -2
- 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 +42 -11
- package/dist/type.js +7 -1
- package/package.json +5 -5
- package/dist/processor/basic.d.ts +0 -24
- package/dist/processor/basic.js +0 -147
- 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 -131
- package/dist/processor/config.d.ts +0 -11
- package/dist/processor/config.js +0 -88
- 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 -104
- 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 -65
- package/dist/processor/hook.d.ts +0 -44
- package/dist/processor/hook.js +0 -206
- 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 -307
- package/dist/processor/hot.d.ts +0 -17
- package/dist/processor/hot.js +0 -147
- 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 -170
- 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 -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 -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/watch.js
CHANGED
|
@@ -3,16 +3,205 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createWatchInitialProcessor = createWatchInitialProcessor;
|
|
7
|
+
exports.createWatchStepProcessor = createWatchStepProcessor;
|
|
6
8
|
exports.createWatchCase = createWatchCase;
|
|
9
|
+
exports.getWatchRunnerKey = getWatchRunnerKey;
|
|
10
|
+
exports.createWatchRunner = createWatchRunner;
|
|
7
11
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const
|
|
13
|
+
const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
14
|
+
const compiler_1 = require("../compiler");
|
|
15
|
+
const helper_1 = require("../helper");
|
|
16
|
+
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
17
|
+
const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
|
|
10
18
|
const runner_1 = require("../runner");
|
|
11
19
|
const creator_1 = require("../test/creator");
|
|
12
20
|
const type_1 = require("../type");
|
|
21
|
+
const common_1 = require("./common");
|
|
22
|
+
// This file is used to port step number to rspack.config.js/webpack.config.js
|
|
23
|
+
const currentWatchStepModulePath = node_path_1.default.resolve(__dirname, "../helper/util/currentWatchStep");
|
|
24
|
+
function createWatchInitialProcessor(name, tempDir, step, watchState, { incremental = false, nativeWatcher = false, ignoreNotFriendlyForIncrementalWarnings = false } = {}) {
|
|
25
|
+
const watchContext = {
|
|
26
|
+
currentTriggerFilename: null,
|
|
27
|
+
lastHash: null,
|
|
28
|
+
step,
|
|
29
|
+
tempDir,
|
|
30
|
+
nativeWatcher,
|
|
31
|
+
watchState
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
before: async (context) => {
|
|
35
|
+
context.setValue(name, "watchContext", watchContext);
|
|
36
|
+
},
|
|
37
|
+
config: async (context) => {
|
|
38
|
+
const multiCompilerOptions = [];
|
|
39
|
+
const caseOptions = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)));
|
|
40
|
+
for (const [index, options] of caseOptions.entries()) {
|
|
41
|
+
const compilerOptions = (0, webpack_merge_1.default)(defaultOptions({
|
|
42
|
+
incremental,
|
|
43
|
+
ignoreNotFriendlyForIncrementalWarnings
|
|
44
|
+
}), options);
|
|
45
|
+
overrideOptions(index, context, compilerOptions, tempDir, nativeWatcher);
|
|
46
|
+
multiCompilerOptions.push(compilerOptions);
|
|
47
|
+
}
|
|
48
|
+
const compilerOptions = multiCompilerOptions.length === 1
|
|
49
|
+
? multiCompilerOptions[0]
|
|
50
|
+
: multiCompilerOptions;
|
|
51
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
52
|
+
compiler.setOptions(compilerOptions);
|
|
53
|
+
context.setValue(name, "multiCompilerOptions", multiCompilerOptions);
|
|
54
|
+
},
|
|
55
|
+
compiler: async (context) => {
|
|
56
|
+
const c = await (0, common_1.compiler)(context, name);
|
|
57
|
+
c.hooks.invalid.tap("WatchTestCasesTest", (filename, mtime) => {
|
|
58
|
+
watchContext.currentTriggerFilename = filename;
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
build: async (context) => {
|
|
62
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
63
|
+
const currentWatchStepModule = require(currentWatchStepModulePath);
|
|
64
|
+
currentWatchStepModule.step[name] = watchContext.step;
|
|
65
|
+
node_fs_1.default.mkdirSync(watchContext.tempDir, { recursive: true });
|
|
66
|
+
(0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), watchContext.tempDir, true);
|
|
67
|
+
const task = new Promise((resolve, reject) => {
|
|
68
|
+
compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
|
|
69
|
+
if (e)
|
|
70
|
+
return reject(e);
|
|
71
|
+
resolve(stats);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
compiler.watch();
|
|
75
|
+
await task;
|
|
76
|
+
},
|
|
77
|
+
run: async (env, context) => {
|
|
78
|
+
await (0, common_1.run)(env, context, name, (context) => (0, common_1.findMultiCompilerBundle)(context, name, (index, context, options) => findBundle(index, context, options, step)));
|
|
79
|
+
},
|
|
80
|
+
check: async (env, context) => {
|
|
81
|
+
const testConfig = context.getTestConfig();
|
|
82
|
+
if (testConfig.noTests)
|
|
83
|
+
return;
|
|
84
|
+
const errors = (context.getError(name) || []).map(e => ({
|
|
85
|
+
message: e.message,
|
|
86
|
+
stack: e.stack
|
|
87
|
+
}));
|
|
88
|
+
const warnings = [];
|
|
89
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
90
|
+
const stats = compiler.getStats();
|
|
91
|
+
const options = compiler.getOptions();
|
|
92
|
+
const checkStats = testConfig.checkStats || (() => true);
|
|
93
|
+
if (stats) {
|
|
94
|
+
if (testConfig.writeStatsOuptut) {
|
|
95
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
|
|
96
|
+
preset: "verbose",
|
|
97
|
+
colors: false
|
|
98
|
+
}), "utf-8");
|
|
99
|
+
}
|
|
100
|
+
const getJsonStats = (() => {
|
|
101
|
+
let cached = null;
|
|
102
|
+
return () => {
|
|
103
|
+
if (!cached) {
|
|
104
|
+
cached = stats.toJson({
|
|
105
|
+
errorDetails: true
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return cached;
|
|
109
|
+
};
|
|
110
|
+
})();
|
|
111
|
+
const getStringStats = (() => {
|
|
112
|
+
let cached = null;
|
|
113
|
+
return () => {
|
|
114
|
+
if (!cached) {
|
|
115
|
+
cached = stats.toString({
|
|
116
|
+
logging: "verbose"
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return cached;
|
|
120
|
+
};
|
|
121
|
+
})();
|
|
122
|
+
if (checkStats.length > 1) {
|
|
123
|
+
if (!checkStats(watchContext.step, getJsonStats(), getStringStats())) {
|
|
124
|
+
throw new Error("stats check failed");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// @ts-expect-error only one param
|
|
129
|
+
if (!checkStats(watchContext.step)) {
|
|
130
|
+
throw new Error("stats check failed");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (testConfig.writeStatsJson) {
|
|
134
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.json"), JSON.stringify(getJsonStats(), null, 2), "utf-8");
|
|
135
|
+
}
|
|
136
|
+
if (node_fs_1.default.existsSync(context.getSource(`${watchContext.step}/errors.js`)) ||
|
|
137
|
+
node_fs_1.default.existsSync(context.getSource(`${watchContext.step}/warnings.js`)) ||
|
|
138
|
+
stats.hasErrors() ||
|
|
139
|
+
stats.hasWarnings()) {
|
|
140
|
+
const statsJson = stats.toJson({
|
|
141
|
+
errorDetails: true
|
|
142
|
+
});
|
|
143
|
+
if (statsJson.errors) {
|
|
144
|
+
errors.push(...statsJson.errors);
|
|
145
|
+
}
|
|
146
|
+
if (statsJson.warnings) {
|
|
147
|
+
warnings.push(...statsJson.warnings);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), { errors }, "error", "errors", "Error", options);
|
|
152
|
+
await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), { warnings }, "warning", "warnings", "Warning", options);
|
|
153
|
+
// clear error if checked
|
|
154
|
+
if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
|
|
155
|
+
context.clearError(name);
|
|
156
|
+
}
|
|
157
|
+
// check hash
|
|
158
|
+
if (testConfig.writeStatsOuptut) {
|
|
159
|
+
node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.txt"), node_path_1.default.join(context.getDist(), `stats.${watchContext.step}.txt`));
|
|
160
|
+
}
|
|
161
|
+
if (testConfig.writeStatsJson) {
|
|
162
|
+
node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.json"), node_path_1.default.join(context.getDist(), `stats.${watchContext.step}.json`));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function createWatchStepProcessor(name, tempDir, step, watchState, { incremental = false, nativeWatcher = false, ignoreNotFriendlyForIncrementalWarnings = false } = {}) {
|
|
168
|
+
const processor = createWatchInitialProcessor(name, tempDir, step, watchState, { incremental, ignoreNotFriendlyForIncrementalWarnings });
|
|
169
|
+
processor.compiler = async (context) => {
|
|
170
|
+
// do nothing
|
|
171
|
+
};
|
|
172
|
+
processor.build = async (context) => {
|
|
173
|
+
const watchContext = context.getValue(name, "watchContext");
|
|
174
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
175
|
+
const currentWatchStepModule = require(currentWatchStepModulePath);
|
|
176
|
+
currentWatchStepModule.step[name] = watchContext.step;
|
|
177
|
+
const task = new Promise((resolve, reject) => {
|
|
178
|
+
compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
|
|
179
|
+
if (e)
|
|
180
|
+
return reject(e);
|
|
181
|
+
resolve(stats);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
// wait compiler to ready watch the files and diretories
|
|
185
|
+
// Native Watcher using [notify](https://github.com/notify-rs/notify) to watch files.
|
|
186
|
+
// After tests, notify will cost many milliseconds to watch in windows OS when jest run concurrently.
|
|
187
|
+
// So we need to wait a while to ensure the watcher is ready.
|
|
188
|
+
// If we don't wait, copyDiff will happen before the watcher is ready,
|
|
189
|
+
// which will cause the compiler not rebuild when the files change.
|
|
190
|
+
// The timeout is set to 400ms for windows OS and 100ms for other OS.
|
|
191
|
+
// TODO: This is a workaround, we can remove it when notify support windows better.
|
|
192
|
+
const timeout = nativeWatcher && process.platform === "win32" ? 400 : 100;
|
|
193
|
+
await new Promise(resolve => setTimeout(resolve, timeout));
|
|
194
|
+
(0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), step), tempDir, false);
|
|
195
|
+
await task;
|
|
196
|
+
};
|
|
197
|
+
return processor;
|
|
198
|
+
}
|
|
13
199
|
const creator = new creator_1.BasicCaseCreator({
|
|
14
200
|
clean: true,
|
|
15
|
-
runner:
|
|
201
|
+
runner: {
|
|
202
|
+
key: getWatchRunnerKey,
|
|
203
|
+
runner: createWatchRunner
|
|
204
|
+
},
|
|
16
205
|
description: (name, index) => {
|
|
17
206
|
return index === 0
|
|
18
207
|
? `${name} should compile`
|
|
@@ -24,30 +213,141 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
24
213
|
const runs = node_fs_1.default
|
|
25
214
|
.readdirSync(src)
|
|
26
215
|
.sort()
|
|
27
|
-
.filter(name =>
|
|
28
|
-
return node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory();
|
|
29
|
-
})
|
|
216
|
+
.filter(name => node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory())
|
|
30
217
|
.map(name => ({ name }));
|
|
31
218
|
return runs.map((run, index) => index === 0
|
|
32
|
-
?
|
|
33
|
-
|
|
34
|
-
stepName: run.name,
|
|
35
|
-
tempDir: temp,
|
|
36
|
-
runable: true,
|
|
37
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
38
|
-
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
39
|
-
}, watchState)
|
|
40
|
-
: new watch_1.WatchStepProcessor({
|
|
41
|
-
name,
|
|
42
|
-
stepName: run.name,
|
|
43
|
-
tempDir: temp,
|
|
44
|
-
runable: true,
|
|
45
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
46
|
-
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
47
|
-
}, watchState));
|
|
219
|
+
? createWatchInitialProcessor(name, temp, run.name, watchState)
|
|
220
|
+
: createWatchStepProcessor(name, temp, run.name, watchState));
|
|
48
221
|
},
|
|
49
222
|
concurrent: true
|
|
50
223
|
});
|
|
51
224
|
function createWatchCase(name, src, dist, temp) {
|
|
52
225
|
creator.create(name, src, dist, temp);
|
|
53
226
|
}
|
|
227
|
+
function overrideOptions(index, context, options, tempDir, nativeWatcher) {
|
|
228
|
+
if (!options.mode)
|
|
229
|
+
options.mode = "development";
|
|
230
|
+
if (!options.context)
|
|
231
|
+
options.context = tempDir;
|
|
232
|
+
if (!options.entry)
|
|
233
|
+
options.entry = "./index.js";
|
|
234
|
+
if (!options.target)
|
|
235
|
+
options.target = "async-node";
|
|
236
|
+
if (!options.devtool)
|
|
237
|
+
options.devtool = false;
|
|
238
|
+
if (!options.output)
|
|
239
|
+
options.output = {};
|
|
240
|
+
if (!options.output.path)
|
|
241
|
+
options.output.path = context.getDist();
|
|
242
|
+
if (typeof options.output.pathinfo === "undefined")
|
|
243
|
+
options.output.pathinfo = false;
|
|
244
|
+
if (!options.output.filename)
|
|
245
|
+
options.output.filename = "bundle.js";
|
|
246
|
+
if (options.cache && options.cache.type === "filesystem") {
|
|
247
|
+
const cacheDirectory = node_path_1.default.join(tempDir, ".cache");
|
|
248
|
+
options.cache.cacheDirectory = cacheDirectory;
|
|
249
|
+
options.cache.name = `config-${index}`;
|
|
250
|
+
}
|
|
251
|
+
options.optimization ??= {};
|
|
252
|
+
options.experiments ??= {};
|
|
253
|
+
options.experiments.css ??= true;
|
|
254
|
+
if (nativeWatcher) {
|
|
255
|
+
options.experiments.nativeWatcher ??= true;
|
|
256
|
+
}
|
|
257
|
+
options.experiments.rspackFuture ??= {};
|
|
258
|
+
options.experiments.rspackFuture.bundlerInfo ??= {};
|
|
259
|
+
options.experiments.rspackFuture.bundlerInfo.force ??= false;
|
|
260
|
+
// test incremental: "safe" here, we test default incremental in Incremental-*.test.js
|
|
261
|
+
options.experiments.incremental ??= "safe";
|
|
262
|
+
if (!global.printLogger) {
|
|
263
|
+
options.infrastructureLogging = {
|
|
264
|
+
level: "error"
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function findBundle(index, context, options, stepName) {
|
|
269
|
+
const testConfig = context.getTestConfig();
|
|
270
|
+
if (typeof testConfig.findBundle === "function") {
|
|
271
|
+
return testConfig.findBundle(index, options, stepName);
|
|
272
|
+
}
|
|
273
|
+
return "./bundle.js";
|
|
274
|
+
}
|
|
275
|
+
function defaultOptions({ incremental = false, ignoreNotFriendlyForIncrementalWarnings = false } = {}) {
|
|
276
|
+
if (incremental) {
|
|
277
|
+
return {
|
|
278
|
+
experiments: {
|
|
279
|
+
incremental: "advance"
|
|
280
|
+
},
|
|
281
|
+
ignoreWarnings: ignoreNotFriendlyForIncrementalWarnings
|
|
282
|
+
? [/is not friendly for incremental/]
|
|
283
|
+
: undefined
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return {};
|
|
287
|
+
}
|
|
288
|
+
function getWatchRunnerKey(context, name, file) {
|
|
289
|
+
const watchContext = context.getValue(name, "watchContext");
|
|
290
|
+
const stepName = watchContext?.step;
|
|
291
|
+
return `${name}-${stepName}`;
|
|
292
|
+
}
|
|
293
|
+
function cachedWatchStats(context, name) {
|
|
294
|
+
const compiler = context.getCompiler(name);
|
|
295
|
+
const watchContext = context.getValue(name, "watchContext");
|
|
296
|
+
const stepName = watchContext?.step;
|
|
297
|
+
const statsGetter = (() => {
|
|
298
|
+
const cached = {};
|
|
299
|
+
return () => {
|
|
300
|
+
if (cached[stepName]) {
|
|
301
|
+
return cached[stepName];
|
|
302
|
+
}
|
|
303
|
+
cached[stepName] = compiler.getStats().toJson({
|
|
304
|
+
errorDetails: true
|
|
305
|
+
});
|
|
306
|
+
return cached[stepName];
|
|
307
|
+
};
|
|
308
|
+
})();
|
|
309
|
+
return statsGetter;
|
|
310
|
+
}
|
|
311
|
+
function createWatchRunner(context, name, file, env) {
|
|
312
|
+
const compiler = context.getCompiler(name);
|
|
313
|
+
const compilerOptions = compiler.getOptions();
|
|
314
|
+
const watchContext = context.getValue(name, "watchContext");
|
|
315
|
+
const stepName = watchContext?.step;
|
|
316
|
+
if (!stepName) {
|
|
317
|
+
throw new Error("Can not get watch step name from context");
|
|
318
|
+
}
|
|
319
|
+
const state = watchContext?.watchState;
|
|
320
|
+
if (!state) {
|
|
321
|
+
throw new Error("Can not get watch state from context");
|
|
322
|
+
}
|
|
323
|
+
const isWeb = Array.isArray(compilerOptions)
|
|
324
|
+
? compilerOptions.some(option => {
|
|
325
|
+
return option.target === "web" || option.target === "webworker";
|
|
326
|
+
})
|
|
327
|
+
: compilerOptions.target === "web" ||
|
|
328
|
+
compilerOptions.target === "webworker";
|
|
329
|
+
const testConfig = context.getTestConfig();
|
|
330
|
+
const documentType = context.getValue(name, "documentType") || type_1.EDocumentType.Fake;
|
|
331
|
+
return new runner_1.WebRunner({
|
|
332
|
+
dom: documentType,
|
|
333
|
+
env,
|
|
334
|
+
stats: cachedWatchStats(context, name),
|
|
335
|
+
name: name,
|
|
336
|
+
runInNewContext: isWeb,
|
|
337
|
+
cachable: false,
|
|
338
|
+
testConfig: {
|
|
339
|
+
...(testConfig || {}),
|
|
340
|
+
moduleScope: (ms, stats, options) => {
|
|
341
|
+
ms.STATE = state;
|
|
342
|
+
ms.WATCH_STEP = stepName;
|
|
343
|
+
if (typeof testConfig.moduleScope === "function") {
|
|
344
|
+
return testConfig.moduleScope(ms, stats, options);
|
|
345
|
+
}
|
|
346
|
+
return ms;
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
source: context.getSource(),
|
|
350
|
+
dist: context.getDist(),
|
|
351
|
+
compilerOptions
|
|
352
|
+
});
|
|
353
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Compiler } from "@rspack/core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { THotUpdateContext } from "../../type";
|
|
3
3
|
export declare class TestHotUpdatePlugin {
|
|
4
4
|
private updateOptions;
|
|
5
|
-
constructor(updateOptions:
|
|
5
|
+
constructor(updateOptions: THotUpdateContext);
|
|
6
6
|
apply(compiler: Compiler): void;
|
|
7
7
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,9 @@ export * from "./case";
|
|
|
2
2
|
export * from "./compare";
|
|
3
3
|
export * from "./helper";
|
|
4
4
|
export * from "./plugin";
|
|
5
|
-
export * from "./processor";
|
|
6
5
|
export * from "./reporter";
|
|
7
6
|
export * from "./runner";
|
|
8
7
|
export * from "./test/context";
|
|
9
8
|
export * from "./test/creator";
|
|
10
|
-
export * from "./test/simple";
|
|
11
9
|
export * from "./test/tester";
|
|
12
10
|
export * from "./type";
|
package/dist/index.js
CHANGED
|
@@ -18,11 +18,9 @@ __exportStar(require("./case"), exports);
|
|
|
18
18
|
__exportStar(require("./compare"), exports);
|
|
19
19
|
__exportStar(require("./helper"), exports);
|
|
20
20
|
__exportStar(require("./plugin"), exports);
|
|
21
|
-
__exportStar(require("./processor"), exports);
|
|
22
21
|
__exportStar(require("./reporter"), exports);
|
|
23
22
|
__exportStar(require("./runner"), exports);
|
|
24
23
|
__exportStar(require("./test/context"), exports);
|
|
25
24
|
__exportStar(require("./test/creator"), exports);
|
|
26
|
-
__exportStar(require("./test/simple"), exports);
|
|
27
25
|
__exportStar(require("./test/tester"), exports);
|
|
28
26
|
__exportStar(require("./type"), exports);
|
package/dist/runner/index.d.ts
CHANGED
package/dist/runner/index.js
CHANGED
|
@@ -14,10 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./hot"), exports);
|
|
20
|
-
__exportStar(require("./multiple"), exports);
|
|
21
|
-
__exportStar(require("./runner/node"), exports);
|
|
22
|
-
__exportStar(require("./type"), exports);
|
|
23
|
-
__exportStar(require("./watch"), exports);
|
|
17
|
+
__exportStar(require("./node"), exports);
|
|
18
|
+
__exportStar(require("./web"), exports);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type IGlobalContext, type IModuleScope, type TModuleObject, type TRunnerFile, type TRunnerRequirer } from "../../type";
|
|
1
|
+
import { type ECompilerType, type IGlobalContext, type IModuleScope, type ITestEnv, type ITestRunner, type TCompilerOptions, type TCompilerStatsCompilation, type TModuleObject, type TRunnerFile, type TRunnerRequirer, type TTestConfig } from "../../type";
|
|
3
2
|
declare global {
|
|
4
3
|
var printLogger: boolean;
|
|
5
4
|
}
|
|
@@ -41,8 +41,8 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
41
41
|
const node_path_1 = __importDefault(require("node:path"));
|
|
42
42
|
const node_url_1 = require("node:url");
|
|
43
43
|
const node_vm_1 = __importStar(require("node:vm"));
|
|
44
|
-
const asModule_1 = __importDefault(require("
|
|
45
|
-
const urlToRelativePath_1 = __importDefault(require("
|
|
44
|
+
const asModule_1 = __importDefault(require("../../helper/legacy/asModule"));
|
|
45
|
+
const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
|
|
46
46
|
const type_1 = require("../../type");
|
|
47
47
|
const isRelativePath = (p) => /^\.\.?\//.test(p);
|
|
48
48
|
const getSubPath = (p) => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type TRunnerFile, type TRunnerRequirer } from "../../type";
|
|
1
|
+
import { type ECompilerType, type TRunnerFile, type TRunnerRequirer } from "../../type";
|
|
3
2
|
import { type INodeRunnerOptions, NodeRunner } from "../node";
|
|
4
3
|
export declare class FakeDocumentWebRunner<T extends ECompilerType = ECompilerType.Rspack> extends NodeRunner<T> {
|
|
5
4
|
protected _webOptions: INodeRunnerOptions<T>;
|
|
@@ -41,13 +41,13 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
41
41
|
const node_path_1 = __importDefault(require("node:path"));
|
|
42
42
|
const node_url_1 = require("node:url");
|
|
43
43
|
const node_vm_1 = __importStar(require("node:vm"));
|
|
44
|
-
const helper_1 = require("
|
|
45
|
-
const asModule_1 = __importDefault(require("
|
|
46
|
-
const createFakeWorker_1 = __importDefault(require("
|
|
47
|
-
const currentScript_1 = __importDefault(require("
|
|
48
|
-
const EventSourceForNode_1 = __importDefault(require("
|
|
49
|
-
const FakeDocument_1 = __importDefault(require("
|
|
50
|
-
const urlToRelativePath_1 = __importDefault(require("
|
|
44
|
+
const helper_1 = require("../../helper");
|
|
45
|
+
const asModule_1 = __importDefault(require("../../helper/legacy/asModule"));
|
|
46
|
+
const createFakeWorker_1 = __importDefault(require("../../helper/legacy/createFakeWorker"));
|
|
47
|
+
const currentScript_1 = __importDefault(require("../../helper/legacy/currentScript"));
|
|
48
|
+
const EventSourceForNode_1 = __importDefault(require("../../helper/legacy/EventSourceForNode"));
|
|
49
|
+
const FakeDocument_1 = __importDefault(require("../../helper/legacy/FakeDocument"));
|
|
50
|
+
const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
|
|
51
51
|
const type_1 = require("../../type");
|
|
52
52
|
const node_1 = require("../node");
|
|
53
53
|
class FakeDocumentWebRunner extends node_1.NodeRunner {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ECompilerType, EDocumentType, type ITestRunner } from "
|
|
1
|
+
import { type ECompilerType, EDocumentType, type ITestRunner } from "../../type";
|
|
2
2
|
import type { INodeRunnerOptions, NodeRunner } from "../node";
|
|
3
3
|
export interface IWebRunnerOptions<T extends ECompilerType = ECompilerType.Rspack> extends INodeRunnerOptions<T> {
|
|
4
4
|
dom: EDocumentType;
|
|
@@ -9,6 +9,6 @@ export declare class WebRunner<T extends ECompilerType = ECompilerType.Rspack> i
|
|
|
9
9
|
private implement;
|
|
10
10
|
constructor(_webOptions: IWebRunnerOptions<T>);
|
|
11
11
|
run(file: string): Promise<unknown>;
|
|
12
|
-
getRequire(): import("
|
|
12
|
+
getRequire(): import("../../type").TRunnerRequirer;
|
|
13
13
|
getGlobal(name: string): unknown;
|
|
14
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WebRunner = void 0;
|
|
4
|
-
const type_1 = require("
|
|
4
|
+
const type_1 = require("../../type");
|
|
5
5
|
const fake_1 = require("./fake");
|
|
6
6
|
const jsdom_1 = require("./jsdom");
|
|
7
7
|
class WebRunner {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { ECompilerType } from "
|
|
2
|
-
import type { TRunnerFile, TRunnerRequirer } from "../../type";
|
|
1
|
+
import type { ECompilerType, TRunnerFile, TRunnerRequirer } from "../../type";
|
|
3
2
|
import { type INodeRunnerOptions, NodeRunner } from "../node";
|
|
4
3
|
export declare class JSDOMWebRunner<T extends ECompilerType = ECompilerType.Rspack> extends NodeRunner<T> {
|
|
5
4
|
protected _webOptions: INodeRunnerOptions<T>;
|
|
@@ -7,10 +7,10 @@ exports.JSDOMWebRunner = void 0;
|
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const jsdom_1 = require("jsdom");
|
|
10
|
-
const helper_1 = require("
|
|
11
|
-
const createFakeWorker_1 = __importDefault(require("
|
|
12
|
-
const EventSourceForNode_1 = __importDefault(require("
|
|
13
|
-
const urlToRelativePath_1 = __importDefault(require("
|
|
10
|
+
const helper_1 = require("../../helper");
|
|
11
|
+
const createFakeWorker_1 = __importDefault(require("../../helper/legacy/createFakeWorker"));
|
|
12
|
+
const EventSourceForNode_1 = __importDefault(require("../../helper/legacy/EventSourceForNode"));
|
|
13
|
+
const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
|
|
14
14
|
const node_1 = require("../node");
|
|
15
15
|
// Compatibility code to suppress iconv-lite warnings
|
|
16
16
|
require("iconv-lite").skipDecodeWarning = true;
|
package/dist/test/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ECompilerType, type ITestCompilerManager, type ITestContext, type ITestEnv, type ITesterConfig, type ITestRunner, type TTestConfig } from "../type";
|
|
2
2
|
export type TTestContextOptions = Omit<ITesterConfig, "name" | "steps">;
|
|
3
3
|
export declare class TestContext implements ITestContext {
|
|
4
4
|
private config;
|
|
@@ -6,15 +6,12 @@ export declare class TestContext implements ITestContext {
|
|
|
6
6
|
protected compilers: Map<string, ITestCompilerManager<ECompilerType>>;
|
|
7
7
|
protected store: Map<string, Record<string, unknown>>;
|
|
8
8
|
protected runners: Map<string, ITestRunner>;
|
|
9
|
-
protected runnerFactory: TRunnerFactory<ECompilerType> | null;
|
|
10
9
|
constructor(config: TTestContextOptions);
|
|
11
10
|
getSource(sub?: string): string;
|
|
12
11
|
getDist(sub?: string): string;
|
|
13
12
|
getTemp(sub?: string): string | null;
|
|
14
13
|
getCompiler<T extends ECompilerType>(name: string, type: T | void): ITestCompilerManager<T>;
|
|
15
|
-
|
|
16
|
-
getRunner(key: string): ITestRunner | null;
|
|
17
|
-
setRunner(key: string, runner: ITestRunner): void;
|
|
14
|
+
getRunner(name: string, file: string, env: ITestEnv): ITestRunner;
|
|
18
15
|
getTestConfig<T extends ECompilerType>(): TTestConfig<T>;
|
|
19
16
|
setValue<T>(name: string, key: string, value: T): void;
|
|
20
17
|
getValue<T>(name: string, key: string): T | void;
|
|
@@ -23,4 +20,5 @@ export declare class TestContext implements ITestContext {
|
|
|
23
20
|
getNames(): string[];
|
|
24
21
|
getError(name?: string): Error[];
|
|
25
22
|
clearError(name?: string): void;
|
|
23
|
+
closeCompiler(name: string): Promise<void>;
|
|
26
24
|
}
|
package/dist/test/context.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.TestContext = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const compiler_1 = require("../compiler");
|
|
9
|
+
const type_1 = require("../type");
|
|
9
10
|
class TestContext {
|
|
10
11
|
constructor(config) {
|
|
11
12
|
this.config = config;
|
|
@@ -13,7 +14,6 @@ class TestContext {
|
|
|
13
14
|
this.compilers = new Map();
|
|
14
15
|
this.store = new Map();
|
|
15
16
|
this.runners = new Map();
|
|
16
|
-
this.runnerFactory = null;
|
|
17
17
|
}
|
|
18
18
|
getSource(sub) {
|
|
19
19
|
if (sub) {
|
|
@@ -46,18 +46,18 @@ class TestContext {
|
|
|
46
46
|
}
|
|
47
47
|
return compiler;
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
if (!this.
|
|
51
|
-
|
|
52
|
-
this.runnerFactory = new this.config.runnerFactory(name, this);
|
|
49
|
+
getRunner(name, file, env) {
|
|
50
|
+
if (!this.config.runnerCreator) {
|
|
51
|
+
throw new Error("TestContext: Runner creator not found");
|
|
53
52
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.runners.set(
|
|
53
|
+
const runnerKey = this.config.runnerCreator.key(this, name, file);
|
|
54
|
+
let runner = this.runners.get(runnerKey);
|
|
55
|
+
if (runner) {
|
|
56
|
+
return runner;
|
|
57
|
+
}
|
|
58
|
+
runner = this.config.runnerCreator.runner(this, name, file, env);
|
|
59
|
+
this.runners.set(runnerKey, runner);
|
|
60
|
+
return runner;
|
|
61
61
|
}
|
|
62
62
|
getTestConfig() {
|
|
63
63
|
return this.config.testConfig || {};
|
|
@@ -104,5 +104,15 @@ class TestContext {
|
|
|
104
104
|
this.errors.clear();
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
+
async closeCompiler(name) {
|
|
108
|
+
const rspackCompiler = this.getCompiler(name, type_1.ECompilerType.Rspack);
|
|
109
|
+
if (rspackCompiler) {
|
|
110
|
+
await rspackCompiler.close();
|
|
111
|
+
}
|
|
112
|
+
const webpackCompiler = this.getCompiler(name, type_1.ECompilerType.Webpack);
|
|
113
|
+
if (webpackCompiler) {
|
|
114
|
+
await webpackCompiler.close();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
107
117
|
}
|
|
108
118
|
exports.TestContext = TestContext;
|