@rspack/test-tools 1.7.0-beta.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/case/builtin.d.ts +2 -2
- package/dist/case/builtin.js +58 -58
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +34 -34
- package/dist/case/common.d.ts +2 -2
- package/dist/case/common.js +45 -45
- package/dist/case/compiler.d.ts +3 -3
- package/dist/case/compiler.js +21 -21
- package/dist/case/config.d.ts +3 -3
- package/dist/case/config.js +19 -19
- package/dist/case/defaults.d.ts +2 -2
- package/dist/case/defaults.js +10 -10
- package/dist/case/diagnostic.js +29 -29
- package/dist/case/error.d.ts +2 -2
- package/dist/case/error.js +21 -21
- package/dist/case/esm-output.js +28 -28
- package/dist/case/example.js +7 -7
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +16 -16
- package/dist/case/hook.d.ts +3 -3
- package/dist/case/hook.js +42 -42
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +46 -46
- package/dist/case/hot.d.ts +5 -5
- package/dist/case/hot.js +43 -43
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +9 -9
- package/dist/case/index.d.ts +31 -31
- package/dist/case/multi-compiler.d.ts +3 -3
- package/dist/case/multi-compiler.js +15 -15
- package/dist/case/native-watcher.js +6 -6
- package/dist/case/normal.js +46 -46
- package/dist/case/runner.d.ts +2 -2
- package/dist/case/runner.js +22 -15
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +4 -4
- package/dist/case/stats-api.d.ts +2 -2
- package/dist/case/stats-api.js +7 -7
- package/dist/case/stats-output.d.ts +2 -2
- package/dist/case/stats-output.js +45 -45
- package/dist/case/treeshaking.js +6 -6
- package/dist/case/watch.d.ts +1 -1
- package/dist/case/watch.js +59 -59
- package/dist/compiler.d.ts +3 -3
- package/dist/compiler.js +31 -31
- package/dist/helper/directory.d.ts +1 -1
- package/dist/helper/directory.js +15 -15
- package/dist/helper/disable-iconv-lite-warning.js +3 -3
- package/dist/helper/expect/diff.js +8 -8
- package/dist/helper/expect/error.js +9 -9
- package/dist/helper/expect/placeholder.js +9 -9
- package/dist/helper/expect/rspack.js +5 -5
- package/dist/helper/expect/to-be-typeof.js +2 -2
- package/dist/helper/expect/to-end-with.js +3 -3
- package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -1
- package/dist/helper/expect/to-match-file-snapshot.js +23 -23
- package/dist/helper/hot-update/index.d.ts +1 -1
- package/dist/helper/hot-update/loader.js +1 -1
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +15 -15
- package/dist/helper/index.d.ts +8 -8
- package/dist/helper/is.js +2 -2
- package/dist/helper/legacy/EventSourceForNode.js +8 -8
- package/dist/helper/legacy/LogTestPlugin.js +18 -18
- package/dist/helper/legacy/asModule.js +6 -6
- package/dist/helper/legacy/captureStdio.js +6 -6
- package/dist/helper/legacy/checkArrayExpectation.js +24 -24
- package/dist/helper/legacy/copyDiff.js +5 -5
- package/dist/helper/legacy/createFakeWorker.js +13 -13
- package/dist/helper/legacy/createLazyTestEnv.js +12 -12
- package/dist/helper/legacy/currentScript.js +1 -1
- package/dist/helper/legacy/deprecationTracking.js +5 -5
- package/dist/helper/legacy/expectSource.js +5 -5
- package/dist/helper/legacy/fakeSystem.js +14 -14
- package/dist/helper/legacy/findOutputFiles.js +4 -4
- package/dist/helper/legacy/parseResource.js +4 -4
- package/dist/helper/legacy/regexEscape.js +2 -2
- package/dist/helper/legacy/supportDefaultAssignment.js +2 -2
- package/dist/helper/legacy/supportsTextDecoder.js +2 -2
- package/dist/helper/legacy/supportsUsing.js +1 -1
- package/dist/helper/legacy/urlToRelativePath.js +3 -3
- package/dist/helper/parse-modules.js +13 -13
- package/dist/helper/read-config-file.d.ts +2 -2
- package/dist/helper/read-config-file.js +3 -3
- package/dist/helper/serializers.d.ts +1 -1
- package/dist/helper/serializers.js +11 -11
- package/dist/helper/setup-env.js +17 -17
- package/dist/helper/setup-expect.js +1 -1
- package/dist/helper/setup-wasm.js +4 -4
- package/dist/helper/stringify-config.d.ts +1 -1
- package/dist/helper/stringify-config.js +3 -3
- package/dist/helper/update-snapshot.js +1 -1
- package/dist/helper/util/checkSourceMap.js +16 -17
- package/dist/helper/util/checkStats.js +3 -3
- package/dist/helper/util/expectWarningFactory.js +2 -2
- package/dist/helper/util/filterUtil.js +9 -9
- package/dist/index.d.ts +8 -8
- package/dist/index.js +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/lazy-compilation-test-plugin.d.ts +1 -1
- package/dist/plugin/lazy-compilation-test-plugin.js +13 -13
- package/dist/runner/index.d.ts +2 -2
- package/dist/runner/node/index.d.ts +2 -2
- package/dist/runner/node/index.js +75 -74
- package/dist/runner/web/index.d.ts +2 -2
- package/dist/runner/web/index.js +45 -45
- package/dist/test/context.d.ts +2 -2
- package/dist/test/context.js +4 -4
- package/dist/test/creator.d.ts +1 -1
- package/dist/test/creator.js +28 -28
- package/dist/test/debug.d.ts +1 -1
- package/dist/test/debug.js +31 -31
- package/dist/test/tester.d.ts +1 -1
- package/dist/test/tester.js +11 -11
- package/dist/type.d.ts +3 -3
- package/package.json +3 -3
- package/rstest.d.ts +12 -12
package/dist/case/hot-step.js
CHANGED
|
@@ -11,13 +11,13 @@ const placeholder_1 = require("../helper/expect/placeholder");
|
|
|
11
11
|
const creator_1 = require("../test/creator");
|
|
12
12
|
const hot_1 = require("./hot");
|
|
13
13
|
const NOOP_SET = new Set();
|
|
14
|
-
const escapeLocalName = (str) => str.split(/[-<>:"/|?*.]/).join(
|
|
14
|
+
const escapeLocalName = (str) => str.split(/[-<>:"/|?*.]/).join('_');
|
|
15
15
|
const SELF_HANDLER = (file, options) => {
|
|
16
16
|
let res = [];
|
|
17
17
|
const hotUpdateGlobal = (_, modules) => {
|
|
18
18
|
res = Object.keys(modules);
|
|
19
19
|
};
|
|
20
|
-
const hotUpdateGlobalKey = escapeLocalName(`${options.output?.hotUpdateGlobal ||
|
|
20
|
+
const hotUpdateGlobalKey = escapeLocalName(`${options.output?.hotUpdateGlobal || 'webpackHotUpdate'}${options.output?.uniqueName || ''}`);
|
|
21
21
|
global.self ??= {};
|
|
22
22
|
global.self[hotUpdateGlobalKey] = hotUpdateGlobal;
|
|
23
23
|
require(file);
|
|
@@ -30,8 +30,8 @@ const NODE_HANDLER = (file) => {
|
|
|
30
30
|
const GET_MODULE_HANDLER = {
|
|
31
31
|
web: SELF_HANDLER,
|
|
32
32
|
webworker: SELF_HANDLER,
|
|
33
|
-
|
|
34
|
-
node: NODE_HANDLER
|
|
33
|
+
'async-node': NODE_HANDLER,
|
|
34
|
+
node: NODE_HANDLER,
|
|
35
35
|
};
|
|
36
36
|
const creators = new Map();
|
|
37
37
|
function createHotStepProcessor(name, src, temp, target) {
|
|
@@ -40,7 +40,7 @@ function createHotStepProcessor(name, src, temp, target) {
|
|
|
40
40
|
const hashes = [];
|
|
41
41
|
function matchStepSnapshot(env, context, step, options, stats, runtime) {
|
|
42
42
|
const getModuleHandler = GET_MODULE_HANDLER[options.target];
|
|
43
|
-
env.expect(typeof getModuleHandler).toBe(
|
|
43
|
+
env.expect(typeof getModuleHandler).toBe('function');
|
|
44
44
|
const lastHash = hashes[hashes.length - 1];
|
|
45
45
|
const snapshotPath = context.getSource(`__snapshots__/${options.target}/${step}.snap.txt`);
|
|
46
46
|
const title = `Case ${node_path_1.default.basename(name)}: Step ${step}`;
|
|
@@ -53,14 +53,14 @@ function createHotStepProcessor(name, src, temp, target) {
|
|
|
53
53
|
.map((i) => (0, helper_1.escapeSep)(node_path_1.default.relative(temp, i)));
|
|
54
54
|
changedFiles.sort();
|
|
55
55
|
const resultHashes = {
|
|
56
|
-
[lastHash ||
|
|
57
|
-
[stats.hash]:
|
|
56
|
+
[lastHash || 'LAST_HASH']: 'LAST_HASH',
|
|
57
|
+
[stats.hash]: 'CURRENT_HASH',
|
|
58
58
|
};
|
|
59
59
|
// TODO: find a better way
|
|
60
60
|
// replace [runtime] to [runtime of id] to prevent worker hash
|
|
61
61
|
const runtimes = {};
|
|
62
62
|
for (const [id, runtime] of Object.entries(entries)) {
|
|
63
|
-
if (typeof runtime ===
|
|
63
|
+
if (typeof runtime === 'string') {
|
|
64
64
|
if (runtime !== id) {
|
|
65
65
|
runtimes[runtime] = `[runtime of ${id}]`;
|
|
66
66
|
}
|
|
@@ -83,26 +83,26 @@ function createHotStepProcessor(name, src, temp, target) {
|
|
|
83
83
|
.reduce((str, [raw, replacement]) => {
|
|
84
84
|
return str.split(raw).join(replacement);
|
|
85
85
|
}, str)
|
|
86
|
-
.replace(/\/\/ (\d+)\s+(?=var cssReload)/,
|
|
87
|
-
.replaceAll(/var data = "(?:.*)"/g, match => {
|
|
88
|
-
return decodeURIComponent(match).replaceAll(/\\/g,
|
|
86
|
+
.replace(/\/\/ (\d+)\s+(?=var cssReload)/, '')
|
|
87
|
+
.replaceAll(/var data = "(?:.*)"/g, (match) => {
|
|
88
|
+
return decodeURIComponent(match).replaceAll(/\\/g, '/');
|
|
89
89
|
}));
|
|
90
90
|
};
|
|
91
91
|
const replaceFileName = (str) => {
|
|
92
92
|
return Object.entries({
|
|
93
93
|
...resultHashes,
|
|
94
|
-
...runtimes
|
|
94
|
+
...runtimes,
|
|
95
95
|
}).reduce((str, [raw, replacement]) => {
|
|
96
96
|
return str.split(raw).join(replacement);
|
|
97
97
|
}, str);
|
|
98
98
|
};
|
|
99
99
|
const assets = stats.assets.sort((a, b) => a.name.localeCompare(b.name));
|
|
100
100
|
const fileList = assets
|
|
101
|
-
.map(i => {
|
|
101
|
+
.map((i) => {
|
|
102
102
|
const fileName = i.name;
|
|
103
103
|
const renderName = replaceFileName(fileName);
|
|
104
|
-
const content = replaceContent(fs_extra_1.default.readFileSync(context.getDist(fileName),
|
|
105
|
-
if (fileName.endsWith(
|
|
104
|
+
const content = replaceContent(fs_extra_1.default.readFileSync(context.getDist(fileName), 'utf-8'));
|
|
105
|
+
if (fileName.endsWith('hot-update.js')) {
|
|
106
106
|
const modules = getModuleHandler(context.getDist(fileName), options);
|
|
107
107
|
const runtime = [];
|
|
108
108
|
for (const i of content.matchAll(/\/\/ (webpack\/runtime\/[\w_-]+)\s*\n/g)) {
|
|
@@ -114,22 +114,22 @@ function createHotStepProcessor(name, src, temp, target) {
|
|
|
114
114
|
name: renderName,
|
|
115
115
|
content,
|
|
116
116
|
modules,
|
|
117
|
-
runtime
|
|
117
|
+
runtime,
|
|
118
118
|
});
|
|
119
119
|
return `- Update: ${renderName}, size: ${content.length}`;
|
|
120
120
|
}
|
|
121
|
-
if (fileName.endsWith(
|
|
121
|
+
if (fileName.endsWith('hot-update.json')) {
|
|
122
122
|
const manifest = JSON.parse(content);
|
|
123
123
|
manifest.c?.sort();
|
|
124
124
|
manifest.r?.sort();
|
|
125
125
|
manifest.m?.sort();
|
|
126
126
|
hotUpdateManifest.push({
|
|
127
127
|
name: renderName,
|
|
128
|
-
content: JSON.stringify(manifest)
|
|
128
|
+
content: JSON.stringify(manifest),
|
|
129
129
|
});
|
|
130
130
|
return `- Manifest: ${renderName}, size: ${i.size}`;
|
|
131
131
|
}
|
|
132
|
-
if (fileName.endsWith(
|
|
132
|
+
if (fileName.endsWith('.js')) {
|
|
133
133
|
return `- Bundle: ${renderName}`;
|
|
134
134
|
}
|
|
135
135
|
})
|
|
@@ -151,40 +151,40 @@ function createHotStepProcessor(name, src, temp, target) {
|
|
|
151
151
|
# ${title}
|
|
152
152
|
|
|
153
153
|
## Changed Files
|
|
154
|
-
${changedFiles.map(i => `- ${i}`).join(
|
|
154
|
+
${changedFiles.map((i) => `- ${i}`).join('\n')}
|
|
155
155
|
|
|
156
156
|
## Asset Files
|
|
157
|
-
${fileList.join(
|
|
157
|
+
${fileList.join('\n')}
|
|
158
158
|
|
|
159
159
|
## Manifest
|
|
160
160
|
${hotUpdateManifest
|
|
161
|
-
.map(i => `
|
|
161
|
+
.map((i) => `
|
|
162
162
|
### ${i.name}
|
|
163
163
|
|
|
164
164
|
\`\`\`json
|
|
165
165
|
${i.content}
|
|
166
166
|
\`\`\`
|
|
167
167
|
`)
|
|
168
|
-
.join(
|
|
168
|
+
.join('\n\n')}
|
|
169
169
|
|
|
170
170
|
## Update
|
|
171
171
|
|
|
172
172
|
${hotUpdateFile
|
|
173
|
-
.map(i => `
|
|
173
|
+
.map((i) => `
|
|
174
174
|
### ${i.name}
|
|
175
175
|
|
|
176
176
|
#### Changed Modules
|
|
177
|
-
${i.modules.map(i => `- ${i}`).join(
|
|
177
|
+
${i.modules.map((i) => `- ${i}`).join('\n')}
|
|
178
178
|
|
|
179
179
|
#### Changed Runtime Modules
|
|
180
|
-
${i.runtime.map(i => `- ${i}`).join(
|
|
180
|
+
${i.runtime.map((i) => `- ${i}`).join('\n')}
|
|
181
181
|
|
|
182
182
|
#### Changed Content
|
|
183
183
|
\`\`\`js
|
|
184
184
|
${i.content}
|
|
185
185
|
\`\`\`
|
|
186
186
|
`)
|
|
187
|
-
.join(
|
|
187
|
+
.join('\n\n')}
|
|
188
188
|
|
|
189
189
|
|
|
190
190
|
${runtime
|
|
@@ -193,7 +193,7 @@ ${runtime
|
|
|
193
193
|
### Status
|
|
194
194
|
|
|
195
195
|
\`\`\`txt
|
|
196
|
-
${runtime.statusPath.join(
|
|
196
|
+
${runtime.statusPath.join(' => ')}
|
|
197
197
|
\`\`\`
|
|
198
198
|
|
|
199
199
|
${runtime.javascript
|
|
@@ -204,7 +204,7 @@ ${runtime.javascript
|
|
|
204
204
|
#### Outdated
|
|
205
205
|
|
|
206
206
|
Outdated Modules:
|
|
207
|
-
${runtime.javascript.outdatedModules.map(i => `- ${i}`).join(
|
|
207
|
+
${runtime.javascript.outdatedModules.map((i) => `- ${i}`).join('\n')}
|
|
208
208
|
|
|
209
209
|
|
|
210
210
|
Outdated Dependencies:
|
|
@@ -215,47 +215,47 @@ ${JSON.stringify(runtime.javascript.outdatedDependencies || {}, null, 2)}
|
|
|
215
215
|
#### Updated
|
|
216
216
|
|
|
217
217
|
Updated Modules:
|
|
218
|
-
${runtime.javascript.updatedModules.map(i => `- ${i}`).join(
|
|
218
|
+
${runtime.javascript.updatedModules.map((i) => `- ${i}`).join('\n')}
|
|
219
219
|
|
|
220
220
|
Updated Runtime:
|
|
221
|
-
${runtime.javascript.updatedRuntime.map(i => `- \`${i}\``).join(
|
|
221
|
+
${runtime.javascript.updatedRuntime.map((i) => `- \`${i}\``).join('\n')}
|
|
222
222
|
|
|
223
223
|
|
|
224
224
|
#### Callback
|
|
225
225
|
|
|
226
226
|
Accepted Callback:
|
|
227
|
-
${runtime.javascript.acceptedModules.map(i => `- ${i}`).join(
|
|
227
|
+
${runtime.javascript.acceptedModules.map((i) => `- ${i}`).join('\n')}
|
|
228
228
|
|
|
229
229
|
Disposed Callback:
|
|
230
|
-
${runtime.javascript.disposedModules.map(i => `- ${i}`).join(
|
|
230
|
+
${runtime.javascript.disposedModules.map((i) => `- ${i}`).join('\n')}
|
|
231
231
|
`
|
|
232
|
-
:
|
|
232
|
+
: ''}
|
|
233
233
|
|
|
234
234
|
`
|
|
235
|
-
:
|
|
235
|
+
: ''}
|
|
236
236
|
|
|
237
237
|
`
|
|
238
238
|
.replaceAll(/%3A(\d+)%2F/g, (match, capture) => {
|
|
239
|
-
return match.replace(capture,
|
|
239
|
+
return match.replace(capture, 'PORT');
|
|
240
240
|
})
|
|
241
241
|
.trim();
|
|
242
242
|
env.expect(content).toMatchFileSnapshotSync(snapshotPath);
|
|
243
243
|
}
|
|
244
244
|
const originRun = processor.run;
|
|
245
245
|
processor.run = async function (env, context) {
|
|
246
|
-
context.setValue(
|
|
246
|
+
context.setValue('hotUpdateStepChecker', (updateIndex, stats, runtime) => {
|
|
247
247
|
const statsJson = stats.toJson({
|
|
248
248
|
assets: true,
|
|
249
|
-
chunks: true
|
|
249
|
+
chunks: true,
|
|
250
250
|
});
|
|
251
251
|
const chunks = Array.from(
|
|
252
252
|
// Some chunk fields are missing from rspack
|
|
253
253
|
stats?.compilation.chunks || NOOP_SET);
|
|
254
|
-
for (const entry of chunks.filter(i => i.hasRuntime())) {
|
|
254
|
+
for (const entry of chunks.filter((i) => i.hasRuntime())) {
|
|
255
255
|
if (!entries[entry.id] && entry.runtime) {
|
|
256
256
|
entries[entry.id] =
|
|
257
257
|
// Webpack uses `string | SortableSet<string>` for `entry.runtime`
|
|
258
|
-
typeof entry.runtime ===
|
|
258
|
+
typeof entry.runtime === 'string'
|
|
259
259
|
? [entry.runtime]
|
|
260
260
|
: Array.from(entry.runtime);
|
|
261
261
|
}
|
|
@@ -265,7 +265,7 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
|
|
|
265
265
|
matchStepSnapshot(env, context, updateIndex, compilerOptions, statsJson, runtime);
|
|
266
266
|
hashes.push(stats.hash);
|
|
267
267
|
});
|
|
268
|
-
context.setValue(
|
|
268
|
+
context.setValue('hotUpdateStepErrorChecker', (updateIndex, stats, runtime) => {
|
|
269
269
|
hashes.push(stats.hash);
|
|
270
270
|
});
|
|
271
271
|
await originRun(env, context);
|
|
@@ -281,11 +281,11 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
|
|
|
281
281
|
const chunks = Array.from(
|
|
282
282
|
// Some chunk fields are missing from rspack
|
|
283
283
|
stats?.compilation.chunks || NOOP_SET);
|
|
284
|
-
for (const entry of chunks.filter(i => i.hasRuntime())) {
|
|
284
|
+
for (const entry of chunks.filter((i) => i.hasRuntime())) {
|
|
285
285
|
if (entry.runtime) {
|
|
286
286
|
entries[entry.id] =
|
|
287
287
|
// Webpack uses `string | SortableSet<string>` for `entry.runtime`
|
|
288
|
-
typeof entry.runtime ===
|
|
288
|
+
typeof entry.runtime === 'string'
|
|
289
289
|
? [entry.runtime]
|
|
290
290
|
: Array.from(entry.runtime);
|
|
291
291
|
}
|
|
@@ -311,13 +311,13 @@ function getCreator(target) {
|
|
|
311
311
|
describe: false,
|
|
312
312
|
target,
|
|
313
313
|
steps: ({ name, target, src, temp, dist }) => [
|
|
314
|
-
createHotStepProcessor(name, src, temp || node_path_1.default.resolve(dist,
|
|
314
|
+
createHotStepProcessor(name, src, temp || node_path_1.default.resolve(dist, 'temp'), target),
|
|
315
315
|
],
|
|
316
316
|
runner: {
|
|
317
317
|
key: (context, name, file) => name,
|
|
318
|
-
runner: hot_1.createHotRunner
|
|
318
|
+
runner: hot_1.createHotRunner,
|
|
319
319
|
},
|
|
320
|
-
concurrent: true
|
|
320
|
+
concurrent: true,
|
|
321
321
|
}));
|
|
322
322
|
}
|
|
323
323
|
return creators.get(target);
|
package/dist/case/hot.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type RspackOptions } from
|
|
2
|
-
import { HotUpdatePlugin } from
|
|
3
|
-
import type { ITestContext, ITestEnv, ITestProcessor, ITestRunner } from
|
|
4
|
-
type TTarget = RspackOptions[
|
|
1
|
+
import { type RspackOptions } from '@rspack/core';
|
|
2
|
+
import { HotUpdatePlugin } from '../helper/hot-update/plugin';
|
|
3
|
+
import type { ITestContext, ITestEnv, ITestProcessor, ITestRunner } from '../type';
|
|
4
|
+
type TTarget = RspackOptions['target'];
|
|
5
5
|
export declare function createHotProcessor(name: string, src: string, temp: string, target: TTarget, incremental?: boolean): THotProcessor;
|
|
6
|
-
export declare function createHotCase(name: string, src: string, dist: string, temp: string, target: RspackOptions[
|
|
6
|
+
export declare function createHotCase(name: string, src: string, dist: string, temp: string, target: RspackOptions['target']): void;
|
|
7
7
|
type THotProcessor = ITestProcessor & {
|
|
8
8
|
updatePlugin: HotUpdatePlugin;
|
|
9
9
|
};
|
package/dist/case/hot.js
CHANGED
|
@@ -22,16 +22,16 @@ function createHotProcessor(name, src, temp, target, incremental = false) {
|
|
|
22
22
|
const processor = {
|
|
23
23
|
before: async (context) => {
|
|
24
24
|
await updatePlugin.initialize();
|
|
25
|
-
context.setValue(
|
|
25
|
+
context.setValue('hotUpdatePlugin', updatePlugin);
|
|
26
26
|
},
|
|
27
27
|
config: async (context) => {
|
|
28
28
|
const compiler = context.getCompiler();
|
|
29
29
|
let options = defaultOptions(context, target);
|
|
30
|
-
options = await (0, common_1.config)(context, name, [
|
|
30
|
+
options = await (0, common_1.config)(context, name, ['rspack.config.js', 'webpack.config.js'], options);
|
|
31
31
|
overrideOptions(context, options, target, updatePlugin);
|
|
32
32
|
if (incremental) {
|
|
33
33
|
options.experiments ??= {};
|
|
34
|
-
options.experiments.incremental ??=
|
|
34
|
+
options.experiments.incremental ??= 'advance-silent';
|
|
35
35
|
}
|
|
36
36
|
compiler.setOptions(options);
|
|
37
37
|
},
|
|
@@ -42,7 +42,7 @@ function createHotProcessor(name, src, temp, target, incremental = false) {
|
|
|
42
42
|
await (0, common_1.build)(context, name);
|
|
43
43
|
},
|
|
44
44
|
run: async (env, context) => {
|
|
45
|
-
await (0, common_1.run)(env, context, name, context => findBundle(context, name, target, updatePlugin));
|
|
45
|
+
await (0, common_1.run)(env, context, name, (context) => findBundle(context, name, target, updatePlugin));
|
|
46
46
|
},
|
|
47
47
|
check: async (env, context) => {
|
|
48
48
|
await (0, common_1.check)(env, context, name);
|
|
@@ -59,7 +59,7 @@ function createHotProcessor(name, src, temp, target, incremental = false) {
|
|
|
59
59
|
if (updateIndex + 1 !== totalUpdates) {
|
|
60
60
|
throw new Error(`Should run all hot steps (${updateIndex + 1} / ${totalUpdates}): ${name}`);
|
|
61
61
|
}
|
|
62
|
-
}
|
|
62
|
+
},
|
|
63
63
|
};
|
|
64
64
|
processor.updatePlugin = updatePlugin;
|
|
65
65
|
return processor;
|
|
@@ -71,13 +71,13 @@ function getCreator(target) {
|
|
|
71
71
|
describe: true,
|
|
72
72
|
target,
|
|
73
73
|
steps: ({ name, target, src, dist, temp }) => [
|
|
74
|
-
createHotProcessor(name, src, temp || node_path_1.default.resolve(dist,
|
|
74
|
+
createHotProcessor(name, src, temp || node_path_1.default.resolve(dist, 'temp'), target),
|
|
75
75
|
],
|
|
76
76
|
runner: {
|
|
77
77
|
key: (context, name, file) => name,
|
|
78
|
-
runner: createHotRunner
|
|
78
|
+
runner: createHotRunner,
|
|
79
79
|
},
|
|
80
|
-
concurrent: true
|
|
80
|
+
concurrent: true,
|
|
81
81
|
}));
|
|
82
82
|
}
|
|
83
83
|
return creators.get(target);
|
|
@@ -89,29 +89,29 @@ function createHotCase(name, src, dist, temp, target) {
|
|
|
89
89
|
function defaultOptions(context, target) {
|
|
90
90
|
const options = {
|
|
91
91
|
context: context.getSource(),
|
|
92
|
-
mode:
|
|
92
|
+
mode: 'development',
|
|
93
93
|
devtool: false,
|
|
94
94
|
output: {
|
|
95
95
|
path: context.getDist(),
|
|
96
|
-
filename:
|
|
97
|
-
chunkFilename:
|
|
98
|
-
publicPath:
|
|
99
|
-
library: { type:
|
|
96
|
+
filename: 'bundle.js',
|
|
97
|
+
chunkFilename: '[name].chunk.[fullhash].js',
|
|
98
|
+
publicPath: 'https://test.cases/path/',
|
|
99
|
+
library: { type: 'commonjs2' },
|
|
100
100
|
},
|
|
101
101
|
optimization: {
|
|
102
|
-
moduleIds:
|
|
102
|
+
moduleIds: 'named',
|
|
103
103
|
},
|
|
104
104
|
target,
|
|
105
105
|
experiments: {
|
|
106
106
|
css: true,
|
|
107
107
|
// test incremental: "safe" here, we test default incremental in Incremental-*.test.js
|
|
108
|
-
incremental:
|
|
108
|
+
incremental: 'safe',
|
|
109
109
|
rspackFuture: {
|
|
110
110
|
bundlerInfo: {
|
|
111
|
-
force: false
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
111
|
+
force: false,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
115
|
};
|
|
116
116
|
options.plugins ??= [];
|
|
117
117
|
options.plugins.push(new core_1.default.HotModuleReplacementPlugin());
|
|
@@ -119,20 +119,20 @@ function defaultOptions(context, target) {
|
|
|
119
119
|
}
|
|
120
120
|
function overrideOptions(context, options, target, updatePlugin) {
|
|
121
121
|
if (!options.entry) {
|
|
122
|
-
options.entry =
|
|
122
|
+
options.entry = './index.js';
|
|
123
123
|
}
|
|
124
124
|
options.module ??= {};
|
|
125
|
-
for (const cssModuleType of [
|
|
125
|
+
for (const cssModuleType of ['css/auto', 'css/module', 'css']) {
|
|
126
126
|
options.module.generator ??= {};
|
|
127
127
|
options.module.generator[cssModuleType] ??= {};
|
|
128
128
|
options.module.generator[cssModuleType].exportsOnly ??=
|
|
129
|
-
target ===
|
|
129
|
+
target === 'async-node';
|
|
130
130
|
}
|
|
131
131
|
options.plugins ??= [];
|
|
132
132
|
options.plugins.push(updatePlugin);
|
|
133
133
|
if (!global.printLogger) {
|
|
134
134
|
options.infrastructureLogging = {
|
|
135
|
-
level:
|
|
135
|
+
level: 'error',
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
if (options.lazyCompilation) {
|
|
@@ -142,18 +142,18 @@ function overrideOptions(context, options, target, updatePlugin) {
|
|
|
142
142
|
function findBundle(context, name, target, updatePlugin) {
|
|
143
143
|
const compiler = context.getCompiler();
|
|
144
144
|
if (!compiler)
|
|
145
|
-
throw new Error(
|
|
145
|
+
throw new Error('Compiler should exists when find bundle');
|
|
146
146
|
const testConfig = context.getTestConfig();
|
|
147
|
-
if (typeof testConfig.findBundle ===
|
|
147
|
+
if (typeof testConfig.findBundle === 'function') {
|
|
148
148
|
return testConfig.findBundle(updatePlugin.getUpdateIndex(), compiler.getOptions());
|
|
149
149
|
}
|
|
150
150
|
const files = [];
|
|
151
151
|
const prefiles = [];
|
|
152
152
|
const stats = compiler.getStats();
|
|
153
153
|
if (!stats)
|
|
154
|
-
throw new Error(
|
|
154
|
+
throw new Error('Stats should exists when find bundle');
|
|
155
155
|
const info = stats.toJson({ all: false, entrypoints: true });
|
|
156
|
-
if (target ===
|
|
156
|
+
if (target === 'web' || target === 'webworker') {
|
|
157
157
|
for (const file of info.entrypoints.main.assets) {
|
|
158
158
|
if ((0, helper_1.isJavaScript)(file.name)) {
|
|
159
159
|
files.push(file.name);
|
|
@@ -164,7 +164,7 @@ function findBundle(context, name, target, updatePlugin) {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
else {
|
|
167
|
-
const assets = info.entrypoints.main.assets.filter(s => (0, helper_1.isJavaScript)(s.name));
|
|
167
|
+
const assets = info.entrypoints.main.assets.filter((s) => (0, helper_1.isJavaScript)(s.name));
|
|
168
168
|
files.push(assets[assets.length - 1].name);
|
|
169
169
|
}
|
|
170
170
|
return [...prefiles, ...files];
|
|
@@ -175,28 +175,28 @@ function createHotRunner(context, name, file, env) {
|
|
|
175
175
|
const testConfig = context.getTestConfig();
|
|
176
176
|
const source = context.getSource();
|
|
177
177
|
const dist = context.getDist();
|
|
178
|
-
const updatePlugin = context.getValue(
|
|
178
|
+
const updatePlugin = context.getValue('hotUpdatePlugin');
|
|
179
179
|
const nextHMR = async (m, options) => {
|
|
180
180
|
await updatePlugin.goNext();
|
|
181
181
|
const stats = await compiler.build();
|
|
182
182
|
if (!stats) {
|
|
183
|
-
throw new Error(
|
|
183
|
+
throw new Error('Should generate stats during build');
|
|
184
184
|
}
|
|
185
185
|
const jsonStats = stats.toJson({
|
|
186
186
|
// errorDetails: true
|
|
187
187
|
});
|
|
188
188
|
const compilerOptions = compiler.getOptions();
|
|
189
189
|
const checker = context.getValue(jsonStats.errors?.length
|
|
190
|
-
?
|
|
191
|
-
:
|
|
190
|
+
? 'hotUpdateStepErrorChecker'
|
|
191
|
+
: 'hotUpdateStepChecker');
|
|
192
192
|
if (checker) {
|
|
193
|
-
checker(updatePlugin.getUpdateIndex(), stats, runner.getGlobal(
|
|
193
|
+
checker(updatePlugin.getUpdateIndex(), stats, runner.getGlobal('__HMR_UPDATED_RUNTIME__'));
|
|
194
194
|
}
|
|
195
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats,
|
|
196
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats,
|
|
195
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, 'error', `errors${updatePlugin.getUpdateIndex()}`, 'Error', compilerOptions);
|
|
196
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, 'warning', `warnings${updatePlugin.getUpdateIndex()}`, 'Warning', compilerOptions);
|
|
197
197
|
const updatedModules = await m.hot.check(options || true);
|
|
198
198
|
if (!updatedModules) {
|
|
199
|
-
throw new Error(
|
|
199
|
+
throw new Error('No update available');
|
|
200
200
|
}
|
|
201
201
|
return jsonStats;
|
|
202
202
|
};
|
|
@@ -209,24 +209,24 @@ function createHotRunner(context, name, file, env) {
|
|
|
209
209
|
...testConfig,
|
|
210
210
|
moduleScope(ms, stats, options) {
|
|
211
211
|
const moduleScope = ms;
|
|
212
|
-
if (typeof testConfig.moduleScope ===
|
|
212
|
+
if (typeof testConfig.moduleScope === 'function') {
|
|
213
213
|
testConfig.moduleScope(moduleScope, stats, compilerOptions);
|
|
214
214
|
}
|
|
215
215
|
moduleScope.NEXT_HMR = nextHMR;
|
|
216
216
|
return moduleScope;
|
|
217
|
-
}
|
|
217
|
+
},
|
|
218
218
|
},
|
|
219
219
|
cachable: true,
|
|
220
220
|
source,
|
|
221
221
|
dist,
|
|
222
|
-
compilerOptions
|
|
222
|
+
compilerOptions,
|
|
223
223
|
};
|
|
224
224
|
let runner;
|
|
225
|
-
if (compilerOptions.target ===
|
|
226
|
-
compilerOptions.target ===
|
|
225
|
+
if (compilerOptions.target === 'web' ||
|
|
226
|
+
compilerOptions.target === 'webworker') {
|
|
227
227
|
runner = new runner_1.WebRunner({
|
|
228
|
-
location: testConfig.location ||
|
|
229
|
-
...commonOptions
|
|
228
|
+
location: testConfig.location || 'https://test.cases/path/index.html',
|
|
229
|
+
...commonOptions,
|
|
230
230
|
});
|
|
231
231
|
}
|
|
232
232
|
else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RspackOptions } from
|
|
2
|
-
export declare function createHotIncrementalCase(name: string, src: string, dist: string, temp: string, target: RspackOptions[
|
|
1
|
+
import type { RspackOptions } from '@rspack/core';
|
|
2
|
+
export declare function createHotIncrementalCase(name: string, src: string, dist: string, temp: string, target: RspackOptions['target'], webpackCases: boolean): void;
|
|
3
3
|
export type WatchIncrementalOptions = {
|
|
4
4
|
ignoreNotFriendlyForIncrementalWarnings?: boolean;
|
|
5
5
|
};
|
package/dist/case/incremental.js
CHANGED
|
@@ -22,13 +22,13 @@ function getHotCreator(target, webpackCases) {
|
|
|
22
22
|
describe: true,
|
|
23
23
|
target,
|
|
24
24
|
steps: ({ name, target, src, temp, dist }) => [
|
|
25
|
-
createHotIncrementalProcessor(name, src, temp || node_path_1.default.resolve(dist,
|
|
25
|
+
createHotIncrementalProcessor(name, src, temp || node_path_1.default.resolve(dist, 'temp'), target, webpackCases),
|
|
26
26
|
],
|
|
27
27
|
runner: {
|
|
28
28
|
key: (context, name, file) => name,
|
|
29
|
-
runner: hot_1.createHotRunner
|
|
29
|
+
runner: hot_1.createHotRunner,
|
|
30
30
|
},
|
|
31
|
-
concurrent: true
|
|
31
|
+
concurrent: true,
|
|
32
32
|
}));
|
|
33
33
|
}
|
|
34
34
|
return hotCreators.get(key);
|
|
@@ -45,7 +45,7 @@ function getWatchCreator(options) {
|
|
|
45
45
|
clean: true,
|
|
46
46
|
runner: {
|
|
47
47
|
key: watch_1.getWatchRunnerKey,
|
|
48
|
-
runner: watch_1.createWatchRunner
|
|
48
|
+
runner: watch_1.createWatchRunner,
|
|
49
49
|
},
|
|
50
50
|
description: (name, index) => {
|
|
51
51
|
return index === 0
|
|
@@ -58,17 +58,17 @@ function getWatchCreator(options) {
|
|
|
58
58
|
const runs = node_fs_1.default
|
|
59
59
|
.readdirSync(src)
|
|
60
60
|
.sort()
|
|
61
|
-
.filter(name => node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory())
|
|
62
|
-
.map(name => ({ name }));
|
|
61
|
+
.filter((name) => node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory())
|
|
62
|
+
.map((name) => ({ name }));
|
|
63
63
|
return runs.map((run, index) => index === 0
|
|
64
64
|
? (0, watch_1.createWatchInitialProcessor)(name, temp, run.name, watchState, {
|
|
65
|
-
incremental: true
|
|
65
|
+
incremental: true,
|
|
66
66
|
})
|
|
67
67
|
: (0, watch_1.createWatchStepProcessor)(name, temp, run.name, watchState, {
|
|
68
|
-
incremental: true
|
|
68
|
+
incremental: true,
|
|
69
69
|
}));
|
|
70
70
|
},
|
|
71
|
-
concurrent: true
|
|
71
|
+
concurrent: true,
|
|
72
72
|
}));
|
|
73
73
|
}
|
|
74
74
|
return watchCreators.get(key);
|
package/dist/case/index.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
export { createBuiltinCase } from
|
|
2
|
-
export { createCacheCase } from
|
|
3
|
-
export type { TCompilerCaseConfig } from
|
|
4
|
-
export { createCompilerCase } from
|
|
5
|
-
export type { TConfigCaseConfig } from
|
|
6
|
-
export { createConfigCase } from
|
|
7
|
-
export type { TDefaultsCaseConfig } from
|
|
8
|
-
export { createDefaultsCase, getRspackDefaultConfig } from
|
|
9
|
-
export type { TDiagnosticOptions } from
|
|
10
|
-
export { createDiagnosticCase } from
|
|
11
|
-
export type { TErrorCaseConfig } from
|
|
12
|
-
export { createErrorCase } from
|
|
13
|
-
export { createEsmOutputCase } from
|
|
14
|
-
export { createExampleCase } from
|
|
15
|
-
export type { THashCaseConfig } from
|
|
16
|
-
export { createHashCase } from
|
|
17
|
-
export type { THookCaseConfig } from
|
|
18
|
-
export { createHookCase } from
|
|
19
|
-
export { createHotCase } from
|
|
20
|
-
export { createHotStepCase } from
|
|
21
|
-
export { createHotIncrementalCase, createWatchIncrementalCase } from
|
|
22
|
-
export type { TMultiCompilerCaseConfig } from
|
|
23
|
-
export { createMultiCompilerCase } from
|
|
24
|
-
export { createNativeWatcher } from
|
|
25
|
-
export { createDevNormalCase, createHotNormalCase, createNormalCase, createProdNormalCase } from
|
|
26
|
-
export { createSerialCase } from
|
|
27
|
-
export type { TStatsAPICaseConfig } from
|
|
28
|
-
export { createStatsAPICase } from
|
|
29
|
-
export { createStatsOutputCase } from
|
|
30
|
-
export { createTreeShakingCase } from
|
|
31
|
-
export { createWatchCase } from
|
|
1
|
+
export { createBuiltinCase } from './builtin';
|
|
2
|
+
export { createCacheCase } from './cache';
|
|
3
|
+
export type { TCompilerCaseConfig } from './compiler';
|
|
4
|
+
export { createCompilerCase } from './compiler';
|
|
5
|
+
export type { TConfigCaseConfig } from './config';
|
|
6
|
+
export { createConfigCase } from './config';
|
|
7
|
+
export type { TDefaultsCaseConfig } from './defaults';
|
|
8
|
+
export { createDefaultsCase, getRspackDefaultConfig } from './defaults';
|
|
9
|
+
export type { TDiagnosticOptions } from './diagnostic';
|
|
10
|
+
export { createDiagnosticCase } from './diagnostic';
|
|
11
|
+
export type { TErrorCaseConfig } from './error';
|
|
12
|
+
export { createErrorCase } from './error';
|
|
13
|
+
export { createEsmOutputCase } from './esm-output';
|
|
14
|
+
export { createExampleCase } from './example';
|
|
15
|
+
export type { THashCaseConfig } from './hash';
|
|
16
|
+
export { createHashCase } from './hash';
|
|
17
|
+
export type { THookCaseConfig } from './hook';
|
|
18
|
+
export { createHookCase } from './hook';
|
|
19
|
+
export { createHotCase } from './hot';
|
|
20
|
+
export { createHotStepCase } from './hot-step';
|
|
21
|
+
export { createHotIncrementalCase, createWatchIncrementalCase, } from './incremental';
|
|
22
|
+
export type { TMultiCompilerCaseConfig } from './multi-compiler';
|
|
23
|
+
export { createMultiCompilerCase } from './multi-compiler';
|
|
24
|
+
export { createNativeWatcher } from './native-watcher';
|
|
25
|
+
export { createDevNormalCase, createHotNormalCase, createNormalCase, createProdNormalCase, } from './normal';
|
|
26
|
+
export { createSerialCase } from './serial';
|
|
27
|
+
export type { TStatsAPICaseConfig } from './stats-api';
|
|
28
|
+
export { createStatsAPICase } from './stats-api';
|
|
29
|
+
export { createStatsOutputCase } from './stats-output';
|
|
30
|
+
export { createTreeShakingCase } from './treeshaking';
|
|
31
|
+
export { createWatchCase } from './watch';
|