@rspack/test-tools 2.0.2 → 2.0.4

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.
Files changed (118) hide show
  1. package/dist/case/builtin.js +106 -66
  2. package/dist/case/cache.js +136 -122
  3. package/dist/case/common.d.ts +4 -4
  4. package/dist/case/common.js +162 -157
  5. package/dist/case/compiler.d.ts +4 -4
  6. package/dist/case/compiler.js +75 -64
  7. package/dist/case/config.js +112 -74
  8. package/dist/case/defaults.js +136 -83
  9. package/dist/case/diagnostic.js +112 -84
  10. package/dist/case/error.d.ts +4 -4
  11. package/dist/case/error.js +105 -89
  12. package/dist/case/esm-output.js +118 -87
  13. package/dist/case/example.js +73 -35
  14. package/dist/case/hash.js +74 -59
  15. package/dist/case/hook.js +151 -138
  16. package/dist/case/hot-step.js +130 -161
  17. package/dist/case/hot.js +148 -134
  18. package/dist/case/incremental.js +91 -58
  19. package/dist/case/index.js +134 -51
  20. package/dist/case/multi-compiler.d.ts +4 -4
  21. package/dist/case/multi-compiler.js +81 -56
  22. package/dist/case/native-watcher.js +62 -30
  23. package/dist/case/normal.js +253 -185
  24. package/dist/case/runner.js +80 -51
  25. package/dist/case/serial.js +47 -16
  26. package/dist/case/stats-api.d.ts +4 -4
  27. package/dist/case/stats-api.js +63 -43
  28. package/dist/case/stats-output.d.ts +3 -3
  29. package/dist/case/stats-output.js +147 -152
  30. package/dist/case/treeshaking.js +66 -35
  31. package/dist/case/watch.d.ts +3 -19
  32. package/dist/case/watch.js +204 -224
  33. package/dist/compiler.js +222 -195
  34. package/dist/helper/directory.js +83 -71
  35. package/dist/helper/disable-iconv-lite-warning.js +35 -9
  36. package/dist/helper/expect/diff.js +39 -10
  37. package/dist/helper/expect/error.js +62 -30
  38. package/dist/helper/expect/placeholder.js +47 -21
  39. package/dist/helper/expect/rspack.js +35 -13
  40. package/dist/helper/expect/to-be-typeof.js +39 -7
  41. package/dist/helper/expect/to-end-with.js +40 -8
  42. package/dist/helper/expect/to-match-file-snapshot.js +103 -80
  43. package/dist/helper/hot-update/index.js +35 -4
  44. package/dist/helper/hot-update/loader.d.ts +1 -0
  45. package/dist/helper/hot-update/loader.js +39 -4
  46. package/dist/helper/hot-update/plugin.d.ts +1 -1
  47. package/dist/helper/hot-update/plugin.js +87 -74
  48. package/dist/helper/index.js +138 -24
  49. package/dist/helper/is.js +51 -10
  50. package/dist/helper/legacy/EventSourceForNode.d.ts +11 -3
  51. package/dist/helper/legacy/EventSourceForNode.js +83 -37
  52. package/dist/helper/legacy/LogTestPlugin.d.ts +2 -3
  53. package/dist/helper/legacy/LogTestPlugin.js +39 -6
  54. package/dist/helper/legacy/asModule.d.ts +3 -3
  55. package/dist/helper/legacy/asModule.js +68 -19
  56. package/dist/helper/legacy/captureStdio.d.ts +1 -2
  57. package/dist/helper/legacy/captureStdio.js +69 -29
  58. package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -2
  59. package/dist/helper/legacy/checkArrayExpectation.js +132 -121
  60. package/dist/helper/legacy/copyDiff.d.ts +1 -2
  61. package/dist/helper/legacy/copyDiff.js +86 -42
  62. package/dist/helper/legacy/createFakeWorker.d.ts +2 -3
  63. package/dist/helper/legacy/createFakeWorker.js +90 -47
  64. package/dist/helper/legacy/createLazyTestEnv.d.ts +2 -3
  65. package/dist/helper/legacy/createLazyTestEnv.js +70 -59
  66. package/dist/helper/legacy/currentScript.d.ts +2 -2
  67. package/dist/helper/legacy/currentScript.js +35 -2
  68. package/dist/helper/legacy/deprecationTracking.d.ts +1 -1
  69. package/dist/helper/legacy/deprecationTracking.js +53 -28
  70. package/dist/helper/legacy/expectSource.d.ts +3 -2
  71. package/dist/helper/legacy/expectSource.js +42 -18
  72. package/dist/helper/legacy/fakeSystem.d.ts +12 -9
  73. package/dist/helper/legacy/fakeSystem.js +68 -58
  74. package/dist/helper/legacy/findOutputFiles.d.ts +7 -2
  75. package/dist/helper/legacy/findOutputFiles.js +60 -13
  76. package/dist/helper/legacy/parseResource.d.ts +1 -1
  77. package/dist/helper/legacy/parseResource.js +36 -6
  78. package/dist/helper/legacy/regexEscape.d.ts +1 -2
  79. package/dist/helper/legacy/regexEscape.js +39 -5
  80. package/dist/helper/legacy/supportDefaultAssignment.d.ts +1 -2
  81. package/dist/helper/legacy/supportDefaultAssignment.js +40 -7
  82. package/dist/helper/legacy/supportsTextDecoder.d.ts +1 -2
  83. package/dist/helper/legacy/supportsTextDecoder.js +40 -6
  84. package/dist/helper/legacy/supportsUsing.d.ts +1 -2
  85. package/dist/helper/legacy/supportsUsing.js +40 -7
  86. package/dist/helper/legacy/urlToRelativePath.d.ts +2 -2
  87. package/dist/helper/legacy/urlToRelativePath.js +56 -7
  88. package/dist/helper/parse-modules.js +52 -42
  89. package/dist/helper/read-config-file.js +60 -18
  90. package/dist/helper/serializers.js +62 -33
  91. package/dist/helper/setup-env.js +81 -91
  92. package/dist/helper/setup-expect.js +13 -13
  93. package/dist/helper/setup-wasm.js +18 -9
  94. package/dist/helper/stringify-config.js +44 -26
  95. package/dist/helper/update-snapshot.js +35 -3
  96. package/dist/helper/util/checkSourceMap.js +119 -80
  97. package/dist/helper/util/checkStats.d.ts +1 -1
  98. package/dist/helper/util/checkStats.js +42 -17
  99. package/dist/helper/util/expectWarningFactory.d.ts +1 -2
  100. package/dist/helper/util/expectWarningFactory.js +41 -8
  101. package/dist/helper/util/filterUtil.d.ts +9 -8
  102. package/dist/helper/util/filterUtil.js +63 -23
  103. package/dist/helper/win.js +46 -7
  104. package/dist/index.js +115 -23
  105. package/dist/plugin/index.js +55 -14
  106. package/dist/plugin/lazy-compilation-test-plugin.js +55 -41
  107. package/dist/reporter/index.js +55 -14
  108. package/dist/reporter/streamed-events-reporter.js +51 -77
  109. package/dist/runner/index.js +62 -15
  110. package/dist/runner/node/index.js +365 -431
  111. package/dist/runner/web/index.js +278 -263
  112. package/dist/test/context.js +67 -41
  113. package/dist/test/creator.js +135 -167
  114. package/dist/test/debug.js +89 -58
  115. package/dist/test/tester.js +94 -74
  116. package/dist/type.d.ts +10 -9
  117. package/dist/type.js +43 -9
  118. package/package.json +21 -20
