@rspack-canary/test-tools 1.5.6-canary-e598f284-20250921173624 → 1.5.7-canary-a3406c0a-20250922173625
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 +153 -2
- package/dist/case/cache.js +115 -9
- package/dist/case/compiler.js +1 -1
- package/dist/case/config.d.ts +4 -1
- package/dist/case/config.js +80 -2
- package/dist/case/defaults.d.ts +11 -3
- package/dist/case/defaults.js +47 -2
- package/dist/case/diagnostic.d.ts +6 -0
- package/dist/case/diagnostic.js +109 -9
- package/dist/case/error.d.ts +2 -2
- package/dist/case/error.js +79 -2
- package/dist/case/hash.js +61 -7
- package/dist/case/hook.d.ts +35 -3
- package/dist/case/hook.js +185 -4
- package/dist/case/hot-step.d.ts +1 -1
- package/dist/case/hot-step.js +302 -8
- package/dist/case/hot.d.ts +8 -1
- package/dist/case/hot.js +147 -7
- package/dist/case/incremental.js +21 -8
- package/dist/case/index.d.ts +20 -20
- package/dist/case/index.js +44 -34
- package/dist/case/normal.js +152 -5
- package/dist/case/serial.js +7 -3
- package/dist/case/stats-api.d.ts +0 -5
- package/dist/case/stats-api.js +33 -2
- package/dist/case/stats-output.js +200 -10
- package/dist/case/treeshaking.js +19 -3
- package/dist/helper/plugins/hot-update.d.ts +2 -2
- package/dist/processor/basic.d.ts +4 -1
- package/dist/processor/basic.js +20 -10
- package/dist/processor/index.d.ts +0 -14
- package/dist/processor/index.js +0 -14
- package/dist/processor/multi.d.ts +3 -1
- package/dist/processor/multi.js +2 -0
- package/dist/processor/simple.d.ts +1 -1
- package/dist/processor/simple.js +4 -4
- package/dist/processor/snapshot.js +4 -3
- package/dist/type.d.ts +1 -1
- package/package.json +4 -4
- 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/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/normal.d.ts +0 -12
- package/dist/processor/normal.js +0 -170
- 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/case/hot-step.js
CHANGED
|
@@ -1,11 +1,310 @@
|
|
|
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.createHotStepCase = createHotStepCase;
|
|
4
|
-
const
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const helper_1 = require("../helper");
|
|
10
|
+
const placeholder_1 = require("../helper/expect/placeholder");
|
|
5
11
|
const runner_1 = require("../runner");
|
|
6
12
|
const creator_1 = require("../test/creator");
|
|
7
|
-
const
|
|
13
|
+
const hot_1 = require("./hot");
|
|
14
|
+
const NOOP_SET = new Set();
|
|
15
|
+
const escapeLocalName = (str) => str.split(/[-<>:"/|?*.]/).join("_");
|
|
16
|
+
const SELF_HANDLER = (file, options) => {
|
|
17
|
+
let res = [];
|
|
18
|
+
const hotUpdateGlobal = (_, modules) => {
|
|
19
|
+
res = Object.keys(modules);
|
|
20
|
+
};
|
|
21
|
+
const hotUpdateGlobalKey = escapeLocalName(`${options.output?.hotUpdateGlobal || "webpackHotUpdate"}${options.output?.uniqueName || ""}`);
|
|
22
|
+
global.self ??= {};
|
|
23
|
+
global.self[hotUpdateGlobalKey] = hotUpdateGlobal;
|
|
24
|
+
require(file);
|
|
25
|
+
delete global.self[hotUpdateGlobalKey];
|
|
26
|
+
if (!Object.keys(global.self).length) {
|
|
27
|
+
delete global.self;
|
|
28
|
+
}
|
|
29
|
+
return res;
|
|
30
|
+
};
|
|
31
|
+
const NODE_HANDLER = (file) => {
|
|
32
|
+
return Object.keys(require(file).modules) || [];
|
|
33
|
+
};
|
|
34
|
+
const GET_MODULE_HANDLER = {
|
|
35
|
+
web: SELF_HANDLER,
|
|
36
|
+
webworker: SELF_HANDLER,
|
|
37
|
+
"async-node": NODE_HANDLER,
|
|
38
|
+
node: NODE_HANDLER
|
|
39
|
+
};
|
|
8
40
|
const creators = new Map();
|
|
41
|
+
function createHotStepProcessor(name, target) {
|
|
42
|
+
const processor = (0, hot_1.createHotProcessor)(name, target);
|
|
43
|
+
const entries = {};
|
|
44
|
+
const hashes = [];
|
|
45
|
+
function matchStepSnapshot(env, context, step, options, stats, runtime) {
|
|
46
|
+
const getModuleHandler = GET_MODULE_HANDLER[options.target];
|
|
47
|
+
env.expect(typeof getModuleHandler).toBe("function");
|
|
48
|
+
const lastHash = hashes[hashes.length - 1];
|
|
49
|
+
const snapshotPath = context.getSource(`__snapshots__/${options.target}/${step}.snap.txt`);
|
|
50
|
+
const title = `Case ${node_path_1.default.basename(name)}: Step ${step}`;
|
|
51
|
+
const hotUpdateFile = [];
|
|
52
|
+
const hotUpdateManifest = [];
|
|
53
|
+
const changedFiles = step === 0
|
|
54
|
+
? []
|
|
55
|
+
: processor.hotUpdateContext.changedFiles.map((i) => (0, helper_1.escapeSep)(node_path_1.default.relative(context.getSource(), i)));
|
|
56
|
+
changedFiles.sort();
|
|
57
|
+
const resultHashes = {
|
|
58
|
+
[lastHash || "LAST_HASH"]: "LAST_HASH",
|
|
59
|
+
[stats.hash]: "CURRENT_HASH"
|
|
60
|
+
};
|
|
61
|
+
// TODO: find a better way
|
|
62
|
+
// replace [runtime] to [runtime of id] to prevent worker hash
|
|
63
|
+
const runtimes = {};
|
|
64
|
+
for (const [id, runtime] of Object.entries(entries)) {
|
|
65
|
+
if (typeof runtime === "string") {
|
|
66
|
+
if (runtime !== id) {
|
|
67
|
+
runtimes[runtime] = `[runtime of ${id}]`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (Array.isArray(runtime)) {
|
|
71
|
+
for (const r of runtime) {
|
|
72
|
+
if (r !== id) {
|
|
73
|
+
runtimes[r] = `[runtime of ${id}]`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const replaceContent = (rawStr) => {
|
|
79
|
+
let str = rawStr;
|
|
80
|
+
const replaceContentConfig = context.getTestConfig().snapshotContent;
|
|
81
|
+
if (replaceContentConfig) {
|
|
82
|
+
str = replaceContentConfig(str);
|
|
83
|
+
}
|
|
84
|
+
return (0, placeholder_1.normalizePlaceholder)(Object.entries(resultHashes)
|
|
85
|
+
.reduce((str, [raw, replacement]) => {
|
|
86
|
+
return str.split(raw).join(replacement);
|
|
87
|
+
}, str)
|
|
88
|
+
.replace(/\/\/ (\d+)\s+(?=var cssReload)/, "")
|
|
89
|
+
.replaceAll(/var data = "(?:.*)"/g, match => {
|
|
90
|
+
return decodeURIComponent(match).replaceAll(/\\/g, "/");
|
|
91
|
+
}));
|
|
92
|
+
};
|
|
93
|
+
const replaceFileName = (str) => {
|
|
94
|
+
return Object.entries({
|
|
95
|
+
...resultHashes,
|
|
96
|
+
...runtimes
|
|
97
|
+
}).reduce((str, [raw, replacement]) => {
|
|
98
|
+
return str.split(raw).join(replacement);
|
|
99
|
+
}, str);
|
|
100
|
+
};
|
|
101
|
+
const fileList = stats
|
|
102
|
+
.assets.map(i => {
|
|
103
|
+
const fileName = i.name;
|
|
104
|
+
const renderName = replaceFileName(fileName);
|
|
105
|
+
const content = replaceContent(fs_extra_1.default.readFileSync(context.getDist(fileName), "utf-8"));
|
|
106
|
+
if (fileName.endsWith("hot-update.js")) {
|
|
107
|
+
const modules = getModuleHandler(context.getDist(fileName), options);
|
|
108
|
+
const runtime = [];
|
|
109
|
+
for (const i of content.matchAll(/\/\/ (webpack\/runtime\/[\w_-]+)\s*\n/g)) {
|
|
110
|
+
runtime.push(i[1]);
|
|
111
|
+
}
|
|
112
|
+
modules.sort();
|
|
113
|
+
runtime.sort();
|
|
114
|
+
hotUpdateFile.push({
|
|
115
|
+
name: renderName,
|
|
116
|
+
content,
|
|
117
|
+
modules,
|
|
118
|
+
runtime
|
|
119
|
+
});
|
|
120
|
+
return `- Update: ${renderName}, size: ${content.length}`;
|
|
121
|
+
}
|
|
122
|
+
if (fileName.endsWith("hot-update.json")) {
|
|
123
|
+
const manifest = JSON.parse(content);
|
|
124
|
+
manifest.c?.sort();
|
|
125
|
+
manifest.r?.sort();
|
|
126
|
+
manifest.m?.sort();
|
|
127
|
+
hotUpdateManifest.push({
|
|
128
|
+
name: renderName,
|
|
129
|
+
content: JSON.stringify(manifest)
|
|
130
|
+
});
|
|
131
|
+
return `- Manifest: ${renderName}, size: ${i.size}`;
|
|
132
|
+
}
|
|
133
|
+
if (fileName.endsWith(".js")) {
|
|
134
|
+
return `- Bundle: ${renderName}`;
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
.filter(Boolean);
|
|
138
|
+
fileList.sort();
|
|
139
|
+
hotUpdateManifest.sort((a, b) => (a.name > b.name ? 1 : -1));
|
|
140
|
+
hotUpdateFile.sort((a, b) => (a.name > b.name ? 1 : -1));
|
|
141
|
+
if (runtime?.javascript) {
|
|
142
|
+
runtime.javascript.outdatedModules.sort();
|
|
143
|
+
runtime.javascript.updatedModules.sort();
|
|
144
|
+
runtime.javascript.updatedRuntime.sort();
|
|
145
|
+
runtime.javascript.acceptedModules.sort();
|
|
146
|
+
runtime.javascript.disposedModules.sort();
|
|
147
|
+
for (const value of Object.values(runtime.javascript.outdatedDependencies)) {
|
|
148
|
+
value.sort();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const content = `
|
|
152
|
+
# ${title}
|
|
153
|
+
|
|
154
|
+
## Changed Files
|
|
155
|
+
${changedFiles.map(i => `- ${i}`).join("\n")}
|
|
156
|
+
|
|
157
|
+
## Asset Files
|
|
158
|
+
${fileList.join("\n")}
|
|
159
|
+
|
|
160
|
+
## Manifest
|
|
161
|
+
${hotUpdateManifest
|
|
162
|
+
.map(i => `
|
|
163
|
+
### ${i.name}
|
|
164
|
+
|
|
165
|
+
\`\`\`json
|
|
166
|
+
${i.content}
|
|
167
|
+
\`\`\`
|
|
168
|
+
`)
|
|
169
|
+
.join("\n\n")}
|
|
170
|
+
|
|
171
|
+
## Update
|
|
172
|
+
|
|
173
|
+
${hotUpdateFile
|
|
174
|
+
.map(i => `
|
|
175
|
+
### ${i.name}
|
|
176
|
+
|
|
177
|
+
#### Changed Modules
|
|
178
|
+
${i.modules.map(i => `- ${i}`).join("\n")}
|
|
179
|
+
|
|
180
|
+
#### Changed Runtime Modules
|
|
181
|
+
${i.runtime.map(i => `- ${i}`).join("\n")}
|
|
182
|
+
|
|
183
|
+
#### Changed Content
|
|
184
|
+
\`\`\`js
|
|
185
|
+
${i.content}
|
|
186
|
+
\`\`\`
|
|
187
|
+
`)
|
|
188
|
+
.join("\n\n")}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
${runtime
|
|
192
|
+
? `
|
|
193
|
+
## Runtime
|
|
194
|
+
### Status
|
|
195
|
+
|
|
196
|
+
\`\`\`txt
|
|
197
|
+
${runtime.statusPath.join(" => ")}
|
|
198
|
+
\`\`\`
|
|
199
|
+
|
|
200
|
+
${runtime.javascript
|
|
201
|
+
? `
|
|
202
|
+
|
|
203
|
+
### JavaScript
|
|
204
|
+
|
|
205
|
+
#### Outdated
|
|
206
|
+
|
|
207
|
+
Outdated Modules:
|
|
208
|
+
${runtime.javascript.outdatedModules.map(i => `- ${i}`).join("\n")}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
Outdated Dependencies:
|
|
212
|
+
\`\`\`json
|
|
213
|
+
${JSON.stringify(runtime.javascript.outdatedDependencies || {}, null, 2)}
|
|
214
|
+
\`\`\`
|
|
215
|
+
|
|
216
|
+
#### Updated
|
|
217
|
+
|
|
218
|
+
Updated Modules:
|
|
219
|
+
${runtime.javascript.updatedModules.map(i => `- ${i}`).join("\n")}
|
|
220
|
+
|
|
221
|
+
Updated Runtime:
|
|
222
|
+
${runtime.javascript.updatedRuntime.map(i => `- \`${i}\``).join("\n")}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
#### Callback
|
|
226
|
+
|
|
227
|
+
Accepted Callback:
|
|
228
|
+
${runtime.javascript.acceptedModules.map(i => `- ${i}`).join("\n")}
|
|
229
|
+
|
|
230
|
+
Disposed Callback:
|
|
231
|
+
${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
|
|
232
|
+
`
|
|
233
|
+
: ""}
|
|
234
|
+
|
|
235
|
+
`
|
|
236
|
+
: ""}
|
|
237
|
+
|
|
238
|
+
`
|
|
239
|
+
.replaceAll(/%3A(\d+)%2F/g, (match, capture) => {
|
|
240
|
+
return match.replace(capture, "PORT");
|
|
241
|
+
})
|
|
242
|
+
.trim();
|
|
243
|
+
env.expect(content).toMatchFileSnapshot(snapshotPath);
|
|
244
|
+
}
|
|
245
|
+
const originRun = processor.run;
|
|
246
|
+
processor.run = async function (env, context) {
|
|
247
|
+
context.setValue(name, "hotUpdateStepChecker", (hotUpdateContext, stats, runtime) => {
|
|
248
|
+
const statsJson = stats.toJson({
|
|
249
|
+
assets: true,
|
|
250
|
+
chunks: true
|
|
251
|
+
});
|
|
252
|
+
const chunks = Array.from(
|
|
253
|
+
// Some chunk fields are missing from rspack
|
|
254
|
+
stats?.compilation.chunks || NOOP_SET);
|
|
255
|
+
for (const entry of chunks.filter(i => i.hasRuntime())) {
|
|
256
|
+
if (!entries[entry.id] && entry.runtime) {
|
|
257
|
+
entries[entry.id] =
|
|
258
|
+
// Webpack uses `string | SortableSet<string>` for `entry.runtime`
|
|
259
|
+
typeof entry.runtime === "string"
|
|
260
|
+
? [entry.runtime]
|
|
261
|
+
: Array.from(entry.runtime);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const compiler = this.getCompiler(context);
|
|
265
|
+
const compilerOptions = compiler.getOptions();
|
|
266
|
+
matchStepSnapshot(env, context, hotUpdateContext.updateIndex, compilerOptions, statsJson, runtime);
|
|
267
|
+
hashes.push(stats.hash);
|
|
268
|
+
});
|
|
269
|
+
context.setValue(name, "hotUpdateStepErrorChecker", (_, stats, runtime) => {
|
|
270
|
+
hashes.push(stats.hash);
|
|
271
|
+
});
|
|
272
|
+
await originRun.call(this, env, context);
|
|
273
|
+
};
|
|
274
|
+
processor.check = async function (env, context) {
|
|
275
|
+
const compiler = this.getCompiler(context);
|
|
276
|
+
const stats = compiler.getStats();
|
|
277
|
+
if (!stats || !stats.hash) {
|
|
278
|
+
env.expect(false);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const statsJson = stats.toJson({ assets: true, chunks: true });
|
|
282
|
+
const chunks = Array.from(
|
|
283
|
+
// Some chunk fields are missing from rspack
|
|
284
|
+
stats?.compilation.chunks || NOOP_SET);
|
|
285
|
+
for (const entry of chunks.filter(i => i.hasRuntime())) {
|
|
286
|
+
if (entry.runtime) {
|
|
287
|
+
entries[entry.id] =
|
|
288
|
+
// Webpack uses `string | SortableSet<string>` for `entry.runtime`
|
|
289
|
+
typeof entry.runtime === "string"
|
|
290
|
+
? [entry.runtime]
|
|
291
|
+
: Array.from(entry.runtime);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
let matchFailed = null;
|
|
295
|
+
try {
|
|
296
|
+
matchStepSnapshot(env, context, 0, compiler.getOptions(), statsJson);
|
|
297
|
+
}
|
|
298
|
+
catch (e) {
|
|
299
|
+
matchFailed = e;
|
|
300
|
+
}
|
|
301
|
+
hashes.push(stats.hash);
|
|
302
|
+
if (matchFailed) {
|
|
303
|
+
throw matchFailed;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
return processor;
|
|
307
|
+
}
|
|
9
308
|
function getCreator(target) {
|
|
10
309
|
if (!creators.has(target)) {
|
|
11
310
|
creators.set(target, new creator_1.BasicCaseCreator({
|
|
@@ -13,12 +312,7 @@ function getCreator(target) {
|
|
|
13
312
|
describe: false,
|
|
14
313
|
target,
|
|
15
314
|
steps: ({ name, target }) => [
|
|
16
|
-
|
|
17
|
-
name,
|
|
18
|
-
target: target,
|
|
19
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
20
|
-
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
21
|
-
})
|
|
315
|
+
createHotStepProcessor(name, target)
|
|
22
316
|
],
|
|
23
317
|
runner: runner_1.HotRunnerFactory,
|
|
24
318
|
concurrent: true
|
package/dist/case/hot.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BasicProcessor } from "../processor";
|
|
2
|
+
import { ECompilerType, type TCompilerOptions, type THotUpdateContext } from "../type";
|
|
3
|
+
type TTarget = TCompilerOptions<ECompilerType.Rspack>["target"];
|
|
4
|
+
type THotProcessor = BasicProcessor<ECompilerType.Rspack> & {
|
|
5
|
+
hotUpdateContext: THotUpdateContext;
|
|
6
|
+
};
|
|
7
|
+
export declare function createHotProcessor(name: string, target: TTarget, incremental?: boolean): THotProcessor;
|
|
2
8
|
export declare function createHotCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
|
9
|
+
export {};
|
package/dist/case/hot.js
CHANGED
|
@@ -1,11 +1,156 @@
|
|
|
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 });
|
|
6
|
+
exports.createHotProcessor = createHotProcessor;
|
|
3
7
|
exports.createHotCase = createHotCase;
|
|
4
|
-
const
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const core_1 = __importDefault(require("@rspack/core"));
|
|
10
|
+
const helper_1 = require("../helper");
|
|
11
|
+
const plugins_1 = require("../helper/plugins");
|
|
12
|
+
const plugin_1 = require("../plugin");
|
|
13
|
+
const processor_1 = require("../processor");
|
|
5
14
|
const runner_1 = require("../runner");
|
|
6
15
|
const creator_1 = require("../test/creator");
|
|
7
16
|
const type_1 = require("../type");
|
|
8
17
|
const creators = new Map();
|
|
18
|
+
function defaultOptions(context, target, updateOptions) {
|
|
19
|
+
const options = {
|
|
20
|
+
context: context.getSource(),
|
|
21
|
+
mode: "development",
|
|
22
|
+
devtool: false,
|
|
23
|
+
output: {
|
|
24
|
+
path: context.getDist(),
|
|
25
|
+
filename: "bundle.js",
|
|
26
|
+
chunkFilename: "[name].chunk.[fullhash].js",
|
|
27
|
+
publicPath: "https://test.cases/path/",
|
|
28
|
+
library: { type: "commonjs2" }
|
|
29
|
+
},
|
|
30
|
+
optimization: {
|
|
31
|
+
moduleIds: "named"
|
|
32
|
+
},
|
|
33
|
+
target,
|
|
34
|
+
experiments: {
|
|
35
|
+
css: true,
|
|
36
|
+
// test incremental: "safe" here, we test default incremental in Incremental-*.test.js
|
|
37
|
+
incremental: "safe",
|
|
38
|
+
rspackFuture: {
|
|
39
|
+
bundlerInfo: {
|
|
40
|
+
force: false
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
inlineConst: true,
|
|
44
|
+
lazyBarrel: true
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
options.plugins ??= [];
|
|
48
|
+
options.plugins.push(new core_1.default.HotModuleReplacementPlugin(), new plugins_1.TestHotUpdatePlugin(updateOptions));
|
|
49
|
+
return options;
|
|
50
|
+
}
|
|
51
|
+
function overrideOptions(context, options, target, updateOptions) {
|
|
52
|
+
if (!options.entry) {
|
|
53
|
+
options.entry = "./index.js";
|
|
54
|
+
}
|
|
55
|
+
options.module ??= {};
|
|
56
|
+
for (const cssModuleType of ["css/auto", "css/module", "css"]) {
|
|
57
|
+
options.module.generator ??= {};
|
|
58
|
+
options.module.generator[cssModuleType] ??= {};
|
|
59
|
+
options.module.generator[cssModuleType].exportsOnly ??=
|
|
60
|
+
target === "async-node";
|
|
61
|
+
}
|
|
62
|
+
options.module.rules ??= [];
|
|
63
|
+
options.module.rules.push({
|
|
64
|
+
use: [
|
|
65
|
+
{
|
|
66
|
+
loader: node_path_1.default.resolve(__dirname, "../helper/loaders/hot-update.js"),
|
|
67
|
+
options: updateOptions
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
enforce: "pre"
|
|
71
|
+
});
|
|
72
|
+
options.plugins ??= [];
|
|
73
|
+
options.plugins.push(new core_1.default.LoaderOptionsPlugin(updateOptions));
|
|
74
|
+
if (!global.printLogger) {
|
|
75
|
+
options.infrastructureLogging = {
|
|
76
|
+
level: "error"
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (options.lazyCompilation) {
|
|
80
|
+
options.plugins.push(new plugin_1.LazyCompilationTestPlugin());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function findBundle(context, name, target, updateOptions) {
|
|
84
|
+
const compiler = context.getCompiler(name);
|
|
85
|
+
if (!compiler)
|
|
86
|
+
throw new Error("Compiler should exists when find bundle");
|
|
87
|
+
const testConfig = context.getTestConfig();
|
|
88
|
+
if (typeof testConfig.findBundle === "function") {
|
|
89
|
+
return testConfig.findBundle(updateOptions.updateIndex, compiler.getOptions());
|
|
90
|
+
}
|
|
91
|
+
const files = [];
|
|
92
|
+
const prefiles = [];
|
|
93
|
+
const stats = compiler.getStats();
|
|
94
|
+
if (!stats)
|
|
95
|
+
throw new Error("Stats should exists when find bundle");
|
|
96
|
+
const info = stats.toJson({ all: false, entrypoints: true });
|
|
97
|
+
if (target === "web" || target === "webworker") {
|
|
98
|
+
for (const file of info.entrypoints.main.assets) {
|
|
99
|
+
if ((0, helper_1.isJavaScript)(file.name)) {
|
|
100
|
+
files.push(file.name);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
prefiles.push(file.name);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const assets = info.entrypoints.main.assets.filter(s => (0, helper_1.isJavaScript)(s.name));
|
|
109
|
+
files.push(assets[assets.length - 1].name);
|
|
110
|
+
}
|
|
111
|
+
return [...prefiles, ...files];
|
|
112
|
+
}
|
|
113
|
+
function createHotProcessor(name, target, incremental = false) {
|
|
114
|
+
const hotUpdateContext = {
|
|
115
|
+
updateIndex: 0,
|
|
116
|
+
totalUpdates: 1,
|
|
117
|
+
changedFiles: []
|
|
118
|
+
};
|
|
119
|
+
const processor = new processor_1.BasicProcessor({
|
|
120
|
+
name,
|
|
121
|
+
compilerType: type_1.ECompilerType.Rspack,
|
|
122
|
+
runable: true,
|
|
123
|
+
configFiles: ["rspack.config.js", "webpack.config.js"],
|
|
124
|
+
defaultOptions(context) {
|
|
125
|
+
return defaultOptions(context, target, hotUpdateContext);
|
|
126
|
+
},
|
|
127
|
+
overrideOptions(context, options) {
|
|
128
|
+
overrideOptions(context, options, target, hotUpdateContext);
|
|
129
|
+
if (incremental) {
|
|
130
|
+
options.experiments ??= {};
|
|
131
|
+
options.experiments.incremental ??= "advance-silent";
|
|
132
|
+
}
|
|
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
|
+
}
|
|
140
|
+
});
|
|
141
|
+
processor.hotUpdateContext = hotUpdateContext;
|
|
142
|
+
const originalAfterAll = processor.afterAll;
|
|
143
|
+
processor.afterAll = async function (context) {
|
|
144
|
+
await originalAfterAll.call(this, context);
|
|
145
|
+
if (context.getTestConfig().checkSteps === false) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (hotUpdateContext.updateIndex + 1 !== hotUpdateContext.totalUpdates) {
|
|
149
|
+
throw new Error(`Should run all hot steps (${hotUpdateContext.updateIndex + 1} / ${hotUpdateContext.totalUpdates}): ${name}`);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
return processor;
|
|
153
|
+
}
|
|
9
154
|
function getCreator(target) {
|
|
10
155
|
if (!creators.has(target)) {
|
|
11
156
|
creators.set(target, new creator_1.BasicCaseCreator({
|
|
@@ -13,12 +158,7 @@ function getCreator(target) {
|
|
|
13
158
|
describe: true,
|
|
14
159
|
target,
|
|
15
160
|
steps: ({ name, target }) => [
|
|
16
|
-
|
|
17
|
-
name,
|
|
18
|
-
target: target,
|
|
19
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
20
|
-
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
21
|
-
})
|
|
161
|
+
createHotProcessor(name, target)
|
|
22
162
|
],
|
|
23
163
|
runner: runner_1.HotRunnerFactory,
|
|
24
164
|
concurrent: true
|
package/dist/case/incremental.js
CHANGED
|
@@ -7,12 +7,31 @@ 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 hot_incremental_1 = require("../processor/hot-incremental");
|
|
11
10
|
const watch_1 = require("../processor/watch");
|
|
12
11
|
const runner_1 = require("../runner");
|
|
13
12
|
const creator_1 = require("../test/creator");
|
|
14
13
|
const type_1 = require("../type");
|
|
14
|
+
const hot_1 = require("./hot");
|
|
15
15
|
const hotCreators = new Map();
|
|
16
|
+
function createHotIncrementalProcessor(name, target, webpackCases) {
|
|
17
|
+
const processor = (0, hot_1.createHotProcessor)(name, target, true);
|
|
18
|
+
processor.before = async (context) => {
|
|
19
|
+
context.setValue(name, "documentType", webpackCases ? type_1.EDocumentType.Fake : type_1.EDocumentType.JSDOM);
|
|
20
|
+
};
|
|
21
|
+
const originalAfterAll = processor.afterAll;
|
|
22
|
+
processor.afterAll = async function (context) {
|
|
23
|
+
try {
|
|
24
|
+
await originalAfterAll.call(this, context);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
const isFake = context.getValue(name, "documentType") === type_1.EDocumentType.Fake;
|
|
28
|
+
if (isFake && /Should run all hot steps/.test(e.message))
|
|
29
|
+
return;
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return processor;
|
|
34
|
+
}
|
|
16
35
|
function getHotCreator(target, webpackCases) {
|
|
17
36
|
const key = JSON.stringify({ target, webpackCases });
|
|
18
37
|
if (!hotCreators.has(key)) {
|
|
@@ -21,13 +40,7 @@ function getHotCreator(target, webpackCases) {
|
|
|
21
40
|
describe: true,
|
|
22
41
|
target,
|
|
23
42
|
steps: ({ name, target }) => [
|
|
24
|
-
|
|
25
|
-
name,
|
|
26
|
-
target: target,
|
|
27
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
28
|
-
configFiles: ["rspack.config.js", "webpack.config.js"],
|
|
29
|
-
webpackCases
|
|
30
|
-
})
|
|
43
|
+
createHotIncrementalProcessor(name, target, webpackCases)
|
|
31
44
|
],
|
|
32
45
|
runner: runner_1.HotRunnerFactory,
|
|
33
46
|
concurrent: true
|
package/dist/case/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
1
|
+
export { createBuiltinCase } from "./builtin";
|
|
2
|
+
export { createCacheCase } from "./cache";
|
|
3
|
+
export { createCompilerCase } from "./compiler";
|
|
4
|
+
export { createConfigCase } from "./config";
|
|
5
|
+
export { createDefaultsCase, getRspackDefaultConfig } from "./defaults";
|
|
6
|
+
export { createDiagnosticCase } from "./diagnostic";
|
|
7
|
+
export { createDiffCase } from "./diff";
|
|
8
|
+
export { createErrorCase } from "./error";
|
|
9
|
+
export { createHashCase } from "./hash";
|
|
10
|
+
export { createHookCase } from "./hook";
|
|
11
|
+
export { createHotCase } from "./hot";
|
|
12
|
+
export { createHotStepCase } from "./hot-step";
|
|
13
|
+
export { createHotIncrementalCase, createWatchIncrementalCase } from "./incremental";
|
|
14
|
+
export { createNativeWatcher } from "./native-watcher";
|
|
15
|
+
export { createHotNormalCase, createNormalCase } from "./normal";
|
|
16
|
+
export { createSerialCase } from "./serial";
|
|
17
|
+
export { createStatsAPICase } from "./stats-api";
|
|
18
|
+
export { createStatsOutputCase } from "./stats-output";
|
|
19
|
+
export { createTreeShakingCase } from "./treeshaking";
|
|
20
|
+
export { createWatchCase } from "./watch";
|