@rspack-debug/test-tools 1.4.11 → 1.6.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 (259) hide show
  1. package/README.md +1 -1
  2. package/dist/case/builtin.d.ts +3 -0
  3. package/dist/case/builtin.js +152 -14
  4. package/dist/case/cache.d.ts +2 -2
  5. package/dist/case/cache.js +214 -12
  6. package/dist/case/common.d.ts +11 -0
  7. package/dist/case/common.js +249 -0
  8. package/dist/case/compiler.d.ts +17 -4
  9. package/dist/case/compiler.js +149 -12
  10. package/dist/case/config.d.ts +7 -2
  11. package/dist/case/config.js +106 -18
  12. package/dist/case/defaults.d.ts +13 -4
  13. package/dist/case/defaults.js +73 -18
  14. package/dist/case/diagnostic.d.ts +6 -0
  15. package/dist/case/diagnostic.js +121 -14
  16. package/dist/case/error.d.ts +15 -4
  17. package/dist/case/error.js +137 -12
  18. package/dist/case/esm-output.d.ts +1 -0
  19. package/dist/case/esm-output.js +117 -0
  20. package/dist/case/example.d.ts +1 -0
  21. package/dist/case/example.js +57 -0
  22. package/dist/case/hash.d.ts +2 -2
  23. package/dist/case/hash.js +72 -9
  24. package/dist/case/hook.d.ts +36 -4
  25. package/dist/case/hook.js +209 -20
  26. package/dist/case/hot-step.d.ts +2 -2
  27. package/dist/case/hot-step.js +309 -13
  28. package/dist/case/hot.d.ts +11 -2
  29. package/dist/case/hot.js +217 -12
  30. package/dist/case/incremental.d.ts +2 -2
  31. package/dist/case/incremental.js +24 -45
  32. package/dist/case/index.d.ts +31 -20
  33. package/dist/case/index.js +50 -34
  34. package/dist/case/multi-compiler.d.ts +19 -0
  35. package/dist/case/multi-compiler.js +97 -0
  36. package/dist/case/{nativeWatcher.js → native-watcher.js} +11 -23
  37. package/dist/case/normal.d.ts +3 -0
  38. package/dist/case/normal.js +202 -18
  39. package/dist/case/runner.d.ts +19 -0
  40. package/dist/case/runner.js +113 -0
  41. package/dist/case/serial.d.ts +2 -2
  42. package/dist/case/serial.js +10 -14
  43. package/dist/case/stats-api.d.ts +8 -3
  44. package/dist/case/stats-api.js +69 -10
  45. package/dist/case/stats-output.d.ts +11 -0
  46. package/dist/case/stats-output.js +199 -8
  47. package/dist/case/treeshaking.js +34 -7
  48. package/dist/case/watch.d.ts +27 -0
  49. package/dist/case/watch.js +318 -22
  50. package/dist/compiler.d.ts +16 -16
  51. package/dist/compiler.js +120 -15
  52. package/dist/helper/directory.d.ts +1 -1
  53. package/dist/helper/directory.js +6 -2
  54. package/dist/helper/disable-iconv-lite-warning.d.ts +1 -0
  55. package/dist/helper/disable-iconv-lite-warning.js +12 -0
  56. package/dist/helper/expect/error.js +1 -1
  57. package/dist/helper/expect/placeholder.js +7 -7
  58. package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
  59. package/dist/helper/expect/to-match-file-snapshot.js +3 -3
  60. package/dist/helper/hot-update/loader.d.ts +2 -1
  61. package/dist/helper/hot-update/loader.js +5 -30
  62. package/dist/helper/hot-update/plugin.d.ts +1 -1
  63. package/dist/helper/hot-update/plugin.js +14 -13
  64. package/dist/helper/index.d.ts +2 -1
  65. package/dist/helper/index.js +2 -1
  66. package/dist/helper/is.d.ts +2 -0
  67. package/dist/helper/is.js +15 -0
  68. package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
  69. package/dist/helper/legacy/LogTestPlugin.js +35 -0
  70. package/dist/helper/legacy/asModule.js +0 -2
  71. package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
  72. package/dist/helper/legacy/checkArrayExpectation.js +8 -8
  73. package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
  74. package/dist/helper/legacy/createFakeWorker.js +44 -20
  75. package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
  76. package/dist/helper/legacy/createLazyTestEnv.js +3 -3
  77. package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
  78. package/dist/helper/legacy/deprecationTracking.js +41 -0
  79. package/dist/helper/legacy/expectSource.d.ts +10 -0
  80. package/dist/helper/legacy/expectSource.js +23 -0
  81. package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
  82. package/dist/helper/legacy/findOutputFiles.js +14 -0
  83. package/dist/helper/legacy/regexEscape.d.ts +2 -0
  84. package/dist/helper/legacy/regexEscape.js +5 -0
  85. package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
  86. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  87. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  88. package/dist/helper/legacy/supportsUsing.d.ts +2 -0
  89. package/dist/helper/legacy/supportsUsing.js +26 -0
  90. package/dist/helper/legacy/urlToRelativePath.js +5 -2
  91. package/dist/helper/read-config-file.d.ts +3 -2
  92. package/dist/helper/read-config-file.js +12 -2
  93. package/dist/helper/setup-env.js +26 -4
  94. package/dist/helper/setup-expect.js +2 -2
  95. package/dist/helper/setup-wasm.js +2 -2
  96. package/dist/helper/stringify-config.d.ts +2 -0
  97. package/dist/helper/stringify-config.js +43 -0
  98. package/dist/helper/util/checkStats.d.ts +0 -1
  99. package/dist/helper/util/checkStats.js +0 -18
  100. package/dist/helper/util/expectWarningFactory.js +2 -4
  101. package/dist/index.d.ts +0 -4
  102. package/dist/index.js +1 -4
  103. package/dist/plugin/index.d.ts +0 -3
  104. package/dist/plugin/index.js +0 -3
  105. package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
  106. package/dist/runner/index.d.ts +2 -9
  107. package/dist/runner/index.js +2 -9
  108. package/dist/runner/node/index.d.ts +41 -0
  109. package/dist/runner/node/index.js +450 -0
  110. package/dist/runner/web/index.d.ts +30 -0
  111. package/dist/runner/web/index.js +343 -0
  112. package/dist/test/context.d.ts +15 -18
  113. package/dist/test/context.js +52 -57
  114. package/dist/test/creator.d.ts +20 -19
  115. package/dist/test/creator.js +69 -57
  116. package/dist/test/debug.d.ts +15 -0
  117. package/dist/test/debug.js +205 -0
  118. package/dist/test/tester.d.ts +1 -0
  119. package/dist/test/tester.js +44 -6
  120. package/dist/type.d.ts +94 -64
  121. package/dist/type.js +8 -12
  122. package/package.json +22 -61
  123. package/rstest.d.ts +24 -0
  124. package/dist/case/diff.d.ts +0 -3
  125. package/dist/case/diff.js +0 -126
  126. package/dist/compare/comparator.d.ts +0 -17
  127. package/dist/compare/comparator.js +0 -52
  128. package/dist/compare/compare.d.ts +0 -17
  129. package/dist/compare/compare.js +0 -175
  130. package/dist/compare/format-code.d.ts +0 -16
  131. package/dist/compare/format-code.js +0 -239
  132. package/dist/compare/index.d.ts +0 -5
  133. package/dist/compare/index.js +0 -21
  134. package/dist/compare/replace-module-argument.d.ts +0 -1
  135. package/dist/compare/replace-module-argument.js +0 -8
  136. package/dist/compare/replace-runtime-module-name.d.ts +0 -1
  137. package/dist/compare/replace-runtime-module-name.js +0 -71
  138. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  139. package/dist/helper/legacy/FakeDocument.js +0 -278
  140. package/dist/helper/legacy/createLogger.d.ts +0 -23
  141. package/dist/helper/legacy/createLogger.js +0 -20
  142. package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
  143. package/dist/helper/legacy/supportsImportFn.js +0 -15
  144. package/dist/helper/legacy/supportsWorker.js +0 -17
  145. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  146. package/dist/helper/legacy/walkCssTokens.js +0 -761
  147. package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
  148. package/dist/helper/legacy/warmup-webpack.js +0 -26
  149. package/dist/helper/loaders/hot-update.d.ts +0 -1
  150. package/dist/helper/loaders/hot-update.js +0 -40
  151. package/dist/helper/plugins/hot-update.d.ts +0 -7
  152. package/dist/helper/plugins/hot-update.js +0 -40
  153. package/dist/helper/plugins/index.d.ts +0 -1
  154. package/dist/helper/plugins/index.js +0 -17
  155. package/dist/helper/util/currentWatchStep.d.ts +0 -1
  156. package/dist/helper/util/currentWatchStep.js +0 -2
  157. package/dist/helper/util/identifier.d.ts +0 -76
  158. package/dist/helper/util/identifier.js +0 -339
  159. package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
  160. package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
  161. package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
  162. package/dist/plugin/rspack-diff-config-plugin.js +0 -42
  163. package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
  164. package/dist/plugin/webpack-diff-config-plugin.js +0 -41
  165. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
  166. package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
  167. package/dist/processor/basic.d.ts +0 -24
  168. package/dist/processor/basic.js +0 -146
  169. package/dist/processor/builtin.d.ts +0 -9
  170. package/dist/processor/builtin.js +0 -171
  171. package/dist/processor/cache.d.ts +0 -20
  172. package/dist/processor/cache.js +0 -128
  173. package/dist/processor/config.d.ts +0 -11
  174. package/dist/processor/config.js +0 -81
  175. package/dist/processor/defaults.d.ts +0 -30
  176. package/dist/processor/defaults.js +0 -72
  177. package/dist/processor/diagnostic.d.ts +0 -15
  178. package/dist/processor/diagnostic.js +0 -102
  179. package/dist/processor/diff.d.ts +0 -30
  180. package/dist/processor/diff.js +0 -140
  181. package/dist/processor/error.d.ts +0 -23
  182. package/dist/processor/error.js +0 -95
  183. package/dist/processor/hash.d.ts +0 -10
  184. package/dist/processor/hash.js +0 -63
  185. package/dist/processor/hook.d.ts +0 -44
  186. package/dist/processor/hook.js +0 -204
  187. package/dist/processor/hot-incremental.d.ts +0 -14
  188. package/dist/processor/hot-incremental.js +0 -43
  189. package/dist/processor/hot-step.d.ts +0 -18
  190. package/dist/processor/hot-step.js +0 -304
  191. package/dist/processor/hot.d.ts +0 -17
  192. package/dist/processor/hot.js +0 -140
  193. package/dist/processor/index.d.ts +0 -20
  194. package/dist/processor/index.js +0 -36
  195. package/dist/processor/multi.d.ts +0 -17
  196. package/dist/processor/multi.js +0 -73
  197. package/dist/processor/normal.d.ts +0 -12
  198. package/dist/processor/normal.js +0 -150
  199. package/dist/processor/simple.d.ts +0 -23
  200. package/dist/processor/simple.js +0 -49
  201. package/dist/processor/snapshot.d.ts +0 -12
  202. package/dist/processor/snapshot.js +0 -66
  203. package/dist/processor/stats-api.d.ts +0 -18
  204. package/dist/processor/stats-api.js +0 -48
  205. package/dist/processor/stats.d.ts +0 -18
  206. package/dist/processor/stats.js +0 -206
  207. package/dist/processor/treeshaking.d.ts +0 -10
  208. package/dist/processor/treeshaking.js +0 -33
  209. package/dist/processor/watch.d.ts +0 -30
  210. package/dist/processor/watch.js +0 -241
  211. package/dist/reporter/diff-html.d.ts +0 -15
  212. package/dist/reporter/diff-html.js +0 -69
  213. package/dist/reporter/diff-stats.d.ts +0 -24
  214. package/dist/reporter/diff-stats.js +0 -131
  215. package/dist/reporter/index.d.ts +0 -2
  216. package/dist/reporter/index.js +0 -18
  217. package/dist/runner/basic.d.ts +0 -10
  218. package/dist/runner/basic.js +0 -63
  219. package/dist/runner/cache.d.ts +0 -5
  220. package/dist/runner/cache.js +0 -90
  221. package/dist/runner/hot-step.d.ts +0 -5
  222. package/dist/runner/hot-step.js +0 -87
  223. package/dist/runner/hot.d.ts +0 -5
  224. package/dist/runner/hot.js +0 -83
  225. package/dist/runner/multiple.d.ts +0 -11
  226. package/dist/runner/multiple.js +0 -38
  227. package/dist/runner/normal.d.ts +0 -5
  228. package/dist/runner/normal.js +0 -20
  229. package/dist/runner/runner/basic.d.ts +0 -30
  230. package/dist/runner/runner/basic.js +0 -107
  231. package/dist/runner/runner/cjs.d.ts +0 -14
  232. package/dist/runner/runner/cjs.js +0 -151
  233. package/dist/runner/runner/esm.d.ts +0 -7
  234. package/dist/runner/runner/esm.js +0 -125
  235. package/dist/runner/runner/index.d.ts +0 -8
  236. package/dist/runner/runner/index.js +0 -24
  237. package/dist/runner/runner/normal.d.ts +0 -9
  238. package/dist/runner/runner/normal.js +0 -23
  239. package/dist/runner/runner/watch.d.ts +0 -16
  240. package/dist/runner/runner/watch.js +0 -27
  241. package/dist/runner/runner/web/fake.d.ts +0 -18
  242. package/dist/runner/runner/web/fake.js +0 -143
  243. package/dist/runner/runner/web/jsdom.d.ts +0 -26
  244. package/dist/runner/runner/web/jsdom.js +0 -219
  245. package/dist/runner/runner/web.d.ts +0 -15
  246. package/dist/runner/runner/web.js +0 -32
  247. package/dist/runner/type.d.ts +0 -42
  248. package/dist/runner/type.js +0 -9
  249. package/dist/runner/watch.d.ts +0 -7
  250. package/dist/runner/watch.js +0 -60
  251. package/dist/test/simple.d.ts +0 -5
  252. package/dist/test/simple.js +0 -43
  253. package/jest.d.ts +0 -25
  254. package/template/diff.bundle.css +0 -1
  255. package/template/diff.bundle.js +0 -144
  256. package/template/diff.html +0 -14
  257. package/template/editor.worker.js +0 -1
  258. /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
  259. /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
