@rspack/test-tools 1.5.7 → 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 +48 -42
- package/dist/case/compiler.js +142 -124
- 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 +61 -31
- package/dist/case/esm-output.d.ts +1 -0
- package/dist/case/esm-output.js +96 -0
- package/dist/case/example.d.ts +1 -0
- package/dist/case/example.js +57 -0
- package/dist/case/hash.js +3 -4
- package/dist/case/hook.js +45 -39
- 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 +13 -1
- package/dist/case/index.js +9 -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-api.js +40 -29
- package/dist/case/stats-output.d.ts +10 -0
- package/dist/case/stats-output.js +10 -6
- 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 -2
- package/dist/index.js +0 -2
- 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 +15 -7
- package/dist/runner/web/fake.js +6 -3
- package/dist/runner/web/jsdom.js +1 -5
- package/dist/test/creator.d.ts +12 -11
- package/dist/test/creator.js +52 -44
- package/dist/test/tester.js +14 -5
- package/dist/type.d.ts +10 -0
- package/package.json +13 -10
- 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/test/simple.d.ts +0 -5
- package/dist/test/simple.js +0 -44
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) {
|
|
@@ -135,49 +139,51 @@ async function checkSnapshot(env, context, name, snapshot, filter) {
|
|
|
135
139
|
if (path_1.default.extname(snapshot) === ".snap") {
|
|
136
140
|
throw new Error("Snapshot with `.snap` will be managed by jest, please use `.snap.txt` instead");
|
|
137
141
|
}
|
|
138
|
-
const
|
|
139
|
-
const stats =
|
|
140
|
-
const
|
|
141
|
-
if (!stats || !
|
|
142
|
+
const compilerManager = getCompiler(context, name);
|
|
143
|
+
const stats = compilerManager.getStats();
|
|
144
|
+
const compiler = compilerManager.getCompiler();
|
|
145
|
+
if (!stats || !compiler)
|
|
142
146
|
return;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
const compilers = "compilers" in compiler
|
|
148
|
+
? compiler.compilers
|
|
149
|
+
: [compiler];
|
|
150
|
+
const totalStats = "stats" in stats
|
|
151
|
+
? stats.stats
|
|
152
|
+
: [stats];
|
|
153
|
+
const total = compilers.length;
|
|
154
|
+
for (let i = 0; i < compilers.length; i++) {
|
|
155
|
+
const c = compilers[i];
|
|
156
|
+
const stats = totalStats[i];
|
|
157
|
+
if (stats.hasErrors()) {
|
|
158
|
+
const errors = [];
|
|
159
|
+
errors.push(...stats.compilation.errors);
|
|
160
|
+
throw new Error(`Failed to compile in fixture ${name}, Errors: ${errors
|
|
161
|
+
?.map(i => `${i.message}\n${i.stack}`)
|
|
162
|
+
.join("\n\n")}`);
|
|
151
163
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
fileContents.sort();
|
|
176
|
-
const content = fileContents.join("\n\n");
|
|
177
|
-
const snapshotPath = path_1.default.isAbsolute(snapshot)
|
|
178
|
-
? snapshot
|
|
179
|
-
: path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshot}`);
|
|
180
|
-
env.expect(content).toMatchFileSnapshot(snapshotPath);
|
|
164
|
+
const compilation = c._lastCompilation ||
|
|
165
|
+
c._lastCompilation;
|
|
166
|
+
const snapshotFileFilter = filter ||
|
|
167
|
+
((file) => (file.endsWith(".js") || file.endsWith(".mjs")) &&
|
|
168
|
+
!file.includes("runtime.js"));
|
|
169
|
+
const fileContents = Object.entries(compilation.assets)
|
|
170
|
+
.filter(([file]) => snapshotFileFilter(file))
|
|
171
|
+
.map(([file, source]) => {
|
|
172
|
+
const tag = path_1.default.extname(file).slice(1) || "txt";
|
|
173
|
+
let content = (0, placeholder_1.normalizePlaceholder)(source.source().toString());
|
|
174
|
+
const testConfig = context.getTestConfig();
|
|
175
|
+
if (testConfig.snapshotContent) {
|
|
176
|
+
content = testConfig.snapshotContent(content);
|
|
177
|
+
}
|
|
178
|
+
return `\`\`\`${tag} title=${file}\n${content}\n\`\`\``;
|
|
179
|
+
});
|
|
180
|
+
fileContents.sort();
|
|
181
|
+
const content = fileContents.join("\n\n");
|
|
182
|
+
const snapshotPath = path_1.default.isAbsolute(snapshot)
|
|
183
|
+
? snapshot
|
|
184
|
+
: path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshot}${total > 1 ? `-${i}` : ""}`);
|
|
185
|
+
env.expect(content).toMatchFileSnapshot(snapshotPath);
|
|
186
|
+
}
|
|
181
187
|
}
|
|
182
188
|
function findMultiCompilerBundle(context, name, multiFindBundle) {
|
|
183
189
|
if (typeof multiFindBundle !== "function") {
|
package/dist/case/compiler.js
CHANGED
|
@@ -1,137 +1,155 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCompilerCase = createCompilerCase;
|
|
4
|
-
const
|
|
4
|
+
const creator_1 = require("../test/creator");
|
|
5
5
|
const common_1 = require("./common");
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
6
|
+
function createCompilerProcessor(name, caseConfig) {
|
|
7
|
+
const logs = {
|
|
8
|
+
mkdir: [],
|
|
9
|
+
writeFile: []
|
|
10
|
+
};
|
|
11
|
+
const files = {};
|
|
12
|
+
return {
|
|
13
|
+
config: async (context) => {
|
|
14
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
15
|
+
const options = caseConfig.options?.(context) || {};
|
|
16
|
+
options.mode ??= "production";
|
|
17
|
+
options.context ??= context.getSource();
|
|
18
|
+
options.entry ??= "./a.js";
|
|
19
|
+
options.output ??= {};
|
|
20
|
+
options.output.path ??= "/";
|
|
21
|
+
options.output.pathinfo ??= true;
|
|
22
|
+
options.optimization ??= {};
|
|
23
|
+
options.optimization.minimize ??= false;
|
|
24
|
+
compiler.setOptions(options);
|
|
25
|
+
},
|
|
26
|
+
compiler: async (context) => {
|
|
27
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
28
|
+
if (caseConfig.compilerCallback) {
|
|
29
|
+
compiler.createCompilerWithCallback(caseConfig.compilerCallback);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
compiler.createCompiler();
|
|
33
|
+
}
|
|
34
|
+
const c = compiler.getCompiler();
|
|
35
|
+
c.outputFileSystem = {
|
|
36
|
+
// CHANGE: Added support for the `options` parameter to enable recursive directory creation,
|
|
37
|
+
// accommodating Rspack's requirement that differs from webpack's usage
|
|
38
|
+
mkdir(path, callback) {
|
|
39
|
+
const recursive = false;
|
|
40
|
+
// if (typeof options === "function") {
|
|
41
|
+
// callback = options;
|
|
42
|
+
// } else if (options) {
|
|
43
|
+
// if (options.recursive !== undefined) recursive = options.recursive;
|
|
44
|
+
// }
|
|
45
|
+
logs.mkdir.push(path);
|
|
46
|
+
if (recursive) {
|
|
47
|
+
callback();
|
|
38
48
|
}
|
|
39
49
|
else {
|
|
40
|
-
|
|
50
|
+
const err = new Error();
|
|
51
|
+
err.code = "EEXIST";
|
|
52
|
+
callback(err);
|
|
41
53
|
}
|
|
42
|
-
const c = compiler.getCompiler();
|
|
43
|
-
c.outputFileSystem = {
|
|
44
|
-
// CHANGE: Added support for the `options` parameter to enable recursive directory creation,
|
|
45
|
-
// accommodating Rspack's requirement that differs from webpack's usage
|
|
46
|
-
mkdir(path, callback) {
|
|
47
|
-
const recursive = false;
|
|
48
|
-
// if (typeof options === "function") {
|
|
49
|
-
// callback = options;
|
|
50
|
-
// } else if (options) {
|
|
51
|
-
// if (options.recursive !== undefined) recursive = options.recursive;
|
|
52
|
-
// }
|
|
53
|
-
logs.mkdir.push(path);
|
|
54
|
-
if (recursive) {
|
|
55
|
-
callback();
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
const err = new Error();
|
|
59
|
-
err.code = "EEXIST";
|
|
60
|
-
callback(err);
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
writeFile(name, content, callback) {
|
|
64
|
-
logs.writeFile.push(name, content);
|
|
65
|
-
files[name] = content.toString("utf-8");
|
|
66
|
-
callback();
|
|
67
|
-
},
|
|
68
|
-
stat(path, callback) {
|
|
69
|
-
callback(new Error("ENOENT"));
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
c.hooks.compilation.tap("CompilerTest", compilation => (compilation.bail = true));
|
|
73
|
-
await caseConfig.compiler?.(context, c);
|
|
74
54
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
await compiler.build();
|
|
82
|
-
}
|
|
55
|
+
writeFile(name, content, callback) {
|
|
56
|
+
logs.writeFile.push(name, content);
|
|
57
|
+
files[name] = content.toString("utf-8");
|
|
58
|
+
callback();
|
|
83
59
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const compiler = (0, common_1.getCompiler)(context, name);
|
|
87
|
-
const c = compiler.getCompiler();
|
|
88
|
-
const stats = compiler.getStats();
|
|
89
|
-
if (caseConfig.error) {
|
|
90
|
-
const statsJson = stats?.toJson({
|
|
91
|
-
modules: true,
|
|
92
|
-
reasons: true
|
|
93
|
-
});
|
|
94
|
-
const compilation = stats?.compilation;
|
|
95
|
-
await caseConfig.check?.({
|
|
96
|
-
context,
|
|
97
|
-
compiler: c,
|
|
98
|
-
stats: statsJson,
|
|
99
|
-
compilation,
|
|
100
|
-
files
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else if (stats) {
|
|
104
|
-
expect(typeof stats).toBe("object");
|
|
105
|
-
const compilation = stats.compilation;
|
|
106
|
-
const statsJson = stats.toJson({
|
|
107
|
-
modules: true,
|
|
108
|
-
reasons: true
|
|
109
|
-
});
|
|
110
|
-
expect(typeof statsJson).toBe("object");
|
|
111
|
-
expect(statsJson).toHaveProperty("errors");
|
|
112
|
-
expect(Array.isArray(statsJson.errors)).toBe(true);
|
|
113
|
-
if (statsJson.errors.length > 0) {
|
|
114
|
-
expect(statsJson.errors[0]).toBeInstanceOf(Object);
|
|
115
|
-
throw statsJson.errors[0];
|
|
116
|
-
}
|
|
117
|
-
statsJson.logs = logs;
|
|
118
|
-
await caseConfig.check?.({
|
|
119
|
-
context,
|
|
120
|
-
stats: statsJson,
|
|
121
|
-
files,
|
|
122
|
-
compiler: c,
|
|
123
|
-
compilation
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
await caseConfig.check?.({
|
|
128
|
-
context,
|
|
129
|
-
files,
|
|
130
|
-
compiler: c
|
|
131
|
-
});
|
|
132
|
-
}
|
|
60
|
+
stat(path, callback) {
|
|
61
|
+
callback(new Error("ENOENT"));
|
|
133
62
|
}
|
|
134
|
-
}
|
|
63
|
+
};
|
|
64
|
+
c.hooks.compilation.tap("CompilerTest", compilation => (compilation.bail = true));
|
|
65
|
+
await caseConfig.compiler?.(context, c);
|
|
66
|
+
},
|
|
67
|
+
build: async (context) => {
|
|
68
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
69
|
+
if (typeof caseConfig.build === "function") {
|
|
70
|
+
await caseConfig.build?.(context, compiler.getCompiler());
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
await compiler.build();
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
run: async (env, context) => { },
|
|
77
|
+
check: async (env, context) => {
|
|
78
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
79
|
+
const c = compiler.getCompiler();
|
|
80
|
+
const stats = compiler.getStats();
|
|
81
|
+
if (caseConfig.error) {
|
|
82
|
+
const statsJson = stats?.toJson({
|
|
83
|
+
modules: true,
|
|
84
|
+
reasons: true
|
|
85
|
+
});
|
|
86
|
+
const compilation = stats?.compilation;
|
|
87
|
+
await caseConfig.check?.({
|
|
88
|
+
context,
|
|
89
|
+
compiler: c,
|
|
90
|
+
stats: statsJson,
|
|
91
|
+
compilation,
|
|
92
|
+
files
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else if (stats) {
|
|
96
|
+
expect(typeof stats).toBe("object");
|
|
97
|
+
const compilation = stats.compilation;
|
|
98
|
+
const statsJson = stats.toJson({
|
|
99
|
+
modules: true,
|
|
100
|
+
reasons: true
|
|
101
|
+
});
|
|
102
|
+
expect(typeof statsJson).toBe("object");
|
|
103
|
+
expect(statsJson).toHaveProperty("errors");
|
|
104
|
+
expect(Array.isArray(statsJson.errors)).toBe(true);
|
|
105
|
+
if (statsJson.errors.length > 0) {
|
|
106
|
+
expect(statsJson.errors[0]).toBeInstanceOf(Object);
|
|
107
|
+
throw statsJson.errors[0];
|
|
108
|
+
}
|
|
109
|
+
statsJson.logs = logs;
|
|
110
|
+
await caseConfig.check?.({
|
|
111
|
+
context,
|
|
112
|
+
stats: statsJson,
|
|
113
|
+
files,
|
|
114
|
+
compiler: c,
|
|
115
|
+
compilation
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
await caseConfig.check?.({
|
|
120
|
+
context,
|
|
121
|
+
files,
|
|
122
|
+
compiler: c
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
after: async (context) => {
|
|
127
|
+
await context.closeCompiler(name);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const creator = new creator_1.BasicCaseCreator({
|
|
132
|
+
clean: true,
|
|
133
|
+
describe: false,
|
|
134
|
+
steps: ({ name, caseConfig }) => {
|
|
135
|
+
return [createCompilerProcessor(name, caseConfig)];
|
|
136
|
+
},
|
|
137
|
+
concurrent: false
|
|
138
|
+
});
|
|
139
|
+
function createCompilerCase(name, src, dist, testConfig) {
|
|
140
|
+
let caseConfigList = require(testConfig);
|
|
141
|
+
if (!Array.isArray(caseConfigList)) {
|
|
142
|
+
caseConfigList = [caseConfigList];
|
|
143
|
+
}
|
|
144
|
+
for (let i = 0; i < caseConfigList.length; i++) {
|
|
145
|
+
const caseConfig = caseConfigList[i];
|
|
146
|
+
if (caseConfig.skip) {
|
|
147
|
+
it.skip(`${name}[${i}]`, () => { });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
creator.create(`${name}[${i}]`, src, dist, undefined, {
|
|
151
|
+
caseConfig,
|
|
152
|
+
description: () => caseConfig.description
|
|
135
153
|
});
|
|
136
154
|
}
|
|
137
155
|
}
|
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
|
@@ -6,47 +6,72 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createErrorCase = createErrorCase;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
9
|
-
const
|
|
9
|
+
const creator_1 = require("../test/creator");
|
|
10
10
|
const common_1 = require("./common");
|
|
11
11
|
let addedSerializer = false;
|
|
12
|
+
const creator = new creator_1.BasicCaseCreator({
|
|
13
|
+
clean: true,
|
|
14
|
+
describe: true,
|
|
15
|
+
steps: ({ name, caseConfig }) => {
|
|
16
|
+
const config = caseConfig;
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
config: async (context) => {
|
|
20
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
21
|
+
compiler.setOptions(options(context, config.options));
|
|
22
|
+
},
|
|
23
|
+
compiler: async (context) => {
|
|
24
|
+
const compilerManager = (0, common_1.getCompiler)(context, name);
|
|
25
|
+
compilerManager.createCompiler();
|
|
26
|
+
compiler(context, compilerManager.getCompiler(), config.compiler);
|
|
27
|
+
},
|
|
28
|
+
build: async (context) => {
|
|
29
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
30
|
+
if (typeof config.build === "function") {
|
|
31
|
+
await config.build(context, compiler.getCompiler());
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
await compiler.build();
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
run: async (env, context) => {
|
|
38
|
+
// no need to run, just check the snapshot of diagnostics
|
|
39
|
+
},
|
|
40
|
+
check: async (env, context) => {
|
|
41
|
+
await check(env, context, name, config.check);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
},
|
|
46
|
+
concurrent: true
|
|
47
|
+
});
|
|
12
48
|
function createErrorCase(name, src, dist, testConfig) {
|
|
13
49
|
if (!addedSerializer) {
|
|
14
50
|
addedSerializer = true;
|
|
15
51
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const compilerManager = (0, common_1.getCompiler)(context, name);
|
|
26
|
-
compilerManager.createCompiler();
|
|
27
|
-
compiler(context, compilerManager.getCompiler(), caseConfig.compiler);
|
|
28
|
-
},
|
|
29
|
-
build: async (context) => {
|
|
30
|
-
const compiler = (0, common_1.getCompiler)(context, name);
|
|
31
|
-
if (typeof caseConfig.build === "function") {
|
|
32
|
-
await caseConfig.build(context, compiler.getCompiler());
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
await compiler.build();
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
run: async (env, context) => {
|
|
39
|
-
// no need to run, just check the snapshot of diagnostics
|
|
40
|
-
},
|
|
41
|
-
check: async (env, context) => {
|
|
42
|
-
await check(env, context, name, caseConfig.check);
|
|
43
|
-
}
|
|
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
|
|
44
61
|
});
|
|
45
|
-
}
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(caseConfigList)) {
|
|
64
|
+
for (const caseConfig of caseConfigList) {
|
|
65
|
+
createCase(caseConfig);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
createCase(caseConfigList);
|
|
70
|
+
}
|
|
46
71
|
}
|
|
47
72
|
function options(context, custom) {
|
|
48
73
|
let options = {
|
|
49
|
-
context: node_path_1.default.resolve(
|
|
74
|
+
context: node_path_1.default.resolve(__TEST_FIXTURES_PATH__, "errors"),
|
|
50
75
|
mode: "none",
|
|
51
76
|
devtool: false,
|
|
52
77
|
optimization: {
|
|
@@ -105,6 +130,11 @@ class RspackStatsDiagnostics {
|
|
|
105
130
|
}
|
|
106
131
|
}
|
|
107
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
|
+
}
|
|
108
138
|
const compiler = (0, common_1.getCompiler)(context, name);
|
|
109
139
|
const stats = compiler.getStats();
|
|
110
140
|
env.expect(typeof stats).toBe("object");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createEsmOutputCase(name: string, src: string, dist: string): void;
|