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