@@ -0,0 +1,249 @@
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 fs_extra_1 = __importDefault(require("fs-extra"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const webpack_merge_1 = __importDefault(require("webpack-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 = {}) {
23
+ const compiler = context.getCompiler();
24
+ compiler.setOptions(defaultOptions);
25
+ if (Array.isArray(configFiles)) {
26
+ const fileOptions = (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), context, defaultOptions)[0];
27
+ compiler.mergeOptions(fileOptions);
28
+ }
29
+ return compiler.getOptions();
30
+ }
31
+ async function compiler(context, name) {
32
+ const compiler = context.getCompiler();
33
+ compiler.createCompiler();
34
+ return compiler.getCompiler();
35
+ }
36
+ async function build(context, name) {
37
+ const compiler = context.getCompiler();
38
+ await compiler.build();
39
+ return compiler.getCompiler();
40
+ }
41
+ async function run(env, context, name, findBundle) {
42
+ const testConfig = context.getTestConfig();
43
+ if (testConfig.noTests)
44
+ return;
45
+ const compiler = context.getCompiler();
46
+ if (typeof testConfig.beforeExecute === "function") {
47
+ testConfig.beforeExecute(compiler.getOptions());
48
+ }
49
+ 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
+ }
65
+ if (__DEBUG__) {
66
+ context.setValue(debug_1.DEBUG_SCOPES.RunLogs, []);
67
+ context.setValue(debug_1.DEBUG_SCOPES.RunErrors, []);
68
+ }
69
+ for (const bundle of bundles) {
70
+ if (!bundle) {
71
+ continue;
72
+ }
73
+ const runner = context.getRunner(bundle, env);
74
+ if (__DEBUG__) {
75
+ const runLogs = context.getValue(debug_1.DEBUG_SCOPES.RunLogs);
76
+ runLogs?.push(`Start running entry: ${bundle} in ${runner.constructor.name}(${runner.__key__})`);
77
+ }
78
+ const mod = runner.run(bundle);
79
+ const result = context.getValue("modules") || [];
80
+ result.push(mod);
81
+ context.setValue("modules", result);
82
+ }
83
+ const results = context.getValue("modules") || [];
84
+ await Promise.all(results);
85
+ }
86
+ async function check(env, context, name) {
87
+ const testConfig = context.getTestConfig();
88
+ if (testConfig.noTests)
89
+ return;
90
+ const compiler = context.getCompiler();
91
+ const errors = (context.getError() || []).map(e => ({
92
+ message: e.message,
93
+ stack: e.stack
94
+ }));
95
+ const warnings = [];
96
+ const stats = compiler.getStats();
97
+ const options = compiler.getOptions();
98
+ if (stats) {
99
+ if (testConfig.writeStatsOuptut) {
100
+ fs_extra_1.default.writeFileSync(path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
101
+ preset: "verbose",
102
+ colors: false
103
+ }), "utf-8");
104
+ }
105
+ if (testConfig.writeStatsJson) {
106
+ const jsonStats = stats.toJson({
107
+ errorDetails: true
108
+ });
109
+ fs_extra_1.default.writeFileSync(path_1.default.join(context.getDist(), "stats.json"), JSON.stringify(jsonStats, null, 2), "utf-8");
110
+ }
111
+ if (fs_extra_1.default.existsSync(context.getSource("errors.js")) ||
112
+ fs_extra_1.default.existsSync(context.getSource("warnings.js")) ||
113
+ stats.hasErrors() ||
114
+ stats.hasWarnings()) {
115
+ const statsJson = stats.toJson({
116
+ errorDetails: true
117
+ });
118
+ if (statsJson.errors) {
119
+ errors.push(...statsJson.errors);
120
+ }
121
+ if (statsJson.warnings) {
122
+ warnings.push(...statsJson.warnings);
123
+ }
124
+ }
125
+ }
126
+ await (0, checkArrayExpectation_1.default)(context.getSource(), { errors }, "error", "errors", "Error", options);
127
+ await (0, checkArrayExpectation_1.default)(context.getSource(), { warnings }, "warning", "warnings", "Warning", options);
128
+ // clear error if checked
129
+ if (fs_extra_1.default.existsSync(context.getSource("errors.js"))) {
130
+ context.clearError();
131
+ }
132
+ }
133
+ async function checkSnapshot(env, context, name, snapshot, filter) {
134
+ if (path_1.default.extname(snapshot) === ".snap") {
135
+ throw new Error("Snapshot with `.snap` will be managed by rstest, please use `.snap.txt` instead");
136
+ }
137
+ const compilerManager = context.getCompiler();
138
+ const stats = compilerManager.getStats();
139
+ const compiler = compilerManager.getCompiler();
140
+ if (!stats || !compiler)
141
+ return;
142
+ const compilers = "compilers" in compiler
143
+ ? compiler.compilers
144
+ : [compiler];
145
+ const totalStats = "stats" in stats ? stats.stats : [stats];
146
+ const total = compilers.length;
147
+ for (let i = 0; i < compilers.length; i++) {
148
+ const c = compilers[i];
149
+ const stats = totalStats[i];
150
+ if (stats.hasErrors()) {
151
+ const errors = [];
152
+ errors.push(...stats.compilation.errors);
153
+ throw new Error(`Failed to compile in fixture ${name}, Errors: ${errors
154
+ ?.map(i => `${i.message}\n${i.stack}`)
155
+ .join("\n\n")}`);
156
+ }
157
+ const compilation = c._lastCompilation ||
158
+ c._lastCompilation;
159
+ const snapshotFileFilter = filter ||
160
+ ((file) => (file.endsWith(".js") || file.endsWith(".mjs")) &&
161
+ !file.includes("runtime.js"));
162
+ const fileContents = Object.entries(compilation.assets)
163
+ .filter(([file]) => snapshotFileFilter(file))
164
+ .map(([file, source]) => {
165
+ const tag = path_1.default.extname(file).slice(1) || "txt";
166
+ let content = (0, placeholder_1.normalizePlaceholder)(source.source().toString());
167
+ const testConfig = context.getTestConfig();
168
+ if (testConfig.snapshotContent) {
169
+ content = testConfig.snapshotContent(content);
170
+ }
171
+ const filePath = file.replaceAll(path_1.default.sep, "/");
172
+ return `\`\`\`${tag} title=${filePath}\n${content}\n\`\`\``;
173
+ });
174
+ fileContents.sort();
175
+ const content = fileContents.join("\n\n");
176
+ const snapshotPath = path_1.default.isAbsolute(snapshot)
177
+ ? snapshot
178
+ : path_1.default.resolve(context.getSource(), path_1.default.join("__snapshots__", `${snapshot}${total > 1 ? `-${i}` : ""}`));
179
+ env.expect(content).toMatchFileSnapshotSync(snapshotPath);
180
+ }
181
+ }
182
+ async function afterExecute(context, name) {
183
+ const compiler = context.getCompiler();
184
+ const testConfig = context.getTestConfig();
185
+ if (typeof testConfig.afterExecute === "function") {
186
+ let options = compiler.getOptions();
187
+ if (Array.isArray(options) && options.length === 1) {
188
+ options = options[0];
189
+ }
190
+ testConfig.afterExecute(options);
191
+ }
192
+ }
193
+ function findMultiCompilerBundle(context, name, multiFindBundle) {
194
+ if (typeof multiFindBundle !== "function") {
195
+ return [];
196
+ }
197
+ const multiCompilerOptions = (context.getValue("multiCompilerOptions") ||
198
+ []);
199
+ const result = [];
200
+ const multiFileIndexMap = context.getValue("multiFileIndexMap") || {};
201
+ for (const [index, compilerOptions] of multiCompilerOptions.entries()) {
202
+ const curBundles = multiFindBundle(index, context, compilerOptions);
203
+ const bundles = Array.isArray(curBundles)
204
+ ? curBundles
205
+ : curBundles
206
+ ? [curBundles]
207
+ : [];
208
+ for (const bundle of bundles) {
209
+ if (multiFileIndexMap[bundle]) {
210
+ multiFileIndexMap[bundle].push(index);
211
+ }
212
+ else {
213
+ multiFileIndexMap[bundle] = [index];
214
+ }
215
+ }
216
+ result.push(...bundles);
217
+ }
218
+ context.setValue("multiFileIndexMap", multiFileIndexMap);
219
+ return result;
220
+ }
221
+ function configMultiCompiler(context, name, configFiles, defaultOptions, overrideOptions) {
222
+ const multiCompilerOptions = [];
223
+ const caseOptions = Array.isArray(configFiles)
224
+ ? (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), context, {}, configs => {
225
+ return configs.flatMap(c => {
226
+ if (typeof c === "function") {
227
+ const options = {
228
+ testPath: context.getDist(),
229
+ env: undefined
230
+ };
231
+ return c(options.env, options);
232
+ }
233
+ return c;
234
+ });
235
+ })
236
+ : [{}];
237
+ for (const [index, options] of caseOptions.entries()) {
238
+ const compilerOptions = (0, webpack_merge_1.default)(typeof defaultOptions === "function"
239
+ ? defaultOptions(index, context)
240
+ : {}, options);
241
+ if (typeof overrideOptions === "function") {
242
+ overrideOptions(index, context, compilerOptions);
243
+ }
244
+ multiCompilerOptions.push(compilerOptions);
245
+ }
246
+ const compiler = context.getCompiler();
247
+ compiler.setOptions(multiCompilerOptions);
248
+ context.setValue("multiCompilerOptions", multiCompilerOptions);
249
+ }
@@ -1,6 +1,19 @@
1
- import { type ISimpleProcessorOptions } from "../processor";
2
- import { ECompilerType } from "../type";
3
- export type TCompilerCaseConfig = Omit<ISimpleProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
1
+ import type { Compilation, Compiler, RspackOptions, Stats, StatsCompilation } from "@rspack/core";
2
+ import type { ITestContext } from "../type";
3
+ export declare function createCompilerCase(name: string, src: string, dist: string, testConfig: string): void;
4
+ export type TCompilerCaseConfig = {
4
5
  description: string;
6
+ error?: boolean;
7
+ skip?: boolean;
8
+ options?: (context: ITestContext) => RspackOptions;
9
+ compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
10
+ build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
11
+ check?: ({ context, stats, files, compiler, compilation }: {
12
+ context: ITestContext;
13
+ stats?: StatsCompilation;
14
+ files?: Record<string, string>;
15
+ compiler: Compiler;
16
+ compilation?: Compilation;
17
+ }) => Promise<void>;
18
+ compilerCallback?: (error: Error | null, stats: Stats | null) => void;
5
19
  };
