@rspack/test-tools 1.7.2 → 2.0.0-alpha.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 +4 -7
- package/dist/case/cache.js +20 -11
- package/dist/case/common.js +10 -0
- package/dist/case/compiler.js +5 -0
- package/dist/case/config.d.ts +1 -0
- package/dist/case/config.js +22 -17
- package/dist/case/defaults.js +1 -2
- package/dist/case/diagnostic.js +11 -7
- package/dist/case/error.js +10 -5
- package/dist/case/esm-output.js +16 -31
- package/dist/case/hash.js +11 -7
- package/dist/case/hook.js +12 -8
- package/dist/case/hot-step.js +1 -1
- package/dist/case/hot.js +22 -13
- package/dist/case/normal.js +8 -6
- package/dist/case/runner.js +6 -0
- package/dist/case/stats-api.js +9 -5
- package/dist/case/stats-output.js +23 -14
- package/dist/case/watch.js +28 -14
- package/dist/helper/directory.d.ts +5 -1
- package/dist/helper/directory.js +16 -3
- package/dist/helper/expect/placeholder.js +4 -0
- package/dist/helper/index.d.ts +1 -0
- package/dist/helper/index.js +3 -0
- package/dist/plugin/lazy-compilation-test-plugin.js +2 -0
- package/dist/runner/node/index.js +3 -2
- package/dist/runner/web/index.js +5 -1
- package/dist/type.d.ts +0 -3
- package/package.json +8 -8
package/dist/case/builtin.js
CHANGED
|
@@ -63,7 +63,7 @@ function defaultOptions(context) {
|
|
|
63
63
|
cssChunkFilename: '[name].css',
|
|
64
64
|
assetModuleFilename: '[hash][ext][query]',
|
|
65
65
|
sourceMapFilename: '[file].map',
|
|
66
|
-
chunkLoadingGlobal: '
|
|
66
|
+
chunkLoadingGlobal: 'rspackChunk',
|
|
67
67
|
chunkLoading: 'jsonp',
|
|
68
68
|
uniqueName: '__rspack_test__',
|
|
69
69
|
enabledLibraryTypes: ['system'],
|
|
@@ -78,6 +78,9 @@ function defaultOptions(context) {
|
|
|
78
78
|
webassemblyModuleFilename: '[hash].module.wasm',
|
|
79
79
|
workerChunkLoading: 'import-scripts',
|
|
80
80
|
workerWasmLoading: 'fetch',
|
|
81
|
+
bundlerInfo: {
|
|
82
|
+
force: false,
|
|
83
|
+
},
|
|
81
84
|
},
|
|
82
85
|
module: {
|
|
83
86
|
rules: [
|
|
@@ -144,13 +147,7 @@ function defaultOptions(context) {
|
|
|
144
147
|
extensions: ['.js'],
|
|
145
148
|
},
|
|
146
149
|
experiments: {
|
|
147
|
-
css: true,
|
|
148
150
|
futureDefaults: true,
|
|
149
|
-
rspackFuture: {
|
|
150
|
-
bundlerInfo: {
|
|
151
|
-
force: false,
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
151
|
},
|
|
155
152
|
devtool: false,
|
|
156
153
|
context: context.getSource(),
|
package/dist/case/cache.js
CHANGED
|
@@ -84,20 +84,15 @@ async function generateOptions(context, temp, target, updatePlugin) {
|
|
|
84
84
|
chunkFilename: '[name].chunk.[fullhash].js',
|
|
85
85
|
publicPath: 'https://test.cases/path/',
|
|
86
86
|
library: { type: 'commonjs2' },
|
|
87
|
+
bundlerInfo: {
|
|
88
|
+
force: false,
|
|
89
|
+
},
|
|
87
90
|
},
|
|
88
91
|
optimization: {
|
|
89
92
|
moduleIds: 'named',
|
|
90
93
|
emitOnErrors: true,
|
|
91
94
|
},
|
|
92
95
|
target,
|
|
93
|
-
experiments: {
|
|
94
|
-
css: true,
|
|
95
|
-
rspackFuture: {
|
|
96
|
-
bundlerInfo: {
|
|
97
|
-
force: false,
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
96
|
};
|
|
102
97
|
options.plugins ??= [];
|
|
103
98
|
options.plugins.push(new core_1.default.HotModuleReplacementPlugin());
|
|
@@ -196,7 +191,13 @@ function createRunner(context, name, file, env) {
|
|
|
196
191
|
await updatePlugin.goNext();
|
|
197
192
|
const stats = await compiler.build();
|
|
198
193
|
const jsonStats = stats.toJson({
|
|
199
|
-
|
|
194
|
+
assets: true,
|
|
195
|
+
chunks: true,
|
|
196
|
+
chunkModules: true,
|
|
197
|
+
modules: true,
|
|
198
|
+
entrypoints: true,
|
|
199
|
+
chunkGroups: true,
|
|
200
|
+
// errorDetails: true
|
|
200
201
|
});
|
|
201
202
|
await checkStats(jsonStats);
|
|
202
203
|
const updatedModules = await m.hot.check(options || true);
|
|
@@ -212,7 +213,11 @@ function createRunner(context, name, file, env) {
|
|
|
212
213
|
compiler.createCompiler();
|
|
213
214
|
const stats = await compiler.build();
|
|
214
215
|
const jsonStats = stats.toJson({
|
|
215
|
-
|
|
216
|
+
assets: true,
|
|
217
|
+
chunks: true,
|
|
218
|
+
entrypoints: true,
|
|
219
|
+
chunkGroups: true,
|
|
220
|
+
// errorDetails: true
|
|
216
221
|
});
|
|
217
222
|
await checkStats(jsonStats);
|
|
218
223
|
env.it(`NEXT_START run with compilerIndex==${compilerIndex}`, async () => {
|
|
@@ -230,7 +235,11 @@ function createRunner(context, name, file, env) {
|
|
|
230
235
|
compiler.createCompiler();
|
|
231
236
|
const stats = await compiler.build();
|
|
232
237
|
const jsonStats = stats.toJson({
|
|
233
|
-
|
|
238
|
+
assets: true,
|
|
239
|
+
chunks: true,
|
|
240
|
+
entrypoints: true,
|
|
241
|
+
chunkGroups: true,
|
|
242
|
+
// errorDetails: true
|
|
234
243
|
});
|
|
235
244
|
await checkStats(jsonStats);
|
|
236
245
|
env.it(`NEXT_MOVE_DIR_START run with compilerIndex==${compilerIndex}`, async () => {
|
package/dist/case/common.js
CHANGED
|
@@ -104,6 +104,10 @@ async function check(env, context, name) {
|
|
|
104
104
|
}
|
|
105
105
|
if (testConfig.writeStatsJson) {
|
|
106
106
|
const jsonStats = stats.toJson({
|
|
107
|
+
assets: true,
|
|
108
|
+
chunks: true,
|
|
109
|
+
entrypoints: true,
|
|
110
|
+
chunkGroups: true,
|
|
107
111
|
errorDetails: true,
|
|
108
112
|
});
|
|
109
113
|
fs_extra_1.default.writeFileSync(path_1.default.join(context.getDist(), 'stats.json'), JSON.stringify(jsonStats, null, 2), 'utf-8');
|
|
@@ -113,6 +117,12 @@ async function check(env, context, name) {
|
|
|
113
117
|
stats.hasErrors() ||
|
|
114
118
|
stats.hasWarnings()) {
|
|
115
119
|
const statsJson = stats.toJson({
|
|
120
|
+
assets: true,
|
|
121
|
+
chunks: true,
|
|
122
|
+
chunkModules: true,
|
|
123
|
+
modules: true,
|
|
124
|
+
entrypoints: true,
|
|
125
|
+
chunkGroups: true,
|
|
116
126
|
errorDetails: true,
|
|
117
127
|
});
|
|
118
128
|
if (statsJson.errors) {
|
package/dist/case/compiler.js
CHANGED
|
@@ -95,7 +95,12 @@ function createCompilerProcessor(name, caseConfig) {
|
|
|
95
95
|
expect(typeof stats).toBe('object');
|
|
96
96
|
const compilation = stats.compilation;
|
|
97
97
|
const statsJson = stats.toJson({
|
|
98
|
+
assets: true,
|
|
99
|
+
chunks: true,
|
|
100
|
+
chunkModules: true,
|
|
98
101
|
modules: true,
|
|
102
|
+
entrypoints: true,
|
|
103
|
+
chunkGroups: true,
|
|
99
104
|
reasons: true,
|
|
100
105
|
});
|
|
101
106
|
expect(typeof statsJson).toBe('object');
|
package/dist/case/config.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export type TConfigCaseConfig = Omit<TTestConfig, 'validate'>;
|
|
|
4
4
|
export declare function createConfigProcessor(name: string): ITestProcessor;
|
|
5
5
|
export declare function createConfigCase(name: string, src: string, dist: string): void;
|
|
6
6
|
export declare function defaultOptions(index: number, context: ITestContext): RspackOptions;
|
|
7
|
+
export declare function enableEsmLibraryPlugin(options: RspackOptions): boolean;
|
|
7
8
|
export declare function overrideOptions(index: number, context: ITestContext, options: RspackOptions): void;
|
|
8
9
|
export declare function findBundle(index: number, context: ITestContext, options: RspackOptions): string | string[];
|
package/dist/case/config.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createConfigProcessor = createConfigProcessor;
|
|
7
7
|
exports.createConfigCase = createConfigCase;
|
|
8
8
|
exports.defaultOptions = defaultOptions;
|
|
9
|
+
exports.enableEsmLibraryPlugin = enableEsmLibraryPlugin;
|
|
9
10
|
exports.overrideOptions = overrideOptions;
|
|
10
11
|
exports.findBundle = findBundle;
|
|
11
12
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -69,20 +70,20 @@ function defaultOptions(index, context) {
|
|
|
69
70
|
cache: false,
|
|
70
71
|
output: {
|
|
71
72
|
path: context.getDist(),
|
|
73
|
+
bundlerInfo: {
|
|
74
|
+
force: false,
|
|
75
|
+
},
|
|
72
76
|
},
|
|
73
77
|
optimization: {
|
|
74
78
|
minimize: false,
|
|
75
79
|
},
|
|
76
|
-
experiments: {
|
|
77
|
-
css: true,
|
|
78
|
-
rspackFuture: {
|
|
79
|
-
bundlerInfo: {
|
|
80
|
-
force: false,
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
80
|
};
|
|
85
81
|
}
|
|
82
|
+
function enableEsmLibraryPlugin(options) {
|
|
83
|
+
return (options.output?.library === 'modern-module' ||
|
|
84
|
+
(typeof options.output?.library === 'object' &&
|
|
85
|
+
(options.output?.library).type === 'modern-module'));
|
|
86
|
+
}
|
|
86
87
|
function overrideOptions(index, context, options) {
|
|
87
88
|
if (!options.entry) {
|
|
88
89
|
options.entry = './index.js';
|
|
@@ -91,9 +92,15 @@ function overrideOptions(index, context, options) {
|
|
|
91
92
|
options.amd = {};
|
|
92
93
|
}
|
|
93
94
|
if (!options.output?.filename) {
|
|
94
|
-
const
|
|
95
|
+
const runtimeChunkForModernModule = options.optimization?.runtimeChunk === undefined &&
|
|
96
|
+
enableEsmLibraryPlugin(options);
|
|
97
|
+
const outputModule = options.experiments?.outputModule || enableEsmLibraryPlugin(options);
|
|
95
98
|
options.output ??= {};
|
|
96
|
-
options.output.filename = `bundle${index}${outputModule ? '.mjs' : '.js'}`;
|
|
99
|
+
options.output.filename = `${runtimeChunkForModernModule ? `[name]${outputModule ? '.mjs' : '.js'}` : `bundle${index}${outputModule ? '.mjs' : '.js'}`}`;
|
|
100
|
+
}
|
|
101
|
+
if (enableEsmLibraryPlugin(options)) {
|
|
102
|
+
options.optimization ??= {};
|
|
103
|
+
options.optimization.runtimeChunk ??= { name: `runtime~${index}` };
|
|
97
104
|
}
|
|
98
105
|
if (options.cache === undefined)
|
|
99
106
|
options.cache = false;
|
|
@@ -112,13 +119,11 @@ function findBundle(index, context, options) {
|
|
|
112
119
|
const bundlePath = [];
|
|
113
120
|
if (options.output?.path &&
|
|
114
121
|
fs_extra_1.default.existsSync(path_1.default.join(options.output.path, `bundle${index}${ext}`))) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
bundlePath.push(path_1.default.relative(options.output.path, cssOutputPath));
|
|
121
|
-
}
|
|
122
|
+
const cssOutputPath = path_1.default.join(options.output.path, (typeof options.output?.cssFilename === 'string' &&
|
|
123
|
+
options.output?.cssFilename) ||
|
|
124
|
+
`bundle${index}.css`);
|
|
125
|
+
if (fs_extra_1.default.existsSync(cssOutputPath)) {
|
|
126
|
+
bundlePath.push(path_1.default.relative(options.output.path, cssOutputPath));
|
|
122
127
|
}
|
|
123
128
|
bundlePath.push(`./bundle${index}${ext}`);
|
|
124
129
|
}
|
package/dist/case/defaults.js
CHANGED
|
@@ -40,8 +40,7 @@ function getRspackDefaultConfig(cwd, config) {
|
|
|
40
40
|
const normalizedConfig = getNormalizedWebpackOptions(config);
|
|
41
41
|
applyWebpackOptionsDefaults(normalizedConfig);
|
|
42
42
|
// make snapshot stable
|
|
43
|
-
normalizedConfig.
|
|
44
|
-
'$version$';
|
|
43
|
+
normalizedConfig.output.bundlerInfo.version = '$version$';
|
|
45
44
|
process.chdir(CURRENT_CWD);
|
|
46
45
|
return normalizedConfig;
|
|
47
46
|
}
|
package/dist/case/diagnostic.js
CHANGED
|
@@ -66,6 +66,15 @@ function defaultOptions(context) {
|
|
|
66
66
|
entry: {
|
|
67
67
|
main: './',
|
|
68
68
|
},
|
|
69
|
+
module: {
|
|
70
|
+
defaultRules: [
|
|
71
|
+
'...',
|
|
72
|
+
{
|
|
73
|
+
test: /\.css/,
|
|
74
|
+
type: 'css/auto',
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
69
78
|
mode: 'development',
|
|
70
79
|
devServer: {
|
|
71
80
|
hot: false,
|
|
@@ -75,13 +84,8 @@ function defaultOptions(context) {
|
|
|
75
84
|
},
|
|
76
85
|
output: {
|
|
77
86
|
path: context.getDist(),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
css: true,
|
|
81
|
-
rspackFuture: {
|
|
82
|
-
bundlerInfo: {
|
|
83
|
-
force: false,
|
|
84
|
-
},
|
|
87
|
+
bundlerInfo: {
|
|
88
|
+
force: false,
|
|
85
89
|
},
|
|
86
90
|
},
|
|
87
91
|
};
|
package/dist/case/error.js
CHANGED
|
@@ -78,12 +78,17 @@ function options(context, custom) {
|
|
|
78
78
|
moduleIds: 'named',
|
|
79
79
|
chunkIds: 'named',
|
|
80
80
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
module: {
|
|
82
|
+
defaultRules: [
|
|
83
|
+
{
|
|
84
|
+
test: /\.css$/i,
|
|
85
|
+
type: 'css/auto',
|
|
86
86
|
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
otuput: {
|
|
90
|
+
bundlerInfo: {
|
|
91
|
+
force: false,
|
|
87
92
|
},
|
|
88
93
|
},
|
|
89
94
|
};
|
package/dist/case/esm-output.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.createEsmOutputCase = createEsmOutputCase;
|
|
7
|
-
const core_1 = __importDefault(require("@rspack/core"));
|
|
8
4
|
const creator_1 = require("../test/creator");
|
|
9
5
|
const common_1 = require("./common");
|
|
10
6
|
const runner_1 = require("./runner");
|
|
@@ -25,26 +21,7 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
25
21
|
steps: ({ name }) => [
|
|
26
22
|
{
|
|
27
23
|
config: async (context) => {
|
|
28
|
-
(0, common_1.configMultiCompiler)(context, name, ['rspack.config.cjs', 'rspack.config.js', 'webpack.config.js'], defaultOptions, (
|
|
29
|
-
const testConfig = context.getTestConfig();
|
|
30
|
-
if (testConfig.esmLibPluginOptions) {
|
|
31
|
-
let target;
|
|
32
|
-
const otherPlugins = options.plugins?.filter((plugin) => {
|
|
33
|
-
const isTarget = plugin instanceof core_1.default.experiments.EsmLibraryPlugin;
|
|
34
|
-
if (isTarget) {
|
|
35
|
-
target = plugin;
|
|
36
|
-
}
|
|
37
|
-
return !isTarget;
|
|
38
|
-
}) ?? [];
|
|
39
|
-
options.plugins = [
|
|
40
|
-
...otherPlugins,
|
|
41
|
-
new core_1.default.experiments.EsmLibraryPlugin({
|
|
42
|
-
...target.options,
|
|
43
|
-
...testConfig.esmLibPluginOptions,
|
|
44
|
-
}),
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
});
|
|
24
|
+
(0, common_1.configMultiCompiler)(context, name, ['rspack.config.cjs', 'rspack.config.js', 'webpack.config.js'], defaultOptions, () => { });
|
|
48
25
|
},
|
|
49
26
|
compiler: async (context) => {
|
|
50
27
|
await (0, common_1.compiler)(context, name);
|
|
@@ -93,6 +70,21 @@ const defaultOptions = (_index, context) => ({
|
|
|
93
70
|
filename: '[name].mjs',
|
|
94
71
|
pathinfo: true,
|
|
95
72
|
module: true,
|
|
73
|
+
library: {
|
|
74
|
+
type: 'modern-module',
|
|
75
|
+
},
|
|
76
|
+
bundlerInfo: {
|
|
77
|
+
force: false,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
module: {
|
|
81
|
+
defaultRules: [
|
|
82
|
+
'...',
|
|
83
|
+
{
|
|
84
|
+
test: /\.css$/i,
|
|
85
|
+
type: 'css/auto',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
96
88
|
},
|
|
97
89
|
bail: true,
|
|
98
90
|
optimization: {
|
|
@@ -105,14 +97,7 @@ const defaultOptions = (_index, context) => ({
|
|
|
105
97
|
fs: 'module-import fs',
|
|
106
98
|
path: 'module-import path',
|
|
107
99
|
},
|
|
108
|
-
plugins: [new core_1.default.experiments.EsmLibraryPlugin()],
|
|
109
100
|
experiments: {
|
|
110
|
-
css: true,
|
|
111
|
-
rspackFuture: {
|
|
112
|
-
bundlerInfo: {
|
|
113
|
-
force: false,
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
101
|
outputModule: true,
|
|
117
102
|
},
|
|
118
103
|
});
|
package/dist/case/hash.js
CHANGED
|
@@ -43,15 +43,19 @@ function createHashCase(name, src, dist) {
|
|
|
43
43
|
function defaultOptions(index, context) {
|
|
44
44
|
return {
|
|
45
45
|
context: context.getSource(),
|
|
46
|
+
module: {
|
|
47
|
+
defaultRules: [
|
|
48
|
+
'...',
|
|
49
|
+
{
|
|
50
|
+
test: /\.css$/i,
|
|
51
|
+
type: 'css/auto',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
46
55
|
output: {
|
|
47
56
|
path: context.getDist(),
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
css: true,
|
|
51
|
-
rspackFuture: {
|
|
52
|
-
bundlerInfo: {
|
|
53
|
-
force: false,
|
|
54
|
-
},
|
|
57
|
+
bundlerInfo: {
|
|
58
|
+
force: false,
|
|
55
59
|
},
|
|
56
60
|
},
|
|
57
61
|
};
|
package/dist/case/hook.js
CHANGED
|
@@ -203,18 +203,22 @@ function defaultOptions(context, custom) {
|
|
|
203
203
|
entry: './hook',
|
|
204
204
|
output: {
|
|
205
205
|
path: context.getDist(),
|
|
206
|
+
bundlerInfo: {
|
|
207
|
+
force: false,
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
module: {
|
|
211
|
+
defaultRules: [
|
|
212
|
+
'...',
|
|
213
|
+
{
|
|
214
|
+
test: /\.css$/i,
|
|
215
|
+
type: 'css/auto',
|
|
216
|
+
},
|
|
217
|
+
],
|
|
206
218
|
},
|
|
207
219
|
optimization: {
|
|
208
220
|
minimize: false,
|
|
209
221
|
},
|
|
210
|
-
experiments: {
|
|
211
|
-
css: true,
|
|
212
|
-
rspackFuture: {
|
|
213
|
-
bundlerInfo: {
|
|
214
|
-
force: false,
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
222
|
};
|
|
219
223
|
if (custom) {
|
|
220
224
|
defaultOptions = (0, webpack_merge_1.default)(defaultOptions, custom(context));
|
package/dist/case/hot-step.js
CHANGED
|
@@ -17,7 +17,7 @@ const SELF_HANDLER = (file, options) => {
|
|
|
17
17
|
const hotUpdateGlobal = (_, modules) => {
|
|
18
18
|
res = Object.keys(modules);
|
|
19
19
|
};
|
|
20
|
-
const hotUpdateGlobalKey = escapeLocalName(`${options.output?.hotUpdateGlobal || '
|
|
20
|
+
const hotUpdateGlobalKey = escapeLocalName(`${options.output?.hotUpdateGlobal || 'rspackHotUpdate'}${options.output?.uniqueName || ''}`);
|
|
21
21
|
global.self ??= {};
|
|
22
22
|
global.self[hotUpdateGlobalKey] = hotUpdateGlobal;
|
|
23
23
|
require(file);
|
package/dist/case/hot.js
CHANGED
|
@@ -30,8 +30,7 @@ function createHotProcessor(name, src, temp, target, incremental = false) {
|
|
|
30
30
|
options = await (0, common_1.config)(context, name, ['rspack.config.js', 'webpack.config.js'], options);
|
|
31
31
|
overrideOptions(context, options, target, updatePlugin);
|
|
32
32
|
if (incremental) {
|
|
33
|
-
options.
|
|
34
|
-
options.experiments.incremental ??= 'advance-silent';
|
|
33
|
+
options.incremental ??= 'advance-silent';
|
|
35
34
|
}
|
|
36
35
|
compiler.setOptions(options);
|
|
37
36
|
},
|
|
@@ -97,21 +96,25 @@ function defaultOptions(context, target) {
|
|
|
97
96
|
chunkFilename: '[name].chunk.[fullhash].js',
|
|
98
97
|
publicPath: 'https://test.cases/path/',
|
|
99
98
|
library: { type: 'commonjs2' },
|
|
99
|
+
bundlerInfo: {
|
|
100
|
+
force: false,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
module: {
|
|
104
|
+
defaultRules: [
|
|
105
|
+
'...',
|
|
106
|
+
{
|
|
107
|
+
test: /\.css$/i,
|
|
108
|
+
type: 'css/auto',
|
|
109
|
+
},
|
|
110
|
+
],
|
|
100
111
|
},
|
|
101
112
|
optimization: {
|
|
102
113
|
moduleIds: 'named',
|
|
103
114
|
},
|
|
104
115
|
target,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
// test incremental: "safe" here, we test default incremental in Incremental-*.test.js
|
|
108
|
-
incremental: 'safe',
|
|
109
|
-
rspackFuture: {
|
|
110
|
-
bundlerInfo: {
|
|
111
|
-
force: false,
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
},
|
|
116
|
+
// test incremental: "safe" here, we test default incremental in Incremental-*.test.js
|
|
117
|
+
incremental: 'safe',
|
|
115
118
|
};
|
|
116
119
|
options.plugins ??= [];
|
|
117
120
|
options.plugins.push(new core_1.default.HotModuleReplacementPlugin());
|
|
@@ -183,7 +186,13 @@ function createHotRunner(context, name, file, env) {
|
|
|
183
186
|
throw new Error('Should generate stats during build');
|
|
184
187
|
}
|
|
185
188
|
const jsonStats = stats.toJson({
|
|
186
|
-
|
|
189
|
+
assets: true,
|
|
190
|
+
chunks: true,
|
|
191
|
+
chunkModules: true,
|
|
192
|
+
modules: true,
|
|
193
|
+
entrypoints: true,
|
|
194
|
+
chunkGroups: true,
|
|
195
|
+
// errorDetails: true
|
|
187
196
|
});
|
|
188
197
|
const compilerOptions = compiler.getOptions();
|
|
189
198
|
const checker = context.getValue(jsonStats.errors?.length
|
package/dist/case/normal.js
CHANGED
|
@@ -141,6 +141,9 @@ function defaultOptions(context, compilerOptions, mode) {
|
|
|
141
141
|
pathinfo: 'verbose',
|
|
142
142
|
path: context.getDist(),
|
|
143
143
|
filename: compilerOptions?.module ? 'bundle.mjs' : 'bundle.js',
|
|
144
|
+
bundlerInfo: {
|
|
145
|
+
force: false,
|
|
146
|
+
},
|
|
144
147
|
},
|
|
145
148
|
resolve: {
|
|
146
149
|
modules: ['web_modules', 'node_modules'],
|
|
@@ -169,6 +172,11 @@ function defaultOptions(context, compilerOptions, mode) {
|
|
|
169
172
|
type: 'webassembly/async',
|
|
170
173
|
},
|
|
171
174
|
],
|
|
175
|
+
parser: {
|
|
176
|
+
javascript: {
|
|
177
|
+
requireAlias: true,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
172
180
|
},
|
|
173
181
|
plugins: (compilerOptions?.plugins || [])
|
|
174
182
|
.concat(testConfig.plugins || [])
|
|
@@ -189,13 +197,7 @@ function defaultOptions(context, compilerOptions, mode) {
|
|
|
189
197
|
}),
|
|
190
198
|
experiments: {
|
|
191
199
|
css: false,
|
|
192
|
-
rspackFuture: {
|
|
193
|
-
bundlerInfo: {
|
|
194
|
-
force: false,
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
200
|
asyncWebAssembly: true,
|
|
198
|
-
topLevelAwait: true,
|
|
199
201
|
// CHANGE: rspack does not support `backCompat` yet.
|
|
200
202
|
// backCompat: false,
|
|
201
203
|
// CHANGE: Rspack enables `css` by default.
|
package/dist/case/runner.js
CHANGED
|
@@ -22,6 +22,12 @@ function cachedStats(context, name) {
|
|
|
22
22
|
return cached;
|
|
23
23
|
}
|
|
24
24
|
cached = compiler.getStats().toJson({
|
|
25
|
+
assets: true,
|
|
26
|
+
chunks: true,
|
|
27
|
+
chunkModules: true,
|
|
28
|
+
modules: true,
|
|
29
|
+
entrypoints: true,
|
|
30
|
+
chunkGroups: true,
|
|
25
31
|
errorDetails: true,
|
|
26
32
|
});
|
|
27
33
|
return cached;
|
package/dist/case/stats-api.js
CHANGED
|
@@ -52,11 +52,15 @@ function createStatsAPICase(name, src, dist, testConfig) {
|
|
|
52
52
|
}
|
|
53
53
|
function options(context, custom) {
|
|
54
54
|
const res = (custom?.(context) || {});
|
|
55
|
-
res.
|
|
56
|
-
res.
|
|
57
|
-
res.
|
|
58
|
-
res.
|
|
59
|
-
|
|
55
|
+
res.output ??= {};
|
|
56
|
+
res.module ??= {};
|
|
57
|
+
res.module.defaultRules ??= ['...'];
|
|
58
|
+
res.module.defaultRules.push({
|
|
59
|
+
test: /\.css$/,
|
|
60
|
+
type: 'css/auto',
|
|
61
|
+
});
|
|
62
|
+
res.output.bundlerInfo ??= {};
|
|
63
|
+
res.output.bundlerInfo.force ??= false;
|
|
60
64
|
if (!global.printLogger) {
|
|
61
65
|
res.infrastructureLogging = {
|
|
62
66
|
level: 'error',
|
|
@@ -56,14 +56,20 @@ function defaultOptions(index, context) {
|
|
|
56
56
|
if (fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), 'rspack.config.js')) ||
|
|
57
57
|
fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), 'webpack.config.js'))) {
|
|
58
58
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
bundlerInfo: {
|
|
63
|
-
force: false,
|
|
64
|
-
},
|
|
59
|
+
output: {
|
|
60
|
+
bundlerInfo: {
|
|
61
|
+
force: false,
|
|
65
62
|
},
|
|
66
63
|
},
|
|
64
|
+
module: {
|
|
65
|
+
defaultRules: [
|
|
66
|
+
'...',
|
|
67
|
+
{
|
|
68
|
+
test: /\.css$/i,
|
|
69
|
+
type: 'css/auto',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
67
73
|
};
|
|
68
74
|
}
|
|
69
75
|
return {
|
|
@@ -73,18 +79,21 @@ function defaultOptions(index, context) {
|
|
|
73
79
|
output: {
|
|
74
80
|
filename: 'bundle.js',
|
|
75
81
|
path: context.getDist(),
|
|
82
|
+
bundlerInfo: {
|
|
83
|
+
force: false,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
module: {
|
|
87
|
+
defaultRules: [
|
|
88
|
+
{
|
|
89
|
+
test: /\.css$/i,
|
|
90
|
+
type: 'css/auto',
|
|
91
|
+
},
|
|
92
|
+
],
|
|
76
93
|
},
|
|
77
94
|
optimization: {
|
|
78
95
|
minimize: false,
|
|
79
96
|
},
|
|
80
|
-
experiments: {
|
|
81
|
-
css: true,
|
|
82
|
-
rspackFuture: {
|
|
83
|
-
bundlerInfo: {
|
|
84
|
-
force: false,
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
97
|
};
|
|
89
98
|
}
|
|
90
99
|
function overrideOptions(index, context, options) {
|
package/dist/case/watch.js
CHANGED
|
@@ -104,6 +104,12 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
104
104
|
return () => {
|
|
105
105
|
if (!cached) {
|
|
106
106
|
cached = stats.toJson({
|
|
107
|
+
assets: true,
|
|
108
|
+
chunks: true,
|
|
109
|
+
chunkModules: true,
|
|
110
|
+
modules: true,
|
|
111
|
+
entrypoints: true,
|
|
112
|
+
chunkGroups: true,
|
|
107
113
|
errorDetails: true,
|
|
108
114
|
});
|
|
109
115
|
}
|
|
@@ -140,6 +146,12 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
140
146
|
stats.hasErrors() ||
|
|
141
147
|
stats.hasWarnings()) {
|
|
142
148
|
const statsJson = stats.toJson({
|
|
149
|
+
assets: true,
|
|
150
|
+
chunks: true,
|
|
151
|
+
chunkModules: true,
|
|
152
|
+
modules: true,
|
|
153
|
+
entrypoints: true,
|
|
154
|
+
chunkGroups: true,
|
|
143
155
|
errorDetails: true,
|
|
144
156
|
});
|
|
145
157
|
if (statsJson.errors) {
|
|
@@ -245,23 +257,22 @@ function overrideOptions(index, context, options, tempDir, nativeWatcher) {
|
|
|
245
257
|
options.output.pathinfo = false;
|
|
246
258
|
if (!options.output.filename)
|
|
247
259
|
options.output.filename = 'bundle.js';
|
|
248
|
-
if (options.cache && options.cache.type === 'filesystem') {
|
|
249
|
-
const cacheDirectory = node_path_1.default.join(tempDir, '.cache');
|
|
250
|
-
options.cache.cacheDirectory = cacheDirectory;
|
|
251
|
-
options.cache.name = `config-${index}`;
|
|
252
|
-
}
|
|
253
260
|
options.optimization ??= {};
|
|
254
261
|
options.experiments ??= {};
|
|
255
|
-
options.
|
|
262
|
+
options.module ??= {};
|
|
263
|
+
options.module.defaultRules ??= ['...'];
|
|
264
|
+
options.module.defaultRules.push({
|
|
265
|
+
test: /\.css$/,
|
|
266
|
+
type: 'css/auto',
|
|
267
|
+
});
|
|
256
268
|
if (nativeWatcher) {
|
|
257
269
|
options.experiments.nativeWatcher ??= true;
|
|
258
270
|
}
|
|
259
|
-
options.
|
|
260
|
-
options.
|
|
261
|
-
options.
|
|
262
|
-
false;
|
|
271
|
+
options.output ??= {};
|
|
272
|
+
options.output.bundlerInfo ??= {};
|
|
273
|
+
options.output.bundlerInfo.force ??= false;
|
|
263
274
|
// test incremental: "safe" here, we test default incremental in Incremental-*.test.js
|
|
264
|
-
options.
|
|
275
|
+
options.incremental ??= 'safe';
|
|
265
276
|
if (!global.printLogger) {
|
|
266
277
|
options.infrastructureLogging = {
|
|
267
278
|
level: 'error',
|
|
@@ -278,9 +289,7 @@ function findBundle(index, context, options, stepName) {
|
|
|
278
289
|
function defaultOptions({ incremental = false, ignoreNotFriendlyForIncrementalWarnings = false, } = {}) {
|
|
279
290
|
if (incremental) {
|
|
280
291
|
return {
|
|
281
|
-
|
|
282
|
-
incremental: 'advance',
|
|
283
|
-
},
|
|
292
|
+
incremental: 'advance',
|
|
284
293
|
ignoreWarnings: ignoreNotFriendlyForIncrementalWarnings
|
|
285
294
|
? [/is not friendly for incremental/]
|
|
286
295
|
: undefined,
|
|
@@ -304,6 +313,11 @@ function cachedWatchStats(context, name) {
|
|
|
304
313
|
return cached[stepName];
|
|
305
314
|
}
|
|
306
315
|
cached[stepName] = compiler.getStats().toJson({
|
|
316
|
+
entrypoints: true,
|
|
317
|
+
assets: true,
|
|
318
|
+
chunks: true,
|
|
319
|
+
chunkModules: true,
|
|
320
|
+
modules: true,
|
|
307
321
|
errorDetails: true,
|
|
308
322
|
});
|
|
309
323
|
return cached[stepName];
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export declare const isDirectory: (p: string) => boolean;
|
|
2
2
|
export declare const isFile: (p: string) => boolean;
|
|
3
3
|
export declare const isValidCaseDirectory: (name: string) => boolean;
|
|
4
|
-
export declare function describeByWalk(
|
|
4
|
+
export declare function describeByWalk(
|
|
5
|
+
/**
|
|
6
|
+
* The test file absolute path.
|
|
7
|
+
*/
|
|
8
|
+
testFile: string, createCase: (name: string, src: string, dist: string) => void, options?: {
|
|
5
9
|
type?: 'file' | 'directory';
|
|
6
10
|
level?: number;
|
|
7
11
|
source?: string;
|
package/dist/helper/directory.js
CHANGED
|
@@ -14,7 +14,11 @@ const isFile = (p) => node_fs_1.default.lstatSync(p).isFile();
|
|
|
14
14
|
exports.isFile = isFile;
|
|
15
15
|
const isValidCaseDirectory = (name) => !name.startsWith('_') && !name.startsWith('.') && name !== 'node_modules';
|
|
16
16
|
exports.isValidCaseDirectory = isValidCaseDirectory;
|
|
17
|
-
function describeByWalk(
|
|
17
|
+
function describeByWalk(
|
|
18
|
+
/**
|
|
19
|
+
* The test file absolute path.
|
|
20
|
+
*/
|
|
21
|
+
testFile, createCase, options = {}) {
|
|
18
22
|
const describeFn = options.describe || describe;
|
|
19
23
|
const testBasename = node_path_1.default
|
|
20
24
|
.basename(testFile)
|
|
@@ -22,6 +26,7 @@ function describeByWalk(testFile, createCase, options = {}) {
|
|
|
22
26
|
const testId = testBasename.charAt(0).toLowerCase() + testBasename.slice(1);
|
|
23
27
|
const sourceBase = options.source || node_path_1.default.join(node_path_1.default.dirname(testFile), `${testId}Cases`);
|
|
24
28
|
const testSourceId = node_path_1.default.basename(sourceBase);
|
|
29
|
+
const absoluteTestDir = node_path_1.default.dirname(testFile);
|
|
25
30
|
const distBase = options.dist || node_path_1.default.join(node_path_1.default.dirname(testFile), 'js', testId);
|
|
26
31
|
const level = options.level || 2;
|
|
27
32
|
const type = options.type || 'directory';
|
|
@@ -59,7 +64,15 @@ function describeByWalk(testFile, createCase, options = {}) {
|
|
|
59
64
|
.join(`${testId}Cases-${testSourceId}`, caseName)
|
|
60
65
|
.split('.')
|
|
61
66
|
.shift());
|
|
62
|
-
|
|
67
|
+
let suiteName = name;
|
|
68
|
+
// support filter test by absolute path
|
|
69
|
+
if (process.env.testFilter?.includes(absoluteTestDir)) {
|
|
70
|
+
const fullCasePath = node_path_1.default.join(absoluteTestDir, testSourceId, caseName);
|
|
71
|
+
if (fullCasePath.includes(process.env.testFilter)) {
|
|
72
|
+
suiteName = fullCasePath;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
describeFn(suiteName, () => {
|
|
63
76
|
const source = node_path_1.default.join(sourceBase, caseName);
|
|
64
77
|
let dist = '';
|
|
65
78
|
if (absoluteDist) {
|
|
@@ -74,7 +87,7 @@ function describeByWalk(testFile, createCase, options = {}) {
|
|
|
74
87
|
dist = node_path_1.default.join(sourceBase, caseName, relativeDist);
|
|
75
88
|
}
|
|
76
89
|
}
|
|
77
|
-
createCase(
|
|
90
|
+
createCase(suiteName, source, dist);
|
|
78
91
|
});
|
|
79
92
|
}
|
|
80
93
|
});
|
|
@@ -23,6 +23,10 @@ const placeholderSerializer = (0, path_serializer_1.createSnapshotSerializer)({
|
|
|
23
23
|
match: __RSPACK_PATH__,
|
|
24
24
|
mark: 'rspack_root',
|
|
25
25
|
},
|
|
26
|
+
{
|
|
27
|
+
match: /<ROOT>\/packages\/rspack/g,
|
|
28
|
+
mark: 'rspack_root',
|
|
29
|
+
},
|
|
26
30
|
{
|
|
27
31
|
match: /:\d+:\d+-\d+:\d+/g,
|
|
28
32
|
mark: 'line_col_range',
|
package/dist/helper/index.d.ts
CHANGED
package/dist/helper/index.js
CHANGED
|
@@ -14,7 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.normalizePlaceholder = void 0;
|
|
17
18
|
__exportStar(require("./directory"), exports);
|
|
19
|
+
var placeholder_1 = require("./expect/placeholder");
|
|
20
|
+
Object.defineProperty(exports, "normalizePlaceholder", { enumerable: true, get: function () { return placeholder_1.normalizePlaceholder; } });
|
|
18
21
|
__exportStar(require("./is"), exports);
|
|
19
22
|
__exportStar(require("./parse-modules"), exports);
|
|
20
23
|
__exportStar(require("./read-config-file"), exports);
|
|
@@ -33,6 +33,8 @@ class LazyCompilationTestPlugin {
|
|
|
33
33
|
resolve(null);
|
|
34
34
|
});
|
|
35
35
|
server.on('request', (req, res) => {
|
|
36
|
+
// Set CORS headers for jsdom's XMLHttpRequest
|
|
37
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
36
38
|
middleware(req, res, () => { });
|
|
37
39
|
});
|
|
38
40
|
server.on('connection', (socket) => {
|
|
@@ -41,6 +41,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
41
41
|
const node_path_1 = __importDefault(require("node:path"));
|
|
42
42
|
const node_url_1 = require("node:url");
|
|
43
43
|
const node_vm_1 = __importStar(require("node:vm"));
|
|
44
|
+
const config_1 = require("../../case/config");
|
|
44
45
|
const asModule_1 = __importDefault(require("../../helper/legacy/asModule"));
|
|
45
46
|
const createFakeWorker_1 = __importDefault(require("../../helper/legacy/createFakeWorker"));
|
|
46
47
|
const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
|
|
@@ -279,8 +280,8 @@ class NodeRunner {
|
|
|
279
280
|
file,
|
|
280
281
|
});
|
|
281
282
|
}
|
|
282
|
-
if (file.path.endsWith('.mjs')
|
|
283
|
-
this._options.compilerOptions
|
|
283
|
+
if (file.path.endsWith('.mjs') ||
|
|
284
|
+
(0, config_1.enableEsmLibraryPlugin)(this._options.compilerOptions)) {
|
|
284
285
|
return this.requirers.get('esm')(currentDirectory, modulePath, {
|
|
285
286
|
...context,
|
|
286
287
|
file,
|
package/dist/runner/web/index.js
CHANGED
|
@@ -152,7 +152,11 @@ class WebRunner extends node_1.NodeRunner {
|
|
|
152
152
|
createBaseModuleScope() {
|
|
153
153
|
const moduleScope = super.createBaseModuleScope();
|
|
154
154
|
moduleScope.EventSource = EventSourceForNode_1.default;
|
|
155
|
-
moduleScope.fetch = async (url) => {
|
|
155
|
+
moduleScope.fetch = async (url, options) => {
|
|
156
|
+
// For Lazy Compilation Proxy the POST request to the real dev server.
|
|
157
|
+
if (options?.method === 'POST') {
|
|
158
|
+
return fetch(url, options);
|
|
159
|
+
}
|
|
156
160
|
try {
|
|
157
161
|
const filePath = this.urlToPath(url);
|
|
158
162
|
this.log(`fetch: ${url} -> ${filePath}`);
|
package/dist/type.d.ts
CHANGED
|
@@ -136,9 +136,6 @@ export type TTestConfig = {
|
|
|
136
136
|
snapshotContent?(content: string): string;
|
|
137
137
|
checkSteps?: boolean;
|
|
138
138
|
ignoreNotFriendlyForIncrementalWarnings?: boolean;
|
|
139
|
-
esmLibPluginOptions?: {
|
|
140
|
-
preserveModules?: string;
|
|
141
|
-
};
|
|
142
139
|
resourceLoader?: (url: string, element: HTMLScriptElement) => Buffer | null;
|
|
143
140
|
};
|
|
144
141
|
export type TTestFilter = (creatorConfig: Record<string, unknown>, testConfig: TTestConfig) => boolean | string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,19 +35,19 @@
|
|
|
35
35
|
"directory": "packages/rspack-test-tools"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@babel/generator": "7.28.
|
|
39
|
-
"@babel/parser": "7.28.
|
|
40
|
-
"@babel/traverse": "7.28.
|
|
41
|
-
"@babel/types": "7.28.
|
|
38
|
+
"@babel/generator": "7.28.6",
|
|
39
|
+
"@babel/parser": "7.28.6",
|
|
40
|
+
"@babel/traverse": "7.28.6",
|
|
41
|
+
"@babel/types": "7.28.6",
|
|
42
42
|
"cross-env": "^10.1.0",
|
|
43
43
|
"filenamify": "4.3.0",
|
|
44
44
|
"fs-extra": "^11.3.3",
|
|
45
|
-
"iconv-lite": "^0.7.
|
|
45
|
+
"iconv-lite": "^0.7.2",
|
|
46
46
|
"javascript-stringify": "^2.1.0",
|
|
47
47
|
"jest-diff": "^30.2.0",
|
|
48
48
|
"jest-snapshot": "29.7.0",
|
|
49
49
|
"jsdom": "^26.1.0",
|
|
50
|
-
"memfs": "4.
|
|
50
|
+
"memfs": "4.53.0",
|
|
51
51
|
"path-serializer": "0.5.1",
|
|
52
52
|
"pretty-format": "30.2.0",
|
|
53
53
|
"rimraf": "^5.0.10",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@types/jsdom": "^21.1.7",
|
|
66
66
|
"typescript": "^5.9.3",
|
|
67
67
|
"wast-loader": "^1.14.1",
|
|
68
|
-
"@rspack/core": "
|
|
68
|
+
"@rspack/core": "2.0.0-alpha.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@rspack/core": ">=1.0.0"
|