@rspack/test-tools 2.0.1 → 2.0.3
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 +106 -66
- package/dist/case/cache.js +152 -132
- package/dist/case/common.d.ts +4 -4
- package/dist/case/common.js +162 -157
- package/dist/case/compiler.d.ts +4 -4
- package/dist/case/compiler.js +75 -64
- package/dist/case/config.js +112 -74
- package/dist/case/defaults.js +136 -83
- package/dist/case/diagnostic.js +112 -84
- package/dist/case/error.d.ts +4 -4
- package/dist/case/error.js +105 -89
- package/dist/case/esm-output.js +118 -87
- package/dist/case/example.js +73 -35
- package/dist/case/hash.js +74 -59
- package/dist/case/hook.js +151 -138
- package/dist/case/hot-step.js +130 -161
- package/dist/case/hot.js +148 -134
- package/dist/case/incremental.js +91 -58
- package/dist/case/index.js +134 -51
- package/dist/case/multi-compiler.d.ts +4 -4
- package/dist/case/multi-compiler.js +81 -56
- package/dist/case/native-watcher.js +62 -30
- package/dist/case/normal.js +253 -185
- package/dist/case/runner.js +80 -51
- package/dist/case/serial.js +47 -16
- package/dist/case/stats-api.d.ts +4 -4
- package/dist/case/stats-api.js +63 -43
- package/dist/case/stats-output.d.ts +3 -3
- package/dist/case/stats-output.js +147 -152
- package/dist/case/treeshaking.js +66 -35
- package/dist/case/watch.d.ts +3 -19
- package/dist/case/watch.js +204 -224
- package/dist/compiler.js +222 -195
- package/dist/helper/directory.js +83 -71
- package/dist/helper/disable-iconv-lite-warning.js +35 -9
- package/dist/helper/expect/diff.js +39 -10
- package/dist/helper/expect/error.js +62 -30
- package/dist/helper/expect/placeholder.js +47 -21
- package/dist/helper/expect/rspack.js +35 -13
- package/dist/helper/expect/to-be-typeof.js +39 -7
- package/dist/helper/expect/to-end-with.js +40 -8
- package/dist/helper/expect/to-match-file-snapshot.js +103 -80
- package/dist/helper/hot-update/index.js +35 -4
- package/dist/helper/hot-update/loader.d.ts +1 -0
- package/dist/helper/hot-update/loader.js +39 -4
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +87 -74
- package/dist/helper/index.js +138 -24
- package/dist/helper/is.js +51 -10
- package/dist/helper/legacy/EventSourceForNode.d.ts +11 -3
- package/dist/helper/legacy/EventSourceForNode.js +83 -37
- package/dist/helper/legacy/LogTestPlugin.d.ts +2 -3
- package/dist/helper/legacy/LogTestPlugin.js +39 -6
- package/dist/helper/legacy/asModule.d.ts +3 -3
- package/dist/helper/legacy/asModule.js +68 -19
- package/dist/helper/legacy/captureStdio.d.ts +1 -2
- package/dist/helper/legacy/captureStdio.js +69 -29
- package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -2
- package/dist/helper/legacy/checkArrayExpectation.js +132 -121
- package/dist/helper/legacy/copyDiff.d.ts +1 -2
- package/dist/helper/legacy/copyDiff.js +86 -42
- package/dist/helper/legacy/createFakeWorker.d.ts +2 -3
- package/dist/helper/legacy/createFakeWorker.js +90 -47
- package/dist/helper/legacy/createLazyTestEnv.d.ts +2 -3
- package/dist/helper/legacy/createLazyTestEnv.js +70 -59
- package/dist/helper/legacy/currentScript.d.ts +2 -2
- package/dist/helper/legacy/currentScript.js +35 -2
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -1
- package/dist/helper/legacy/deprecationTracking.js +53 -28
- package/dist/helper/legacy/expectSource.d.ts +3 -2
- package/dist/helper/legacy/expectSource.js +42 -18
- package/dist/helper/legacy/fakeSystem.d.ts +12 -9
- package/dist/helper/legacy/fakeSystem.js +68 -58
- package/dist/helper/legacy/findOutputFiles.d.ts +7 -2
- package/dist/helper/legacy/findOutputFiles.js +60 -13
- package/dist/helper/legacy/parseResource.d.ts +1 -1
- package/dist/helper/legacy/parseResource.js +36 -6
- package/dist/helper/legacy/regexEscape.d.ts +1 -2
- package/dist/helper/legacy/regexEscape.js +39 -5
- package/dist/helper/legacy/supportDefaultAssignment.d.ts +1 -2
- package/dist/helper/legacy/supportDefaultAssignment.js +40 -7
- package/dist/helper/legacy/supportsTextDecoder.d.ts +1 -2
- package/dist/helper/legacy/supportsTextDecoder.js +40 -6
- package/dist/helper/legacy/supportsUsing.d.ts +1 -2
- package/dist/helper/legacy/supportsUsing.js +40 -7
- package/dist/helper/legacy/urlToRelativePath.d.ts +2 -2
- package/dist/helper/legacy/urlToRelativePath.js +56 -7
- package/dist/helper/parse-modules.js +52 -42
- package/dist/helper/read-config-file.js +60 -18
- package/dist/helper/serializers.js +62 -33
- package/dist/helper/setup-env.js +81 -91
- package/dist/helper/setup-expect.js +13 -13
- package/dist/helper/setup-wasm.js +18 -9
- package/dist/helper/stringify-config.js +44 -26
- package/dist/helper/update-snapshot.js +35 -3
- package/dist/helper/util/checkSourceMap.js +119 -80
- package/dist/helper/util/checkStats.d.ts +1 -1
- package/dist/helper/util/checkStats.js +42 -17
- package/dist/helper/util/expectWarningFactory.d.ts +1 -2
- package/dist/helper/util/expectWarningFactory.js +41 -8
- package/dist/helper/util/filterUtil.d.ts +9 -8
- package/dist/helper/util/filterUtil.js +63 -23
- package/dist/helper/win.js +46 -7
- package/dist/index.js +115 -23
- package/dist/plugin/index.js +55 -14
- package/dist/plugin/lazy-compilation-test-plugin.js +55 -41
- package/dist/reporter/index.js +55 -14
- package/dist/reporter/streamed-events-reporter.js +51 -77
- package/dist/runner/index.js +62 -15
- package/dist/runner/node/index.js +365 -431
- package/dist/runner/web/index.js +278 -263
- package/dist/test/context.js +67 -41
- package/dist/test/creator.js +135 -167
- package/dist/test/debug.js +89 -58
- package/dist/test/tester.js +94 -74
- package/dist/type.d.ts +10 -9
- package/dist/type.js +43 -9
- package/package.json +24 -23
package/dist/case/common.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Compiler, RspackOptions } from '@rspack/core';
|
|
2
2
|
import type { ITestContext, ITestEnv } from '../type';
|
|
3
|
-
export declare function config(context: ITestContext, name: string, configFiles: string[], defaultOptions?: RspackOptions):
|
|
4
|
-
export declare function compiler(context: ITestContext, name: string):
|
|
3
|
+
export declare function config(context: ITestContext, name: string, configFiles: string[], defaultOptions?: RspackOptions): RspackOptions;
|
|
4
|
+
export declare function compiler(context: ITestContext, name: string): Compiler;
|
|
5
5
|
export declare function build(context: ITestContext, name: string): Promise<Compiler>;
|
|
6
6
|
export declare function run(env: ITestEnv, context: ITestContext, name: string, findBundle: (context: ITestContext, options: RspackOptions) => string[] | string | void): Promise<void>;
|
|
7
7
|
export declare function check(env: ITestEnv, context: ITestContext, name: string): Promise<void>;
|
|
8
|
-
export declare function checkSnapshot(env: ITestEnv, context: ITestContext, name: string, snapshot: string, filter?: (file: string) => boolean):
|
|
9
|
-
export declare function afterExecute(context: ITestContext, name: string):
|
|
8
|
+
export declare function checkSnapshot(env: ITestEnv, context: ITestContext, name: string, snapshot: string, filter?: (file: string) => boolean): void;
|
|
9
|
+
export declare function afterExecute(context: ITestContext, name: string): void;
|
|
10
10
|
export declare function findMultiCompilerBundle(context: ITestContext, name: string, multiFindBundle: (index: number, context: ITestContext, options: RspackOptions) => string[] | string | void): string[];
|
|
11
11
|
export declare function configMultiCompiler(context: ITestContext, name: string, configFiles: string[], defaultOptions: (index: number, context: ITestContext) => RspackOptions, overrideOptions: (index: number, context: ITestContext, options: RspackOptions) => void): void;
|
package/dist/case/common.js
CHANGED
|
@@ -1,34 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
afterExecute: ()=>afterExecute,
|
|
37
|
+
build: ()=>build,
|
|
38
|
+
check: ()=>check,
|
|
39
|
+
checkSnapshot: ()=>checkSnapshot,
|
|
40
|
+
compiler: ()=>common_compiler,
|
|
41
|
+
config: ()=>config,
|
|
42
|
+
configMultiCompiler: ()=>configMultiCompiler,
|
|
43
|
+
findMultiCompilerBundle: ()=>findMultiCompilerBundle,
|
|
44
|
+
run: ()=>run
|
|
45
|
+
});
|
|
46
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
47
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
48
|
+
const external_fs_extra_namespaceObject = require("fs-extra");
|
|
49
|
+
var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
|
|
50
|
+
const external_rspack_merge_namespaceObject = require("rspack-merge");
|
|
51
|
+
var external_rspack_merge_default = /*#__PURE__*/ __webpack_require__.n(external_rspack_merge_namespaceObject);
|
|
52
|
+
const index_js_namespaceObject = require("../helper/index.js");
|
|
53
|
+
const placeholder_js_namespaceObject = require("../helper/expect/placeholder.js");
|
|
54
|
+
const checkArrayExpectation_js_namespaceObject = require("../helper/legacy/checkArrayExpectation.js");
|
|
55
|
+
const debug_js_namespaceObject = require("../test/debug.js");
|
|
56
|
+
function config(context, name, configFiles, defaultOptions = {}) {
|
|
23
57
|
const compiler = context.getCompiler();
|
|
24
58
|
compiler.setOptions(defaultOptions);
|
|
25
59
|
if (Array.isArray(configFiles)) {
|
|
26
|
-
const fileOptions = (0,
|
|
60
|
+
const fileOptions = (0, index_js_namespaceObject.readConfigFile)(configFiles.map((i)=>context.getSource(i)), context, defaultOptions)[0];
|
|
27
61
|
compiler.mergeOptions(fileOptions);
|
|
28
62
|
}
|
|
29
63
|
return compiler.getOptions();
|
|
30
64
|
}
|
|
31
|
-
|
|
65
|
+
function common_compiler(context, name) {
|
|
32
66
|
const compiler = context.getCompiler();
|
|
33
67
|
compiler.createCompiler();
|
|
34
68
|
return compiler.getCompiler();
|
|
@@ -40,39 +74,25 @@ async function build(context, name) {
|
|
|
40
74
|
}
|
|
41
75
|
async function run(env, context, name, findBundle) {
|
|
42
76
|
const testConfig = context.getTestConfig();
|
|
43
|
-
if (testConfig.noTests)
|
|
44
|
-
return;
|
|
77
|
+
if (testConfig.noTests) return;
|
|
45
78
|
const compiler = context.getCompiler();
|
|
46
|
-
if (typeof testConfig.beforeExecute
|
|
47
|
-
testConfig.beforeExecute(compiler.getOptions());
|
|
48
|
-
}
|
|
79
|
+
if ('function' == typeof testConfig.beforeExecute) testConfig.beforeExecute(compiler.getOptions());
|
|
49
80
|
let bundles;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (typeof bundles === 'string') {
|
|
57
|
-
bundles = [bundles];
|
|
58
|
-
}
|
|
59
|
-
if (__DEBUG__) {
|
|
60
|
-
context.setValue(debug_1.DEBUG_SCOPES.RunFindBundle, bundles);
|
|
61
|
-
}
|
|
62
|
-
if (!bundles || !bundles.length) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
81
|
+
bundles = 'function' == typeof findBundle ? findBundle(context, compiler.getOptions()) : [];
|
|
82
|
+
if ('string' == typeof bundles) bundles = [
|
|
83
|
+
bundles
|
|
84
|
+
];
|
|
85
|
+
if (__DEBUG__) context.setValue(debug_js_namespaceObject.DEBUG_SCOPES.RunFindBundle, bundles);
|
|
86
|
+
if (!bundles || !bundles.length) return;
|
|
65
87
|
if (__DEBUG__) {
|
|
66
|
-
context.setValue(
|
|
67
|
-
context.setValue(
|
|
88
|
+
context.setValue(debug_js_namespaceObject.DEBUG_SCOPES.RunLogs, []);
|
|
89
|
+
context.setValue(debug_js_namespaceObject.DEBUG_SCOPES.RunErrors, []);
|
|
68
90
|
}
|
|
69
|
-
for (const bundle of bundles)
|
|
70
|
-
if (!bundle)
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
91
|
+
for (const bundle of bundles){
|
|
92
|
+
if (!bundle) continue;
|
|
73
93
|
const runner = context.getRunner(bundle, env);
|
|
74
94
|
if (__DEBUG__) {
|
|
75
|
-
const runLogs = context.getValue(
|
|
95
|
+
const runLogs = context.getValue(debug_js_namespaceObject.DEBUG_SCOPES.RunLogs);
|
|
76
96
|
runLogs?.push(`Start running entry: ${bundle} in ${runner.constructor.name}(${runner.__key__})`);
|
|
77
97
|
}
|
|
78
98
|
const mod = runner.run(bundle);
|
|
@@ -85,37 +105,31 @@ async function run(env, context, name, findBundle) {
|
|
|
85
105
|
}
|
|
86
106
|
async function check(env, context, name) {
|
|
87
107
|
const testConfig = context.getTestConfig();
|
|
88
|
-
if (testConfig.noTests)
|
|
89
|
-
return;
|
|
108
|
+
if (testConfig.noTests) return;
|
|
90
109
|
const compiler = context.getCompiler();
|
|
91
|
-
const errors = (context.getError() || []).map((e)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
110
|
+
const errors = (context.getError() || []).map((e)=>({
|
|
111
|
+
message: e.message,
|
|
112
|
+
stack: e.stack
|
|
113
|
+
}));
|
|
95
114
|
const warnings = [];
|
|
96
115
|
const stats = compiler.getStats();
|
|
97
116
|
const options = compiler.getOptions();
|
|
98
117
|
if (stats) {
|
|
99
|
-
if (testConfig.writeStatsOuptut) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}), 'utf-8');
|
|
104
|
-
}
|
|
118
|
+
if (testConfig.writeStatsOuptut) external_fs_extra_default().writeFileSync(external_node_path_default().join(context.getDist(), 'stats.txt'), stats.toString({
|
|
119
|
+
preset: 'verbose',
|
|
120
|
+
colors: false
|
|
121
|
+
}), 'utf-8');
|
|
105
122
|
if (testConfig.writeStatsJson) {
|
|
106
123
|
const jsonStats = stats.toJson({
|
|
107
124
|
assets: true,
|
|
108
125
|
chunks: true,
|
|
109
126
|
entrypoints: true,
|
|
110
127
|
chunkGroups: true,
|
|
111
|
-
errorDetails: true
|
|
128
|
+
errorDetails: true
|
|
112
129
|
});
|
|
113
|
-
|
|
130
|
+
external_fs_extra_default().writeFileSync(external_node_path_default().join(context.getDist(), 'stats.json'), JSON.stringify(jsonStats, null, 2), 'utf-8');
|
|
114
131
|
}
|
|
115
|
-
if (
|
|
116
|
-
fs_extra_1.default.existsSync(context.getSource('warnings.js')) ||
|
|
117
|
-
stats.hasErrors() ||
|
|
118
|
-
stats.hasWarnings()) {
|
|
132
|
+
if (external_fs_extra_default().existsSync(context.getSource('errors.js')) || external_fs_extra_default().existsSync(context.getSource('warnings.js')) || stats.hasErrors() || stats.hasWarnings()) {
|
|
119
133
|
const statsJson = stats.toJson({
|
|
120
134
|
assets: true,
|
|
121
135
|
chunks: true,
|
|
@@ -123,106 +137,80 @@ async function check(env, context, name) {
|
|
|
123
137
|
modules: true,
|
|
124
138
|
entrypoints: true,
|
|
125
139
|
chunkGroups: true,
|
|
126
|
-
errorDetails: true
|
|
140
|
+
errorDetails: true
|
|
127
141
|
});
|
|
128
|
-
if (statsJson.errors)
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
if (statsJson.warnings) {
|
|
132
|
-
warnings.push(...statsJson.warnings);
|
|
133
|
-
}
|
|
142
|
+
if (statsJson.errors) errors.push(...statsJson.errors);
|
|
143
|
+
if (statsJson.warnings) warnings.push(...statsJson.warnings);
|
|
134
144
|
}
|
|
135
145
|
}
|
|
136
|
-
await (0,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
146
|
+
await (0, checkArrayExpectation_js_namespaceObject.checkArrayExpectation)(context.getSource(), {
|
|
147
|
+
errors
|
|
148
|
+
}, 'error', 'errors', 'Error', options);
|
|
149
|
+
await (0, checkArrayExpectation_js_namespaceObject.checkArrayExpectation)(context.getSource(), {
|
|
150
|
+
warnings
|
|
151
|
+
}, 'warning', 'warnings', 'Warning', options);
|
|
152
|
+
if (external_fs_extra_default().existsSync(context.getSource('errors.js'))) context.clearError();
|
|
142
153
|
}
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
throw new Error('Snapshot with `.snap` will be managed by rstest, please use `.snap.txt` instead');
|
|
146
|
-
}
|
|
154
|
+
function checkSnapshot(env, context, name, snapshot, filter) {
|
|
155
|
+
if ('.snap' === external_node_path_default().extname(snapshot)) throw new Error('Snapshot with `.snap` will be managed by rstest, please use `.snap.txt` instead');
|
|
147
156
|
const compilerManager = context.getCompiler();
|
|
148
157
|
const stats = compilerManager.getStats();
|
|
149
158
|
const compiler = compilerManager.getCompiler();
|
|
150
|
-
if (!stats || !compiler)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
159
|
+
if (!stats || !compiler) return;
|
|
160
|
+
const compilers = 'compilers' in compiler ? compiler.compilers : [
|
|
161
|
+
compiler
|
|
162
|
+
];
|
|
163
|
+
const totalStats = 'stats' in stats ? stats.stats : [
|
|
164
|
+
stats
|
|
165
|
+
];
|
|
156
166
|
const total = compilers.length;
|
|
157
|
-
for
|
|
167
|
+
for(let i = 0; i < compilers.length; i++){
|
|
158
168
|
const c = compilers[i];
|
|
159
169
|
const stats = totalStats[i];
|
|
160
170
|
if (stats.hasErrors()) {
|
|
161
171
|
const errors = [];
|
|
162
172
|
errors.push(...stats.compilation.errors);
|
|
163
|
-
throw new Error(`Failed to compile in fixture ${name}, Errors: ${errors
|
|
164
|
-
?.map((i) => `${i.message}\n${i.stack}`)
|
|
165
|
-
.join('\n\n')}`);
|
|
173
|
+
throw new Error(`Failed to compile in fixture ${name}, Errors: ${errors?.map((i)=>`${i.message}\n${i.stack}`).join('\n\n')}`);
|
|
166
174
|
}
|
|
167
|
-
const compilation = c._lastCompilation ||
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
((file)
|
|
171
|
-
|
|
172
|
-
const fileContents = Object.entries(compilation.assets)
|
|
173
|
-
.filter(([file]) => snapshotFileFilter(file))
|
|
174
|
-
.map(([file, source]) => {
|
|
175
|
-
const tag = node_path_1.default.extname(file).slice(1) || 'txt';
|
|
176
|
-
let content = (0, placeholder_1.normalizePlaceholder)(source.source().toString());
|
|
175
|
+
const compilation = c._lastCompilation || c._lastCompilation;
|
|
176
|
+
const snapshotFileFilter = filter || ((file)=>(file.endsWith('.js') || file.endsWith('.mjs')) && !file.includes('runtime.js'));
|
|
177
|
+
const fileContents = Object.entries(compilation.assets).filter(([file])=>snapshotFileFilter(file)).map(([file, source])=>{
|
|
178
|
+
const tag = external_node_path_default().extname(file).slice(1) || 'txt';
|
|
179
|
+
let content = (0, placeholder_js_namespaceObject.normalizePlaceholder)(source.source().toString());
|
|
177
180
|
const testConfig = context.getTestConfig();
|
|
178
|
-
if (testConfig.snapshotContent)
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
const filePath = file.replaceAll(node_path_1.default.sep, '/');
|
|
181
|
+
if (testConfig.snapshotContent) content = testConfig.snapshotContent(content);
|
|
182
|
+
const filePath = file.replaceAll(external_node_path_default().sep, '/');
|
|
182
183
|
return `\`\`\`${tag} title=${filePath}\n${content}\n\`\`\``;
|
|
183
184
|
});
|
|
184
185
|
fileContents.sort();
|
|
185
186
|
const content = fileContents.join('\n\n');
|
|
186
|
-
const snapshotPath =
|
|
187
|
-
? snapshot
|
|
188
|
-
: node_path_1.default.resolve(context.getSource(), node_path_1.default.join('__snapshots__', `${snapshot}${total > 1 ? `-${i}` : ''}`));
|
|
187
|
+
const snapshotPath = external_node_path_default().isAbsolute(snapshot) ? snapshot : external_node_path_default().resolve(context.getSource(), external_node_path_default().join('__snapshots__', `${snapshot}${total > 1 ? `-${i}` : ''}`));
|
|
189
188
|
env.expect(content).toMatchFileSnapshotSync(snapshotPath);
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
|
-
|
|
191
|
+
function afterExecute(context, name) {
|
|
193
192
|
const compiler = context.getCompiler();
|
|
194
193
|
const testConfig = context.getTestConfig();
|
|
195
|
-
if (typeof testConfig.afterExecute
|
|
194
|
+
if ('function' == typeof testConfig.afterExecute) {
|
|
196
195
|
let options = compiler.getOptions();
|
|
197
|
-
if (Array.isArray(options) && options.length
|
|
198
|
-
options = options[0];
|
|
199
|
-
}
|
|
196
|
+
if (Array.isArray(options) && 1 === options.length) options = options[0];
|
|
200
197
|
testConfig.afterExecute(options);
|
|
201
198
|
}
|
|
202
199
|
}
|
|
203
200
|
function findMultiCompilerBundle(context, name, multiFindBundle) {
|
|
204
|
-
if (typeof multiFindBundle
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
const multiCompilerOptions = (context.getValue('multiCompilerOptions') ||
|
|
208
|
-
[]);
|
|
201
|
+
if ('function' != typeof multiFindBundle) return [];
|
|
202
|
+
const multiCompilerOptions = context.getValue('multiCompilerOptions') || [];
|
|
209
203
|
const result = [];
|
|
210
204
|
const multiFileIndexMap = context.getValue('multiFileIndexMap') || {};
|
|
211
|
-
for (const [index, compilerOptions] of multiCompilerOptions.entries())
|
|
205
|
+
for (const [index, compilerOptions] of multiCompilerOptions.entries()){
|
|
212
206
|
const curBundles = multiFindBundle(index, context, compilerOptions);
|
|
213
|
-
const bundles = Array.isArray(curBundles)
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
multiFileIndexMap[bundle].push(index);
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
multiFileIndexMap[bundle] = [index];
|
|
224
|
-
}
|
|
225
|
-
}
|
|
207
|
+
const bundles = Array.isArray(curBundles) ? curBundles : curBundles ? [
|
|
208
|
+
curBundles
|
|
209
|
+
] : [];
|
|
210
|
+
for (const bundle of bundles)if (multiFileIndexMap[bundle]) multiFileIndexMap[bundle].push(index);
|
|
211
|
+
else multiFileIndexMap[bundle] = [
|
|
212
|
+
index
|
|
213
|
+
];
|
|
226
214
|
result.push(...bundles);
|
|
227
215
|
}
|
|
228
216
|
context.setValue('multiFileIndexMap', multiFileIndexMap);
|
|
@@ -230,30 +218,47 @@ function findMultiCompilerBundle(context, name, multiFindBundle) {
|
|
|
230
218
|
}
|
|
231
219
|
function configMultiCompiler(context, name, configFiles, defaultOptions, overrideOptions) {
|
|
232
220
|
const multiCompilerOptions = [];
|
|
233
|
-
const caseOptions = Array.isArray(configFiles)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
:
|
|
247
|
-
|
|
248
|
-
const compilerOptions = (0, webpack_merge_1.default)(typeof defaultOptions === 'function'
|
|
249
|
-
? defaultOptions(index, context)
|
|
250
|
-
: {}, options);
|
|
251
|
-
if (typeof overrideOptions === 'function') {
|
|
252
|
-
overrideOptions(index, context, compilerOptions);
|
|
253
|
-
}
|
|
221
|
+
const caseOptions = Array.isArray(configFiles) ? (0, index_js_namespaceObject.readConfigFile)(configFiles.map((i)=>context.getSource(i)), context, {}, (configs)=>configs.flatMap((c)=>{
|
|
222
|
+
if ('function' == typeof c) {
|
|
223
|
+
const options = {
|
|
224
|
+
testPath: context.getDist(),
|
|
225
|
+
env: void 0
|
|
226
|
+
};
|
|
227
|
+
return c(options.env, options);
|
|
228
|
+
}
|
|
229
|
+
return c;
|
|
230
|
+
})) : [
|
|
231
|
+
{}
|
|
232
|
+
];
|
|
233
|
+
for (const [index, options] of caseOptions.entries()){
|
|
234
|
+
const compilerOptions = external_rspack_merge_default()('function' == typeof defaultOptions ? defaultOptions(index, context) : {}, options);
|
|
235
|
+
if ('function' == typeof overrideOptions) overrideOptions(index, context, compilerOptions);
|
|
254
236
|
multiCompilerOptions.push(compilerOptions);
|
|
255
237
|
}
|
|
256
238
|
const compiler = context.getCompiler();
|
|
257
239
|
compiler.setOptions(multiCompilerOptions);
|
|
258
240
|
context.setValue('multiCompilerOptions', multiCompilerOptions);
|
|
259
241
|
}
|
|
242
|
+
exports.afterExecute = __webpack_exports__.afterExecute;
|
|
243
|
+
exports.build = __webpack_exports__.build;
|
|
244
|
+
exports.check = __webpack_exports__.check;
|
|
245
|
+
exports.checkSnapshot = __webpack_exports__.checkSnapshot;
|
|
246
|
+
exports.compiler = __webpack_exports__.compiler;
|
|
247
|
+
exports.config = __webpack_exports__.config;
|
|
248
|
+
exports.configMultiCompiler = __webpack_exports__.configMultiCompiler;
|
|
249
|
+
exports.findMultiCompilerBundle = __webpack_exports__.findMultiCompilerBundle;
|
|
250
|
+
exports.run = __webpack_exports__.run;
|
|
251
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
252
|
+
"afterExecute",
|
|
253
|
+
"build",
|
|
254
|
+
"check",
|
|
255
|
+
"checkSnapshot",
|
|
256
|
+
"compiler",
|
|
257
|
+
"config",
|
|
258
|
+
"configMultiCompiler",
|
|
259
|
+
"findMultiCompilerBundle",
|
|
260
|
+
"run"
|
|
261
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
262
|
+
Object.defineProperty(exports, '__esModule', {
|
|
263
|
+
value: true
|
|
264
|
+
});
|
package/dist/case/compiler.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { Compilation, Compiler, RspackOptions, Stats, StatsCompilation } from '@rspack/core';
|
|
2
|
-
import type { ITestContext } from '../type';
|
|
2
|
+
import type { ITestContext, MaybePromise } 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;
|
|
6
6
|
error?: boolean;
|
|
7
7
|
skip?: boolean;
|
|
8
8
|
options?: (context: ITestContext) => RspackOptions;
|
|
9
|
-
compiler?: (context: ITestContext, compiler: Compiler) =>
|
|
10
|
-
build?: (context: ITestContext, compiler: Compiler) =>
|
|
9
|
+
compiler?: (context: ITestContext, compiler: Compiler) => MaybePromise<void>;
|
|
10
|
+
build?: (context: ITestContext, compiler: Compiler) => MaybePromise<void>;
|
|
11
11
|
check?: ({ context, stats, files, compiler, compilation, }: {
|
|
12
12
|
context: ITestContext;
|
|
13
13
|
stats?: StatsCompilation;
|
|
14
14
|
files?: Record<string, string>;
|
|
15
15
|
compiler: Compiler;
|
|
16
16
|
compilation?: Compilation;
|
|
17
|
-
}) =>
|
|
17
|
+
}) => MaybePromise<void>;
|
|
18
18
|
compilerCallback?: (error: Error | null, stats: Stats | null) => void;
|
|
19
19
|
};
|