6
- export declare function createCompilerCase(name: string, src: string, dist: string, testConfig: string): void;
@@ -1,17 +1,154 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCompilerCase = createCompilerCase;
4
- const processor_1 = require("../processor");
5
- const simple_1 = require("../test/simple");
6
- const type_1 = require("../type");
4
+ const creator_1 = require("../test/creator");
5
+ function createCompilerProcessor(name, caseConfig) {
6
+ const logs = {
7
+ mkdir: [],
8
+ writeFile: []
9
+ };
10
+ const files = {};
11
+ return {
12
+ config: async (context) => {
13
+ const compiler = context.getCompiler();
14
+ const options = caseConfig.options?.(context) || {};
15
+ options.mode ??= "production";
16
+ options.context ??= context.getSource();
17
+ options.entry ??= "./a.js";
18
+ options.output ??= {};
19
+ options.output.path ??= "/";
20
+ options.output.pathinfo ??= true;
21
+ options.optimization ??= {};
22
+ options.optimization.minimize ??= false;
23
+ compiler.setOptions(options);
24
+ },
25
+ compiler: async (context) => {
26
+ const compiler = context.getCompiler();
27
+ if (caseConfig.compilerCallback) {
28
+ compiler.createCompilerWithCallback(caseConfig.compilerCallback);
29
+ }
30
+ else {
31
+ compiler.createCompiler();
32
+ }
33
+ const c = compiler.getCompiler();
34
+ 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) {
38
+ 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
+ logs.mkdir.push(path);
45
+ if (recursive) {
46
+ callback();
47
+ }
48
+ else {
49
+ const err = new Error();
50
+ err.code = "EEXIST";
51
+ callback(err);
52
+ }
53
+ },
54
+ writeFile(name, content, callback) {
55
+ logs.writeFile.push(name, content);
56
+ files[name] = content.toString("utf-8");
57
+ callback();
58
+ },
59
+ stat(path, callback) {
60
+ callback(new Error("ENOENT"));
61
+ }
62
+ };
63
+ c.hooks.compilation.tap("CompilerTest", compilation => (compilation.bail = true));
64
+ await caseConfig.compiler?.(context, c);
65
+ },
66
+ build: async (context) => {
67
+ 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
+ }
74
+ },
75
+ run: async (env, context) => { },
76
+ check: async (env, context) => {
77
+ const compiler = context.getCompiler();
78
+ const c = compiler.getCompiler();
79
+ const stats = compiler.getStats();
80
+ if (caseConfig.error) {
81
+ const statsJson = stats?.toJson({
82
+ modules: true,
83
+ reasons: true
84
+ });
85
+ const compilation = stats?.compilation;
86
+ await caseConfig.check?.({
87
+ context,
88
+ compiler: c,
89
+ stats: statsJson,
90
+ compilation,
91
+ files
92
+ });
93
+ }
94
+ else if (stats) {
95
+ expect(typeof stats).toBe("object");
96
+ const compilation = stats.compilation;
97
+ const statsJson = stats.toJson({
98
+ modules: true,
99
+ reasons: true
100
+ });
101
+ expect(typeof statsJson).toBe("object");
102
+ expect(statsJson).toHaveProperty("errors");
103
+ expect(Array.isArray(statsJson.errors)).toBe(true);
104
+ if (statsJson.errors.length > 0) {
105
+ expect(statsJson.errors[0]).toBeInstanceOf(Object);
106
+ throw statsJson.errors[0];
107
+ }
108
+ statsJson.logs = logs;
109
+ await caseConfig.check?.({
110
+ context,
111
+ stats: statsJson,
112
+ files,
113
+ compiler: c,
114
+ compilation
115
+ });
116
+ }
117
+ else {
118
+ await caseConfig.check?.({
119
+ context,
120
+ files,
121
+ compiler: c
122
+ });
123
+ }
124
+ },
125
+ after: async (context) => {
126
+ await context.closeCompiler();
127
+ }
128
+ };
129
+ }
130
+ const creator = new creator_1.BasicCaseCreator({
131
+ clean: true,
132
+ describe: false,
133
+ steps: ({ name, caseConfig }) => {
134
+ return [createCompilerProcessor(name, caseConfig)];
135
+ },
136
+ concurrent: false
137
+ });
7
138
  function createCompilerCase(name, src, dist, testConfig) {
8
- const caseConfig = require(testConfig);
9
- const runner = (0, simple_1.getSimpleProcessorRunner)(src, dist);
10
- it(caseConfig.description, async () => {
11
- await runner(name, new processor_1.SimpleTaskProcessor({
12
- name: name,
13
- compilerType: type_1.ECompilerType.Rspack,
14
- ...caseConfig
15
- }));
16
- });
139
+ let caseConfigList = require(testConfig);
140
+ if (!Array.isArray(caseConfigList)) {
141
+ caseConfigList = [caseConfigList];
142
+ }
143
+ for (let i = 0; i < caseConfigList.length; i++) {
144
+ const caseConfig = caseConfigList[i];
145
+ if (caseConfig.skip) {
146
+ it.skip(`${name}[${i}]`, () => { });
147
+ continue;
148
+ }
149
+ creator.create(`${name}[${i}]`, src, dist, undefined, {
150
+ caseConfig,
151
+ description: () => caseConfig.description
152
+ });
153
+ }
17
154
  }
