@rspack/test-tools 1.7.0-beta.1 → 1.7.1
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 +2 -2
- package/dist/case/builtin.js +58 -58
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +34 -34
- package/dist/case/common.d.ts +2 -2
- package/dist/case/common.js +45 -45
- package/dist/case/compiler.d.ts +3 -3
- package/dist/case/compiler.js +21 -21
- package/dist/case/config.d.ts +3 -3
- package/dist/case/config.js +19 -19
- package/dist/case/defaults.d.ts +2 -2
- package/dist/case/defaults.js +10 -10
- package/dist/case/diagnostic.js +29 -29
- package/dist/case/error.d.ts +2 -2
- package/dist/case/error.js +21 -21
- package/dist/case/esm-output.js +28 -28
- package/dist/case/example.js +7 -7
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +16 -16
- package/dist/case/hook.d.ts +3 -3
- package/dist/case/hook.js +42 -42
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +46 -46
- package/dist/case/hot.d.ts +5 -5
- package/dist/case/hot.js +43 -43
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +9 -9
- package/dist/case/index.d.ts +31 -31
- package/dist/case/multi-compiler.d.ts +3 -3
- package/dist/case/multi-compiler.js +15 -15
- package/dist/case/native-watcher.js +6 -6
- package/dist/case/normal.js +46 -46
- package/dist/case/runner.d.ts +2 -2
- package/dist/case/runner.js +22 -15
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +4 -4
- package/dist/case/stats-api.d.ts +2 -2
- package/dist/case/stats-api.js +7 -7
- package/dist/case/stats-output.d.ts +2 -2
- package/dist/case/stats-output.js +45 -45
- package/dist/case/treeshaking.js +6 -6
- package/dist/case/watch.d.ts +1 -1
- package/dist/case/watch.js +59 -59
- package/dist/compiler.d.ts +3 -3
- package/dist/compiler.js +31 -31
- package/dist/helper/directory.d.ts +1 -1
- package/dist/helper/directory.js +15 -15
- package/dist/helper/disable-iconv-lite-warning.js +3 -3
- package/dist/helper/expect/diff.js +8 -8
- package/dist/helper/expect/error.js +9 -9
- package/dist/helper/expect/placeholder.js +9 -9
- package/dist/helper/expect/rspack.js +5 -5
- package/dist/helper/expect/to-be-typeof.js +2 -2
- package/dist/helper/expect/to-end-with.js +3 -3
- package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -1
- package/dist/helper/expect/to-match-file-snapshot.js +23 -23
- package/dist/helper/hot-update/index.d.ts +1 -1
- package/dist/helper/hot-update/loader.js +1 -1
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +15 -15
- package/dist/helper/index.d.ts +8 -8
- package/dist/helper/is.js +2 -2
- package/dist/helper/legacy/EventSourceForNode.js +8 -8
- package/dist/helper/legacy/LogTestPlugin.js +18 -18
- package/dist/helper/legacy/asModule.js +6 -6
- package/dist/helper/legacy/captureStdio.js +6 -6
- package/dist/helper/legacy/checkArrayExpectation.js +24 -24
- package/dist/helper/legacy/copyDiff.js +5 -5
- package/dist/helper/legacy/createFakeWorker.js +13 -13
- package/dist/helper/legacy/createLazyTestEnv.js +12 -12
- package/dist/helper/legacy/currentScript.js +1 -1
- package/dist/helper/legacy/deprecationTracking.js +5 -5
- package/dist/helper/legacy/expectSource.js +5 -5
- package/dist/helper/legacy/fakeSystem.js +14 -14
- package/dist/helper/legacy/findOutputFiles.js +4 -4
- package/dist/helper/legacy/parseResource.js +4 -4
- package/dist/helper/legacy/regexEscape.js +2 -2
- package/dist/helper/legacy/supportDefaultAssignment.js +2 -2
- package/dist/helper/legacy/supportsTextDecoder.js +2 -2
- package/dist/helper/legacy/supportsUsing.js +1 -1
- package/dist/helper/legacy/urlToRelativePath.js +3 -3
- package/dist/helper/parse-modules.js +13 -13
- package/dist/helper/read-config-file.d.ts +2 -2
- package/dist/helper/read-config-file.js +3 -3
- package/dist/helper/serializers.d.ts +1 -1
- package/dist/helper/serializers.js +11 -11
- package/dist/helper/setup-env.js +17 -17
- package/dist/helper/setup-expect.js +1 -1
- package/dist/helper/setup-wasm.js +4 -4
- package/dist/helper/stringify-config.d.ts +1 -1
- package/dist/helper/stringify-config.js +3 -3
- package/dist/helper/update-snapshot.js +1 -1
- package/dist/helper/util/checkSourceMap.js +16 -17
- package/dist/helper/util/checkStats.js +3 -3
- package/dist/helper/util/expectWarningFactory.js +2 -2
- package/dist/helper/util/filterUtil.js +9 -9
- package/dist/index.d.ts +8 -8
- package/dist/index.js +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/lazy-compilation-test-plugin.d.ts +1 -1
- package/dist/plugin/lazy-compilation-test-plugin.js +13 -13
- package/dist/runner/index.d.ts +2 -2
- package/dist/runner/node/index.d.ts +2 -2
- package/dist/runner/node/index.js +75 -74
- package/dist/runner/web/index.d.ts +2 -2
- package/dist/runner/web/index.js +45 -45
- package/dist/test/context.d.ts +2 -2
- package/dist/test/context.js +4 -4
- package/dist/test/creator.d.ts +1 -1
- package/dist/test/creator.js +28 -28
- package/dist/test/debug.d.ts +1 -1
- package/dist/test/debug.js +31 -31
- package/dist/test/tester.d.ts +1 -1
- package/dist/test/tester.js +11 -11
- package/dist/type.d.ts +3 -3
- package/package.json +3 -3
- package/rstest.d.ts +12 -12
|
@@ -14,14 +14,14 @@ const common_1 = require("./common");
|
|
|
14
14
|
const REG_ERROR_CASE = /error$/;
|
|
15
15
|
function createStatsProcessor(name, defaultOptions, overrideOptions) {
|
|
16
16
|
const writeStatsOuptut = false;
|
|
17
|
-
const snapshotName =
|
|
17
|
+
const snapshotName = 'stats.txt';
|
|
18
18
|
let stderr = null;
|
|
19
19
|
return {
|
|
20
20
|
before: async (context) => {
|
|
21
21
|
stderr = (0, captureStdio_1.default)(process.stderr, true);
|
|
22
22
|
},
|
|
23
23
|
config: async (context) => {
|
|
24
|
-
(0, common_1.configMultiCompiler)(context, name, [
|
|
24
|
+
(0, common_1.configMultiCompiler)(context, name, ['rspack.config.js', 'webpack.config.js'], defaultOptions, overrideOptions);
|
|
25
25
|
},
|
|
26
26
|
compiler: async (context) => {
|
|
27
27
|
const c = await (0, common_1.compiler)(context, name);
|
|
@@ -38,53 +38,53 @@ function createStatsProcessor(name, defaultOptions, overrideOptions) {
|
|
|
38
38
|
},
|
|
39
39
|
after: async (context) => {
|
|
40
40
|
stderr.restore();
|
|
41
|
-
}
|
|
41
|
+
},
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
const creator = new creator_1.BasicCaseCreator({
|
|
45
45
|
clean: true,
|
|
46
46
|
describe: false,
|
|
47
47
|
steps: ({ name }) => [
|
|
48
|
-
createStatsProcessor(name, defaultOptions, overrideOptions)
|
|
48
|
+
createStatsProcessor(name, defaultOptions, overrideOptions),
|
|
49
49
|
],
|
|
50
|
-
description: () =>
|
|
50
|
+
description: () => 'should print correct stats for',
|
|
51
51
|
});
|
|
52
52
|
function createStatsOutputCase(name, src, dist) {
|
|
53
53
|
creator.create(name, src, dist);
|
|
54
54
|
}
|
|
55
55
|
function defaultOptions(index, context) {
|
|
56
|
-
if (fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(),
|
|
57
|
-
fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(),
|
|
56
|
+
if (fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), 'rspack.config.js')) ||
|
|
57
|
+
fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), 'webpack.config.js'))) {
|
|
58
58
|
return {
|
|
59
59
|
experiments: {
|
|
60
60
|
css: true,
|
|
61
61
|
rspackFuture: {
|
|
62
62
|
bundlerInfo: {
|
|
63
|
-
force: false
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
63
|
+
force: false,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
return {
|
|
70
70
|
context: context.getSource(),
|
|
71
|
-
mode:
|
|
72
|
-
entry:
|
|
71
|
+
mode: 'development',
|
|
72
|
+
entry: './index.js',
|
|
73
73
|
output: {
|
|
74
|
-
filename:
|
|
75
|
-
path: context.getDist()
|
|
74
|
+
filename: 'bundle.js',
|
|
75
|
+
path: context.getDist(),
|
|
76
76
|
},
|
|
77
77
|
optimization: {
|
|
78
|
-
minimize: false
|
|
78
|
+
minimize: false,
|
|
79
79
|
},
|
|
80
80
|
experiments: {
|
|
81
81
|
css: true,
|
|
82
82
|
rspackFuture: {
|
|
83
83
|
bundlerInfo: {
|
|
84
|
-
force: false
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
84
|
+
force: false,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
function overrideOptions(index, context, options) {
|
|
@@ -103,7 +103,7 @@ function overrideOptions(index, context, options) {
|
|
|
103
103
|
}
|
|
104
104
|
if (!global.printLogger) {
|
|
105
105
|
options.infrastructureLogging = {
|
|
106
|
-
level:
|
|
106
|
+
level: 'error',
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
}
|
|
@@ -121,7 +121,7 @@ async function check(env, context, name, writeStatsOuptut, snapshot, stderr) {
|
|
|
121
121
|
for (const compilation of []
|
|
122
122
|
.concat(stats.stats || stats)
|
|
123
123
|
.map((s) => s.compilation)) {
|
|
124
|
-
compilation.logging.delete(
|
|
124
|
+
compilation.logging.delete('webpack.Compilation.ModuleProfile');
|
|
125
125
|
}
|
|
126
126
|
if (REG_ERROR_CASE.test(name)) {
|
|
127
127
|
env.expect(stats.hasErrors()).toBe(true);
|
|
@@ -129,64 +129,64 @@ async function check(env, context, name, writeStatsOuptut, snapshot, stderr) {
|
|
|
129
129
|
else if (stats.hasErrors()) {
|
|
130
130
|
throw new Error(stats.toString({
|
|
131
131
|
all: false,
|
|
132
|
-
errors: true
|
|
132
|
+
errors: true,
|
|
133
133
|
// errorStack: true,
|
|
134
134
|
// errorDetails: true
|
|
135
135
|
}));
|
|
136
136
|
}
|
|
137
137
|
else if (writeStatsOuptut) {
|
|
138
|
-
fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(),
|
|
139
|
-
preset:
|
|
138
|
+
fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(), 'stats.txt'), stats.toString({
|
|
139
|
+
preset: 'verbose',
|
|
140
140
|
// context: context.getSource(),
|
|
141
|
-
colors: false
|
|
142
|
-
}),
|
|
141
|
+
colors: false,
|
|
142
|
+
}), 'utf-8');
|
|
143
143
|
}
|
|
144
144
|
let toStringOptions = {
|
|
145
145
|
context: context.getSource(),
|
|
146
|
-
colors: false
|
|
146
|
+
colors: false,
|
|
147
147
|
};
|
|
148
148
|
let hasColorSetting = false;
|
|
149
|
-
if (typeof options.stats !==
|
|
149
|
+
if (typeof options.stats !== 'undefined') {
|
|
150
150
|
toStringOptions = options.stats;
|
|
151
|
-
if (toStringOptions === null || typeof toStringOptions !==
|
|
151
|
+
if (toStringOptions === null || typeof toStringOptions !== 'object')
|
|
152
152
|
toStringOptions = { preset: toStringOptions };
|
|
153
153
|
if (!toStringOptions.context)
|
|
154
154
|
toStringOptions.context = context.getSource();
|
|
155
|
-
hasColorSetting = typeof toStringOptions.colors !==
|
|
155
|
+
hasColorSetting = typeof toStringOptions.colors !== 'undefined';
|
|
156
156
|
}
|
|
157
157
|
if (Array.isArray(options) && !toStringOptions.children) {
|
|
158
|
-
toStringOptions.children = options.map(o => o.stats);
|
|
158
|
+
toStringOptions.children = options.map((o) => o.stats);
|
|
159
159
|
}
|
|
160
160
|
// mock timestamps
|
|
161
161
|
for (const { compilation: s } of [].concat(stats.stats || stats)) {
|
|
162
162
|
env.expect(s.startTime).toBeGreaterThan(0);
|
|
163
163
|
env.expect(s.endTime).toBeGreaterThan(0);
|
|
164
|
-
s.endTime = new Date(
|
|
164
|
+
s.endTime = new Date('04/20/1970, 12:42:42 PM').getTime();
|
|
165
165
|
s.startTime = s.endTime - 1234;
|
|
166
166
|
}
|
|
167
167
|
let actual = stats.toString(toStringOptions);
|
|
168
|
-
env.expect(typeof actual).toBe(
|
|
168
|
+
env.expect(typeof actual).toBe('string');
|
|
169
169
|
actual = stderr.toString() + actual;
|
|
170
170
|
if (!hasColorSetting) {
|
|
171
171
|
actual = actual
|
|
172
|
-
.replace(/\u001b\[[0-9;]*m/g,
|
|
172
|
+
.replace(/\u001b\[[0-9;]*m/g, '')
|
|
173
173
|
// CHANGE: The time unit display in Rspack is second
|
|
174
|
-
.replace(/[.0-9]+(\s?s)/g,
|
|
174
|
+
.replace(/[.0-9]+(\s?s)/g, 'X$1')
|
|
175
175
|
// CHANGE: Replace bundle size, since bundle sizes may differ between platforms
|
|
176
|
-
.replace(/[0-9]+(\.[0-9]+)? KiB/g,
|
|
177
|
-
.replace(/[0-9]+(\.[0-9]+)? bytes/g,
|
|
178
|
-
.replace(/[0-9]+(\.[0-9]+)? ms/g,
|
|
176
|
+
.replace(/[0-9]+(\.[0-9]+)? KiB/g, 'xx KiB')
|
|
177
|
+
.replace(/[0-9]+(\.[0-9]+)? bytes/g, 'xx bytes')
|
|
178
|
+
.replace(/[0-9]+(\.[0-9]+)? ms/g, 'xx ms');
|
|
179
179
|
}
|
|
180
180
|
actual = actual
|
|
181
|
-
.split(
|
|
182
|
-
.filter(line => !line.includes(
|
|
183
|
-
.join(
|
|
181
|
+
.split('\n')
|
|
182
|
+
.filter((line) => !line.includes('@rstest/core/dist'))
|
|
183
|
+
.join('\n');
|
|
184
184
|
const snapshotPath = node_path_1.default.isAbsolute(snapshot)
|
|
185
185
|
? snapshot
|
|
186
186
|
: node_path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshot}`);
|
|
187
187
|
env.expect(new RspackStats(actual)).toMatchFileSnapshotSync(snapshotPath);
|
|
188
188
|
const testConfig = context.getTestConfig();
|
|
189
|
-
if (typeof testConfig?.validate ===
|
|
189
|
+
if (typeof testConfig?.validate === 'function') {
|
|
190
190
|
testConfig.validate(stats, stderr.toString());
|
|
191
191
|
}
|
|
192
192
|
}
|
|
@@ -209,8 +209,8 @@ async function statsCompiler(context, compiler) {
|
|
|
209
209
|
return callback(err);
|
|
210
210
|
if (!/\.(js|json|txt)$/.test(args[0]))
|
|
211
211
|
return callback(null, result);
|
|
212
|
-
callback(null, (0, placeholder_1.normalizePlaceholder)(result.toString(
|
|
213
|
-
}
|
|
212
|
+
callback(null, (0, placeholder_1.normalizePlaceholder)(result.toString('utf-8')));
|
|
213
|
+
},
|
|
214
214
|
]));
|
|
215
215
|
};
|
|
216
216
|
}
|
package/dist/case/treeshaking.js
CHANGED
|
@@ -28,23 +28,23 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
28
28
|
// no need to run, just check snapshot
|
|
29
29
|
},
|
|
30
30
|
check: async (env, context) => {
|
|
31
|
-
await (0, common_1.checkSnapshot)(env, context, name,
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
]
|
|
31
|
+
await (0, common_1.checkSnapshot)(env, context, name, 'treeshaking.snap.txt');
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
35
|
});
|
|
36
36
|
function createTreeShakingCase(name, src, dist) {
|
|
37
37
|
creator.create(name, src, dist);
|
|
38
38
|
}
|
|
39
39
|
function overrideOptions(context, options) {
|
|
40
|
-
options.target = options.target || [
|
|
40
|
+
options.target = options.target || ['web', 'es2022'];
|
|
41
41
|
options.optimization ??= {};
|
|
42
42
|
options.optimization.providedExports = true;
|
|
43
43
|
options.optimization.innerGraph = true;
|
|
44
44
|
options.optimization.usedExports = true;
|
|
45
45
|
if (!global.printLogger) {
|
|
46
46
|
options.infrastructureLogging = {
|
|
47
|
-
level:
|
|
47
|
+
level: 'error',
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
}
|
package/dist/case/watch.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ITestContext, ITestEnv, ITestRunner } from
|
|
1
|
+
import type { ITestContext, ITestEnv, ITestRunner } from '../type';
|
|
2
2
|
export declare function createWatchInitialProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher }?: {
|
|
3
3
|
incremental?: boolean | undefined;
|
|
4
4
|
nativeWatcher?: boolean | undefined;
|
package/dist/case/watch.js
CHANGED
|
@@ -25,20 +25,20 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
25
25
|
step,
|
|
26
26
|
tempDir,
|
|
27
27
|
nativeWatcher,
|
|
28
|
-
watchState
|
|
28
|
+
watchState,
|
|
29
29
|
};
|
|
30
30
|
return {
|
|
31
31
|
before: async (context) => {
|
|
32
|
-
context.setValue(
|
|
32
|
+
context.setValue('watchContext', watchContext);
|
|
33
33
|
},
|
|
34
34
|
config: async (context) => {
|
|
35
35
|
const testConfig = context.getTestConfig();
|
|
36
36
|
const multiCompilerOptions = [];
|
|
37
|
-
const caseOptions = (0, helper_1.readConfigFile)([
|
|
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
39
|
const compilerOptions = (0, webpack_merge_1.default)(defaultOptions({
|
|
40
40
|
incremental,
|
|
41
|
-
ignoreNotFriendlyForIncrementalWarnings: testConfig.ignoreNotFriendlyForIncrementalWarnings
|
|
41
|
+
ignoreNotFriendlyForIncrementalWarnings: testConfig.ignoreNotFriendlyForIncrementalWarnings,
|
|
42
42
|
}), options);
|
|
43
43
|
overrideOptions(index, context, compilerOptions, tempDir, nativeWatcher);
|
|
44
44
|
multiCompilerOptions.push(compilerOptions);
|
|
@@ -48,11 +48,11 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
48
48
|
: multiCompilerOptions;
|
|
49
49
|
const compiler = context.getCompiler();
|
|
50
50
|
compiler.setOptions(compilerOptions);
|
|
51
|
-
context.setValue(
|
|
51
|
+
context.setValue('multiCompilerOptions', multiCompilerOptions);
|
|
52
52
|
},
|
|
53
53
|
compiler: async (context) => {
|
|
54
54
|
const c = await (0, common_1.compiler)(context, name);
|
|
55
|
-
c.hooks.invalid.tap(
|
|
55
|
+
c.hooks.invalid.tap('WatchTestCasesTest', (filename, mtime) => {
|
|
56
56
|
watchContext.currentTriggerFilename = filename;
|
|
57
57
|
});
|
|
58
58
|
},
|
|
@@ -60,9 +60,9 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
60
60
|
const compiler = context.getCompiler();
|
|
61
61
|
fs_extra_1.default.mkdirSync(watchContext.tempDir, { recursive: true });
|
|
62
62
|
(0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), watchContext.tempDir, true);
|
|
63
|
-
const pkgJsonFile = node_path_1.default.join(watchContext.tempDir,
|
|
63
|
+
const pkgJsonFile = node_path_1.default.join(watchContext.tempDir, 'package.json');
|
|
64
64
|
if (!fs_extra_1.default.existsSync(pkgJsonFile)) {
|
|
65
|
-
fs_extra_1.default.writeJsonSync(pkgJsonFile, { name, version:
|
|
65
|
+
fs_extra_1.default.writeJsonSync(pkgJsonFile, { name, version: '0.0.1' });
|
|
66
66
|
const longTimeAgo = Date.now() - 1000 * 60 * 60 * 24;
|
|
67
67
|
fs_extra_1.default.utimesSync(pkgJsonFile, Date.now() - longTimeAgo, Date.now() - longTimeAgo);
|
|
68
68
|
}
|
|
@@ -83,9 +83,9 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
83
83
|
const testConfig = context.getTestConfig();
|
|
84
84
|
if (testConfig.noTests)
|
|
85
85
|
return;
|
|
86
|
-
const errors = (context.getError() || []).map(e => ({
|
|
86
|
+
const errors = (context.getError() || []).map((e) => ({
|
|
87
87
|
message: e.message,
|
|
88
|
-
stack: e.stack
|
|
88
|
+
stack: e.stack,
|
|
89
89
|
}));
|
|
90
90
|
const warnings = [];
|
|
91
91
|
const compiler = context.getCompiler();
|
|
@@ -94,17 +94,17 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
94
94
|
const checkStats = testConfig.checkStats || (() => true);
|
|
95
95
|
if (stats) {
|
|
96
96
|
if (testConfig.writeStatsOuptut) {
|
|
97
|
-
fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(),
|
|
98
|
-
preset:
|
|
99
|
-
colors: false
|
|
100
|
-
}),
|
|
97
|
+
fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(), 'stats.txt'), stats.toString({
|
|
98
|
+
preset: 'verbose',
|
|
99
|
+
colors: false,
|
|
100
|
+
}), 'utf-8');
|
|
101
101
|
}
|
|
102
102
|
const getJsonStats = (() => {
|
|
103
103
|
let cached = null;
|
|
104
104
|
return () => {
|
|
105
105
|
if (!cached) {
|
|
106
106
|
cached = stats.toJson({
|
|
107
|
-
errorDetails: true
|
|
107
|
+
errorDetails: true,
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
return cached;
|
|
@@ -115,7 +115,7 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
115
115
|
return () => {
|
|
116
116
|
if (!cached) {
|
|
117
117
|
cached = stats.toString({
|
|
118
|
-
logging:
|
|
118
|
+
logging: 'verbose',
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
return cached;
|
|
@@ -123,24 +123,24 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
123
123
|
})();
|
|
124
124
|
if (checkStats.length > 1) {
|
|
125
125
|
if (!checkStats(watchContext.step, getJsonStats(), getStringStats())) {
|
|
126
|
-
throw new Error(
|
|
126
|
+
throw new Error('stats check failed');
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
else {
|
|
130
130
|
// @ts-expect-error only one param
|
|
131
131
|
if (!checkStats(watchContext.step)) {
|
|
132
|
-
throw new Error(
|
|
132
|
+
throw new Error('stats check failed');
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
if (testConfig.writeStatsJson) {
|
|
136
|
-
fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(),
|
|
136
|
+
fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(), 'stats.json'), JSON.stringify(getJsonStats(), null, 2), 'utf-8');
|
|
137
137
|
}
|
|
138
138
|
if (fs_extra_1.default.existsSync(context.getSource(`${watchContext.step}/errors.js`)) ||
|
|
139
139
|
fs_extra_1.default.existsSync(context.getSource(`${watchContext.step}/warnings.js`)) ||
|
|
140
140
|
stats.hasErrors() ||
|
|
141
141
|
stats.hasWarnings()) {
|
|
142
142
|
const statsJson = stats.toJson({
|
|
143
|
-
errorDetails: true
|
|
143
|
+
errorDetails: true,
|
|
144
144
|
});
|
|
145
145
|
if (statsJson.errors) {
|
|
146
146
|
errors.push(...statsJson.errors);
|
|
@@ -150,23 +150,23 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), { errors },
|
|
154
|
-
await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), { warnings },
|
|
153
|
+
await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), { errors }, 'error', 'errors', 'Error', options);
|
|
154
|
+
await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), { warnings }, 'warning', 'warnings', 'Warning', options);
|
|
155
155
|
// clear error if checked
|
|
156
|
-
if (fs_extra_1.default.existsSync(context.getSource(
|
|
156
|
+
if (fs_extra_1.default.existsSync(context.getSource('errors.js'))) {
|
|
157
157
|
context.clearError();
|
|
158
158
|
}
|
|
159
159
|
// check hash
|
|
160
160
|
if (testConfig.writeStatsOuptut) {
|
|
161
|
-
fs_extra_1.default.renameSync(node_path_1.default.join(context.getDist(),
|
|
161
|
+
fs_extra_1.default.renameSync(node_path_1.default.join(context.getDist(), 'stats.txt'), node_path_1.default.join(context.getDist(), `stats.${watchContext.step}.txt`));
|
|
162
162
|
}
|
|
163
163
|
if (testConfig.writeStatsJson) {
|
|
164
|
-
fs_extra_1.default.renameSync(node_path_1.default.join(context.getDist(),
|
|
164
|
+
fs_extra_1.default.renameSync(node_path_1.default.join(context.getDist(), 'stats.json'), node_path_1.default.join(context.getDist(), `stats.${watchContext.step}.json`));
|
|
165
165
|
}
|
|
166
166
|
},
|
|
167
167
|
after: async (context) => {
|
|
168
168
|
await (0, common_1.afterExecute)(context, name);
|
|
169
|
-
}
|
|
169
|
+
},
|
|
170
170
|
};
|
|
171
171
|
}
|
|
172
172
|
function createWatchStepProcessor(name, tempDir, step, watchState, { incremental = false, nativeWatcher = false } = {}) {
|
|
@@ -191,8 +191,8 @@ function createWatchStepProcessor(name, tempDir, step, watchState, { incremental
|
|
|
191
191
|
// which will cause the compiler not rebuild when the files change.
|
|
192
192
|
// The timeout is set to 400ms for windows OS and 100ms for other OS.
|
|
193
193
|
// TODO: This is a workaround, we can remove it when notify support windows better.
|
|
194
|
-
const timeout = nativeWatcher && process.platform ===
|
|
195
|
-
await new Promise(resolve => setTimeout(resolve, timeout));
|
|
194
|
+
const timeout = nativeWatcher && process.platform === 'win32' ? 400 : 100;
|
|
195
|
+
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
196
196
|
(0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), step), tempDir, false);
|
|
197
197
|
await task;
|
|
198
198
|
};
|
|
@@ -202,7 +202,7 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
202
202
|
clean: true,
|
|
203
203
|
runner: {
|
|
204
204
|
key: getWatchRunnerKey,
|
|
205
|
-
runner: createWatchRunner
|
|
205
|
+
runner: createWatchRunner,
|
|
206
206
|
},
|
|
207
207
|
description: (name, index) => {
|
|
208
208
|
return index === 0
|
|
@@ -215,38 +215,38 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
215
215
|
const runs = fs_extra_1.default
|
|
216
216
|
.readdirSync(src)
|
|
217
217
|
.sort()
|
|
218
|
-
.filter(name => fs_extra_1.default.statSync(node_path_1.default.join(src, name)).isDirectory())
|
|
219
|
-
.map(name => ({ name }));
|
|
218
|
+
.filter((name) => fs_extra_1.default.statSync(node_path_1.default.join(src, name)).isDirectory())
|
|
219
|
+
.map((name) => ({ name }));
|
|
220
220
|
return runs.map((run, index) => index === 0
|
|
221
221
|
? createWatchInitialProcessor(name, temp, run.name, watchState)
|
|
222
222
|
: createWatchStepProcessor(name, temp, run.name, watchState));
|
|
223
223
|
},
|
|
224
|
-
concurrent: true
|
|
224
|
+
concurrent: true,
|
|
225
225
|
});
|
|
226
226
|
function createWatchCase(name, src, dist, temp) {
|
|
227
227
|
creator.create(name, src, dist, temp);
|
|
228
228
|
}
|
|
229
229
|
function overrideOptions(index, context, options, tempDir, nativeWatcher) {
|
|
230
230
|
if (!options.mode)
|
|
231
|
-
options.mode =
|
|
231
|
+
options.mode = 'development';
|
|
232
232
|
if (!options.context)
|
|
233
233
|
options.context = tempDir;
|
|
234
234
|
if (!options.entry)
|
|
235
|
-
options.entry =
|
|
235
|
+
options.entry = './index.js';
|
|
236
236
|
if (!options.target)
|
|
237
|
-
options.target =
|
|
237
|
+
options.target = 'async-node';
|
|
238
238
|
if (!options.devtool)
|
|
239
239
|
options.devtool = false;
|
|
240
240
|
if (!options.output)
|
|
241
241
|
options.output = {};
|
|
242
242
|
if (!options.output.path)
|
|
243
243
|
options.output.path = context.getDist();
|
|
244
|
-
if (typeof options.output.pathinfo ===
|
|
244
|
+
if (typeof options.output.pathinfo === 'undefined')
|
|
245
245
|
options.output.pathinfo = false;
|
|
246
246
|
if (!options.output.filename)
|
|
247
|
-
options.output.filename =
|
|
248
|
-
if (options.cache && options.cache.type ===
|
|
249
|
-
const cacheDirectory = node_path_1.default.join(tempDir,
|
|
247
|
+
options.output.filename = 'bundle.js';
|
|
248
|
+
if (options.cache && options.cache.type === 'filesystem') {
|
|
249
|
+
const cacheDirectory = node_path_1.default.join(tempDir, '.cache');
|
|
250
250
|
options.cache.cacheDirectory = cacheDirectory;
|
|
251
251
|
options.cache.name = `config-${index}`;
|
|
252
252
|
}
|
|
@@ -261,41 +261,41 @@ function overrideOptions(index, context, options, tempDir, nativeWatcher) {
|
|
|
261
261
|
options.experiments.rspackFuture.bundlerInfo.force ??=
|
|
262
262
|
false;
|
|
263
263
|
// test incremental: "safe" here, we test default incremental in Incremental-*.test.js
|
|
264
|
-
options.experiments.incremental ??=
|
|
264
|
+
options.experiments.incremental ??= 'safe';
|
|
265
265
|
if (!global.printLogger) {
|
|
266
266
|
options.infrastructureLogging = {
|
|
267
|
-
level:
|
|
267
|
+
level: 'error',
|
|
268
268
|
};
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
function findBundle(index, context, options, stepName) {
|
|
272
272
|
const testConfig = context.getTestConfig();
|
|
273
|
-
if (typeof testConfig.findBundle ===
|
|
273
|
+
if (typeof testConfig.findBundle === 'function') {
|
|
274
274
|
return testConfig.findBundle(index, options, stepName);
|
|
275
275
|
}
|
|
276
|
-
return
|
|
276
|
+
return './bundle.js';
|
|
277
277
|
}
|
|
278
|
-
function defaultOptions({ incremental = false, ignoreNotFriendlyForIncrementalWarnings = false } = {}) {
|
|
278
|
+
function defaultOptions({ incremental = false, ignoreNotFriendlyForIncrementalWarnings = false, } = {}) {
|
|
279
279
|
if (incremental) {
|
|
280
280
|
return {
|
|
281
281
|
experiments: {
|
|
282
|
-
incremental:
|
|
282
|
+
incremental: 'advance',
|
|
283
283
|
},
|
|
284
284
|
ignoreWarnings: ignoreNotFriendlyForIncrementalWarnings
|
|
285
285
|
? [/is not friendly for incremental/]
|
|
286
|
-
: undefined
|
|
286
|
+
: undefined,
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
289
|
return {};
|
|
290
290
|
}
|
|
291
291
|
function getWatchRunnerKey(context, name, file) {
|
|
292
|
-
const watchContext = context.getValue(
|
|
292
|
+
const watchContext = context.getValue('watchContext');
|
|
293
293
|
const stepName = watchContext?.step;
|
|
294
294
|
return `${name}-${stepName}`;
|
|
295
295
|
}
|
|
296
296
|
function cachedWatchStats(context, name) {
|
|
297
297
|
const compiler = context.getCompiler();
|
|
298
|
-
const watchContext = context.getValue(
|
|
298
|
+
const watchContext = context.getValue('watchContext');
|
|
299
299
|
const stepName = watchContext?.step;
|
|
300
300
|
const statsGetter = (() => {
|
|
301
301
|
const cached = {};
|
|
@@ -304,7 +304,7 @@ function cachedWatchStats(context, name) {
|
|
|
304
304
|
return cached[stepName];
|
|
305
305
|
}
|
|
306
306
|
cached[stepName] = compiler.getStats().toJson({
|
|
307
|
-
errorDetails: true
|
|
307
|
+
errorDetails: true,
|
|
308
308
|
});
|
|
309
309
|
return cached[stepName];
|
|
310
310
|
};
|
|
@@ -314,21 +314,21 @@ function cachedWatchStats(context, name) {
|
|
|
314
314
|
function createWatchRunner(context, name, file, env) {
|
|
315
315
|
const compiler = context.getCompiler();
|
|
316
316
|
const compilerOptions = compiler.getOptions();
|
|
317
|
-
const watchContext = context.getValue(
|
|
317
|
+
const watchContext = context.getValue('watchContext');
|
|
318
318
|
const stepName = watchContext?.step;
|
|
319
319
|
if (!stepName) {
|
|
320
|
-
throw new Error(
|
|
320
|
+
throw new Error('Can not get watch step name from context');
|
|
321
321
|
}
|
|
322
322
|
const state = watchContext?.watchState;
|
|
323
323
|
if (!state) {
|
|
324
|
-
throw new Error(
|
|
324
|
+
throw new Error('Can not get watch state from context');
|
|
325
325
|
}
|
|
326
326
|
const isWeb = Array.isArray(compilerOptions)
|
|
327
|
-
? compilerOptions.some(option => {
|
|
328
|
-
return option.target ===
|
|
327
|
+
? compilerOptions.some((option) => {
|
|
328
|
+
return option.target === 'web' || option.target === 'webworker';
|
|
329
329
|
})
|
|
330
|
-
: compilerOptions.target ===
|
|
331
|
-
compilerOptions.target ===
|
|
330
|
+
: compilerOptions.target === 'web' ||
|
|
331
|
+
compilerOptions.target === 'webworker';
|
|
332
332
|
const testConfig = context.getTestConfig();
|
|
333
333
|
return new runner_1.WebRunner({
|
|
334
334
|
env,
|
|
@@ -341,15 +341,15 @@ function createWatchRunner(context, name, file, env) {
|
|
|
341
341
|
moduleScope: (ms, stats, options) => {
|
|
342
342
|
ms.STATE = state;
|
|
343
343
|
ms.WATCH_STEP = stepName;
|
|
344
|
-
if (typeof testConfig.moduleScope ===
|
|
344
|
+
if (typeof testConfig.moduleScope === 'function') {
|
|
345
345
|
return testConfig.moduleScope(ms, stats, options);
|
|
346
346
|
}
|
|
347
347
|
return ms;
|
|
348
|
-
}
|
|
348
|
+
},
|
|
349
349
|
},
|
|
350
350
|
source: context.getSource(),
|
|
351
351
|
dist: context.getDist(),
|
|
352
352
|
compilerOptions,
|
|
353
|
-
location: testConfig.location ||
|
|
353
|
+
location: testConfig.location || 'https://test.cases/path/index.html',
|
|
354
354
|
});
|
|
355
355
|
}
|
package/dist/compiler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import EventEmitter from
|
|
2
|
-
import { Compiler, type RspackOptions, type Stats } from
|
|
3
|
-
import type { ITestCompilerManager, ITestContext } from
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
import { Compiler, type RspackOptions, type Stats } from '@rspack/core';
|
|
3
|
+
import type { ITestCompilerManager, ITestContext } from './type';
|
|
4
4
|
export declare enum ECompilerEvent {
|
|
5
5
|
Build = "build",
|
|
6
6
|
Option = "option",
|