@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
@@ -1,32 +1,328 @@
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 });
3
6
  exports.createHotStepCase = createHotStepCase;
4
- const hot_step_1 = require("../processor/hot-step");
5
- const runner_1 = require("../runner");
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const helper_1 = require("../helper");
10
+ const placeholder_1 = require("../helper/expect/placeholder");
6
11
  const creator_1 = require("../test/creator");
7
- const type_1 = require("../type");
12
+ const hot_1 = require("./hot");
13
+ const NOOP_SET = new Set();
14
+ const escapeLocalName = (str) => str.split(/[-<>:"/|?*.]/).join("_");
15
+ const SELF_HANDLER = (file, options) => {
16
+ let res = [];
17
+ const hotUpdateGlobal = (_, modules) => {
18
+ res = Object.keys(modules);
19
+ };
20
+ const hotUpdateGlobalKey = escapeLocalName(`${options.output?.hotUpdateGlobal || "webpackHotUpdate"}${options.output?.uniqueName || ""}`);
21
+ global.self ??= {};
22
+ global.self[hotUpdateGlobalKey] = hotUpdateGlobal;
23
+ require(file);
24
+ delete global.self[hotUpdateGlobalKey];
25
+ return res;
26
+ };
27
+ const NODE_HANDLER = (file) => {
28
+ return Object.keys(require(file).modules) || [];
29
+ };
30
+ const GET_MODULE_HANDLER = {
31
+ web: SELF_HANDLER,
32
+ webworker: SELF_HANDLER,
33
+ "async-node": NODE_HANDLER,
34
+ node: NODE_HANDLER
35
+ };
8
36
  const creators = new Map();
37
+ function createHotStepProcessor(name, src, temp, target) {
38
+ const processor = (0, hot_1.createHotProcessor)(name, src, temp, target);
39
+ const entries = {};
40
+ const hashes = [];
41
+ function matchStepSnapshot(env, context, step, options, stats, runtime) {
42
+ const getModuleHandler = GET_MODULE_HANDLER[options.target];
43
+ env.expect(typeof getModuleHandler).toBe("function");
44
+ const lastHash = hashes[hashes.length - 1];
45
+ const snapshotPath = context.getSource(`__snapshots__/${options.target}/${step}.snap.txt`);
46
+ const title = `Case ${node_path_1.default.basename(name)}: Step ${step}`;
47
+ const hotUpdateFile = [];
48
+ const hotUpdateManifest = [];
49
+ const changedFiles = step === 0
50
+ ? []
51
+ : processor.updatePlugin
52
+ .getModifiedFiles()
53
+ .map((i) => (0, helper_1.escapeSep)(node_path_1.default.relative(temp, i)));
54
+ changedFiles.sort();
55
+ const resultHashes = {
56
+ [lastHash || "LAST_HASH"]: "LAST_HASH",
57
+ [stats.hash]: "CURRENT_HASH"
58
+ };
59
+ // TODO: find a better way
60
+ // replace [runtime] to [runtime of id] to prevent worker hash
61
+ const runtimes = {};
62
+ for (const [id, runtime] of Object.entries(entries)) {
63
+ if (typeof runtime === "string") {
64
+ if (runtime !== id) {
65
+ runtimes[runtime] = `[runtime of ${id}]`;
66
+ }
67
+ }
68
+ else if (Array.isArray(runtime)) {
69
+ for (const r of runtime) {
70
+ if (r !== id) {
71
+ runtimes[r] = `[runtime of ${id}]`;
72
+ }
73
+ }
74
+ }
75
+ }
76
+ const replaceContent = (rawStr) => {
77
+ let str = rawStr;
78
+ const replaceContentConfig = context.getTestConfig().snapshotContent;
79
+ if (replaceContentConfig) {
80
+ str = replaceContentConfig(str);
81
+ }
82
+ return (0, placeholder_1.normalizePlaceholder)(Object.entries(resultHashes)
83
+ .reduce((str, [raw, replacement]) => {
84
+ return str.split(raw).join(replacement);
85
+ }, str)
86
+ .replace(/\/\/ (\d+)\s+(?=var cssReload)/, "")
87
+ .replaceAll(/var data = "(?:.*)"/g, match => {
88
+ return decodeURIComponent(match).replaceAll(/\\/g, "/");
89
+ }));
90
+ };
91
+ const replaceFileName = (str) => {
92
+ return Object.entries({
93
+ ...resultHashes,
94
+ ...runtimes
95
+ }).reduce((str, [raw, replacement]) => {
96
+ return str.split(raw).join(replacement);
97
+ }, str);
98
+ };
99
+ const assets = stats.assets.sort((a, b) => a.name.localeCompare(b.name));
100
+ const fileList = assets
101
+ .map(i => {
102
+ const fileName = i.name;
103
+ const renderName = replaceFileName(fileName);
104
+ const content = replaceContent(fs_extra_1.default.readFileSync(context.getDist(fileName), "utf-8"));
105
+ if (fileName.endsWith("hot-update.js")) {
106
+ const modules = getModuleHandler(context.getDist(fileName), options);
107
+ const runtime = [];
108
+ for (const i of content.matchAll(/\/\/ (webpack\/runtime\/[\w_-]+)\s*\n/g)) {
109
+ runtime.push(i[1]);
110
+ }
111
+ modules.sort();
112
+ runtime.sort();
113
+ hotUpdateFile.push({
114
+ name: renderName,
115
+ content,
116
+ modules,
117
+ runtime
118
+ });
119
+ return `- Update: ${renderName}, size: ${content.length}`;
120
+ }
121
+ if (fileName.endsWith("hot-update.json")) {
122
+ const manifest = JSON.parse(content);
123
+ manifest.c?.sort();
124
+ manifest.r?.sort();
125
+ manifest.m?.sort();
126
+ hotUpdateManifest.push({
127
+ name: renderName,
128
+ content: JSON.stringify(manifest)
129
+ });
130
+ return `- Manifest: ${renderName}, size: ${i.size}`;
131
+ }
132
+ if (fileName.endsWith(".js")) {
133
+ return `- Bundle: ${renderName}`;
134
+ }
135
+ })
136
+ .filter(Boolean);
137
+ fileList.sort();
138
+ hotUpdateManifest.sort((a, b) => (a.name > b.name ? 1 : -1));
139
+ hotUpdateFile.sort((a, b) => (a.name > b.name ? 1 : -1));
140
+ if (runtime?.javascript) {
141
+ runtime.javascript.outdatedModules.sort();
142
+ runtime.javascript.updatedModules.sort();
143
+ runtime.javascript.updatedRuntime.sort();
144
+ runtime.javascript.acceptedModules.sort();
145
+ runtime.javascript.disposedModules.sort();
146
+ for (const value of Object.values(runtime.javascript.outdatedDependencies)) {
147
+ value.sort();
148
+ }
149
+ }
150
+ const content = `
151
+ # ${title}
152
+
153
+ ## Changed Files
154
+ ${changedFiles.map(i => `- ${i}`).join("\n")}
155
+
156
+ ## Asset Files
157
+ ${fileList.join("\n")}
158
+
159
+ ## Manifest
160
+ ${hotUpdateManifest
161
+ .map(i => `
162
+ ### ${i.name}
163
+
164
+ \`\`\`json
165
+ ${i.content}
166
+ \`\`\`
167
+ `)
168
+ .join("\n\n")}
169
+
170
+ ## Update
171
+
172
+ ${hotUpdateFile
173
+ .map(i => `
174
+ ### ${i.name}
175
+
176
+ #### Changed Modules
177
+ ${i.modules.map(i => `- ${i}`).join("\n")}
178
+
179
+ #### Changed Runtime Modules
180
+ ${i.runtime.map(i => `- ${i}`).join("\n")}
181
+
182
+ #### Changed Content
183
+ \`\`\`js
184
+ ${i.content}
185
+ \`\`\`
186
+ `)
187
+ .join("\n\n")}
188
+
189
+
190
+ ${runtime
191
+ ? `
192
+ ## Runtime
193
+ ### Status
194
+
195
+ \`\`\`txt
196
+ ${runtime.statusPath.join(" => ")}
197
+ \`\`\`
198
+
199
+ ${runtime.javascript
200
+ ? `
201
+
202
+ ### JavaScript
203
+
204
+ #### Outdated
205
+
206
+ Outdated Modules:
207
+ ${runtime.javascript.outdatedModules.map(i => `- ${i}`).join("\n")}
208
+
209
+
210
+ Outdated Dependencies:
211
+ \`\`\`json
212
+ ${JSON.stringify(runtime.javascript.outdatedDependencies || {}, null, 2)}
213
+ \`\`\`
214
+
215
+ #### Updated
216
+
217
+ Updated Modules:
218
+ ${runtime.javascript.updatedModules.map(i => `- ${i}`).join("\n")}
219
+
220
+ Updated Runtime:
221
+ ${runtime.javascript.updatedRuntime.map(i => `- \`${i}\``).join("\n")}
222
+
223
+
224
+ #### Callback
225
+
226
+ Accepted Callback:
227
+ ${runtime.javascript.acceptedModules.map(i => `- ${i}`).join("\n")}
228
+
229
+ Disposed Callback:
230
+ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
231
+ `
232
+ : ""}
233
+
234
+ `
235
+ : ""}
236
+
237
+ `
238
+ .replaceAll(/%3A(\d+)%2F/g, (match, capture) => {
239
+ return match.replace(capture, "PORT");
240
+ })
241
+ .trim();
242
+ env.expect(content).toMatchFileSnapshotSync(snapshotPath);
243
+ }
244
+ const originRun = processor.run;
245
+ processor.run = async function (env, context) {
246
+ context.setValue("hotUpdateStepChecker", (updateIndex, stats, runtime) => {
247
+ const statsJson = stats.toJson({
248
+ assets: true,
249
+ chunks: true
250
+ });
251
+ const chunks = Array.from(
252
+ // Some chunk fields are missing from rspack
253
+ stats?.compilation.chunks || NOOP_SET);
254
+ for (const entry of chunks.filter(i => i.hasRuntime())) {
255
+ if (!entries[entry.id] && entry.runtime) {
256
+ entries[entry.id] =
257
+ // Webpack uses `string | SortableSet<string>` for `entry.runtime`
258
+ typeof entry.runtime === "string"
259
+ ? [entry.runtime]
260
+ : Array.from(entry.runtime);
261
+ }
262
+ }
263
+ const compiler = context.getCompiler();
264
+ const compilerOptions = compiler.getOptions();
265
+ matchStepSnapshot(env, context, updateIndex, compilerOptions, statsJson, runtime);
266
+ hashes.push(stats.hash);
267
+ });
268
+ context.setValue("hotUpdateStepErrorChecker", (updateIndex, stats, runtime) => {
269
+ hashes.push(stats.hash);
270
+ });
271
+ await originRun(env, context);
272
+ };
273
+ processor.check = async function (env, context) {
274
+ const compiler = context.getCompiler();
275
+ const stats = compiler.getStats();
276
+ if (!stats || !stats.hash) {
277
+ env.expect(false);
278
+ return;
279
+ }
280
+ const statsJson = stats.toJson({ assets: true, chunks: true });
281
+ const chunks = Array.from(
282
+ // Some chunk fields are missing from rspack
283
+ stats?.compilation.chunks || NOOP_SET);
284
+ for (const entry of chunks.filter(i => i.hasRuntime())) {
285
+ if (entry.runtime) {
286
+ entries[entry.id] =
287
+ // Webpack uses `string | SortableSet<string>` for `entry.runtime`
288
+ typeof entry.runtime === "string"
289
+ ? [entry.runtime]
290
+ : Array.from(entry.runtime);
291
+ }
292
+ }
293
+ let matchFailed = null;
294
+ try {
295
+ matchStepSnapshot(env, context, 0, compiler.getOptions(), statsJson);
296
+ }
297
+ catch (e) {
298
+ matchFailed = e;
299
+ }
300
+ hashes.push(stats.hash);
301
+ if (matchFailed) {
302
+ throw matchFailed;
303
+ }
304
+ };
305
+ return processor;
306
+ }
9
307
  function getCreator(target) {
10
308
  if (!creators.has(target)) {
11
309
  creators.set(target, new creator_1.BasicCaseCreator({
12
310
  clean: true,
13
311
  describe: false,
14
312
  target,
15
- steps: ({ name, target }) => [
16
- new hot_step_1.HotSnapshotProcessor({
17
- name,
18
- target: target,
19
- compilerType: type_1.ECompilerType.Rspack,
20
- configFiles: ["rspack.config.js", "webpack.config.js"]
21
- })
313
+ steps: ({ name, target, src, temp, dist }) => [
314
+ createHotStepProcessor(name, src, temp || node_path_1.default.resolve(dist, "temp"), target)
22
315
  ],
23
- runner: runner_1.HotStepRunnerFactory,
316
+ runner: {
317
+ key: (context, name, file) => name,
318
+ runner: hot_1.createHotRunner
319
+ },
24
320
  concurrent: true
25
321
  }));
26
322
  }
27
323
  return creators.get(target);
28
324
  }
29
- function createHotStepCase(name, src, dist, target) {
325
+ function createHotStepCase(name, src, dist, temp, target) {
30
326
  const creator = getCreator(target);
31
- creator.create(name, src, dist);
327
+ creator.create(name, src, dist, temp);
32
328
  }
@@ -1,2 +1,11 @@
1
- import { ECompilerType, type TCompilerOptions } from "../type";
2
- export declare function createHotCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
1
+ import { type RspackOptions } from "@rspack/core";
2
+ import { HotUpdatePlugin } from "../helper/hot-update/plugin";
3
+ import type { ITestContext, ITestEnv, ITestProcessor, ITestRunner } from "../type";
4
+ type TTarget = RspackOptions["target"];
5
+ export declare function createHotProcessor(name: string, src: string, temp: string, target: TTarget, incremental?: boolean): THotProcessor;
6
+ export declare function createHotCase(name: string, src: string, dist: string, temp: string, target: RspackOptions["target"]): void;
7
+ type THotProcessor = ITestProcessor & {
8
+ updatePlugin: HotUpdatePlugin;
9
+ };
10
+ export declare function createHotRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
11
+ export {};
package/dist/case/hot.js CHANGED
@@ -1,32 +1,237 @@
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.createHotProcessor = createHotProcessor;
3
7
  exports.createHotCase = createHotCase;
4
- const hot_1 = require("../processor/hot");
8
+ exports.createHotRunner = createHotRunner;
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const core_1 = __importDefault(require("@rspack/core"));
11
+ const helper_1 = require("../helper");
12
+ const plugin_1 = require("../helper/hot-update/plugin");
13
+ const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
14
+ const plugin_2 = require("../plugin");
5
15
  const runner_1 = require("../runner");
6
16
  const creator_1 = require("../test/creator");
7
- const type_1 = require("../type");
17
+ const common_1 = require("./common");
18
+ const runner_2 = require("./runner");
8
19
  const creators = new Map();
20
+ function createHotProcessor(name, src, temp, target, incremental = false) {
21
+ const updatePlugin = new plugin_1.HotUpdatePlugin(src, temp);
22
+ const processor = {
23
+ before: async (context) => {
24
+ await updatePlugin.initialize();
25
+ context.setValue("hotUpdatePlugin", updatePlugin);
26
+ },
27
+ config: async (context) => {
28
+ const compiler = context.getCompiler();
29
+ let options = defaultOptions(context, target);
30
+ options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"], options);
31
+ overrideOptions(context, options, target, updatePlugin);
32
+ if (incremental) {
33
+ options.experiments ??= {};
34
+ options.experiments.incremental ??= "advance-silent";
35
+ }
36
+ compiler.setOptions(options);
37
+ },
38
+ compiler: async (context) => {
39
+ await (0, common_1.compiler)(context, name);
40
+ },
41
+ build: async (context) => {
42
+ await (0, common_1.build)(context, name);
43
+ },
44
+ run: async (env, context) => {
45
+ await (0, common_1.run)(env, context, name, context => findBundle(context, name, target, updatePlugin));
46
+ },
47
+ check: async (env, context) => {
48
+ await (0, common_1.check)(env, context, name);
49
+ },
50
+ after: async (context) => {
51
+ await (0, common_1.afterExecute)(context, name);
52
+ },
53
+ afterAll: async (context) => {
54
+ if (context.getTestConfig().checkSteps === false) {
55
+ return;
56
+ }
57
+ const updateIndex = updatePlugin.getUpdateIndex();
58
+ const totalUpdates = updatePlugin.getTotalUpdates();
59
+ if (updateIndex + 1 !== totalUpdates) {
60
+ throw new Error(`Should run all hot steps (${updateIndex + 1} / ${totalUpdates}): ${name}`);
61
+ }
62
+ }
63
+ };
64
+ processor.updatePlugin = updatePlugin;
65
+ return processor;
66
+ }
9
67
  function getCreator(target) {
10
68
  if (!creators.has(target)) {
11
69
  creators.set(target, new creator_1.BasicCaseCreator({
12
70
  clean: true,
13
71
  describe: true,
14
72
  target,
15
- steps: ({ name, target }) => [
16
- new hot_1.HotProcessor({
17
- name,
18
- target: target,
19
- compilerType: type_1.ECompilerType.Rspack,
20
- configFiles: ["rspack.config.js", "webpack.config.js"]
21
- })
73
+ steps: ({ name, target, src, dist, temp }) => [
74
+ createHotProcessor(name, src, temp || node_path_1.default.resolve(dist, "temp"), target)
22
75
  ],
23
- runner: runner_1.HotRunnerFactory,
76
+ runner: {
77
+ key: (context, name, file) => name,
78
+ runner: createHotRunner
79
+ },
24
80
  concurrent: true
25
81
  }));
26
82
  }
27
83
  return creators.get(target);
28
84
  }
29
- function createHotCase(name, src, dist, target) {
85
+ function createHotCase(name, src, dist, temp, target) {
30
86
  const creator = getCreator(target);
31
- creator.create(name, src, dist);
87
+ creator.create(name, src, dist, temp);
88
+ }
89
+ function defaultOptions(context, target) {
90
+ const options = {
91
+ context: context.getSource(),
92
+ mode: "development",
93
+ devtool: false,
94
+ output: {
95
+ path: context.getDist(),
96
+ filename: "bundle.js",
97
+ chunkFilename: "[name].chunk.[fullhash].js",
98
+ publicPath: "https://test.cases/path/",
99
+ library: { type: "commonjs2" }
100
+ },
101
+ optimization: {
102
+ moduleIds: "named"
103
+ },
104
+ target,
105
+ experiments: {
106
+ css: true,
107
+ // test incremental: "safe" here, we test default incremental in Incremental-*.test.js
108
+ incremental: "safe",
109
+ rspackFuture: {
110
+ bundlerInfo: {
111
+ force: false
112
+ }
113
+ },
114
+ inlineConst: true
115
+ }
116
+ };
117
+ options.plugins ??= [];
118
+ options.plugins.push(new core_1.default.HotModuleReplacementPlugin());
119
+ return options;
120
+ }
121
+ function overrideOptions(context, options, target, updatePlugin) {
122
+ if (!options.entry) {
123
+ options.entry = "./index.js";
124
+ }
125
+ options.module ??= {};
126
+ for (const cssModuleType of ["css/auto", "css/module", "css"]) {
127
+ options.module.generator ??= {};
128
+ options.module.generator[cssModuleType] ??= {};
129
+ options.module.generator[cssModuleType].exportsOnly ??=
130
+ target === "async-node";
131
+ }
132
+ options.plugins ??= [];
133
+ options.plugins.push(updatePlugin);
134
+ if (!global.printLogger) {
135
+ options.infrastructureLogging = {
136
+ level: "error"
137
+ };
138
+ }
139
+ if (options.lazyCompilation) {
140
+ options.plugins.push(new plugin_2.LazyCompilationTestPlugin());
141
+ }
142
+ }
143
+ function findBundle(context, name, target, updatePlugin) {
144
+ const compiler = context.getCompiler();
145
+ if (!compiler)
146
+ throw new Error("Compiler should exists when find bundle");
147
+ const testConfig = context.getTestConfig();
148
+ if (typeof testConfig.findBundle === "function") {
149
+ return testConfig.findBundle(updatePlugin.getUpdateIndex(), compiler.getOptions());
150
+ }
151
+ const files = [];
152
+ const prefiles = [];
153
+ const stats = compiler.getStats();
154
+ if (!stats)
155
+ throw new Error("Stats should exists when find bundle");
156
+ const info = stats.toJson({ all: false, entrypoints: true });
157
+ if (target === "web" || target === "webworker") {
158
+ for (const file of info.entrypoints.main.assets) {
159
+ if ((0, helper_1.isJavaScript)(file.name)) {
160
+ files.push(file.name);
161
+ }
162
+ else {
163
+ prefiles.push(file.name);
164
+ }
165
+ }
166
+ }
167
+ else {
168
+ const assets = info.entrypoints.main.assets.filter(s => (0, helper_1.isJavaScript)(s.name));
169
+ files.push(assets[assets.length - 1].name);
170
+ }
171
+ return [...prefiles, ...files];
172
+ }
173
+ function createHotRunner(context, name, file, env) {
174
+ const compiler = context.getCompiler();
175
+ const compilerOptions = compiler.getOptions();
176
+ const testConfig = context.getTestConfig();
177
+ const source = context.getSource();
178
+ const dist = context.getDist();
179
+ const updatePlugin = context.getValue("hotUpdatePlugin");
180
+ const nextHMR = async (m, options) => {
181
+ await updatePlugin.goNext();
182
+ const stats = await compiler.build();
183
+ if (!stats) {
184
+ throw new Error("Should generate stats during build");
185
+ }
186
+ const jsonStats = stats.toJson({
187
+ // errorDetails: true
188
+ });
189
+ const compilerOptions = compiler.getOptions();
190
+ const checker = context.getValue(jsonStats.errors?.length
191
+ ? "hotUpdateStepErrorChecker"
192
+ : "hotUpdateStepChecker");
193
+ if (checker) {
194
+ checker(updatePlugin.getUpdateIndex(), stats, runner.getGlobal("__HMR_UPDATED_RUNTIME__"));
195
+ }
196
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updatePlugin.getUpdateIndex()}`, "Error", compilerOptions);
197
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updatePlugin.getUpdateIndex()}`, "Warning", compilerOptions);
198
+ const updatedModules = await m.hot.check(options || true);
199
+ if (!updatedModules) {
200
+ throw new Error("No update available");
201
+ }
202
+ return jsonStats;
203
+ };
204
+ const commonOptions = {
205
+ env,
206
+ stats: (0, runner_2.cachedStats)(context, name),
207
+ name: name,
208
+ runInNewContext: false,
209
+ testConfig: {
210
+ ...testConfig,
211
+ moduleScope(ms, stats, options) {
212
+ const moduleScope = ms;
213
+ if (typeof testConfig.moduleScope === "function") {
214
+ testConfig.moduleScope(moduleScope, stats, compilerOptions);
215
+ }
216
+ moduleScope.NEXT_HMR = nextHMR;
217
+ return moduleScope;
218
+ }
219
+ },
220
+ cachable: true,
221
+ source,
222
+ dist,
223
+ compilerOptions
224
+ };
225
+ let runner;
226
+ if (compilerOptions.target === "web" ||
227
+ compilerOptions.target === "webworker") {
228
+ runner = new runner_1.WebRunner({
229
+ location: testConfig.location || "https://test.cases/path/index.html",
230
+ ...commonOptions
231
+ });
232
+ }
233
+ else {
234
+ runner = new runner_1.NodeRunner(commonOptions);
235
+ }
236
+ return runner;
32
237
  }
@@ -1,5 +1,5 @@
1
- import { ECompilerType, type TCompilerOptions } from "../type";
2
- export declare function createHotIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], webpackCases: boolean): void;
1
+ import type { RspackOptions } from "@rspack/core";
2
+ export declare function createHotIncrementalCase(name: string, src: string, dist: string, temp: string, target: RspackOptions["target"], webpackCases: boolean): void;
3
3
  export type WatchIncrementalOptions = {
4
4
  ignoreNotFriendlyForIncrementalWarnings?: boolean;
5
5
  };