@@ -1,3 +1,8 @@
1
- import { ECompilerType, type TTestConfig } from "../type";
2
- export type TConfigCaseConfig = Omit<TTestConfig<ECompilerType.Rspack>, "validate">;
1
+ import type { RspackOptions } from "@rspack/core";
2
+ import type { ITestContext, ITestProcessor, TTestConfig } from "../type";
3
+ export type TConfigCaseConfig = Omit<TTestConfig, "validate">;
4
+ export declare function createConfigProcessor(name: string): ITestProcessor;
3
5
  export declare function createConfigCase(name: string, src: string, dist: string): void;
6
+ export declare function defaultOptions(index: number, context: ITestContext): RspackOptions;
7
+ export declare function overrideOptions(index: number, context: ITestContext, options: RspackOptions): void;
8
+ export declare function findBundle(index: number, context: ITestContext, options: RspackOptions): string | string[];
@@ -1,39 +1,127 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createConfigProcessor = createConfigProcessor;
3
7
  exports.createConfigCase = createConfigCase;
4
- const config_1 = require("../processor/config");
5
- const runner_1 = require("../runner");
8
+ exports.defaultOptions = defaultOptions;
9
+ exports.overrideOptions = overrideOptions;
10
+ exports.findBundle = findBundle;
11
+ const fs_extra_1 = __importDefault(require("fs-extra"));
12
+ const path_1 = __importDefault(require("path"));
13
+ const parseResource_1 = require("../helper/legacy/parseResource");
6
14
  const creator_1 = require("../test/creator");
