@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
package/dist/case/compiler.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Compilation, Compiler, RspackOptions, Stats, StatsCompilation } from
|
|
2
|
-
import type { ITestContext } from
|
|
1
|
+
import type { Compilation, Compiler, RspackOptions, Stats, StatsCompilation } from '@rspack/core';
|
|
2
|
+
import type { ITestContext } from '../type';
|
|
3
3
|
export declare function createCompilerCase(name: string, src: string, dist: string, testConfig: string): void;
|
|
4
4
|
export type TCompilerCaseConfig = {
|
|
5
5
|
description: string;
|
|
@@ -8,7 +8,7 @@ export type TCompilerCaseConfig = {
|
|
|
8
8
|
options?: (context: ITestContext) => RspackOptions;
|
|
9
9
|
compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
|
|
10
10
|
build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
|
|
11
|
-
check?: ({ context, stats, files, compiler, compilation }: {
|
|
11
|
+
check?: ({ context, stats, files, compiler, compilation, }: {
|
|
12
12
|
context: ITestContext;
|
|
13
13
|
stats?: StatsCompilation;
|
|
14
14
|
files?: Record<string, string>;
|
package/dist/case/compiler.js
CHANGED
|
@@ -5,18 +5,18 @@ const creator_1 = require("../test/creator");
|
|
|
5
5
|
function createCompilerProcessor(name, caseConfig) {
|
|
6
6
|
const logs = {
|
|
7
7
|
mkdir: [],
|
|
8
|
-
writeFile: []
|
|
8
|
+
writeFile: [],
|
|
9
9
|
};
|
|
10
10
|
const files = {};
|
|
11
11
|
return {
|
|
12
12
|
config: async (context) => {
|
|
13
13
|
const compiler = context.getCompiler();
|
|
14
14
|
const options = caseConfig.options?.(context) || {};
|
|
15
|
-
options.mode ??=
|
|
15
|
+
options.mode ??= 'production';
|
|
16
16
|
options.context ??= context.getSource();
|
|
17
|
-
options.entry ??=
|
|
17
|
+
options.entry ??= './a.js';
|
|
18
18
|
options.output ??= {};
|
|
19
|
-
options.output.path ??=
|
|
19
|
+
options.output.path ??= '/';
|
|
20
20
|
options.output.pathinfo ??= true;
|
|
21
21
|
options.optimization ??= {};
|
|
22
22
|
options.optimization.minimize ??= false;
|
|
@@ -47,25 +47,25 @@ function createCompilerProcessor(name, caseConfig) {
|
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
49
|
const err = new Error();
|
|
50
|
-
err.code =
|
|
50
|
+
err.code = 'EEXIST';
|
|
51
51
|
callback(err);
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
writeFile(name, content, callback) {
|
|
55
55
|
logs.writeFile.push(name, content);
|
|
56
|
-
files[name] = content.toString(
|
|
56
|
+
files[name] = content.toString('utf-8');
|
|
57
57
|
callback();
|
|
58
58
|
},
|
|
59
59
|
stat(path, callback) {
|
|
60
|
-
callback(new Error(
|
|
61
|
-
}
|
|
60
|
+
callback(new Error('ENOENT'));
|
|
61
|
+
},
|
|
62
62
|
};
|
|
63
|
-
c.hooks.compilation.tap(
|
|
63
|
+
c.hooks.compilation.tap('CompilerTest', (compilation) => (compilation.bail = true));
|
|
64
64
|
await caseConfig.compiler?.(context, c);
|
|
65
65
|
},
|
|
66
66
|
build: async (context) => {
|
|
67
67
|
const compiler = context.getCompiler();
|
|
68
|
-
if (typeof caseConfig.build ===
|
|
68
|
+
if (typeof caseConfig.build === 'function') {
|
|
69
69
|
await caseConfig.build?.(context, compiler.getCompiler());
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
@@ -80,7 +80,7 @@ function createCompilerProcessor(name, caseConfig) {
|
|
|
80
80
|
if (caseConfig.error) {
|
|
81
81
|
const statsJson = stats?.toJson({
|
|
82
82
|
modules: true,
|
|
83
|
-
reasons: true
|
|
83
|
+
reasons: true,
|
|
84
84
|
});
|
|
85
85
|
const compilation = stats?.compilation;
|
|
86
86
|
await caseConfig.check?.({
|
|
@@ -88,18 +88,18 @@ function createCompilerProcessor(name, caseConfig) {
|
|
|
88
88
|
compiler: c,
|
|
89
89
|
stats: statsJson,
|
|
90
90
|
compilation,
|
|
91
|
-
files
|
|
91
|
+
files,
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
else if (stats) {
|
|
95
|
-
expect(typeof stats).toBe(
|
|
95
|
+
expect(typeof stats).toBe('object');
|
|
96
96
|
const compilation = stats.compilation;
|
|
97
97
|
const statsJson = stats.toJson({
|
|
98
98
|
modules: true,
|
|
99
|
-
reasons: true
|
|
99
|
+
reasons: true,
|
|
100
100
|
});
|
|
101
|
-
expect(typeof statsJson).toBe(
|
|
102
|
-
expect(statsJson).toHaveProperty(
|
|
101
|
+
expect(typeof statsJson).toBe('object');
|
|
102
|
+
expect(statsJson).toHaveProperty('errors');
|
|
103
103
|
expect(Array.isArray(statsJson.errors)).toBe(true);
|
|
104
104
|
if (statsJson.errors.length > 0) {
|
|
105
105
|
expect(statsJson.errors[0]).toBeInstanceOf(Object);
|
|
@@ -111,20 +111,20 @@ function createCompilerProcessor(name, caseConfig) {
|
|
|
111
111
|
stats: statsJson,
|
|
112
112
|
files,
|
|
113
113
|
compiler: c,
|
|
114
|
-
compilation
|
|
114
|
+
compilation,
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
else {
|
|
118
118
|
await caseConfig.check?.({
|
|
119
119
|
context,
|
|
120
120
|
files,
|
|
121
|
-
compiler: c
|
|
121
|
+
compiler: c,
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
125
|
after: async (context) => {
|
|
126
126
|
await context.closeCompiler();
|
|
127
|
-
}
|
|
127
|
+
},
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
const creator = new creator_1.BasicCaseCreator({
|
|
@@ -133,7 +133,7 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
133
133
|
steps: ({ name, caseConfig }) => {
|
|
134
134
|
return [createCompilerProcessor(name, caseConfig)];
|
|
135
135
|
},
|
|
136
|
-
concurrent: false
|
|
136
|
+
concurrent: false,
|
|
137
137
|
});
|
|
138
138
|
function createCompilerCase(name, src, dist, testConfig) {
|
|
139
139
|
let caseConfigList = require(testConfig);
|
|
@@ -148,7 +148,7 @@ function createCompilerCase(name, src, dist, testConfig) {
|
|
|
148
148
|
}
|
|
149
149
|
creator.create(`${name}[${i}]`, src, dist, undefined, {
|
|
150
150
|
caseConfig,
|
|
151
|
-
description: () => caseConfig.description
|
|
151
|
+
description: () => caseConfig.description,
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
154
|
}
|
package/dist/case/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { RspackOptions } from
|
|
2
|
-
import type { ITestContext, ITestProcessor, TTestConfig } from
|
|
3
|
-
export type TConfigCaseConfig = Omit<TTestConfig,
|
|
1
|
+
import type { RspackOptions } from '@rspack/core';
|
|
2
|
+
import type { ITestContext, ITestProcessor, TTestConfig } from '../type';
|
|
3
|
+
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;
|
package/dist/case/config.js
CHANGED
|
@@ -17,7 +17,7 @@ const runner_1 = require("./runner");
|
|
|
17
17
|
function createConfigProcessor(name) {
|
|
18
18
|
return {
|
|
19
19
|
config: async (context) => {
|
|
20
|
-
(0, common_1.configMultiCompiler)(context, name, [
|
|
20
|
+
(0, common_1.configMultiCompiler)(context, name, ['rspack.config.cjs', 'rspack.config.js', 'webpack.config.js'], defaultOptions, overrideOptions);
|
|
21
21
|
},
|
|
22
22
|
compiler: async (context) => {
|
|
23
23
|
await (0, common_1.compiler)(context, name);
|
|
@@ -33,18 +33,18 @@ function createConfigProcessor(name) {
|
|
|
33
33
|
},
|
|
34
34
|
after: async (context) => {
|
|
35
35
|
await (0, common_1.afterExecute)(context, name);
|
|
36
|
-
}
|
|
36
|
+
},
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
const creator = new creator_1.BasicCaseCreator({
|
|
40
40
|
clean: true,
|
|
41
41
|
describe: false,
|
|
42
|
-
testConfig: testConfig => {
|
|
42
|
+
testConfig: (testConfig) => {
|
|
43
43
|
const oldModuleScope = testConfig.moduleScope;
|
|
44
44
|
testConfig.moduleScope = (ms, stats, compilerOptions) => {
|
|
45
45
|
let res = ms;
|
|
46
46
|
// TODO: modify runner module scope based on stats here
|
|
47
|
-
if (typeof oldModuleScope ===
|
|
47
|
+
if (typeof oldModuleScope === 'function') {
|
|
48
48
|
res = oldModuleScope(ms, stats, compilerOptions);
|
|
49
49
|
}
|
|
50
50
|
return res;
|
|
@@ -53,9 +53,9 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
53
53
|
steps: ({ name }) => [createConfigProcessor(name)],
|
|
54
54
|
runner: {
|
|
55
55
|
key: runner_1.getMultiCompilerRunnerKey,
|
|
56
|
-
runner: runner_1.createMultiCompilerRunner
|
|
56
|
+
runner: runner_1.createMultiCompilerRunner,
|
|
57
57
|
},
|
|
58
|
-
concurrent: true
|
|
58
|
+
concurrent: true,
|
|
59
59
|
});
|
|
60
60
|
function createConfigCase(name, src, dist) {
|
|
61
61
|
creator.create(name, src, dist);
|
|
@@ -63,29 +63,29 @@ function createConfigCase(name, src, dist) {
|
|
|
63
63
|
function defaultOptions(index, context) {
|
|
64
64
|
return {
|
|
65
65
|
context: context.getSource(),
|
|
66
|
-
mode:
|
|
67
|
-
target:
|
|
66
|
+
mode: 'production',
|
|
67
|
+
target: 'async-node',
|
|
68
68
|
devtool: false,
|
|
69
69
|
cache: false,
|
|
70
70
|
output: {
|
|
71
|
-
path: context.getDist()
|
|
71
|
+
path: context.getDist(),
|
|
72
72
|
},
|
|
73
73
|
optimization: {
|
|
74
|
-
minimize: false
|
|
74
|
+
minimize: false,
|
|
75
75
|
},
|
|
76
76
|
experiments: {
|
|
77
77
|
css: true,
|
|
78
78
|
rspackFuture: {
|
|
79
79
|
bundlerInfo: {
|
|
80
|
-
force: false
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
80
|
+
force: false,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
function overrideOptions(index, context, options) {
|
|
87
87
|
if (!options.entry) {
|
|
88
|
-
options.entry =
|
|
88
|
+
options.entry = './index.js';
|
|
89
89
|
}
|
|
90
90
|
if (options.amd === undefined) {
|
|
91
91
|
options.amd = {};
|
|
@@ -93,19 +93,19 @@ function overrideOptions(index, context, options) {
|
|
|
93
93
|
if (!options.output?.filename) {
|
|
94
94
|
const outputModule = options.experiments?.outputModule;
|
|
95
95
|
options.output ??= {};
|
|
96
|
-
options.output.filename = `bundle${index}${outputModule ?
|
|
96
|
+
options.output.filename = `bundle${index}${outputModule ? '.mjs' : '.js'}`;
|
|
97
97
|
}
|
|
98
98
|
if (options.cache === undefined)
|
|
99
99
|
options.cache = false;
|
|
100
100
|
if (!global.printLogger) {
|
|
101
101
|
options.infrastructureLogging = {
|
|
102
|
-
level:
|
|
102
|
+
level: 'error',
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
function findBundle(index, context, options) {
|
|
107
107
|
const testConfig = context.getTestConfig();
|
|
108
|
-
if (typeof testConfig.findBundle ===
|
|
108
|
+
if (typeof testConfig.findBundle === 'function') {
|
|
109
109
|
return testConfig.findBundle(index, options);
|
|
110
110
|
}
|
|
111
111
|
const ext = path_1.default.extname((0, parseResource_1.parseResource)(options.output?.filename).path);
|
|
@@ -113,7 +113,7 @@ function findBundle(index, context, options) {
|
|
|
113
113
|
if (options.output?.path &&
|
|
114
114
|
fs_extra_1.default.existsSync(path_1.default.join(options.output.path, `bundle${index}${ext}`))) {
|
|
115
115
|
if (options.experiments?.css) {
|
|
116
|
-
const cssOutputPath = path_1.default.join(options.output.path, (typeof options.output?.cssFilename ===
|
|
116
|
+
const cssOutputPath = path_1.default.join(options.output.path, (typeof options.output?.cssFilename === 'string' &&
|
|
117
117
|
options.output?.cssFilename) ||
|
|
118
118
|
`bundle${index}.css`);
|
|
119
119
|
if (fs_extra_1.default.existsSync(cssOutputPath)) {
|
package/dist/case/defaults.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RspackOptions } from
|
|
2
|
-
import type { ITestContext } from
|
|
1
|
+
import type { RspackOptions } from '@rspack/core';
|
|
2
|
+
import type { ITestContext } from '../type';
|
|
3
3
|
export declare function createDefaultsCase(name: string, src: string): void;
|
|
4
4
|
export declare function getRspackDefaultConfig(cwd: string, config: RspackOptions): RspackOptions;
|
|
5
5
|
export type TDefaultsCaseConfig = {
|
package/dist/case/defaults.js
CHANGED
|
@@ -30,33 +30,33 @@ function createDefaultsCase(name, src) {
|
|
|
30
30
|
},
|
|
31
31
|
check: async (env, context) => {
|
|
32
32
|
await check(env, context, name, caseConfig);
|
|
33
|
-
}
|
|
33
|
+
},
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
function getRspackDefaultConfig(cwd, config) {
|
|
38
38
|
process.chdir(cwd);
|
|
39
|
-
const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = require(
|
|
39
|
+
const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = require('@rspack/core').config;
|
|
40
40
|
const normalizedConfig = getNormalizedWebpackOptions(config);
|
|
41
41
|
applyWebpackOptionsDefaults(normalizedConfig);
|
|
42
42
|
// make snapshot stable
|
|
43
43
|
normalizedConfig.experiments.rspackFuture.bundlerInfo.version =
|
|
44
|
-
|
|
44
|
+
'$version$';
|
|
45
45
|
process.chdir(CURRENT_CWD);
|
|
46
46
|
return normalizedConfig;
|
|
47
47
|
}
|
|
48
|
-
const srcDir = node_path_1.default.resolve(__dirname,
|
|
49
|
-
const distDir = node_path_1.default.resolve(__dirname,
|
|
48
|
+
const srcDir = node_path_1.default.resolve(__dirname, '../../tests/fixtures');
|
|
49
|
+
const distDir = node_path_1.default.resolve(__dirname, '../../tests/js/defaults');
|
|
50
50
|
function options(context, custom) {
|
|
51
51
|
let res;
|
|
52
|
-
if (typeof custom ===
|
|
52
|
+
if (typeof custom === 'function') {
|
|
53
53
|
res = custom(context);
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
56
|
res = {};
|
|
57
57
|
}
|
|
58
|
-
if (!(
|
|
59
|
-
res.mode =
|
|
58
|
+
if (!('mode' in res)) {
|
|
59
|
+
res.mode = 'none';
|
|
60
60
|
}
|
|
61
61
|
return res;
|
|
62
62
|
}
|
|
@@ -69,7 +69,7 @@ async function check(env, context, name, options) {
|
|
|
69
69
|
const compiler = context.getCompiler();
|
|
70
70
|
const config = getRspackDefaultConfig(options.cwd || CURRENT_CWD, compiler.getOptions());
|
|
71
71
|
const defaultConfig = getRspackDefaultConfig(options.cwd || CURRENT_CWD, {
|
|
72
|
-
mode:
|
|
72
|
+
mode: 'none',
|
|
73
73
|
});
|
|
74
74
|
const diff = (0, node_util_1.stripVTControlCharacters)((0, jest_diff_1.diff)(defaultConfig, config, { expand: false, contextLines: 0 }));
|
|
75
75
|
await options.diff(env.expect(new RspackTestDiff(diff)), env.expect(defaultConfig));
|
|
@@ -78,7 +78,7 @@ async function run(name, processor) {
|
|
|
78
78
|
const context = new context_1.TestContext({
|
|
79
79
|
name: name,
|
|
80
80
|
src: srcDir,
|
|
81
|
-
dist: distDir
|
|
81
|
+
dist: distDir,
|
|
82
82
|
});
|
|
83
83
|
try {
|
|
84
84
|
await processor.before?.(context);
|
package/dist/case/diagnostic.js
CHANGED
|
@@ -18,13 +18,13 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
18
18
|
config: async (context) => {
|
|
19
19
|
const compiler = context.getCompiler();
|
|
20
20
|
let options = defaultOptions(context);
|
|
21
|
-
const custom = (0, helper_1.readConfigFile)([
|
|
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
23
|
options = (0, webpack_merge_1.default)(options, custom);
|
|
24
24
|
}
|
|
25
25
|
if (!global.printLogger) {
|
|
26
26
|
options.infrastructureLogging = {
|
|
27
|
-
level:
|
|
27
|
+
level: 'error',
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
compiler.setOptions(options);
|
|
@@ -42,89 +42,89 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
42
42
|
},
|
|
43
43
|
check: async (env, context) => {
|
|
44
44
|
await check(env, context, name, {
|
|
45
|
-
snapshot:
|
|
46
|
-
snapshotErrors:
|
|
47
|
-
snapshotWarning:
|
|
45
|
+
snapshot: './stats.err',
|
|
46
|
+
snapshotErrors: './raw-error.err',
|
|
47
|
+
snapshotWarning: './raw-warning.err',
|
|
48
48
|
format: (output) => {
|
|
49
49
|
// TODO: change to stats.errorStack
|
|
50
50
|
// TODO: add `errorStack: false`
|
|
51
|
-
return output.replace(/(│.* at ).*/g,
|
|
52
|
-
}
|
|
51
|
+
return output.replace(/(│.* at ).*/g, '$1xxx');
|
|
52
|
+
},
|
|
53
53
|
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
56
|
],
|
|
57
|
-
concurrent: true
|
|
57
|
+
concurrent: true,
|
|
58
58
|
});
|
|
59
59
|
function createDiagnosticCase(name, src, dist) {
|
|
60
60
|
creator.create(name, src, dist);
|
|
61
61
|
}
|
|
62
62
|
function defaultOptions(context) {
|
|
63
63
|
return {
|
|
64
|
-
target:
|
|
64
|
+
target: 'node',
|
|
65
65
|
context: context.getSource(),
|
|
66
66
|
entry: {
|
|
67
|
-
main:
|
|
67
|
+
main: './',
|
|
68
68
|
},
|
|
69
|
-
mode:
|
|
69
|
+
mode: 'development',
|
|
70
70
|
devServer: {
|
|
71
|
-
hot: false
|
|
71
|
+
hot: false,
|
|
72
72
|
},
|
|
73
73
|
infrastructureLogging: {
|
|
74
|
-
debug: false
|
|
74
|
+
debug: false,
|
|
75
75
|
},
|
|
76
76
|
output: {
|
|
77
|
-
path: context.getDist()
|
|
77
|
+
path: context.getDist(),
|
|
78
78
|
},
|
|
79
79
|
experiments: {
|
|
80
80
|
css: true,
|
|
81
81
|
rspackFuture: {
|
|
82
82
|
bundlerInfo: {
|
|
83
|
-
force: false
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
83
|
+
force: false,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
async function check(env, context, name, options) {
|
|
90
90
|
const compiler = context.getCompiler();
|
|
91
91
|
const stats = compiler.getStats();
|
|
92
92
|
if (!stats) {
|
|
93
|
-
throw new Error(
|
|
93
|
+
throw new Error('Stats should exists');
|
|
94
94
|
}
|
|
95
95
|
(0, node_assert_1.default)(stats.hasErrors() || stats.hasWarnings());
|
|
96
96
|
let output = (0, placeholder_1.normalizePlaceholder)(stats.toString({
|
|
97
97
|
all: false,
|
|
98
98
|
errors: true,
|
|
99
|
-
warnings: true
|
|
100
|
-
})).replaceAll(
|
|
99
|
+
warnings: true,
|
|
100
|
+
})).replaceAll('\\', '/');
|
|
101
101
|
const statsJson = stats.toJson({
|
|
102
102
|
all: false,
|
|
103
103
|
errors: true,
|
|
104
|
-
warnings: true
|
|
104
|
+
warnings: true,
|
|
105
105
|
});
|
|
106
|
-
const errors = (statsJson.errors || []).map(e => {
|
|
106
|
+
const errors = (statsJson.errors || []).map((e) => {
|
|
107
107
|
// @ts-expect-error error message is already serialized in `stats.err`
|
|
108
108
|
delete e.message;
|
|
109
109
|
delete e.stack;
|
|
110
110
|
return e;
|
|
111
111
|
});
|
|
112
|
-
const warnings = (statsJson.warnings || []).map(e => {
|
|
112
|
+
const warnings = (statsJson.warnings || []).map((e) => {
|
|
113
113
|
// @ts-expect-error error message is already serialized in `stats.err`
|
|
114
114
|
delete e.message;
|
|
115
115
|
delete e.stack;
|
|
116
116
|
return e;
|
|
117
117
|
});
|
|
118
|
-
if (typeof options.format ===
|
|
118
|
+
if (typeof options.format === 'function') {
|
|
119
119
|
output = options.format(output);
|
|
120
120
|
}
|
|
121
121
|
env.expect.addSnapshotSerializer({
|
|
122
122
|
test(received) {
|
|
123
|
-
return typeof received ===
|
|
123
|
+
return typeof received === 'string';
|
|
124
124
|
},
|
|
125
125
|
serialize(received) {
|
|
126
126
|
return (0, placeholder_1.normalizePlaceholder)(received.trim());
|
|
127
|
-
}
|
|
127
|
+
},
|
|
128
128
|
});
|
|
129
129
|
const errorOutputPath = node_path_1.default.resolve(context.getSource(options.snapshot));
|
|
130
130
|
const errorStatsOutputPath = node_path_1.default.resolve(context.getSource(options.snapshotErrors));
|
package/dist/case/error.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Compiler, RspackOptions, StatsError } from
|
|
2
|
-
import type { ITestContext } from
|
|
1
|
+
import type { Compiler, RspackOptions, StatsError } from '@rspack/core';
|
|
2
|
+
import type { ITestContext } from '../type';
|
|
3
3
|
export declare function createErrorCase(name: string, src: string, dist: string, testConfig: string): void;
|
|
4
4
|
declare class RspackStatsDiagnostics {
|
|
5
5
|
errors: StatsError[];
|
package/dist/case/error.js
CHANGED
|
@@ -26,7 +26,7 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
26
26
|
},
|
|
27
27
|
build: async (context) => {
|
|
28
28
|
const compiler = context.getCompiler();
|
|
29
|
-
if (typeof config.build ===
|
|
29
|
+
if (typeof config.build === 'function') {
|
|
30
30
|
await config.build(context, compiler.getCompiler());
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
@@ -38,11 +38,11 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
38
38
|
},
|
|
39
39
|
check: async (env, context) => {
|
|
40
40
|
await check(env, context, name, config.check);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
43
|
];
|
|
44
44
|
},
|
|
45
|
-
concurrent: true
|
|
45
|
+
concurrent: true,
|
|
46
46
|
});
|
|
47
47
|
function createErrorCase(name, src, dist, testConfig) {
|
|
48
48
|
if (!addedSerializer) {
|
|
@@ -56,7 +56,7 @@ function createErrorCase(name, src, dist, testConfig) {
|
|
|
56
56
|
}
|
|
57
57
|
creator.create(name, src, dist, undefined, {
|
|
58
58
|
caseConfig,
|
|
59
|
-
description: () => caseConfig.description
|
|
59
|
+
description: () => caseConfig.description,
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
if (Array.isArray(caseConfigList)) {
|
|
@@ -70,27 +70,27 @@ function createErrorCase(name, src, dist, testConfig) {
|
|
|
70
70
|
}
|
|
71
71
|
function options(context, custom) {
|
|
72
72
|
let options = {
|
|
73
|
-
context: node_path_1.default.resolve(__TEST_FIXTURES_PATH__,
|
|
74
|
-
mode:
|
|
73
|
+
context: node_path_1.default.resolve(__TEST_FIXTURES_PATH__, 'errors'),
|
|
74
|
+
mode: 'none',
|
|
75
75
|
devtool: false,
|
|
76
76
|
optimization: {
|
|
77
77
|
minimize: false,
|
|
78
|
-
moduleIds:
|
|
79
|
-
chunkIds:
|
|
78
|
+
moduleIds: 'named',
|
|
79
|
+
chunkIds: 'named',
|
|
80
80
|
},
|
|
81
81
|
experiments: {
|
|
82
82
|
css: true,
|
|
83
83
|
rspackFuture: {
|
|
84
84
|
bundlerInfo: {
|
|
85
|
-
force: false
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
85
|
+
force: false,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
89
|
};
|
|
90
|
-
if (typeof custom ===
|
|
90
|
+
if (typeof custom === 'function') {
|
|
91
91
|
options = (0, webpack_merge_1.default)(options, custom(context, options));
|
|
92
92
|
}
|
|
93
|
-
if (options.mode ===
|
|
93
|
+
if (options.mode === 'production') {
|
|
94
94
|
if (options.optimization)
|
|
95
95
|
options.optimization.minimize = true;
|
|
96
96
|
else
|
|
@@ -103,10 +103,10 @@ async function compiler(context, compiler, custom) {
|
|
|
103
103
|
compiler.outputFileSystem = {
|
|
104
104
|
// CHANGE: rspack outputFileSystem `mkdirp` uses option `{ recursive: true }`, webpack's second parameter is alway a callback
|
|
105
105
|
mkdir(dir, maybeOptionOrCallback, maybeCallback) {
|
|
106
|
-
if (typeof maybeOptionOrCallback ===
|
|
106
|
+
if (typeof maybeOptionOrCallback === 'function') {
|
|
107
107
|
maybeOptionOrCallback();
|
|
108
108
|
}
|
|
109
|
-
else if (typeof maybeCallback ===
|
|
109
|
+
else if (typeof maybeCallback === 'function') {
|
|
110
110
|
maybeCallback();
|
|
111
111
|
}
|
|
112
112
|
},
|
|
@@ -114,10 +114,10 @@ async function compiler(context, compiler, custom) {
|
|
|
114
114
|
callback();
|
|
115
115
|
},
|
|
116
116
|
stat(file, callback) {
|
|
117
|
-
callback(new Error(
|
|
117
|
+
callback(new Error('ENOENT'));
|
|
118
118
|
},
|
|
119
119
|
mkdirSync() { },
|
|
120
|
-
writeFileSync() { }
|
|
120
|
+
writeFileSync() { },
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
123
|
await custom?.(context, compiler);
|
|
@@ -136,9 +136,9 @@ async function check(env, context, name, check) {
|
|
|
136
136
|
}
|
|
137
137
|
const compiler = context.getCompiler();
|
|
138
138
|
const stats = compiler.getStats();
|
|
139
|
-
env.expect(typeof stats).toBe(
|
|
139
|
+
env.expect(typeof stats).toBe('object');
|
|
140
140
|
const statsResult = stats.toJson({ errorDetails: false });
|
|
141
|
-
env.expect(typeof statsResult).toBe(
|
|
141
|
+
env.expect(typeof statsResult).toBe('object');
|
|
142
142
|
const { errors, warnings } = statsResult;
|
|
143
143
|
env.expect(Array.isArray(errors)).toBe(true);
|
|
144
144
|
env.expect(Array.isArray(warnings)).toBe(true);
|