@rspack/test-tools 1.6.0-beta.0 → 1.6.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 +3 -2
- package/dist/case/builtin.js +1 -1
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +13 -9
- package/dist/case/common.d.ts +11 -10
- package/dist/case/common.js +49 -43
- package/dist/case/compiler.d.ts +9 -8
- package/dist/case/compiler.js +5 -6
- package/dist/case/config.d.ts +6 -5
- package/dist/case/config.js +4 -1
- package/dist/case/defaults.d.ts +5 -4
- package/dist/case/defaults.js +10 -10
- package/dist/case/diagnostic.js +5 -6
- package/dist/case/error.d.ts +5 -5
- package/dist/case/error.js +7 -8
- package/dist/case/esm-output.js +30 -9
- package/dist/case/example.js +2 -2
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +1 -1
- package/dist/case/hook.d.ts +4 -3
- package/dist/case/hook.js +3 -2
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +4 -9
- package/dist/case/hot.d.ts +5 -4
- package/dist/case/hot.js +37 -49
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +1 -20
- package/dist/case/index.d.ts +0 -1
- package/dist/case/index.js +1 -3
- package/dist/case/multi-compiler.d.ts +9 -8
- package/dist/case/multi-compiler.js +3 -4
- package/dist/case/normal.js +5 -2
- package/dist/case/runner.d.ts +5 -4
- package/dist/case/runner.js +16 -11
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +1 -1
- package/dist/case/stats-api.d.ts +6 -5
- package/dist/case/stats-api.js +5 -7
- package/dist/case/stats-output.d.ts +3 -2
- package/dist/case/stats-output.js +1 -1
- package/dist/case/treeshaking.js +1 -1
- package/dist/case/watch.d.ts +8 -6
- package/dist/case/watch.js +21 -19
- package/dist/compiler.d.ts +16 -17
- package/dist/compiler.js +116 -16
- package/dist/helper/hot-update/loader.d.ts +2 -1
- package/dist/helper/hot-update/loader.js +5 -30
- package/dist/helper/hot-update/plugin.js +10 -14
- package/dist/helper/index.d.ts +1 -0
- package/dist/helper/index.js +1 -0
- package/dist/helper/legacy/asModule.js +0 -2
- package/dist/helper/legacy/checkArrayExpectation.js +1 -1
- package/dist/helper/legacy/createLazyTestEnv.d.ts +1 -0
- package/dist/helper/legacy/createLazyTestEnv.js +4 -3
- package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
- package/dist/helper/legacy/supportsTextDecoder.js +9 -0
- package/dist/helper/read-config-file.d.ts +3 -2
- package/dist/helper/read-config-file.js +12 -2
- package/dist/helper/setup-env.js +19 -2
- package/dist/helper/stringify-config.d.ts +2 -0
- package/dist/helper/stringify-config.js +43 -0
- package/dist/helper/util/expectWarningFactory.js +2 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/plugin/index.d.ts +0 -3
- package/dist/plugin/index.js +0 -3
- package/dist/runner/node/index.d.ts +13 -8
- package/dist/runner/node/index.js +88 -10
- package/dist/runner/web/index.d.ts +24 -10
- package/dist/runner/web/index.js +286 -18
- package/dist/test/context.d.ts +15 -16
- package/dist/test/context.js +44 -59
- package/dist/test/creator.d.ts +14 -14
- package/dist/test/creator.js +17 -12
- package/dist/test/debug.d.ts +15 -0
- package/dist/test/debug.js +205 -0
- package/dist/test/tester.d.ts +1 -0
- package/dist/test/tester.js +23 -4
- package/dist/type.d.ts +42 -55
- package/dist/type.js +1 -11
- package/jest.d.ts +2 -0
- package/package.json +10 -48
- package/dist/case/diff.d.ts +0 -19
- package/dist/case/diff.js +0 -274
- package/dist/compare/comparator.d.ts +0 -17
- package/dist/compare/comparator.js +0 -52
- package/dist/compare/compare.d.ts +0 -17
- package/dist/compare/compare.js +0 -178
- package/dist/compare/format-code.d.ts +0 -16
- package/dist/compare/format-code.js +0 -244
- package/dist/compare/index.d.ts +0 -5
- package/dist/compare/index.js +0 -21
- package/dist/compare/replace-module-argument.d.ts +0 -1
- package/dist/compare/replace-module-argument.js +0 -8
- package/dist/compare/replace-runtime-module-name.d.ts +0 -1
- package/dist/compare/replace-runtime-module-name.js +0 -71
- package/dist/helper/legacy/FakeDocument.d.ts +0 -54
- package/dist/helper/legacy/FakeDocument.js +0 -280
- package/dist/helper/legacy/update.d.ts +0 -2
- package/dist/helper/legacy/update.esm.d.ts +0 -1
- package/dist/helper/legacy/update.esm.js +0 -23
- package/dist/helper/legacy/update.js +0 -19
- package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
- package/dist/helper/legacy/walkCssTokens.js +0 -761
- package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/rspack-diff-config-plugin.js +0 -42
- package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/webpack-diff-config-plugin.js +0 -41
- package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
- package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
- package/dist/runner/web/fake.d.ts +0 -15
- package/dist/runner/web/fake.js +0 -216
- package/dist/runner/web/jsdom.d.ts +0 -24
- package/dist/runner/web/jsdom.js +0 -224
- package/template/diff.bundle.css +0 -1
- package/template/diff.bundle.js +0 -144
- package/template/diff.html +0 -14
- package/template/editor.worker.js +0 -1
|
@@ -0,0 +1,205 @@
|
|
|
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.DEBUG_SCOPES = void 0;
|
|
7
|
+
exports.generateDebugReport = generateDebugReport;
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const javascript_stringify_1 = require("javascript-stringify");
|
|
11
|
+
const stringify_config_1 = __importDefault(require("../helper/stringify-config"));
|
|
12
|
+
function generateDebugReport(context) {
|
|
13
|
+
const report = `
|
|
14
|
+
## Case Meta
|
|
15
|
+
|
|
16
|
+
${generateCaseMetaPathReport(context)}
|
|
17
|
+
|
|
18
|
+
${generateCaseMetaTestConfigReport(context)}
|
|
19
|
+
|
|
20
|
+
## Compiler Options
|
|
21
|
+
|
|
22
|
+
${generateReadConfigFileReport(context)}
|
|
23
|
+
|
|
24
|
+
${generateFinalOptionsReport(context)}
|
|
25
|
+
|
|
26
|
+
## Create Compiler
|
|
27
|
+
|
|
28
|
+
${generateCreateCompilerInstanceReport(context)}
|
|
29
|
+
|
|
30
|
+
${generateCreateCompilerSetPropertiesReport(context)}
|
|
31
|
+
|
|
32
|
+
## Build
|
|
33
|
+
|
|
34
|
+
${generateBuildMethodReport(context)}
|
|
35
|
+
|
|
36
|
+
${generateBuildErrorReport(context)}
|
|
37
|
+
|
|
38
|
+
${generateBuildWarningReport(context)}
|
|
39
|
+
|
|
40
|
+
## Run
|
|
41
|
+
|
|
42
|
+
${generateRunFindBundleReport(context)}
|
|
43
|
+
|
|
44
|
+
${generateRunGetRunnerReport(context)}
|
|
45
|
+
|
|
46
|
+
${generateRunLogsReport(context)}
|
|
47
|
+
|
|
48
|
+
${generateRunErrorsReport(context)}
|
|
49
|
+
|
|
50
|
+
`;
|
|
51
|
+
const dist = context.getDist("debug.md");
|
|
52
|
+
fs_extra_1.default.ensureDirSync(node_path_1.default.dirname(dist));
|
|
53
|
+
fs_extra_1.default.writeFileSync(dist, report);
|
|
54
|
+
}
|
|
55
|
+
function generateCaseMetaPathReport(context) {
|
|
56
|
+
return `
|
|
57
|
+
### Case Path
|
|
58
|
+
|
|
59
|
+
- Source: ${context.getSource()}
|
|
60
|
+
- Dist: ${context.getDist()}
|
|
61
|
+
- Temp: ${context.getTemp()}
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
function generateCaseMetaTestConfigReport(context) {
|
|
65
|
+
return `
|
|
66
|
+
### Test Config
|
|
67
|
+
|
|
68
|
+
\`\`\`js
|
|
69
|
+
// ${node_path_1.default.resolve(context.getSource(), "./test.config.js")}
|
|
70
|
+
${(0, javascript_stringify_1.stringify)(context.getTestConfig(), null, 2)}
|
|
71
|
+
\`\`\`
|
|
72
|
+
`;
|
|
73
|
+
}
|
|
74
|
+
function generateReadConfigFileReport(context) {
|
|
75
|
+
const configFileInfo = context.getValue(exports.DEBUG_SCOPES.CompilerOptionsReadConfigFile);
|
|
76
|
+
if (!configFileInfo)
|
|
77
|
+
return "";
|
|
78
|
+
return `
|
|
79
|
+
### Read Config File
|
|
80
|
+
|
|
81
|
+
\`\`\`js
|
|
82
|
+
// ${configFileInfo.file}
|
|
83
|
+
${(0, stringify_config_1.default)(configFileInfo.config)}
|
|
84
|
+
\`\`\`
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
function generateFinalOptionsReport(context) {
|
|
88
|
+
const finalOptions = context.getCompiler().getOptions();
|
|
89
|
+
return `
|
|
90
|
+
### Final Options
|
|
91
|
+
|
|
92
|
+
\`\`\`js
|
|
93
|
+
${(0, stringify_config_1.default)(finalOptions)}
|
|
94
|
+
\`\`\`
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
function generateCreateCompilerInstanceReport(context) {
|
|
98
|
+
const instanceInfo = context.getValue(exports.DEBUG_SCOPES.CreateCompilerInstance);
|
|
99
|
+
if (!instanceInfo)
|
|
100
|
+
return "";
|
|
101
|
+
return `
|
|
102
|
+
### Create Compiler Instance
|
|
103
|
+
|
|
104
|
+
- Rspack Path: ${instanceInfo.path}
|
|
105
|
+
- Callback Mode: ${instanceInfo.mode}
|
|
106
|
+
`;
|
|
107
|
+
}
|
|
108
|
+
function generateCreateCompilerSetPropertiesReport(context) {
|
|
109
|
+
const setPropertiesInfo = context.getValue(exports.DEBUG_SCOPES.CreateCompilerSetProperties);
|
|
110
|
+
if (!setPropertiesInfo || setPropertiesInfo.length === 0)
|
|
111
|
+
return "";
|
|
112
|
+
return `
|
|
113
|
+
### Set Properties
|
|
114
|
+
|
|
115
|
+
${setPropertiesInfo.map(p => `- ${p}`).join("\n")}
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
function generateBuildMethodReport(context) {
|
|
119
|
+
const buildMethod = context.getValue(exports.DEBUG_SCOPES.BuildMethod);
|
|
120
|
+
if (!buildMethod)
|
|
121
|
+
return "";
|
|
122
|
+
return `
|
|
123
|
+
### Build Method
|
|
124
|
+
|
|
125
|
+
- Method: \`compiler.${buildMethod.method}()\`
|
|
126
|
+
${buildMethod.options ? `- Options:\n\`\`\`js\n${(0, javascript_stringify_1.stringify)(buildMethod.options, null, 2)}\n\`\`\`` : ""}
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
function generateBuildErrorReport(context) {
|
|
130
|
+
const buildError = context.getValue(exports.DEBUG_SCOPES.BuildError);
|
|
131
|
+
if (!buildError)
|
|
132
|
+
return "";
|
|
133
|
+
return `
|
|
134
|
+
### Build Error
|
|
135
|
+
|
|
136
|
+
type: ${buildError.type}
|
|
137
|
+
|
|
138
|
+
${buildError.errors.map(e => `\`\`\`\n// message:\n${e.message}\n// stack:\n${e.stack}\n\`\`\``).join("\n\n")}
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
function generateBuildWarningReport(context) {
|
|
142
|
+
const buildWarning = context.getValue(exports.DEBUG_SCOPES.BuildWarning);
|
|
143
|
+
if (!buildWarning)
|
|
144
|
+
return "";
|
|
145
|
+
return `
|
|
146
|
+
### Build Warning
|
|
147
|
+
|
|
148
|
+
${buildWarning.map(w => `\`\`\`\n// message:\n${w.message}\n// stack:\n${w.stack}\n\`\`\``).join("\n\n")}
|
|
149
|
+
`;
|
|
150
|
+
}
|
|
151
|
+
function generateRunFindBundleReport(context) {
|
|
152
|
+
const runFindBundle = context.getValue(exports.DEBUG_SCOPES.RunFindBundle);
|
|
153
|
+
if (!runFindBundle)
|
|
154
|
+
return "";
|
|
155
|
+
return `
|
|
156
|
+
### Find Bundle
|
|
157
|
+
|
|
158
|
+
${runFindBundle.map(b => `- ${context.getDist(b)}`).join("\n")}
|
|
159
|
+
`;
|
|
160
|
+
}
|
|
161
|
+
function generateRunGetRunnerReport(context) {
|
|
162
|
+
const getRunnerInfo = context.getValue(exports.DEBUG_SCOPES.RunGetRunner);
|
|
163
|
+
if (!getRunnerInfo)
|
|
164
|
+
return "";
|
|
165
|
+
return `
|
|
166
|
+
### Get Runner
|
|
167
|
+
|
|
168
|
+
${Object.entries(getRunnerInfo)
|
|
169
|
+
.map(([file, info]) => `- ${file}: ${info.runnerKey} (Reused: ${info.reused}, Type: \`${info.runnerType}\`)`)
|
|
170
|
+
.join("\n")}
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
function generateRunLogsReport(context) {
|
|
174
|
+
const runLogs = context.getValue(exports.DEBUG_SCOPES.RunLogs);
|
|
175
|
+
if (!runLogs)
|
|
176
|
+
return "";
|
|
177
|
+
return `
|
|
178
|
+
### Run Logs
|
|
179
|
+
|
|
180
|
+
${runLogs.map(l => `- ${l}`).join("\n")}
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
function generateRunErrorsReport(context) {
|
|
184
|
+
const runErrors = context.getValue(exports.DEBUG_SCOPES.RunErrors);
|
|
185
|
+
if (!runErrors)
|
|
186
|
+
return "";
|
|
187
|
+
return `
|
|
188
|
+
### Run Errors
|
|
189
|
+
|
|
190
|
+
${runErrors.map(e => `\`\`\`\n// message:\n${e.message}\n// stack:\n${e.stack}\n\`\`\``).join("\n\n")}
|
|
191
|
+
`;
|
|
192
|
+
}
|
|
193
|
+
exports.DEBUG_SCOPES = {
|
|
194
|
+
CompilerOptionsReadConfigFile: "compiler-options:read-config-file",
|
|
195
|
+
CompilerOptionsFinalOptions: "compiler-options:final-options",
|
|
196
|
+
CreateCompilerInstance: "create-compiler:instance",
|
|
197
|
+
CreateCompilerSetProperties: "create-compiler:set-properties",
|
|
198
|
+
BuildMethod: "build:method",
|
|
199
|
+
BuildError: "build:error",
|
|
200
|
+
BuildWarning: "build:warning",
|
|
201
|
+
RunFindBundle: "run:find-bundle",
|
|
202
|
+
RunGetRunner: "run:get-runner",
|
|
203
|
+
RunLogs: "run:logs",
|
|
204
|
+
RunErrors: "run:errors"
|
|
205
|
+
};
|
package/dist/test/tester.d.ts
CHANGED
package/dist/test/tester.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Tester = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const context_1 = require("./context");
|
|
9
|
+
const debug_1 = require("./debug");
|
|
9
10
|
class Tester {
|
|
10
11
|
constructor(config) {
|
|
11
12
|
this.config = config;
|
|
@@ -20,7 +21,7 @@ class Tester {
|
|
|
20
21
|
this.total = config.steps?.length || 0;
|
|
21
22
|
if (config.contextValue) {
|
|
22
23
|
for (const [key, value] of Array.from(Object.entries(config.contextValue))) {
|
|
23
|
-
this.context.setValue(
|
|
24
|
+
this.context.setValue(key, value);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -55,6 +56,11 @@ class Tester {
|
|
|
55
56
|
if (!currentStep)
|
|
56
57
|
return;
|
|
57
58
|
await this.runCheckStepMethods(currentStep, env, this.context.hasError() ? ["check"] : ["run", "check"]);
|
|
59
|
+
}
|
|
60
|
+
async after() {
|
|
61
|
+
const currentStep = this.steps[this.step];
|
|
62
|
+
if (!currentStep)
|
|
63
|
+
return;
|
|
58
64
|
await this.runStepMethods(currentStep, ["after"], true);
|
|
59
65
|
}
|
|
60
66
|
next() {
|
|
@@ -73,7 +79,20 @@ class Tester {
|
|
|
73
79
|
await i.afterAll(this.context);
|
|
74
80
|
}
|
|
75
81
|
}
|
|
76
|
-
|
|
82
|
+
try {
|
|
83
|
+
await this.context.closeCompiler();
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
console.warn(`Error occured while closing compilers of '${this.config.name}':\n${e.stack}`);
|
|
87
|
+
}
|
|
88
|
+
if (__DEBUG__) {
|
|
89
|
+
try {
|
|
90
|
+
(0, debug_1.generateDebugReport)(this.context);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
console.warn(`Generate debug report failed: ${e.message}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
77
96
|
}
|
|
78
97
|
async runStepMethods(step, methods, force = false) {
|
|
79
98
|
for (const i of methods) {
|
|
@@ -84,7 +103,7 @@ class Tester {
|
|
|
84
103
|
await step[i](this.context);
|
|
85
104
|
}
|
|
86
105
|
catch (e) {
|
|
87
|
-
this.context.emitError(
|
|
106
|
+
this.context.emitError(e);
|
|
88
107
|
}
|
|
89
108
|
}
|
|
90
109
|
}
|
|
@@ -98,7 +117,7 @@ class Tester {
|
|
|
98
117
|
}
|
|
99
118
|
}
|
|
100
119
|
catch (e) {
|
|
101
|
-
const errors = this.context.getError(
|
|
120
|
+
const errors = this.context.getError();
|
|
102
121
|
console.error(new Error([...errors, e].map(e => e.message).join("\n")));
|
|
103
122
|
throw e;
|
|
104
123
|
}
|
package/dist/type.d.ts
CHANGED
|
@@ -1,42 +1,30 @@
|
|
|
1
1
|
import type EventEmitter from "node:events";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Compilation as WebpackCompilation, Compiler as WebpackCompiler, MultiStats as WebpackMultiStats, Configuration as WebpackOptions, Stats as WebpackStats, StatsCompilation as WebpackStatsCompilation } from "webpack";
|
|
2
|
+
import type { Compiler, MultiStats, RspackOptions, Stats, StatsCompilation } from "@rspack/core";
|
|
4
3
|
export interface ITestContext {
|
|
5
4
|
getSource(sub?: string): string;
|
|
6
5
|
getDist(sub?: string): string;
|
|
7
6
|
getTemp(sub?: string): string | null;
|
|
8
|
-
getCompiler
|
|
9
|
-
closeCompiler(
|
|
10
|
-
getTestConfig
|
|
11
|
-
getRunner(
|
|
12
|
-
setValue<T>(
|
|
13
|
-
getValue<T>(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export type TCompilerStats<T> = T extends ECompilerType.Rspack ? RspackStats : WebpackStats;
|
|
28
|
-
export type TCompilerMultiStats<T> = T extends ECompilerType.Rspack ? RspackMultiStats : WebpackMultiStats;
|
|
29
|
-
export type TCompilerStatsCompilation<T> = T extends ECompilerType.Rspack ? RspackStatsCompilation : WebpackStatsCompilation;
|
|
30
|
-
export interface ITestCompilerManager<T extends ECompilerType> {
|
|
31
|
-
getOptions(): TCompilerOptions<T>;
|
|
32
|
-
setOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
|
|
33
|
-
mergeOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
|
|
34
|
-
getCompiler(): TCompiler<T> | null;
|
|
35
|
-
createCompiler(): TCompiler<T>;
|
|
36
|
-
createCompilerWithCallback(callback: (error: Error | null, stats: TCompilerStats<T> | null) => void): TCompiler<T>;
|
|
37
|
-
build(): Promise<TCompilerStats<T>>;
|
|
7
|
+
getCompiler(): ITestCompilerManager;
|
|
8
|
+
closeCompiler(): Promise<void>;
|
|
9
|
+
getTestConfig(): TTestConfig;
|
|
10
|
+
getRunner(file: string, env: ITestEnv): ITestRunner;
|
|
11
|
+
setValue<T>(key: string, value: T): void;
|
|
12
|
+
getValue<T>(key: string): T | void;
|
|
13
|
+
hasError(): boolean;
|
|
14
|
+
emitError(err: Error | string): void;
|
|
15
|
+
getError(): Error[];
|
|
16
|
+
clearError(): void;
|
|
17
|
+
}
|
|
18
|
+
export interface ITestCompilerManager {
|
|
19
|
+
getOptions(): RspackOptions;
|
|
20
|
+
setOptions(newOptions: RspackOptions): RspackOptions;
|
|
21
|
+
mergeOptions(newOptions: RspackOptions): RspackOptions;
|
|
22
|
+
getCompiler(): Compiler | null;
|
|
23
|
+
createCompiler(): Compiler;
|
|
24
|
+
createCompilerWithCallback(callback: (error: Error | null, stats: Stats | null) => void): Compiler;
|
|
25
|
+
build(): Promise<Stats>;
|
|
38
26
|
watch(timeout?: number): void;
|
|
39
|
-
getStats():
|
|
27
|
+
getStats(): Stats | MultiStats | null;
|
|
40
28
|
getEmitter(): EventEmitter;
|
|
41
29
|
close(): Promise<void>;
|
|
42
30
|
}
|
|
@@ -50,8 +38,7 @@ export interface ITesterConfig {
|
|
|
50
38
|
dist: string;
|
|
51
39
|
temp?: string;
|
|
52
40
|
steps?: ITestProcessor[];
|
|
53
|
-
testConfig?: TTestConfig
|
|
54
|
-
compilerFactories?: TCompilerFactories<ECompilerType>;
|
|
41
|
+
testConfig?: TTestConfig;
|
|
55
42
|
contextValue?: Record<string, unknown>;
|
|
56
43
|
runnerCreator?: TTestRunnerCreator;
|
|
57
44
|
createContext?: (config: ITesterConfig) => ITestContext;
|
|
@@ -63,6 +50,7 @@ export interface ITester {
|
|
|
63
50
|
prepare(): Promise<void>;
|
|
64
51
|
compile(): Promise<void>;
|
|
65
52
|
check(env: ITestEnv): Promise<void>;
|
|
53
|
+
after(): Promise<void>;
|
|
66
54
|
next(): boolean;
|
|
67
55
|
resume(): Promise<void>;
|
|
68
56
|
}
|
|
@@ -77,9 +65,9 @@ export interface ITestProcessor {
|
|
|
77
65
|
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
78
66
|
check(env: ITestEnv, context: ITestContext): Promise<unknown>;
|
|
79
67
|
}
|
|
80
|
-
export interface ITestReporter
|
|
81
|
-
init(data?: T): Promise<void>;
|
|
82
|
-
increment(id: string, data: T): Promise<void>;
|
|
68
|
+
export interface ITestReporter {
|
|
69
|
+
init<T>(data?: T): Promise<void>;
|
|
70
|
+
increment<T>(id: string, data: T): Promise<void>;
|
|
83
71
|
failure(id: string): Promise<void>;
|
|
84
72
|
output(): Promise<void>;
|
|
85
73
|
}
|
|
@@ -129,21 +117,17 @@ export interface ITestEnv {
|
|
|
129
117
|
afterEach: (...args: any[]) => void;
|
|
130
118
|
[key: string]: unknown;
|
|
131
119
|
}
|
|
132
|
-
export
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
export type TTestConfig<T extends ECompilerType> = {
|
|
137
|
-
documentType?: EDocumentType;
|
|
138
|
-
validate?: (stats: TCompilerStats<T> | TCompilerMultiStats<T>, stderr?: string) => void;
|
|
120
|
+
export type TTestConfig = {
|
|
121
|
+
location?: string;
|
|
122
|
+
validate?: (stats: Stats | MultiStats, stderr?: string) => void;
|
|
139
123
|
noTests?: boolean;
|
|
140
124
|
writeStatsOuptut?: boolean;
|
|
141
125
|
writeStatsJson?: boolean;
|
|
142
|
-
beforeExecute?: (options:
|
|
143
|
-
afterExecute?: (options:
|
|
144
|
-
moduleScope?: (ms: IModuleScope, stats?:
|
|
145
|
-
checkStats?: (stepName: string, jsonStats:
|
|
146
|
-
findBundle?: (index: number, options:
|
|
126
|
+
beforeExecute?: (options: RspackOptions) => void;
|
|
127
|
+
afterExecute?: (options: RspackOptions) => void;
|
|
128
|
+
moduleScope?: (ms: IModuleScope, stats?: StatsCompilation, options?: RspackOptions) => IModuleScope;
|
|
129
|
+
checkStats?: (stepName: string, jsonStats: StatsCompilation | undefined, stringStats: String) => boolean;
|
|
130
|
+
findBundle?: (index: number, options: RspackOptions, stepName?: string) => string | string[];
|
|
147
131
|
bundlePath?: string[];
|
|
148
132
|
nonEsmThis?: (p: string | string[]) => Object;
|
|
149
133
|
modules?: Record<string, Object>;
|
|
@@ -152,23 +136,25 @@ export type TTestConfig<T extends ECompilerType> = {
|
|
|
152
136
|
snapshotContent?(content: string): string;
|
|
153
137
|
checkSteps?: boolean;
|
|
154
138
|
ignoreNotFriendlyForIncrementalWarnings?: boolean;
|
|
139
|
+
esmLibPluginOptions?: {
|
|
140
|
+
preserveModules?: string;
|
|
141
|
+
};
|
|
155
142
|
};
|
|
156
|
-
export type TTestFilter
|
|
143
|
+
export type TTestFilter = (creatorConfig: Record<string, unknown>, testConfig: TTestConfig) => boolean | string;
|
|
157
144
|
export interface ITestRunner {
|
|
158
145
|
run(file: string): Promise<unknown>;
|
|
159
146
|
getRequire(): TRunnerRequirer;
|
|
160
147
|
getGlobal(name: string): unknown;
|
|
161
148
|
}
|
|
162
|
-
export type TCompilerFactory
|
|
163
|
-
export interface TRunnerFactory
|
|
164
|
-
create(file: string, compilerOptions:
|
|
149
|
+
export type TCompilerFactory = (options: RspackOptions | RspackOptions[], callback?: (error: Error | null, stats: Stats | null) => void) => Compiler;
|
|
150
|
+
export interface TRunnerFactory {
|
|
151
|
+
create(file: string, compilerOptions: RspackOptions, env: ITestEnv): ITestRunner;
|
|
165
152
|
}
|
|
166
153
|
export type THotUpdateContext = {
|
|
167
154
|
updateIndex: number;
|
|
168
155
|
totalUpdates: number;
|
|
169
156
|
changedFiles: string[];
|
|
170
157
|
};
|
|
171
|
-
export type TCompilerFactories<T extends ECompilerType> = Record<T, TCompilerFactory<T>>;
|
|
172
158
|
export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] | string, context?: {
|
|
173
159
|
file?: TRunnerFile;
|
|
174
160
|
esmMode?: EEsmMode;
|
|
@@ -202,6 +188,7 @@ export type TTestRunnerCreator = {
|
|
|
202
188
|
runner: (context: ITestContext, name: string, file: string, env: ITestEnv) => ITestRunner;
|
|
203
189
|
};
|
|
204
190
|
declare global {
|
|
191
|
+
var __DEBUG__: boolean;
|
|
205
192
|
var __TEST_PATH__: string;
|
|
206
193
|
var __TEST_FIXTURES_PATH__: string;
|
|
207
194
|
var __TEST_DIST_PATH__: string;
|
package/dist/type.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/// <reference types="../jest.d.ts" />
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.EEsmMode = exports.
|
|
5
|
-
var ECompilerType;
|
|
6
|
-
(function (ECompilerType) {
|
|
7
|
-
ECompilerType["Rspack"] = "rspack";
|
|
8
|
-
ECompilerType["Webpack"] = "webpack";
|
|
9
|
-
})(ECompilerType || (exports.ECompilerType = ECompilerType = {}));
|
|
4
|
+
exports.EEsmMode = exports.ECompareResultType = void 0;
|
|
10
5
|
var ECompareResultType;
|
|
11
6
|
(function (ECompareResultType) {
|
|
12
7
|
ECompareResultType["Same"] = "same";
|
|
@@ -15,11 +10,6 @@ var ECompareResultType;
|
|
|
15
10
|
ECompareResultType["OnlySource"] = "only-source";
|
|
16
11
|
ECompareResultType["Different"] = "different";
|
|
17
12
|
})(ECompareResultType || (exports.ECompareResultType = ECompareResultType = {}));
|
|
18
|
-
var EDocumentType;
|
|
19
|
-
(function (EDocumentType) {
|
|
20
|
-
EDocumentType["Fake"] = "fake";
|
|
21
|
-
EDocumentType["JSDOM"] = "jsdom";
|
|
22
|
-
})(EDocumentType || (exports.EDocumentType = EDocumentType = {}));
|
|
23
13
|
var EEsmMode;
|
|
24
14
|
(function (EEsmMode) {
|
|
25
15
|
EEsmMode[EEsmMode["Unknown"] = 0] = "Unknown";
|
package/jest.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "1.6.0
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,77 +36,39 @@
|
|
|
36
36
|
"directory": "packages/rspack-test-tools"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@babel/generator": "7.28.
|
|
40
|
-
"@babel/parser": "7.28.
|
|
41
|
-
"@babel/traverse": "7.28.
|
|
42
|
-
"@babel/types": "7.28.
|
|
39
|
+
"@babel/generator": "7.28.5",
|
|
40
|
+
"@babel/parser": "7.28.5",
|
|
41
|
+
"@babel/traverse": "7.28.5",
|
|
42
|
+
"@babel/types": "7.28.5",
|
|
43
43
|
"@jest/reporters": "29.7.0",
|
|
44
44
|
"cross-env": "^10.1.0",
|
|
45
|
-
"csv-to-markdown-table": "1.5.0",
|
|
46
|
-
"deepmerge": "^4.3.1",
|
|
47
45
|
"filenamify": "4.3.0",
|
|
48
46
|
"fs-extra": "^11.3.2",
|
|
49
|
-
"glob": "^11.0.3",
|
|
50
|
-
"graceful-fs": "^4.2.11",
|
|
51
47
|
"iconv-lite": "^0.6.3",
|
|
48
|
+
"javascript-stringify": "^2.1.0",
|
|
52
49
|
"jest-diff": "^29.7.0",
|
|
53
50
|
"jest-snapshot": "29.7.0",
|
|
54
51
|
"jest-environment-node": "29.7.0",
|
|
55
52
|
"jsdom": "^26.1.0",
|
|
56
53
|
"memfs": "4.48.1",
|
|
57
|
-
"loader-utils": "^2.0.4",
|
|
58
54
|
"path-serializer": "0.5.1",
|
|
59
55
|
"pretty-format": "29.7.0",
|
|
60
56
|
"rimraf": "^5.0.10",
|
|
61
57
|
"source-map": "^0.7.6",
|
|
62
58
|
"terser-webpack-plugin": "^5.3.14",
|
|
63
|
-
"webpack": "5.
|
|
59
|
+
"webpack": "5.102.1",
|
|
64
60
|
"webpack-merge": "6.0.1",
|
|
65
|
-
"webpack-sources": "3.3.3"
|
|
61
|
+
"webpack-sources": "3.3.3",
|
|
62
|
+
"chalk": "^4.1.2"
|
|
66
63
|
},
|
|
67
64
|
"devDependencies": {
|
|
68
|
-
"@rspack/plugin-preact-refresh": "1.1.3",
|
|
69
|
-
"@rspack/plugin-react-refresh": "^1.5.1",
|
|
70
|
-
"@swc/helpers": "0.5.17",
|
|
71
|
-
"@swc/plugin-remove-console": "^9.1.0",
|
|
72
65
|
"@types/babel__generator": "7.27.0",
|
|
73
66
|
"@types/babel__traverse": "7.28.0",
|
|
74
67
|
"@types/fs-extra": "11.0.4",
|
|
75
68
|
"@types/jsdom": "^21.1.7",
|
|
76
|
-
"@types/react": "^19.1.13",
|
|
77
|
-
"@types/react-dom": "^19.1.9",
|
|
78
|
-
"@webdiscus/pug-loader": "^2.11.1",
|
|
79
|
-
"acorn": "^8.15.0",
|
|
80
|
-
"babel-loader": "^10.0.0",
|
|
81
|
-
"babel-plugin-import": "^1.13.8",
|
|
82
|
-
"chalk": "^4.1.2",
|
|
83
|
-
"core-js": "3.45.1",
|
|
84
|
-
"css-loader": "^7.1.2",
|
|
85
|
-
"file-loader": "^6.2.0",
|
|
86
|
-
"graceful-fs": "^4.2.11",
|
|
87
|
-
"html-loader": "^5.1.0",
|
|
88
|
-
"html-webpack-plugin": "^5.6.4",
|
|
89
|
-
"less-loader": "^12.3.0",
|
|
90
|
-
"lodash": "^4.17.21",
|
|
91
|
-
"postcss-loader": "^8.2.0",
|
|
92
|
-
"postcss-pxtorem": "^6.1.0",
|
|
93
|
-
"raw-loader": "^4.0.2",
|
|
94
|
-
"react": "^19.1.1",
|
|
95
|
-
"react-dom": "^19.1.1",
|
|
96
|
-
"react-refresh": "^0.17.0",
|
|
97
|
-
"sass-loader": "^16.0.5",
|
|
98
|
-
"source-map": "^0.7.6",
|
|
99
|
-
"source-map-loader": "^5.0.0",
|
|
100
|
-
"style-loader": "^4.0.0",
|
|
101
|
-
"terser": "5.43.1",
|
|
102
69
|
"typescript": "^5.9.3",
|
|
103
70
|
"wast-loader": "^1.14.1",
|
|
104
|
-
"
|
|
105
|
-
"exports-loader": "^5.0.0",
|
|
106
|
-
"@rspack/core": "1.6.0-beta.0",
|
|
107
|
-
"@rspack/cli": "1.6.0-beta.0",
|
|
108
|
-
"@rspack/binding-testing": "1.4.1",
|
|
109
|
-
"@rspack/test-tools": "1.6.0-beta.0"
|
|
71
|
+
"@rspack/core": "1.6.0"
|
|
110
72
|
},
|
|
111
73
|
"peerDependencies": {
|
|
112
74
|
"@rspack/core": ">=1.0.0"
|
package/dist/case/diff.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type IFormatCodeOptions, type IFormatCodeReplacement } from "../compare";
|
|
2
|
-
import { type TCompareModules, type TFileCompareResult, type TModuleCompareResult } from "../type";
|
|
3
|
-
export type TDiffCaseConfig = IDiffProcessorOptions;
|
|
4
|
-
export declare function createDiffCase(name: string, src: string, dist: string): void;
|
|
5
|
-
export interface IDiffProcessorOptions extends IFormatCodeOptions {
|
|
6
|
-
webpackPath: string;
|
|
7
|
-
rspackPath: string;
|
|
8
|
-
files?: string[];
|
|
9
|
-
modules?: TCompareModules;
|
|
10
|
-
runtimeModules?: TCompareModules;
|
|
11
|
-
bootstrap?: boolean;
|
|
12
|
-
detail?: boolean;
|
|
13
|
-
errors?: boolean;
|
|
14
|
-
replacements?: IFormatCodeReplacement[];
|
|
15
|
-
renameModule?: (file: string) => string;
|
|
16
|
-
onCompareFile?: (file: string, result: TFileCompareResult) => void;
|
|
17
|
-
onCompareModules?: (file: string, results: TModuleCompareResult[]) => void;
|
|
18
|
-
onCompareRuntimeModules?: (file: string, results: TModuleCompareResult[]) => void;
|
|
19
|
-
}
|