7
- const type_1 = require("../type");
15
+ const common_1 = require("./common");
16
+ const runner_1 = require("./runner");
17
+ function createConfigProcessor(name) {
18
+ return {
19
+ config: async (context) => {
20
+ (0, common_1.configMultiCompiler)(context, name, ["rspack.config.cjs", "rspack.config.js", "webpack.config.js"], defaultOptions, overrideOptions);
21
+ },
22
+ compiler: async (context) => {
23
+ await (0, common_1.compiler)(context, name);
24
+ },
25
+ build: async (context) => {
26
+ await (0, common_1.build)(context, name);
27
+ },
28
+ run: async (env, context) => {
29
+ await (0, common_1.run)(env, context, name, (context) => (0, common_1.findMultiCompilerBundle)(context, name, findBundle));
30
+ },
31
+ check: async (env, context) => {
32
+ await (0, common_1.check)(env, context, name);
33
+ },
34
+ after: async (context) => {
35
+ await (0, common_1.afterExecute)(context, name);
36
+ }
37
+ };
38
+ }
8
39
  const creator = new creator_1.BasicCaseCreator({
9
40
  clean: true,
10
41
  describe: false,
11
42
  testConfig: testConfig => {
12
43
  const oldModuleScope = testConfig.moduleScope;
13
- testConfig.moduleScope = (ms, stats) => {
44
+ testConfig.moduleScope = (ms, stats, compilerOptions) => {
14
45
  let res = ms;
15
46
  // TODO: modify runner module scope based on stats here
16
47
  if (typeof oldModuleScope === "function") {
17
- res = oldModuleScope(ms, stats);
48
+ res = oldModuleScope(ms, stats, compilerOptions);
18
49
  }
19
50
  return res;
20
51
  };
21
52
  },
22
- steps: ({ name }) => [
23
- new config_1.ConfigProcessor({
24
- name,
25
- runable: true,
26
- compilerType: type_1.ECompilerType.Rspack,
27
- configFiles: [
28
- "rspack.config.cjs",
29
- "rspack.config.js",
30
- "webpack.config.js"
31
- ]
32
- })
33
- ],
34
- runner: runner_1.MultipleRunnerFactory,
53
+ steps: ({ name }) => [createConfigProcessor(name)],
54
+ runner: {
55
+ key: runner_1.getMultiCompilerRunnerKey,
56
+ runner: runner_1.createMultiCompilerRunner
57
+ },
35
58
  concurrent: true
36
59
  });
37
60
  function createConfigCase(name, src, dist) {
38
61
  creator.create(name, src, dist);
39
62
  }
63
+ function defaultOptions(index, context) {
64
+ return {
65
+ context: context.getSource(),
66
+ mode: "production",
67
+ target: "async-node",
68
+ devtool: false,
69
+ cache: false,
70
+ output: {
71
+ path: context.getDist()
72
+ },
73
+ optimization: {
74
+ minimize: false
75
+ },
76
+ experiments: {
77
+ css: true,
78
+ rspackFuture: {
79
+ bundlerInfo: {
80
+ force: false
81
+ }
82
+ },
83
+ inlineConst: true
84
+ }
85
+ };
86
+ }
87
+ function overrideOptions(index, context, options) {
88
+ if (!options.entry) {
89
+ options.entry = "./index.js";
90
+ }
91
+ if (options.amd === undefined) {
92
+ options.amd = {};
93
+ }
94
+ if (!options.output?.filename) {
95
+ const outputModule = options.experiments?.outputModule;
96
+ options.output ??= {};
97
+ options.output.filename = `bundle${index}${outputModule ? ".mjs" : ".js"}`;
98
+ }
99
+ if (options.cache === undefined)
100
+ options.cache = false;
101
+ if (!global.printLogger) {
102
+ options.infrastructureLogging = {
103
+ level: "error"
104
+ };
105
+ }
106
+ }
107
+ function findBundle(index, context, options) {
108
+ const testConfig = context.getTestConfig();
109
+ if (typeof testConfig.findBundle === "function") {
110
+ return testConfig.findBundle(index, options);
111
+ }
112
+ const ext = path_1.default.extname((0, parseResource_1.parseResource)(options.output?.filename).path);
113
+ const bundlePath = [];
114
+ if (options.output?.path &&
115
+ fs_extra_1.default.existsSync(path_1.default.join(options.output.path, `bundle${index}${ext}`))) {
116
+ if (options.experiments?.css) {
117
+ const cssOutputPath = path_1.default.join(options.output.path, (typeof options.output?.cssFilename === "string" &&
118
+ options.output?.cssFilename) ||
119
+ `bundle${index}.css`);
120
+ if (fs_extra_1.default.existsSync(cssOutputPath)) {
121
+ bundlePath.push(path_1.default.relative(options.output.path, cssOutputPath));
122
+ }
123
+ }
124
+ bundlePath.push(`./bundle${index}${ext}`);
125
+ }
126
+ return bundlePath;
127
+ }
@@ -1,6 +1,15 @@
1
- import { type IDefaultsConfigProcessorOptions } from "../processor";
2
- import { ECompilerType } from "../type";
3
- export type TDefaultsCaseConfig = Omit<IDefaultsConfigProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
1
+ import type { RspackOptions } from "@rspack/core";
2
+ import type { ITestContext } from "../type";
3
+ export declare function createDefaultsCase(name: string, src: string): void;
4
+ export declare function getRspackDefaultConfig(cwd: string, config: RspackOptions): RspackOptions;
5
+ export type TDefaultsCaseConfig = {
6
+ options?: (context: ITestContext) => RspackOptions;
7
+ cwd?: string;
8
+ diff: (diff: Assertion<RspackTestDiff>, defaults: Assertion<RspackOptions>) => Promise<void>;
4
9
  description: string;
5
10
  };
6
- export declare function createDefaultsCase(name: string, src: string): void;
11
+ declare class RspackTestDiff {
12
+ value: string;
13
+ constructor(value: string);
14
+ }
15
+ export {};