@rspack/test-tools 2.0.2 → 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 +136 -122
- 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 +21 -20
package/dist/case/config.js
CHANGED
|
@@ -1,62 +1,98 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
createConfigCase: ()=>createConfigCase,
|
|
37
|
+
createConfigProcessor: ()=>createConfigProcessor,
|
|
38
|
+
defaultOptions: ()=>defaultOptions,
|
|
39
|
+
enableEsmLibraryPlugin: ()=>enableEsmLibraryPlugin,
|
|
40
|
+
findBundle: ()=>findBundle,
|
|
41
|
+
overrideOptions: ()=>overrideOptions
|
|
42
|
+
});
|
|
43
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
44
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
45
|
+
const external_fs_extra_namespaceObject = require("fs-extra");
|
|
46
|
+
var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
|
|
47
|
+
const parseResource_js_namespaceObject = require("../helper/legacy/parseResource.js");
|
|
48
|
+
const creator_js_namespaceObject = require("../test/creator.js");
|
|
49
|
+
const external_common_js_namespaceObject = require("./common.js");
|
|
50
|
+
const external_runner_js_namespaceObject = require("./runner.js");
|
|
18
51
|
function createConfigProcessor(name) {
|
|
19
52
|
return {
|
|
20
|
-
config:
|
|
21
|
-
(0,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
53
|
+
config: (context)=>{
|
|
54
|
+
(0, external_common_js_namespaceObject.configMultiCompiler)(context, name, [
|
|
55
|
+
'rspack.config.cjs',
|
|
56
|
+
'rspack.config.js',
|
|
57
|
+
'webpack.config.js'
|
|
58
|
+
], defaultOptions, overrideOptions);
|
|
25
59
|
},
|
|
26
|
-
|
|
27
|
-
await (0,
|
|
60
|
+
compiler: async (context)=>{
|
|
61
|
+
await (0, external_common_js_namespaceObject.compiler)(context, name);
|
|
28
62
|
},
|
|
29
|
-
|
|
30
|
-
await (0,
|
|
63
|
+
build: async (context)=>{
|
|
64
|
+
await (0, external_common_js_namespaceObject.build)(context, name);
|
|
31
65
|
},
|
|
32
|
-
|
|
33
|
-
await (0,
|
|
66
|
+
run: async (env, context)=>{
|
|
67
|
+
await (0, external_common_js_namespaceObject.run)(env, context, name, (context)=>(0, external_common_js_namespaceObject.findMultiCompilerBundle)(context, name, findBundle));
|
|
34
68
|
},
|
|
35
|
-
|
|
36
|
-
await (0,
|
|
69
|
+
check: async (env, context)=>{
|
|
70
|
+
await (0, external_common_js_namespaceObject.check)(env, context, name);
|
|
37
71
|
},
|
|
72
|
+
after: async (context)=>{
|
|
73
|
+
await (0, external_common_js_namespaceObject.afterExecute)(context, name);
|
|
74
|
+
}
|
|
38
75
|
};
|
|
39
76
|
}
|
|
40
|
-
const creator = new
|
|
77
|
+
const creator = new creator_js_namespaceObject.BasicCaseCreator({
|
|
41
78
|
clean: true,
|
|
42
79
|
describe: false,
|
|
43
|
-
testConfig: (testConfig)
|
|
80
|
+
testConfig: (testConfig)=>{
|
|
44
81
|
const oldModuleScope = testConfig.moduleScope;
|
|
45
|
-
testConfig.moduleScope = (ms, stats, compilerOptions)
|
|
82
|
+
testConfig.moduleScope = (ms, stats, compilerOptions)=>{
|
|
46
83
|
let res = ms;
|
|
47
|
-
|
|
48
|
-
if (typeof oldModuleScope === 'function') {
|
|
49
|
-
res = oldModuleScope(ms, stats, compilerOptions);
|
|
50
|
-
}
|
|
84
|
+
if ('function' == typeof oldModuleScope) res = oldModuleScope(ms, stats, compilerOptions);
|
|
51
85
|
return res;
|
|
52
86
|
};
|
|
53
87
|
},
|
|
54
|
-
steps: ({ name })
|
|
88
|
+
steps: ({ name })=>[
|
|
89
|
+
createConfigProcessor(name)
|
|
90
|
+
],
|
|
55
91
|
runner: {
|
|
56
|
-
key:
|
|
57
|
-
runner:
|
|
92
|
+
key: external_runner_js_namespaceObject.getMultiCompilerRunnerKey,
|
|
93
|
+
runner: external_runner_js_namespaceObject.createMultiCompilerRunner
|
|
58
94
|
},
|
|
59
|
-
concurrent: true
|
|
95
|
+
concurrent: true
|
|
60
96
|
});
|
|
61
97
|
function createConfigCase(name, src, dist) {
|
|
62
98
|
creator.create(name, src, dist);
|
|
@@ -71,61 +107,63 @@ function defaultOptions(index, context) {
|
|
|
71
107
|
output: {
|
|
72
108
|
path: context.getDist(),
|
|
73
109
|
bundlerInfo: {
|
|
74
|
-
force: false
|
|
75
|
-
}
|
|
110
|
+
force: false
|
|
111
|
+
}
|
|
76
112
|
},
|
|
77
113
|
optimization: {
|
|
78
|
-
minimize: false
|
|
79
|
-
}
|
|
114
|
+
minimize: false
|
|
115
|
+
}
|
|
80
116
|
};
|
|
81
117
|
}
|
|
82
118
|
function enableEsmLibraryPlugin(options) {
|
|
83
|
-
return
|
|
84
|
-
(typeof options.output?.library === 'object' &&
|
|
85
|
-
(options.output?.library).type === 'modern-module'));
|
|
119
|
+
return options.output?.library === 'modern-module' || 'object' == typeof options.output?.library && 'modern-module' === (options.output?.library).type;
|
|
86
120
|
}
|
|
87
121
|
function overrideOptions(index, context, options) {
|
|
88
|
-
if (!options.entry)
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
if (options.amd === undefined) {
|
|
92
|
-
options.amd = {};
|
|
93
|
-
}
|
|
122
|
+
if (!options.entry) options.entry = './index.js';
|
|
123
|
+
if (void 0 === options.amd) options.amd = {};
|
|
94
124
|
if (!options.output?.filename) {
|
|
95
|
-
const runtimeChunkForModernModule = options.optimization?.runtimeChunk ===
|
|
96
|
-
enableEsmLibraryPlugin(options);
|
|
125
|
+
const runtimeChunkForModernModule = options.optimization?.runtimeChunk === void 0 && enableEsmLibraryPlugin(options);
|
|
97
126
|
const outputModule = options.output?.module || enableEsmLibraryPlugin(options);
|
|
98
127
|
options.output ??= {};
|
|
99
128
|
options.output.filename = `${runtimeChunkForModernModule ? `[name]${outputModule ? '.mjs' : '.js'}` : `bundle${index}${outputModule ? '.mjs' : '.js'}`}`;
|
|
100
129
|
}
|
|
101
130
|
if (enableEsmLibraryPlugin(options)) {
|
|
102
131
|
options.optimization ??= {};
|
|
103
|
-
options.optimization.runtimeChunk ??= {
|
|
104
|
-
|
|
105
|
-
if (options.cache === undefined)
|
|
106
|
-
options.cache = false;
|
|
107
|
-
if (!global.printLogger) {
|
|
108
|
-
options.infrastructureLogging = {
|
|
109
|
-
level: 'error',
|
|
132
|
+
options.optimization.runtimeChunk ??= {
|
|
133
|
+
name: `runtime~${index}`
|
|
110
134
|
};
|
|
111
135
|
}
|
|
136
|
+
if (void 0 === options.cache) options.cache = false;
|
|
137
|
+
if (!global.printLogger) options.infrastructureLogging = {
|
|
138
|
+
level: 'error'
|
|
139
|
+
};
|
|
112
140
|
}
|
|
113
141
|
function findBundle(index, context, options) {
|
|
114
142
|
const testConfig = context.getTestConfig();
|
|
115
|
-
if (typeof testConfig.findBundle
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
const ext = node_path_1.default.extname((0, parseResource_1.parseResource)(options.output?.filename).path);
|
|
143
|
+
if ('function' == typeof testConfig.findBundle) return testConfig.findBundle(index, options);
|
|
144
|
+
const ext = external_node_path_default().extname((0, parseResource_js_namespaceObject.parseResource)(options.output?.filename).path);
|
|
119
145
|
const bundlePath = [];
|
|
120
|
-
if (options.output?.path &&
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
options.output?.cssFilename) ||
|
|
124
|
-
`bundle${index}.css`);
|
|
125
|
-
if (fs_extra_1.default.existsSync(cssOutputPath)) {
|
|
126
|
-
bundlePath.push(node_path_1.default.relative(options.output.path, cssOutputPath));
|
|
127
|
-
}
|
|
146
|
+
if (options.output?.path && external_fs_extra_default().existsSync(external_node_path_default().join(options.output.path, `bundle${index}${ext}`))) {
|
|
147
|
+
const cssOutputPath = external_node_path_default().join(options.output.path, 'string' == typeof options.output?.cssFilename && options.output?.cssFilename || `bundle${index}.css`);
|
|
148
|
+
if (external_fs_extra_default().existsSync(cssOutputPath)) bundlePath.push(external_node_path_default().relative(options.output.path, cssOutputPath));
|
|
128
149
|
bundlePath.push(`./bundle${index}${ext}`);
|
|
129
150
|
}
|
|
130
151
|
return bundlePath;
|
|
131
152
|
}
|
|
153
|
+
exports.createConfigCase = __webpack_exports__.createConfigCase;
|
|
154
|
+
exports.createConfigProcessor = __webpack_exports__.createConfigProcessor;
|
|
155
|
+
exports.defaultOptions = __webpack_exports__.defaultOptions;
|
|
156
|
+
exports.enableEsmLibraryPlugin = __webpack_exports__.enableEsmLibraryPlugin;
|
|
157
|
+
exports.findBundle = __webpack_exports__.findBundle;
|
|
158
|
+
exports.overrideOptions = __webpack_exports__.overrideOptions;
|
|
159
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
160
|
+
"createConfigCase",
|
|
161
|
+
"createConfigProcessor",
|
|
162
|
+
"defaultOptions",
|
|
163
|
+
"enableEsmLibraryPlugin",
|
|
164
|
+
"findBundle",
|
|
165
|
+
"overrideOptions"
|
|
166
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
167
|
+
Object.defineProperty(exports, '__esModule', {
|
|
168
|
+
value: true
|
|
169
|
+
});
|
package/dist/case/defaults.js
CHANGED
|
@@ -1,93 +1,146 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"@rspack/core" (module) {
|
|
4
|
+
module.exports = require("@rspack/core");
|
|
5
|
+
}
|
|
4
6
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
7
|
+
var __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.n = (module)=>{
|
|
19
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
20
|
+
__webpack_require__.d(getter, {
|
|
21
|
+
a: getter
|
|
22
|
+
});
|
|
23
|
+
return getter;
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
28
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: definition[key]
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
(()=>{
|
|
35
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
36
|
+
})();
|
|
37
|
+
(()=>{
|
|
38
|
+
__webpack_require__.r = (exports1)=>{
|
|
39
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
40
|
+
value: 'Module'
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
43
|
+
value: true
|
|
34
44
|
});
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __webpack_exports__ = {};
|
|
48
|
+
(()=>{
|
|
49
|
+
__webpack_require__.r(__webpack_exports__);
|
|
50
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
51
|
+
createDefaultsCase: ()=>createDefaultsCase,
|
|
52
|
+
getRspackDefaultConfig: ()=>getRspackDefaultConfig
|
|
35
53
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
55
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
56
|
+
const external_node_util_namespaceObject = require("node:util");
|
|
57
|
+
const external_jest_diff_namespaceObject = require("jest-diff");
|
|
58
|
+
const context_js_namespaceObject = require("../test/context.js");
|
|
59
|
+
const CURRENT_CWD = process.cwd();
|
|
60
|
+
function createDefaultsCase(name, src) {
|
|
61
|
+
const caseConfig = require(src);
|
|
62
|
+
it(`should generate the correct defaults from ${caseConfig.description}`, async ()=>{
|
|
63
|
+
await run(name, {
|
|
64
|
+
config: (context)=>{
|
|
65
|
+
const compiler = context.getCompiler();
|
|
66
|
+
compiler.setOptions(defaults_options(context, caseConfig.options));
|
|
67
|
+
},
|
|
68
|
+
compiler: (context)=>{
|
|
69
|
+
const compiler = context.getCompiler();
|
|
70
|
+
compiler.createCompiler();
|
|
71
|
+
},
|
|
72
|
+
build: async (context)=>{},
|
|
73
|
+
run: async (env, context)=>{},
|
|
74
|
+
check: async (env, context)=>{
|
|
75
|
+
await check(env, context, name, caseConfig);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
53
79
|
}
|
|
54
|
-
|
|
55
|
-
|
|
80
|
+
function getRspackDefaultConfig(cwd, config) {
|
|
81
|
+
process.chdir(cwd);
|
|
82
|
+
const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = __webpack_require__("@rspack/core").config;
|
|
83
|
+
const normalizedConfig = getNormalizedWebpackOptions(config);
|
|
84
|
+
applyWebpackOptionsDefaults(normalizedConfig);
|
|
85
|
+
normalizedConfig.output.bundlerInfo.version = '$version$';
|
|
86
|
+
process.chdir(CURRENT_CWD);
|
|
87
|
+
return normalizedConfig;
|
|
56
88
|
}
|
|
57
|
-
|
|
58
|
-
|
|
89
|
+
const srcDir = external_node_path_default().resolve(__dirname, '../../tests/fixtures');
|
|
90
|
+
const distDir = external_node_path_default().resolve(__dirname, '../../tests/js/defaults');
|
|
91
|
+
function defaults_options(context, custom) {
|
|
92
|
+
let res;
|
|
93
|
+
res = 'function' == typeof custom ? custom(context) : {};
|
|
94
|
+
if (!('mode' in res)) res.mode = 'none';
|
|
95
|
+
return res;
|
|
59
96
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
97
|
+
class RspackTestDiff {
|
|
98
|
+
value;
|
|
99
|
+
constructor(value){
|
|
100
|
+
this.value = value;
|
|
101
|
+
}
|
|
65
102
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const context = new context_1.TestContext({
|
|
78
|
-
name: name,
|
|
79
|
-
src: srcDir,
|
|
80
|
-
dist: distDir,
|
|
81
|
-
});
|
|
82
|
-
try {
|
|
83
|
-
await processor.before?.(context);
|
|
84
|
-
await processor.config?.(context);
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
context.emitError(e);
|
|
103
|
+
async function check(env, context, name, options) {
|
|
104
|
+
const compiler = context.getCompiler();
|
|
105
|
+
const config = getRspackDefaultConfig(options.cwd || CURRENT_CWD, compiler.getOptions());
|
|
106
|
+
const defaultConfig = getRspackDefaultConfig(options.cwd || CURRENT_CWD, {
|
|
107
|
+
mode: 'none'
|
|
108
|
+
});
|
|
109
|
+
const diff = (0, external_node_util_namespaceObject.stripVTControlCharacters)((0, external_jest_diff_namespaceObject.diff)(defaultConfig, config, {
|
|
110
|
+
expand: false,
|
|
111
|
+
contextLines: 0
|
|
112
|
+
}));
|
|
113
|
+
await options.diff(env.expect(new RspackTestDiff(diff)), env.expect(defaultConfig));
|
|
88
114
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
115
|
+
async function run(name, processor) {
|
|
116
|
+
const context = new context_js_namespaceObject.TestContext({
|
|
117
|
+
name: name,
|
|
118
|
+
src: srcDir,
|
|
119
|
+
dist: distDir
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
await processor.before?.(context);
|
|
123
|
+
await processor.config?.(context);
|
|
124
|
+
} catch (e) {
|
|
125
|
+
context.emitError(e);
|
|
126
|
+
} finally{
|
|
127
|
+
await processor.check?.({
|
|
128
|
+
expect,
|
|
129
|
+
it,
|
|
130
|
+
beforeEach,
|
|
131
|
+
afterEach,
|
|
132
|
+
rstest
|
|
133
|
+
}, context);
|
|
134
|
+
await processor.after?.(context);
|
|
135
|
+
}
|
|
92
136
|
}
|
|
93
|
-
}
|
|
137
|
+
})();
|
|
138
|
+
exports.createDefaultsCase = __webpack_exports__.createDefaultsCase;
|
|
139
|
+
exports.getRspackDefaultConfig = __webpack_exports__.getRspackDefaultConfig;
|
|
140
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
141
|
+
"createDefaultsCase",
|
|
142
|
+
"getRspackDefaultConfig"
|
|
143
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
144
|
+
Object.defineProperty(exports, '__esModule', {
|
|
145
|
+
value: true
|
|
146
|
+
});
|