@rspack/test-tools 1.5.8 → 1.6.0-beta.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.js +0 -22
- package/dist/case/cache.js +1 -2
- package/dist/case/common.js +5 -1
- package/dist/case/config.js +1 -2
- package/dist/case/diagnostic.d.ts +2 -2
- package/dist/case/diagnostic.js +1 -2
- package/dist/case/error.d.ts +1 -0
- package/dist/case/error.js +25 -6
- package/dist/case/example.d.ts +1 -0
- package/dist/case/example.js +57 -0
- package/dist/case/hash.js +1 -2
- package/dist/case/hook.js +3 -4
- package/dist/case/hot-step.d.ts +1 -1
- package/dist/case/hot-step.js +12 -10
- package/dist/case/hot.d.ts +5 -4
- package/dist/case/hot.js +33 -43
- package/dist/case/incremental.d.ts +1 -1
- package/dist/case/incremental.js +10 -10
- package/dist/case/index.d.ts +12 -1
- package/dist/case/index.js +7 -1
- package/dist/case/multi-compiler.d.ts +18 -0
- package/dist/case/multi-compiler.js +98 -0
- package/dist/case/normal.d.ts +2 -0
- package/dist/case/normal.js +19 -12
- package/dist/case/stats-api.d.ts +9 -0
- package/dist/case/stats-output.js +5 -4
- package/dist/case/watch.d.ts +2 -4
- package/dist/case/watch.js +5 -11
- package/dist/compare/compare.js +6 -3
- package/dist/helper/directory.js +1 -1
- package/dist/helper/expect/error.js +1 -1
- package/dist/helper/expect/placeholder.js +7 -7
- package/dist/helper/expect/to-match-file-snapshot.d.ts +0 -1
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +10 -5
- package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
- package/dist/helper/legacy/LogTestPlugin.js +35 -0
- package/dist/helper/legacy/update.d.ts +2 -0
- package/dist/helper/legacy/update.esm.d.ts +1 -0
- package/dist/helper/legacy/update.esm.js +23 -0
- package/dist/helper/legacy/update.js +19 -0
- package/dist/helper/util/checkStats.d.ts +0 -1
- package/dist/helper/util/checkStats.js +0 -18
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/jest/ignore-snapshot-default-reporter.d.ts +2 -0
- package/dist/jest/ignore-snapshot-default-reporter.js +57 -0
- package/dist/jest/ignore-snapshot-summary-reporter.d.ts +2 -0
- package/dist/jest/ignore-snapshot-summary-reporter.js +24 -0
- package/dist/jest/patch-node-env.d.ts +5 -0
- package/dist/jest/patch-node-env.js +18 -0
- package/dist/jest/slash.d.ts +2 -0
- package/dist/jest/slash.js +16 -0
- package/dist/runner/node/index.js +4 -0
- package/dist/runner/web/fake.js +6 -3
- package/dist/runner/web/jsdom.js +1 -5
- package/dist/test/creator.js +2 -3
- package/dist/test/tester.js +10 -3
- package/dist/type.d.ts +9 -0
- package/package.json +12 -9
- package/dist/helper/legacy/createLogger.d.ts +0 -23
- package/dist/helper/legacy/createLogger.js +0 -20
- package/dist/helper/legacy/supportsBlob.d.ts +0 -2
- package/dist/helper/legacy/supportsBlob.js +0 -10
- package/dist/helper/legacy/supportsClassFields.d.ts +0 -2
- package/dist/helper/legacy/supportsClassFields.js +0 -11
- package/dist/helper/legacy/supportsES6.d.ts +0 -2
- package/dist/helper/legacy/supportsES6.js +0 -11
- package/dist/helper/legacy/supportsForOf.d.ts +0 -2
- package/dist/helper/legacy/supportsForOf.js +0 -11
- package/dist/helper/legacy/supportsIteratorDestructuring.d.ts +0 -2
- package/dist/helper/legacy/supportsIteratorDestructuring.js +0 -11
- package/dist/helper/legacy/supportsLogicalAssignment.d.ts +0 -2
- package/dist/helper/legacy/supportsLogicalAssignment.js +0 -11
- package/dist/helper/legacy/supportsObjectDestructuring.d.ts +0 -2
- package/dist/helper/legacy/supportsObjectDestructuring.js +0 -11
- package/dist/helper/legacy/supportsOptionalCatchBinding.d.ts +0 -2
- package/dist/helper/legacy/supportsOptionalCatchBinding.js +0 -11
- package/dist/helper/legacy/supportsOptionalChaining.d.ts +0 -2
- package/dist/helper/legacy/supportsOptionalChaining.js +0 -11
- package/dist/helper/legacy/supportsRequireInModule.d.ts +0 -2
- package/dist/helper/legacy/supportsRequireInModule.js +0 -5
- package/dist/helper/legacy/supportsResponse.d.ts +0 -2
- package/dist/helper/legacy/supportsResponse.js +0 -10
- package/dist/helper/legacy/supportsSpread.d.ts +0 -2
- package/dist/helper/legacy/supportsSpread.js +0 -12
- package/dist/helper/legacy/supportsTemplateStrings.d.ts +0 -2
- package/dist/helper/legacy/supportsTemplateStrings.js +0 -11
- package/dist/helper/legacy/supportsWebAssembly.d.ts +0 -2
- package/dist/helper/legacy/supportsWebAssembly.js +0 -10
- package/dist/helper/legacy/supportsWorker.d.ts +0 -2
- package/dist/helper/legacy/supportsWorker.js +0 -17
- package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
- package/dist/helper/legacy/warmup-webpack.js +0 -26
- package/dist/helper/loaders/hot-update.d.ts +0 -1
- package/dist/helper/loaders/hot-update.js +0 -40
- package/dist/helper/plugins/hot-update.d.ts +0 -7
- package/dist/helper/plugins/hot-update.js +0 -40
- package/dist/helper/plugins/index.d.ts +0 -1
- package/dist/helper/plugins/index.js +0 -17
- package/dist/helper/util/currentWatchStep.d.ts +0 -1
- package/dist/helper/util/currentWatchStep.js +0 -2
- package/dist/helper/util/identifier.d.ts +0 -76
- package/dist/helper/util/identifier.js +0 -339
- package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
- package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
- package/dist/reporter/diff-html.d.ts +0 -15
- package/dist/reporter/diff-html.js +0 -69
- package/dist/reporter/diff-stats.d.ts +0 -24
- package/dist/reporter/diff-stats.js +0 -131
- package/dist/reporter/index.d.ts +0 -2
- package/dist/reporter/index.js +0 -18
package/dist/case/builtin.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createBuiltinCase = createBuiltinCase;
|
|
7
7
|
exports.defaultOptions = defaultOptions;
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const core_1 = require("@rspack/core");
|
|
10
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
10
|
const webpack_merge_1 = require("webpack-merge");
|
|
12
11
|
const helper_1 = require("../helper");
|
|
@@ -164,27 +163,6 @@ function defaultOptions(context) {
|
|
|
164
163
|
}
|
|
165
164
|
defaultOptions = (0, webpack_merge_1.merge)(defaultOptions, caseOptions);
|
|
166
165
|
}
|
|
167
|
-
// TODO: remove builtin compatible code
|
|
168
|
-
const defineOptions = defaultOptions.builtins?.define;
|
|
169
|
-
if (defineOptions) {
|
|
170
|
-
defaultOptions.plugins.push(new core_1.rspack.DefinePlugin(defineOptions));
|
|
171
|
-
}
|
|
172
|
-
const provideOptions = defaultOptions.builtins?.provide;
|
|
173
|
-
if (provideOptions) {
|
|
174
|
-
defaultOptions.plugins.push(new core_1.rspack.ProvidePlugin(provideOptions));
|
|
175
|
-
}
|
|
176
|
-
const htmlOptions = defaultOptions.builtins?.html;
|
|
177
|
-
if (htmlOptions) {
|
|
178
|
-
if (Array.isArray(htmlOptions)) {
|
|
179
|
-
for (const item of htmlOptions) {
|
|
180
|
-
defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(item));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(htmlOptions));
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
delete defaultOptions.builtins;
|
|
188
166
|
if (!global.printLogger) {
|
|
189
167
|
defaultOptions.infrastructureLogging = {
|
|
190
168
|
level: "error"
|
package/dist/case/cache.js
CHANGED
package/dist/case/common.js
CHANGED
|
@@ -81,7 +81,11 @@ async function run(env, context, name, findBundle) {
|
|
|
81
81
|
const results = context.getValue(name, "modules") || [];
|
|
82
82
|
await Promise.all(results);
|
|
83
83
|
if (typeof testConfig.afterExecute === "function") {
|
|
84
|
-
|
|
84
|
+
let options = compiler.getOptions();
|
|
85
|
+
if (Array.isArray(options) && options.length === 1) {
|
|
86
|
+
options = options[0];
|
|
87
|
+
}
|
|
88
|
+
testConfig.afterExecute(options);
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
async function check(env, context, name) {
|
package/dist/case/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare function createDiagnosticCase(name: string, src: string, dist: string): void;
|
|
2
|
-
export
|
|
2
|
+
export type TDiagnosticOptions = {
|
|
3
3
|
snapshot: string;
|
|
4
4
|
snapshotErrors: string;
|
|
5
5
|
snapshotWarning: string;
|
|
6
6
|
format?: (output: string) => string;
|
|
7
|
-
}
|
|
7
|
+
};
|
package/dist/case/diagnostic.js
CHANGED
package/dist/case/error.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare class RspackStatsDiagnostics {
|
|
|
8
8
|
}
|
|
9
9
|
export type TErrorCaseConfig = {
|
|
10
10
|
description: string;
|
|
11
|
+
skip?: boolean;
|
|
11
12
|
options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
|
|
12
13
|
compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
|
|
13
14
|
build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
|
package/dist/case/error.js
CHANGED
|
@@ -49,15 +49,29 @@ function createErrorCase(name, src, dist, testConfig) {
|
|
|
49
49
|
if (!addedSerializer) {
|
|
50
50
|
addedSerializer = true;
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
caseConfig
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
const caseConfigList = require(testConfig);
|
|
53
|
+
function createCase(caseConfig) {
|
|
54
|
+
if (caseConfig.skip) {
|
|
55
|
+
it.skip(name, () => { });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
creator.create(name, src, dist, undefined, {
|
|
59
|
+
caseConfig,
|
|
60
|
+
description: () => caseConfig.description
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(caseConfigList)) {
|
|
64
|
+
for (const caseConfig of caseConfigList) {
|
|
65
|
+
createCase(caseConfig);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
createCase(caseConfigList);
|
|
70
|
+
}
|
|
57
71
|
}
|
|
58
72
|
function options(context, custom) {
|
|
59
73
|
let options = {
|
|
60
|
-
context: node_path_1.default.resolve(
|
|
74
|
+
context: node_path_1.default.resolve(__TEST_FIXTURES_PATH__, "errors"),
|
|
61
75
|
mode: "none",
|
|
62
76
|
devtool: false,
|
|
63
77
|
optimization: {
|
|
@@ -116,6 +130,11 @@ class RspackStatsDiagnostics {
|
|
|
116
130
|
}
|
|
117
131
|
}
|
|
118
132
|
async function check(env, context, name, check) {
|
|
133
|
+
if (context.getError(name).length > 0) {
|
|
134
|
+
await check?.(new RspackStatsDiagnostics(context.getError(name), []));
|
|
135
|
+
context.clearError(name);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
119
138
|
const compiler = (0, common_1.getCompiler)(context, name);
|
|
120
139
|
const stats = compiler.getStats();
|
|
121
140
|
env.expect(typeof stats).toBe("object");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createExampleCase(name: string, src: string): void;
|
|
@@ -0,0 +1,57 @@
|
|
|
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.createExampleCase = createExampleCase;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const creator_1 = require("../test/creator");
|
|
9
|
+
const common_1 = require("./common");
|
|
10
|
+
function overrideOptions(index, context, options) {
|
|
11
|
+
options.context = context.getSource();
|
|
12
|
+
options.output = options.output || {};
|
|
13
|
+
options.output.pathinfo = true;
|
|
14
|
+
options.output.path = context.getDist();
|
|
15
|
+
options.output.publicPath = "dist/";
|
|
16
|
+
if (!options.entry)
|
|
17
|
+
options.entry = "./example.js";
|
|
18
|
+
if (!options.plugins)
|
|
19
|
+
options.plugins = [];
|
|
20
|
+
}
|
|
21
|
+
function createExampleProcessor(name) {
|
|
22
|
+
return {
|
|
23
|
+
config: async (context) => {
|
|
24
|
+
(0, common_1.configMultiCompiler)(context, name, ["rspack.config.js", "webpack.config.js"], () => ({}), overrideOptions);
|
|
25
|
+
},
|
|
26
|
+
compiler: async (context) => {
|
|
27
|
+
await (0, common_1.compiler)(context, name);
|
|
28
|
+
},
|
|
29
|
+
build: async (context) => {
|
|
30
|
+
await (0, common_1.build)(context, name);
|
|
31
|
+
},
|
|
32
|
+
run: async (env, context) => {
|
|
33
|
+
// no need to run, just check the building
|
|
34
|
+
},
|
|
35
|
+
check: async (env, context) => {
|
|
36
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
37
|
+
const stats = compiler.getStats();
|
|
38
|
+
if (stats?.hasErrors()) {
|
|
39
|
+
console.log(stats.toString({
|
|
40
|
+
all: false,
|
|
41
|
+
errors: true,
|
|
42
|
+
errorDetails: true,
|
|
43
|
+
errorStacks: true
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
expect(stats?.hasErrors()).toBe(false);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const creator = new creator_1.BasicCaseCreator({
|
|
51
|
+
clean: true,
|
|
52
|
+
steps: ({ name }) => [createExampleProcessor(name)],
|
|
53
|
+
concurrent: true
|
|
54
|
+
});
|
|
55
|
+
function createExampleCase(name, src) {
|
|
56
|
+
creator.create(name, src, node_path_1.default.join(src, "dist"));
|
|
57
|
+
}
|
package/dist/case/hash.js
CHANGED
package/dist/case/hook.js
CHANGED
|
@@ -14,8 +14,8 @@ const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
|
14
14
|
const context_1 = require("../test/context");
|
|
15
15
|
const creator_1 = require("../test/creator");
|
|
16
16
|
const common_1 = require("./common");
|
|
17
|
-
const srcDir =
|
|
18
|
-
const distDir = node_path_1.default.resolve(
|
|
17
|
+
const srcDir = __TEST_FIXTURES_PATH__;
|
|
18
|
+
const distDir = node_path_1.default.resolve(__TEST_DIST_PATH__, "hook");
|
|
19
19
|
const creator = new creator_1.BasicCaseCreator({
|
|
20
20
|
clean: true,
|
|
21
21
|
describe: true,
|
|
@@ -213,8 +213,7 @@ function defaultOptions(context, custom) {
|
|
|
213
213
|
force: false
|
|
214
214
|
}
|
|
215
215
|
},
|
|
216
|
-
inlineConst: true
|
|
217
|
-
lazyBarrel: true
|
|
216
|
+
inlineConst: true
|
|
218
217
|
}
|
|
219
218
|
};
|
|
220
219
|
if (custom) {
|
package/dist/case/hot-step.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ECompilerType, type TCompilerOptions } from "../type";
|
|
2
|
-
export declare function createHotStepCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
|
2
|
+
export declare function createHotStepCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
package/dist/case/hot-step.js
CHANGED
|
@@ -39,8 +39,8 @@ const GET_MODULE_HANDLER = {
|
|
|
39
39
|
node: NODE_HANDLER
|
|
40
40
|
};
|
|
41
41
|
const creators = new Map();
|
|
42
|
-
function createHotStepProcessor(name, target) {
|
|
43
|
-
const processor = (0, hot_1.createHotProcessor)(name, target);
|
|
42
|
+
function createHotStepProcessor(name, src, temp, target) {
|
|
43
|
+
const processor = (0, hot_1.createHotProcessor)(name, src, temp, target);
|
|
44
44
|
const entries = {};
|
|
45
45
|
const hashes = [];
|
|
46
46
|
function matchStepSnapshot(env, context, step, options, stats, runtime) {
|
|
@@ -53,7 +53,9 @@ function createHotStepProcessor(name, target) {
|
|
|
53
53
|
const hotUpdateManifest = [];
|
|
54
54
|
const changedFiles = step === 0
|
|
55
55
|
? []
|
|
56
|
-
: processor.
|
|
56
|
+
: processor.updatePlugin
|
|
57
|
+
.getModifiedFiles()
|
|
58
|
+
.map((i) => (0, helper_1.escapeSep)(node_path_1.default.relative(temp, i)));
|
|
57
59
|
changedFiles.sort();
|
|
58
60
|
const resultHashes = {
|
|
59
61
|
[lastHash || "LAST_HASH"]: "LAST_HASH",
|
|
@@ -245,7 +247,7 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
|
|
|
245
247
|
}
|
|
246
248
|
const originRun = processor.run;
|
|
247
249
|
processor.run = async function (env, context) {
|
|
248
|
-
context.setValue(name, "hotUpdateStepChecker", (
|
|
250
|
+
context.setValue(name, "hotUpdateStepChecker", (updateIndex, stats, runtime) => {
|
|
249
251
|
const statsJson = stats.toJson({
|
|
250
252
|
assets: true,
|
|
251
253
|
chunks: true
|
|
@@ -264,10 +266,10 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
|
|
|
264
266
|
}
|
|
265
267
|
const compiler = context.getCompiler(name, type_1.ECompilerType.Rspack);
|
|
266
268
|
const compilerOptions = compiler.getOptions();
|
|
267
|
-
matchStepSnapshot(env, context,
|
|
269
|
+
matchStepSnapshot(env, context, updateIndex, compilerOptions, statsJson, runtime);
|
|
268
270
|
hashes.push(stats.hash);
|
|
269
271
|
});
|
|
270
|
-
context.setValue(name, "hotUpdateStepErrorChecker", (
|
|
272
|
+
context.setValue(name, "hotUpdateStepErrorChecker", (updateIndex, stats, runtime) => {
|
|
271
273
|
hashes.push(stats.hash);
|
|
272
274
|
});
|
|
273
275
|
await originRun(env, context);
|
|
@@ -312,8 +314,8 @@ function getCreator(target) {
|
|
|
312
314
|
clean: true,
|
|
313
315
|
describe: false,
|
|
314
316
|
target,
|
|
315
|
-
steps: ({ name, target }) => [
|
|
316
|
-
createHotStepProcessor(name, target)
|
|
317
|
+
steps: ({ name, target, src, temp, dist }) => [
|
|
318
|
+
createHotStepProcessor(name, src, temp || node_path_1.default.resolve(dist, "temp"), target)
|
|
317
319
|
],
|
|
318
320
|
runner: {
|
|
319
321
|
key: (context, name, file) => name,
|
|
@@ -324,7 +326,7 @@ function getCreator(target) {
|
|
|
324
326
|
}
|
|
325
327
|
return creators.get(target);
|
|
326
328
|
}
|
|
327
|
-
function createHotStepCase(name, src, dist, target) {
|
|
329
|
+
function createHotStepCase(name, src, dist, temp, target) {
|
|
328
330
|
const creator = getCreator(target);
|
|
329
|
-
creator.create(name, src, dist);
|
|
331
|
+
creator.create(name, src, dist, temp);
|
|
330
332
|
}
|
package/dist/case/hot.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HotUpdatePlugin } from "../helper/hot-update/plugin";
|
|
2
|
+
import { type ECompilerType, type ITestContext, type ITestEnv, type ITestProcessor, type ITestRunner, type TCompilerOptions } from "../type";
|
|
2
3
|
type TTarget = TCompilerOptions<ECompilerType.Rspack>["target"];
|
|
3
|
-
export declare function createHotProcessor(name: string, target: TTarget, incremental?: boolean): THotProcessor;
|
|
4
|
-
export declare function createHotCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
|
4
|
+
export declare function createHotProcessor(name: string, src: string, temp: string, target: TTarget, incremental?: boolean): THotProcessor;
|
|
5
|
+
export declare function createHotCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
|
5
6
|
type THotProcessor = ITestProcessor & {
|
|
6
|
-
|
|
7
|
+
updatePlugin: HotUpdatePlugin;
|
|
7
8
|
};
|
|
8
9
|
export declare function createHotRunner<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
|
|
9
10
|
export {};
|
package/dist/case/hot.js
CHANGED
|
@@ -9,27 +9,27 @@ exports.createHotRunner = createHotRunner;
|
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const core_1 = __importDefault(require("@rspack/core"));
|
|
11
11
|
const helper_1 = require("../helper");
|
|
12
|
+
const plugin_1 = require("../helper/hot-update/plugin");
|
|
12
13
|
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
13
|
-
const
|
|
14
|
-
const plugin_1 = require("../plugin");
|
|
14
|
+
const plugin_2 = require("../plugin");
|
|
15
15
|
const runner_1 = require("../runner");
|
|
16
16
|
const creator_1 = require("../test/creator");
|
|
17
17
|
const type_1 = require("../type");
|
|
18
18
|
const common_1 = require("./common");
|
|
19
19
|
const runner_2 = require("./runner");
|
|
20
20
|
const creators = new Map();
|
|
21
|
-
function createHotProcessor(name, target, incremental = false) {
|
|
22
|
-
const
|
|
23
|
-
updateIndex: 0,
|
|
24
|
-
totalUpdates: 1,
|
|
25
|
-
changedFiles: []
|
|
26
|
-
};
|
|
21
|
+
function createHotProcessor(name, src, temp, target, incremental = false) {
|
|
22
|
+
const updatePlugin = new plugin_1.HotUpdatePlugin(src, temp);
|
|
27
23
|
const processor = {
|
|
24
|
+
before: async (context) => {
|
|
25
|
+
await updatePlugin.initialize();
|
|
26
|
+
context.setValue(name, "hotUpdatePlugin", updatePlugin);
|
|
27
|
+
},
|
|
28
28
|
config: async (context) => {
|
|
29
29
|
const compiler = (0, common_1.getCompiler)(context, name);
|
|
30
|
-
let options = defaultOptions(context, target
|
|
30
|
+
let options = defaultOptions(context, target);
|
|
31
31
|
options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"], options);
|
|
32
|
-
overrideOptions(context, options, target,
|
|
32
|
+
overrideOptions(context, options, target, updatePlugin);
|
|
33
33
|
if (incremental) {
|
|
34
34
|
options.experiments ??= {};
|
|
35
35
|
options.experiments.incremental ??= "advance-silent";
|
|
@@ -43,8 +43,7 @@ function createHotProcessor(name, target, incremental = false) {
|
|
|
43
43
|
await (0, common_1.build)(context, name);
|
|
44
44
|
},
|
|
45
45
|
run: async (env, context) => {
|
|
46
|
-
|
|
47
|
-
await (0, common_1.run)(env, context, name, context => findBundle(context, name, target, hotUpdateContext));
|
|
46
|
+
await (0, common_1.run)(env, context, name, context => findBundle(context, name, target, updatePlugin));
|
|
48
47
|
},
|
|
49
48
|
check: async (env, context) => {
|
|
50
49
|
await (0, common_1.check)(env, context, name);
|
|
@@ -53,12 +52,14 @@ function createHotProcessor(name, target, incremental = false) {
|
|
|
53
52
|
if (context.getTestConfig().checkSteps === false) {
|
|
54
53
|
return;
|
|
55
54
|
}
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const updateIndex = updatePlugin.getUpdateIndex();
|
|
56
|
+
const totalUpdates = updatePlugin.getTotalUpdates();
|
|
57
|
+
if (updateIndex + 1 !== totalUpdates) {
|
|
58
|
+
throw new Error(`Should run all hot steps (${updateIndex + 1} / ${totalUpdates}): ${name}`);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
};
|
|
61
|
-
processor.
|
|
62
|
+
processor.updatePlugin = updatePlugin;
|
|
62
63
|
return processor;
|
|
63
64
|
}
|
|
64
65
|
function getCreator(target) {
|
|
@@ -67,8 +68,8 @@ function getCreator(target) {
|
|
|
67
68
|
clean: true,
|
|
68
69
|
describe: true,
|
|
69
70
|
target,
|
|
70
|
-
steps: ({ name, target }) => [
|
|
71
|
-
createHotProcessor(name, target)
|
|
71
|
+
steps: ({ name, target, src, dist, temp }) => [
|
|
72
|
+
createHotProcessor(name, src, temp || node_path_1.default.resolve(dist, "temp"), target)
|
|
72
73
|
],
|
|
73
74
|
runner: {
|
|
74
75
|
key: (context, name, file) => name,
|
|
@@ -79,11 +80,11 @@ function getCreator(target) {
|
|
|
79
80
|
}
|
|
80
81
|
return creators.get(target);
|
|
81
82
|
}
|
|
82
|
-
function createHotCase(name, src, dist, target) {
|
|
83
|
+
function createHotCase(name, src, dist, temp, target) {
|
|
83
84
|
const creator = getCreator(target);
|
|
84
|
-
creator.create(name, src, dist);
|
|
85
|
+
creator.create(name, src, dist, temp);
|
|
85
86
|
}
|
|
86
|
-
function defaultOptions(context, target
|
|
87
|
+
function defaultOptions(context, target) {
|
|
87
88
|
const options = {
|
|
88
89
|
context: context.getSource(),
|
|
89
90
|
mode: "development",
|
|
@@ -108,15 +109,14 @@ function defaultOptions(context, target, updateOptions) {
|
|
|
108
109
|
force: false
|
|
109
110
|
}
|
|
110
111
|
},
|
|
111
|
-
inlineConst: true
|
|
112
|
-
lazyBarrel: true
|
|
112
|
+
inlineConst: true
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
115
|
options.plugins ??= [];
|
|
116
|
-
options.plugins.push(new core_1.default.HotModuleReplacementPlugin()
|
|
116
|
+
options.plugins.push(new core_1.default.HotModuleReplacementPlugin());
|
|
117
117
|
return options;
|
|
118
118
|
}
|
|
119
|
-
function overrideOptions(context, options, target,
|
|
119
|
+
function overrideOptions(context, options, target, updatePlugin) {
|
|
120
120
|
if (!options.entry) {
|
|
121
121
|
options.entry = "./index.js";
|
|
122
122
|
}
|
|
@@ -127,34 +127,24 @@ function overrideOptions(context, options, target, updateOptions) {
|
|
|
127
127
|
options.module.generator[cssModuleType].exportsOnly ??=
|
|
128
128
|
target === "async-node";
|
|
129
129
|
}
|
|
130
|
-
options.module.rules ??= [];
|
|
131
|
-
options.module.rules.push({
|
|
132
|
-
use: [
|
|
133
|
-
{
|
|
134
|
-
loader: node_path_1.default.resolve(__dirname, "../helper/loaders/hot-update.js"),
|
|
135
|
-
options: updateOptions
|
|
136
|
-
}
|
|
137
|
-
],
|
|
138
|
-
enforce: "pre"
|
|
139
|
-
});
|
|
140
130
|
options.plugins ??= [];
|
|
141
|
-
options.plugins.push(
|
|
131
|
+
options.plugins.push(updatePlugin);
|
|
142
132
|
if (!global.printLogger) {
|
|
143
133
|
options.infrastructureLogging = {
|
|
144
134
|
level: "error"
|
|
145
135
|
};
|
|
146
136
|
}
|
|
147
137
|
if (options.lazyCompilation) {
|
|
148
|
-
options.plugins.push(new
|
|
138
|
+
options.plugins.push(new plugin_2.LazyCompilationTestPlugin());
|
|
149
139
|
}
|
|
150
140
|
}
|
|
151
|
-
function findBundle(context, name, target,
|
|
141
|
+
function findBundle(context, name, target, updatePlugin) {
|
|
152
142
|
const compiler = context.getCompiler(name);
|
|
153
143
|
if (!compiler)
|
|
154
144
|
throw new Error("Compiler should exists when find bundle");
|
|
155
145
|
const testConfig = context.getTestConfig();
|
|
156
146
|
if (typeof testConfig.findBundle === "function") {
|
|
157
|
-
return testConfig.findBundle(
|
|
147
|
+
return testConfig.findBundle(updatePlugin.getUpdateIndex(), compiler.getOptions());
|
|
158
148
|
}
|
|
159
149
|
const files = [];
|
|
160
150
|
const prefiles = [];
|
|
@@ -184,11 +174,11 @@ function createHotRunner(context, name, file, env) {
|
|
|
184
174
|
const testConfig = context.getTestConfig();
|
|
185
175
|
const source = context.getSource();
|
|
186
176
|
const dist = context.getDist();
|
|
187
|
-
const
|
|
177
|
+
const updatePlugin = context.getValue(name, "hotUpdatePlugin");
|
|
188
178
|
const next = async (callback) => {
|
|
189
179
|
const usePromise = typeof callback === "function";
|
|
190
180
|
try {
|
|
191
|
-
|
|
181
|
+
await updatePlugin.goNext();
|
|
192
182
|
const stats = await compiler.build();
|
|
193
183
|
if (!stats) {
|
|
194
184
|
throw new Error("Should generate stats during build");
|
|
@@ -201,10 +191,10 @@ function createHotRunner(context, name, file, env) {
|
|
|
201
191
|
? "hotUpdateStepErrorChecker"
|
|
202
192
|
: "hotUpdateStepChecker");
|
|
203
193
|
if (checker) {
|
|
204
|
-
checker(
|
|
194
|
+
checker(updatePlugin.getUpdateIndex(), stats, runner.getGlobal("__HMR_UPDATED_RUNTIME__"));
|
|
205
195
|
}
|
|
206
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${
|
|
207
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${
|
|
196
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updatePlugin.getUpdateIndex()}`, "Error", compilerOptions);
|
|
197
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updatePlugin.getUpdateIndex()}`, "Warning", compilerOptions);
|
|
208
198
|
if (usePromise) {
|
|
209
199
|
// old callback style hmr cases
|
|
210
200
|
callback(null, jsonStats);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ECompilerType, type TCompilerOptions } from "../type";
|
|
2
|
-
export declare function createHotIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], webpackCases: boolean): void;
|
|
2
|
+
export declare function createHotIncrementalCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], webpackCases: boolean): void;
|
|
3
3
|
export type WatchIncrementalOptions = {
|
|
4
4
|
ignoreNotFriendlyForIncrementalWarnings?: boolean;
|
|
5
5
|
};
|
package/dist/case/incremental.js
CHANGED
|
@@ -12,9 +12,11 @@ const type_1 = require("../type");
|
|
|
12
12
|
const hot_1 = require("./hot");
|
|
13
13
|
const watch_1 = require("./watch");
|
|
14
14
|
const hotCreators = new Map();
|
|
15
|
-
function createHotIncrementalProcessor(name, target, webpackCases) {
|
|
16
|
-
const processor = (0, hot_1.createHotProcessor)(name, target, true);
|
|
15
|
+
function createHotIncrementalProcessor(name, src, temp, target, webpackCases) {
|
|
16
|
+
const processor = (0, hot_1.createHotProcessor)(name, src, temp, target, true);
|
|
17
|
+
const originalBefore = processor.before;
|
|
17
18
|
processor.before = async (context) => {
|
|
19
|
+
await originalBefore?.(context);
|
|
18
20
|
context.setValue(name, "documentType", webpackCases ? type_1.EDocumentType.Fake : type_1.EDocumentType.JSDOM);
|
|
19
21
|
};
|
|
20
22
|
const originalAfterAll = processor.afterAll;
|
|
@@ -38,8 +40,8 @@ function getHotCreator(target, webpackCases) {
|
|
|
38
40
|
clean: true,
|
|
39
41
|
describe: true,
|
|
40
42
|
target,
|
|
41
|
-
steps: ({ name, target }) => [
|
|
42
|
-
createHotIncrementalProcessor(name, target, webpackCases)
|
|
43
|
+
steps: ({ name, target, src, temp, dist }) => [
|
|
44
|
+
createHotIncrementalProcessor(name, src, temp || node_path_1.default.resolve(dist, "temp"), target, webpackCases)
|
|
43
45
|
],
|
|
44
46
|
runner: {
|
|
45
47
|
key: (context, name, file) => name,
|
|
@@ -50,9 +52,9 @@ function getHotCreator(target, webpackCases) {
|
|
|
50
52
|
}
|
|
51
53
|
return hotCreators.get(key);
|
|
52
54
|
}
|
|
53
|
-
function createHotIncrementalCase(name, src, dist, target, webpackCases) {
|
|
55
|
+
function createHotIncrementalCase(name, src, dist, temp, target, webpackCases) {
|
|
54
56
|
const creator = getHotCreator(target, webpackCases);
|
|
55
|
-
creator.create(name, src, dist);
|
|
57
|
+
creator.create(name, src, dist, temp);
|
|
56
58
|
}
|
|
57
59
|
const watchCreators = new Map();
|
|
58
60
|
function getWatchCreator(options) {
|
|
@@ -79,12 +81,10 @@ function getWatchCreator(options) {
|
|
|
79
81
|
.map(name => ({ name }));
|
|
80
82
|
return runs.map((run, index) => index === 0
|
|
81
83
|
? (0, watch_1.createWatchInitialProcessor)(name, temp, run.name, watchState, {
|
|
82
|
-
incremental: true
|
|
83
|
-
ignoreNotFriendlyForIncrementalWarnings: options.ignoreNotFriendlyForIncrementalWarnings
|
|
84
|
+
incremental: true
|
|
84
85
|
})
|
|
85
86
|
: (0, watch_1.createWatchStepProcessor)(name, temp, run.name, watchState, {
|
|
86
|
-
incremental: true
|
|
87
|
-
ignoreNotFriendlyForIncrementalWarnings: options.ignoreNotFriendlyForIncrementalWarnings
|
|
87
|
+
incremental: true
|
|
88
88
|
}));
|
|
89
89
|
},
|
|
90
90
|
concurrent: true
|
package/dist/case/index.d.ts
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
export { createBuiltinCase } from "./builtin";
|
|
2
2
|
export { createCacheCase } from "./cache";
|
|
3
|
+
export type { TCompilerCaseConfig } from "./compiler";
|
|
3
4
|
export { createCompilerCase } from "./compiler";
|
|
5
|
+
export type { TConfigCaseConfig } from "./config";
|
|
4
6
|
export { createConfigCase } from "./config";
|
|
7
|
+
export type { TDefaultsCaseConfig } from "./defaults";
|
|
5
8
|
export { createDefaultsCase, getRspackDefaultConfig } from "./defaults";
|
|
9
|
+
export type { TDiagnosticOptions } from "./diagnostic";
|
|
6
10
|
export { createDiagnosticCase } from "./diagnostic";
|
|
7
11
|
export { createDiffCase } from "./diff";
|
|
12
|
+
export type { TErrorCaseConfig } from "./error";
|
|
8
13
|
export { createErrorCase } from "./error";
|
|
9
14
|
export { createEsmOutputCase } from "./esm-output";
|
|
15
|
+
export { createExampleCase } from "./example";
|
|
16
|
+
export type { THashCaseConfig } from "./hash";
|
|
10
17
|
export { createHashCase } from "./hash";
|
|
18
|
+
export type { THookCaseConfig } from "./hook";
|
|
11
19
|
export { createHookCase } from "./hook";
|
|
12
20
|
export { createHotCase } from "./hot";
|
|
13
21
|
export { createHotStepCase } from "./hot-step";
|
|
14
22
|
export { createHotIncrementalCase, createWatchIncrementalCase } from "./incremental";
|
|
23
|
+
export type { TMultiCompilerCaseConfig } from "./multi-compiler";
|
|
24
|
+
export { createMultiCompilerCase } from "./multi-compiler";
|
|
15
25
|
export { createNativeWatcher } from "./native-watcher";
|
|
16
|
-
export { createHotNormalCase, createNormalCase } from "./normal";
|
|
26
|
+
export { createDevNormalCase, createHotNormalCase, createNormalCase, createProdNormalCase } from "./normal";
|
|
17
27
|
export { createSerialCase } from "./serial";
|
|
28
|
+
export type { TStatsAPICaseConfig } from "./stats-api";
|
|
18
29
|
export { createStatsAPICase } from "./stats-api";
|
|
19
30
|
export { createStatsOutputCase } from "./stats-output";
|
|
20
31
|
export { createTreeShakingCase } from "./treeshaking";
|
package/dist/case/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createWatchCase = exports.createTreeShakingCase = exports.createStatsOutputCase = exports.createStatsAPICase = exports.createSerialCase = exports.createNormalCase = exports.createHotNormalCase = exports.createNativeWatcher = exports.createWatchIncrementalCase = exports.createHotIncrementalCase = exports.createHotStepCase = exports.createHotCase = exports.createHookCase = exports.createHashCase = exports.createEsmOutputCase = exports.createErrorCase = exports.createDiffCase = exports.createDiagnosticCase = exports.getRspackDefaultConfig = exports.createDefaultsCase = exports.createConfigCase = exports.createCompilerCase = exports.createCacheCase = exports.createBuiltinCase = void 0;
|
|
3
|
+
exports.createWatchCase = exports.createTreeShakingCase = exports.createStatsOutputCase = exports.createStatsAPICase = exports.createSerialCase = exports.createProdNormalCase = exports.createNormalCase = exports.createHotNormalCase = exports.createDevNormalCase = exports.createNativeWatcher = exports.createMultiCompilerCase = exports.createWatchIncrementalCase = exports.createHotIncrementalCase = exports.createHotStepCase = exports.createHotCase = exports.createHookCase = exports.createHashCase = exports.createExampleCase = exports.createEsmOutputCase = exports.createErrorCase = exports.createDiffCase = exports.createDiagnosticCase = exports.getRspackDefaultConfig = exports.createDefaultsCase = exports.createConfigCase = exports.createCompilerCase = exports.createCacheCase = exports.createBuiltinCase = void 0;
|
|
4
4
|
var builtin_1 = require("./builtin");
|
|
5
5
|
Object.defineProperty(exports, "createBuiltinCase", { enumerable: true, get: function () { return builtin_1.createBuiltinCase; } });
|
|
6
6
|
var cache_1 = require("./cache");
|
|
@@ -20,6 +20,8 @@ var error_1 = require("./error");
|
|
|
20
20
|
Object.defineProperty(exports, "createErrorCase", { enumerable: true, get: function () { return error_1.createErrorCase; } });
|
|
21
21
|
var esm_output_1 = require("./esm-output");
|
|
22
22
|
Object.defineProperty(exports, "createEsmOutputCase", { enumerable: true, get: function () { return esm_output_1.createEsmOutputCase; } });
|
|
23
|
+
var example_1 = require("./example");
|
|
24
|
+
Object.defineProperty(exports, "createExampleCase", { enumerable: true, get: function () { return example_1.createExampleCase; } });
|
|
23
25
|
var hash_1 = require("./hash");
|
|
24
26
|
Object.defineProperty(exports, "createHashCase", { enumerable: true, get: function () { return hash_1.createHashCase; } });
|
|
25
27
|
var hook_1 = require("./hook");
|
|
@@ -31,11 +33,15 @@ Object.defineProperty(exports, "createHotStepCase", { enumerable: true, get: fun
|
|
|
31
33
|
var incremental_1 = require("./incremental");
|
|
32
34
|
Object.defineProperty(exports, "createHotIncrementalCase", { enumerable: true, get: function () { return incremental_1.createHotIncrementalCase; } });
|
|
33
35
|
Object.defineProperty(exports, "createWatchIncrementalCase", { enumerable: true, get: function () { return incremental_1.createWatchIncrementalCase; } });
|
|
36
|
+
var multi_compiler_1 = require("./multi-compiler");
|
|
37
|
+
Object.defineProperty(exports, "createMultiCompilerCase", { enumerable: true, get: function () { return multi_compiler_1.createMultiCompilerCase; } });
|
|
34
38
|
var native_watcher_1 = require("./native-watcher");
|
|
35
39
|
Object.defineProperty(exports, "createNativeWatcher", { enumerable: true, get: function () { return native_watcher_1.createNativeWatcher; } });
|
|
36
40
|
var normal_1 = require("./normal");
|
|
41
|
+
Object.defineProperty(exports, "createDevNormalCase", { enumerable: true, get: function () { return normal_1.createDevNormalCase; } });
|
|
37
42
|
Object.defineProperty(exports, "createHotNormalCase", { enumerable: true, get: function () { return normal_1.createHotNormalCase; } });
|
|
38
43
|
Object.defineProperty(exports, "createNormalCase", { enumerable: true, get: function () { return normal_1.createNormalCase; } });
|
|
44
|
+
Object.defineProperty(exports, "createProdNormalCase", { enumerable: true, get: function () { return normal_1.createProdNormalCase; } });
|
|
39
45
|
var serial_1 = require("./serial");
|
|
40
46
|
Object.defineProperty(exports, "createSerialCase", { enumerable: true, get: function () { return serial_1.createSerialCase; } });
|
|
41
47
|
var stats_api_1 = require("./stats-api");
|