@rspack/test-tools 2.0.1 → 2.0.2
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 +2 -2
- package/dist/case/cache.js +31 -25
- package/dist/case/common.js +2 -2
- package/dist/case/diagnostic.js +2 -2
- package/dist/case/error.js +2 -2
- package/dist/case/hook.js +2 -2
- package/dist/case/watch.js +2 -2
- package/dist/compiler.js +2 -2
- package/dist/helper/util/checkStats.js +1 -1
- package/package.json +6 -6
package/dist/case/builtin.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.createBuiltinCase = createBuiltinCase;
|
|
|
7
7
|
exports.defaultOptions = defaultOptions;
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
-
const
|
|
10
|
+
const rspack_merge_1 = require("rspack-merge");
|
|
11
11
|
const helper_1 = require("../helper");
|
|
12
12
|
const creator_1 = require("../test/creator");
|
|
13
13
|
const common_1 = require("./common");
|
|
@@ -158,7 +158,7 @@ function defaultOptions(context) {
|
|
|
158
158
|
if (caseOptions.entry) {
|
|
159
159
|
delete defaultOptions.entry;
|
|
160
160
|
}
|
|
161
|
-
defaultOptions = (0,
|
|
161
|
+
defaultOptions = (0, rspack_merge_1.merge)(defaultOptions, caseOptions);
|
|
162
162
|
}
|
|
163
163
|
if (!global.printLogger) {
|
|
164
164
|
defaultOptions.infrastructureLogging = {
|
package/dist/case/cache.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.createCacheCase = createCacheCase;
|
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const core_1 = __importDefault(require("@rspack/core"));
|
|
9
9
|
const helper_1 = require("../helper");
|
|
10
|
+
const placeholder_1 = require("../helper/expect/placeholder");
|
|
10
11
|
const hot_update_1 = require("../helper/hot-update");
|
|
11
12
|
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
12
13
|
const runner_1 = require("../runner");
|
|
@@ -36,6 +37,10 @@ function createCacheProcessor(name, src, temp, target) {
|
|
|
36
37
|
},
|
|
37
38
|
check: async (env, context) => {
|
|
38
39
|
await (0, common_1.check)(env, context, name);
|
|
40
|
+
const stats = context.getCompiler().getStats();
|
|
41
|
+
if (stats) {
|
|
42
|
+
matchStatsSnapshot(env, context.getSource(), updatePlugin.getUpdateIndex(), stats);
|
|
43
|
+
}
|
|
39
44
|
},
|
|
40
45
|
after: async (context) => {
|
|
41
46
|
await (0, common_1.afterExecute)(context, name);
|
|
@@ -72,6 +77,19 @@ function createCacheCase(name, src, dist, target, temp) {
|
|
|
72
77
|
creator.create(name, src, dist, temp);
|
|
73
78
|
}
|
|
74
79
|
const creators = new Map();
|
|
80
|
+
function matchStatsSnapshot(env, source, updateIndex, stats) {
|
|
81
|
+
const content = (0, placeholder_1.normalizePlaceholder)(stats.toString({
|
|
82
|
+
all: false,
|
|
83
|
+
logging: 'info',
|
|
84
|
+
colors: false,
|
|
85
|
+
})).trim();
|
|
86
|
+
if (!content.includes('rspack.persistentCache')) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
env
|
|
90
|
+
.expect(content)
|
|
91
|
+
.toMatchFileSnapshotSync(node_path_1.default.resolve(source, '__snapshots__', `stats-${updateIndex}.txt`));
|
|
92
|
+
}
|
|
75
93
|
async function generateOptions(context, temp, target, updatePlugin) {
|
|
76
94
|
let options = {
|
|
77
95
|
context: temp,
|
|
@@ -181,14 +199,7 @@ function createRunner(context, name, file, env) {
|
|
|
181
199
|
});
|
|
182
200
|
};
|
|
183
201
|
const checkStats = async (stats) => {
|
|
184
|
-
|
|
185
|
-
const updateIndex = updatePlugin.getUpdateIndex();
|
|
186
|
-
await (0, checkArrayExpectation_1.default)(source, stats, 'error', `errors${updateIndex}`, 'Error', compilerOptions);
|
|
187
|
-
await (0, checkArrayExpectation_1.default)(source, stats, 'warning', `warnings${updateIndex}`, 'Warning', compilerOptions);
|
|
188
|
-
};
|
|
189
|
-
const nextHmr = async (m, options) => {
|
|
190
|
-
await updatePlugin.goNext();
|
|
191
|
-
const stats = await compiler.build();
|
|
202
|
+
matchStatsSnapshot(env, source, updatePlugin.getUpdateIndex(), stats);
|
|
192
203
|
const jsonStats = stats.toJson({
|
|
193
204
|
assets: true,
|
|
194
205
|
chunks: true,
|
|
@@ -198,7 +209,16 @@ function createRunner(context, name, file, env) {
|
|
|
198
209
|
chunkGroups: true,
|
|
199
210
|
// errorDetails: true
|
|
200
211
|
});
|
|
201
|
-
|
|
212
|
+
const compilerOptions = compiler.getOptions();
|
|
213
|
+
const updateIndex = updatePlugin.getUpdateIndex();
|
|
214
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, 'error', `errors${updateIndex}`, 'Error', compilerOptions);
|
|
215
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, 'warning', `warnings${updateIndex}`, 'Warning', compilerOptions);
|
|
216
|
+
return jsonStats;
|
|
217
|
+
};
|
|
218
|
+
const nextHmr = async (m, options) => {
|
|
219
|
+
await updatePlugin.goNext();
|
|
220
|
+
const stats = await compiler.build();
|
|
221
|
+
const jsonStats = await checkStats(stats);
|
|
202
222
|
const updatedModules = await m.hot.check(options || true);
|
|
203
223
|
if (!updatedModules) {
|
|
204
224
|
throw new Error('No update available');
|
|
@@ -211,14 +231,7 @@ function createRunner(context, name, file, env) {
|
|
|
211
231
|
compilerIndex++;
|
|
212
232
|
compiler.createCompiler();
|
|
213
233
|
const stats = await compiler.build();
|
|
214
|
-
const jsonStats = stats
|
|
215
|
-
assets: true,
|
|
216
|
-
chunks: true,
|
|
217
|
-
entrypoints: true,
|
|
218
|
-
chunkGroups: true,
|
|
219
|
-
// errorDetails: true
|
|
220
|
-
});
|
|
221
|
-
await checkStats(jsonStats);
|
|
234
|
+
const jsonStats = await checkStats(stats);
|
|
222
235
|
env.it(`NEXT_START run with compilerIndex==${compilerIndex}`, async () => {
|
|
223
236
|
return getWebRunner().run(file);
|
|
224
237
|
});
|
|
@@ -233,14 +246,7 @@ function createRunner(context, name, file, env) {
|
|
|
233
246
|
compilerIndex++;
|
|
234
247
|
compiler.createCompiler();
|
|
235
248
|
const stats = await compiler.build();
|
|
236
|
-
const jsonStats = stats
|
|
237
|
-
assets: true,
|
|
238
|
-
chunks: true,
|
|
239
|
-
entrypoints: true,
|
|
240
|
-
chunkGroups: true,
|
|
241
|
-
// errorDetails: true
|
|
242
|
-
});
|
|
243
|
-
await checkStats(jsonStats);
|
|
249
|
+
const jsonStats = await checkStats(stats);
|
|
244
250
|
env.it(`NEXT_MOVE_DIR_START run with compilerIndex==${compilerIndex}`, async () => {
|
|
245
251
|
return getWebRunner().run(file);
|
|
246
252
|
});
|
package/dist/case/common.js
CHANGED
|
@@ -14,7 +14,7 @@ exports.findMultiCompilerBundle = findMultiCompilerBundle;
|
|
|
14
14
|
exports.configMultiCompiler = configMultiCompiler;
|
|
15
15
|
const node_path_1 = __importDefault(require("node:path"));
|
|
16
16
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
17
|
-
const
|
|
17
|
+
const rspack_merge_1 = __importDefault(require("rspack-merge"));
|
|
18
18
|
const helper_1 = require("../helper");
|
|
19
19
|
const placeholder_1 = require("../helper/expect/placeholder");
|
|
20
20
|
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
@@ -245,7 +245,7 @@ function configMultiCompiler(context, name, configFiles, defaultOptions, overrid
|
|
|
245
245
|
})
|
|
246
246
|
: [{}];
|
|
247
247
|
for (const [index, options] of caseOptions.entries()) {
|
|
248
|
-
const compilerOptions = (0,
|
|
248
|
+
const compilerOptions = (0, rspack_merge_1.default)(typeof defaultOptions === 'function'
|
|
249
249
|
? defaultOptions(index, context)
|
|
250
250
|
: {}, options);
|
|
251
251
|
if (typeof overrideOptions === 'function') {
|
package/dist/case/diagnostic.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createDiagnosticCase = createDiagnosticCase;
|
|
7
7
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const
|
|
9
|
+
const rspack_merge_1 = __importDefault(require("rspack-merge"));
|
|
10
10
|
const helper_1 = require("../helper");
|
|
11
11
|
const placeholder_1 = require("../helper/expect/placeholder");
|
|
12
12
|
const creator_1 = require("../test/creator");
|
|
@@ -20,7 +20,7 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
20
20
|
let options = defaultOptions(context);
|
|
21
21
|
const custom = (0, helper_1.readConfigFile)(['rspack.config.js', 'webpack.config.js'].map((i) => context.getSource(i)), context, options)[0];
|
|
22
22
|
if (custom) {
|
|
23
|
-
options = (0,
|
|
23
|
+
options = (0, rspack_merge_1.default)(options, custom);
|
|
24
24
|
}
|
|
25
25
|
if (!global.printLogger) {
|
|
26
26
|
options.infrastructureLogging = {
|
package/dist/case/error.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createErrorCase = createErrorCase;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const
|
|
8
|
+
const rspack_merge_1 = __importDefault(require("rspack-merge"));
|
|
9
9
|
const creator_1 = require("../test/creator");
|
|
10
10
|
let addedSerializer = false;
|
|
11
11
|
const creator = new creator_1.BasicCaseCreator({
|
|
@@ -93,7 +93,7 @@ function options(context, custom) {
|
|
|
93
93
|
},
|
|
94
94
|
};
|
|
95
95
|
if (typeof custom === 'function') {
|
|
96
|
-
options = (0,
|
|
96
|
+
options = (0, rspack_merge_1.default)(options, custom(context, options));
|
|
97
97
|
}
|
|
98
98
|
if (options.mode === 'production') {
|
|
99
99
|
if (options.optimization)
|
package/dist/case/hook.js
CHANGED
|
@@ -10,7 +10,7 @@ const core_1 = require("@rspack/core");
|
|
|
10
10
|
const jest_snapshot_1 = require("jest-snapshot");
|
|
11
11
|
const path_serializer_1 = require("path-serializer");
|
|
12
12
|
const pretty_format_1 = require("pretty-format");
|
|
13
|
-
const
|
|
13
|
+
const rspack_merge_1 = __importDefault(require("rspack-merge"));
|
|
14
14
|
const context_1 = require("../test/context");
|
|
15
15
|
const creator_1 = require("../test/creator");
|
|
16
16
|
const common_1 = require("./common");
|
|
@@ -221,7 +221,7 @@ function defaultOptions(context, custom) {
|
|
|
221
221
|
},
|
|
222
222
|
};
|
|
223
223
|
if (custom) {
|
|
224
|
-
defaultOptions = (0,
|
|
224
|
+
defaultOptions = (0, rspack_merge_1.default)(defaultOptions, custom(context));
|
|
225
225
|
}
|
|
226
226
|
return defaultOptions;
|
|
227
227
|
}
|
package/dist/case/watch.js
CHANGED
|
@@ -10,7 +10,7 @@ exports.getWatchRunnerKey = getWatchRunnerKey;
|
|
|
10
10
|
exports.createWatchRunner = createWatchRunner;
|
|
11
11
|
const node_path_1 = __importDefault(require("node:path"));
|
|
12
12
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
13
|
-
const
|
|
13
|
+
const rspack_merge_1 = __importDefault(require("rspack-merge"));
|
|
14
14
|
const compiler_1 = require("../compiler");
|
|
15
15
|
const helper_1 = require("../helper");
|
|
16
16
|
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
@@ -36,7 +36,7 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
36
36
|
const multiCompilerOptions = [];
|
|
37
37
|
const caseOptions = (0, helper_1.readConfigFile)(['rspack.config.js', 'webpack.config.js'].map((i) => context.getSource(i)), context, {});
|
|
38
38
|
for (const [index, options] of caseOptions.entries()) {
|
|
39
|
-
const compilerOptions = (0,
|
|
39
|
+
const compilerOptions = (0, rspack_merge_1.default)(defaultOptions({
|
|
40
40
|
incremental,
|
|
41
41
|
ignoreNotFriendlyForIncrementalWarnings: testConfig.ignoreNotFriendlyForIncrementalWarnings,
|
|
42
42
|
}), options);
|
package/dist/compiler.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.TestCompilerManager = exports.ECompilerEvent = void 0;
|
|
7
7
|
const node_events_1 = __importDefault(require("node:events"));
|
|
8
8
|
const core_1 = require("@rspack/core");
|
|
9
|
-
const
|
|
9
|
+
const rspack_merge_1 = __importDefault(require("rspack-merge"));
|
|
10
10
|
const debug_1 = require("./test/debug");
|
|
11
11
|
var ECompilerEvent;
|
|
12
12
|
(function (ECompilerEvent) {
|
|
@@ -32,7 +32,7 @@ class TestCompilerManager {
|
|
|
32
32
|
return this.compilerOptions;
|
|
33
33
|
}
|
|
34
34
|
mergeOptions(newOptions) {
|
|
35
|
-
this.compilerOptions = (0,
|
|
35
|
+
this.compilerOptions = (0, rspack_merge_1.default)(this.compilerOptions, newOptions);
|
|
36
36
|
this.emitter.emit(ECompilerEvent.Option, this.compilerOptions);
|
|
37
37
|
return this.compilerOptions;
|
|
38
38
|
}
|
|
@@ -17,7 +17,7 @@ exports.checkChunkModules = function checkChunkModules(statsJson, chunkModulesMa
|
|
|
17
17
|
return true;
|
|
18
18
|
};
|
|
19
19
|
function getChunk(statsJson, id) {
|
|
20
|
-
const chunk = statsJson.chunks.find((chunk) => chunk.id.includes(id));
|
|
20
|
+
const chunk = statsJson.chunks.find((chunk) => String(chunk.id).includes(String(id)));
|
|
21
21
|
if (!chunk) {
|
|
22
22
|
throw new Error(`cannot find chunk with id: ${id}`);
|
|
23
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@babel/generator": "7.29.1",
|
|
41
|
-
"@babel/parser": "7.29.
|
|
41
|
+
"@babel/parser": "7.29.3",
|
|
42
42
|
"@babel/traverse": "7.29.0",
|
|
43
43
|
"@babel/types": "7.29.0",
|
|
44
44
|
"chalk": "^4.1.2",
|
|
@@ -50,15 +50,15 @@
|
|
|
50
50
|
"jest-diff": "^30.3.0",
|
|
51
51
|
"jest-snapshot": "29.7.0",
|
|
52
52
|
"jsdom": "^26.1.0",
|
|
53
|
-
"memfs": "4.
|
|
53
|
+
"memfs": "4.57.2",
|
|
54
54
|
"path-serializer": "0.6.0",
|
|
55
55
|
"pretty-format": "30.3.0",
|
|
56
56
|
"rimraf": "^5.0.10",
|
|
57
57
|
"source-map": "^0.7.6",
|
|
58
|
-
"
|
|
58
|
+
"rspack-merge": "0.1.1",
|
|
59
|
+
"terser-webpack-plugin": "^5.5.0",
|
|
59
60
|
"wast-loader": "^1.14.1",
|
|
60
61
|
"webpack": "5.104.1",
|
|
61
|
-
"webpack-merge": "6.0.1",
|
|
62
62
|
"webpack-sources": "3.3.4"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@types/fs-extra": "11.0.4",
|
|
68
68
|
"@types/jsdom": "^21.1.7",
|
|
69
69
|
"typescript": "^6.0.3",
|
|
70
|
-
"@rspack/core": "2.0.
|
|
70
|
+
"@rspack/core": "2.0.2"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"@rspack/core": ">=1.0.0"
|