@@ -1,34 +1,68 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.config = config;
7
- exports.compiler = compiler;
8
- exports.build = build;
9
- exports.run = run;
10
- exports.check = check;
11
- exports.checkSnapshot = checkSnapshot;
12
- exports.afterExecute = afterExecute;
13
- exports.findMultiCompilerBundle = findMultiCompilerBundle;
14
- exports.configMultiCompiler = configMultiCompiler;
15
- const node_path_1 = __importDefault(require("node:path"));
16
- const fs_extra_1 = __importDefault(require("fs-extra"));
17
- const rspack_merge_1 = __importDefault(require("rspack-merge"));
18
- const helper_1 = require("../helper");
19
- const placeholder_1 = require("../helper/expect/placeholder");
20
- const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
21
- const debug_1 = require("../test/debug");
22
- async function config(context, name, configFiles, defaultOptions = {}) {
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, helper_1.readConfigFile)(configFiles.map((i) => context.getSource(i)), context, defaultOptions)[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
- async function compiler(context, name) {
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 === 'function') {
47
- testConfig.beforeExecute(compiler.getOptions());
48
- }
79
+ if ('function' == typeof testConfig.beforeExecute) testConfig.beforeExecute(compiler.getOptions());
49
80
  let bundles;
50
- if (typeof findBundle === 'function') {
51
- bundles = findBundle(context, compiler.getOptions());
52
- }
53
- else {
54
- bundles = [];
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(debug_1.DEBUG_SCOPES.RunLogs, []);
67
- context.setValue(debug_1.DEBUG_SCOPES.RunErrors, []);
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(debug_1.DEBUG_SCOPES.RunLogs);
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
- message: e.message,
93
- stack: e.stack,
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
- fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(), 'stats.txt'), stats.toString({
101
- preset: 'verbose',
102
- colors: false,
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
- fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(), 'stats.json'), JSON.stringify(jsonStats, null, 2), 'utf-8');
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 (fs_extra_1.default.existsSync(context.getSource('errors.js')) ||
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
- errors.push(...statsJson.errors);
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, checkArrayExpectation_1.default)(context.getSource(), { errors }, 'error', 'errors', 'Error', options);
137
- await (0, checkArrayExpectation_1.default)(context.getSource(), { warnings }, 'warning', 'warnings', 'Warning', options);
138
- // clear error if checked
139
- if (fs_extra_1.default.existsSync(context.getSource('errors.js'))) {
140
- context.clearError();
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
- async function checkSnapshot(env, context, name, snapshot, filter) {
144
- if (node_path_1.default.extname(snapshot) === '.snap') {
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
- return;
152
- const compilers = 'compilers' in compiler
153
- ? compiler.compilers
154
- : [compiler];
155
- const totalStats = 'stats' in stats ? stats.stats : [stats];
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 (let i = 0; i < compilers.length; i++) {
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
- c._lastCompilation;
169
- const snapshotFileFilter = filter ||
170
- ((file) => (file.endsWith('.js') || file.endsWith('.mjs')) &&
171
- !file.includes('runtime.js'));
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
- content = testConfig.snapshotContent(content);
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 = node_path_1.default.isAbsolute(snapshot)
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
- async function afterExecute(context, name) {
191
+ function afterExecute(context, name) {
193
192
  const compiler = context.getCompiler();
194
193
  const testConfig = context.getTestConfig();
195
- if (typeof testConfig.afterExecute === 'function') {
194
+ if ('function' == typeof testConfig.afterExecute) {
196
195
  let options = compiler.getOptions();
197
- if (Array.isArray(options) && options.length === 1) {
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 !== 'function') {
205
- return [];
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
- ? curBundles
215
- : curBundles
216
- ? [curBundles]
217
- : [];
218
- for (const bundle of bundles) {
219
- if (multiFileIndexMap[bundle]) {
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
- ? (0, helper_1.readConfigFile)(configFiles.map((i) => context.getSource(i)), context, {}, (configs) => {
235
- return configs.flatMap((c) => {
236
- if (typeof c === 'function') {
237
- const options = {
238
- testPath: context.getDist(),
239
- env: undefined,
240
- };
241
- return c(options.env, options);
242
- }
243
- return c;
244
- });
245
- })
246
- : [{}];
247
- for (const [index, options] of caseOptions.entries()) {
248
- const compilerOptions = (0, rspack_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
+ });
@@ -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) => Promise<void>;
10
- build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
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
- }) => Promise<void>;
17
+ }) => MaybePromise<void>;
18
18
  compilerCallback?: (error: Error | null, stats: Stats | null) => void;
19
19
  };
@@ -1,15 +1,40 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCompilerCase = createCompilerCase;
4
- const creator_1 = require("../test/creator");
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ createCompilerCase: ()=>createCompilerCase
28
+ });
29
+ const creator_js_namespaceObject = require("../test/creator.js");
5
30
  function createCompilerProcessor(name, caseConfig) {
6
31
  const logs = {
7
32
  mkdir: [],
8
- writeFile: [],
33
+ writeFile: []
9
34
  };
10
35
  const files = {};
11
36
  return {
12
- config: async (context) => {
37
+ config: (context)=>{
13
38
  const compiler = context.getCompiler();
14
39
  const options = caseConfig.options?.(context) || {};
15
40
  options.mode ??= 'production';
@@ -22,65 +47,48 @@ function createCompilerProcessor(name, caseConfig) {
22
47
  options.optimization.minimize ??= false;
23
48
  compiler.setOptions(options);
24
49
  },
25
- compiler: async (context) => {
50
+ compiler: async (context)=>{
26
51
  const compiler = context.getCompiler();
27
- if (caseConfig.compilerCallback) {
28
- compiler.createCompilerWithCallback(caseConfig.compilerCallback);
29
- }
30
- else {
31
- compiler.createCompiler();
32
- }
52
+ if (caseConfig.compilerCallback) compiler.createCompilerWithCallback(caseConfig.compilerCallback);
53
+ else compiler.createCompiler();
33
54
  const c = compiler.getCompiler();
34
55
  c.outputFileSystem = {
35
- // CHANGE: Added support for the `options` parameter to enable recursive directory creation,
36
- // accommodating Rspack's requirement that differs from webpack's usage
37
- mkdir(path, callback) {
56
+ mkdir (path, callback) {
38
57
  const recursive = false;
39
- // if (typeof options === "function") {
40
- // callback = options;
41
- // } else if (options) {
42
- // if (options.recursive !== undefined) recursive = options.recursive;
43
- // }
44
58
  logs.mkdir.push(path);
45
- if (recursive) {
46
- callback();
47
- }
59
+ if (recursive) callback();
48
60
  else {
49
61
  const err = new Error();
50
62
  err.code = 'EEXIST';
51
63
  callback(err);
52
64
  }
53
65
  },
54
- writeFile(name, content, callback) {
66
+ writeFile (name, content, callback) {
55
67
  logs.writeFile.push(name, content);
56
68
  files[name] = content.toString('utf-8');
57
69
  callback();
58
70
  },
59
- stat(path, callback) {
71
+ stat (path, callback) {
60
72
  callback(new Error('ENOENT'));
61
- },
73
+ }
62
74
  };
63
- c.hooks.compilation.tap('CompilerTest', (compilation) => (compilation.bail = true));
75
+ c.hooks.compilation.tap('CompilerTest', (compilation)=>compilation.bail = true);
64
76
  await caseConfig.compiler?.(context, c);
65
77
  },
66
- build: async (context) => {
78
+ build: async (context)=>{
67
79
  const compiler = context.getCompiler();
68
- if (typeof caseConfig.build === 'function') {
69
- await caseConfig.build?.(context, compiler.getCompiler());
70
- }
71
- else {
72
- await compiler.build();
73
- }
80
+ if ('function' == typeof caseConfig.build) await caseConfig.build?.(context, compiler.getCompiler());
81
+ else await compiler.build();
74
82
  },
75
- run: async (env, context) => { },
76
- check: async (env, context) => {
83
+ run: async (env, context)=>{},
84
+ check: async (env, context)=>{
77
85
  const compiler = context.getCompiler();
78
86
  const c = compiler.getCompiler();
79
87
  const stats = compiler.getStats();
80
88
  if (caseConfig.error) {
81
89
  const statsJson = stats?.toJson({
82
90
  modules: true,
83
- reasons: true,
91
+ reasons: true
84
92
  });
85
93
  const compilation = stats?.compilation;
86
94
  await caseConfig.check?.({
@@ -88,10 +96,9 @@ function createCompilerProcessor(name, caseConfig) {
88
96
  compiler: c,
89
97
  stats: statsJson,
90
98
  compilation,
91
- files,
99
+ files
92
100
  });
93
- }
94
- else if (stats) {
101
+ } else if (stats) {
95
102
  expect(typeof stats).toBe('object');
96
103
  const compilation = stats.compilation;
97
104
  const statsJson = stats.toJson({
@@ -101,7 +108,7 @@ function createCompilerProcessor(name, caseConfig) {
101
108
  modules: true,
102
109
  entrypoints: true,
103
110
  chunkGroups: true,
104
- reasons: true,
111
+ reasons: true
105
112
  });
106
113
  expect(typeof statsJson).toBe('object');
107
114
  expect(statsJson).toHaveProperty('errors');
@@ -116,44 +123,48 @@ function createCompilerProcessor(name, caseConfig) {
116
123
  stats: statsJson,
117
124
  files,
118
125
  compiler: c,
119
- compilation,
120
- });
121
- }
122
- else {
123
- await caseConfig.check?.({
124
- context,
125
- files,
126
- compiler: c,
126
+ compilation
127
127
  });
128
- }
128
+ } else await caseConfig.check?.({
129
+ context,
130
+ files,
131
+ compiler: c
132
+ });
129
133
  },
130
- after: async (context) => {
134
+ after: async (context)=>{
131
135
  await context.closeCompiler();
132
- },
136
+ }
133
137
  };
134
138
  }
135
- const creator = new creator_1.BasicCaseCreator({
139
+ const creator = new creator_js_namespaceObject.BasicCaseCreator({
136
140
  clean: true,
137
141
  describe: false,
138
- steps: ({ name, caseConfig }) => {
139
- return [createCompilerProcessor(name, caseConfig)];
140
- },
141
- concurrent: false,
142
+ steps: ({ name, caseConfig })=>[
143
+ createCompilerProcessor(name, caseConfig)
144
+ ],
145
+ concurrent: false
142
146
  });
143
147
  function createCompilerCase(name, src, dist, testConfig) {
144
148
  let caseConfigList = require(testConfig);
145
- if (!Array.isArray(caseConfigList)) {
146
- caseConfigList = [caseConfigList];
147
- }
148
- for (let i = 0; i < caseConfigList.length; i++) {
149
+ if (!Array.isArray(caseConfigList)) caseConfigList = [
150
+ caseConfigList
151
+ ];
152
+ for(let i = 0; i < caseConfigList.length; i++){
149
153
  const caseConfig = caseConfigList[i];
150
154
  if (caseConfig.skip) {
151
- it.skip(`${name}[${i}]`, () => { });
155
+ it.skip(`${name}[${i}]`, ()=>{});
152
156
  continue;
153
157
  }
154
- creator.create(`${name}[${i}]`, src, dist, undefined, {
158
+ creator.create(`${name}[${i}]`, src, dist, void 0, {
155
159
  caseConfig,
156
- description: () => caseConfig.description,
160
+ description: ()=>caseConfig.description
157
161
  });
158
162
  }
159
163
  }
164
+ exports.createCompilerCase = __webpack_exports__.createCompilerCase;
165
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
166
+ "createCompilerCase"
167
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
168
+ Object.defineProperty(exports, '__esModule', {
169
+ value: true
170
+ });