@rspack-debug/test-tools 1.3.14

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 (262) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +17 -0
  3. package/dist/case/builtin.d.ts +1 -0
  4. package/dist/case/builtin.js +39 -0
  5. package/dist/case/cache.d.ts +2 -0
  6. package/dist/case/cache.js +34 -0
  7. package/dist/case/compiler.d.ts +6 -0
  8. package/dist/case/compiler.js +17 -0
  9. package/dist/case/config.d.ts +3 -0
  10. package/dist/case/config.js +39 -0
  11. package/dist/case/defaults.d.ts +6 -0
  12. package/dist/case/defaults.js +39 -0
  13. package/dist/case/diagnostic.d.ts +1 -0
  14. package/dist/case/diagnostic.js +29 -0
  15. package/dist/case/diff.d.ts +3 -0
  16. package/dist/case/diff.js +126 -0
  17. package/dist/case/error.d.ts +6 -0
  18. package/dist/case/error.js +21 -0
  19. package/dist/case/hash.d.ts +3 -0
  20. package/dist/case/hash.js +30 -0
  21. package/dist/case/hook.d.ts +6 -0
  22. package/dist/case/hook.js +35 -0
  23. package/dist/case/hot-step.d.ts +2 -0
  24. package/dist/case/hot-step.js +32 -0
  25. package/dist/case/hot.d.ts +2 -0
  26. package/dist/case/hot.js +32 -0
  27. package/dist/case/index.d.ts +19 -0
  28. package/dist/case/index.js +35 -0
  29. package/dist/case/new-incremental.d.ts +6 -0
  30. package/dist/case/new-incremental.js +100 -0
  31. package/dist/case/normal.d.ts +1 -0
  32. package/dist/case/normal.js +29 -0
  33. package/dist/case/serial.d.ts +3 -0
  34. package/dist/case/serial.js +34 -0
  35. package/dist/case/stats-api.d.ts +6 -0
  36. package/dist/case/stats-api.js +21 -0
  37. package/dist/case/stats-output.d.ts +1 -0
  38. package/dist/case/stats-output.js +22 -0
  39. package/dist/case/treeshaking.d.ts +1 -0
  40. package/dist/case/treeshaking.js +23 -0
  41. package/dist/case/watch.d.ts +1 -0
  42. package/dist/case/watch.js +53 -0
  43. package/dist/compare/comparator.d.ts +17 -0
  44. package/dist/compare/comparator.js +52 -0
  45. package/dist/compare/compare.d.ts +17 -0
  46. package/dist/compare/compare.js +175 -0
  47. package/dist/compare/format-code.d.ts +16 -0
  48. package/dist/compare/format-code.js +239 -0
  49. package/dist/compare/index.d.ts +5 -0
  50. package/dist/compare/index.js +21 -0
  51. package/dist/compare/replace-module-argument.d.ts +1 -0
  52. package/dist/compare/replace-module-argument.js +8 -0
  53. package/dist/compare/replace-runtime-module-name.d.ts +1 -0
  54. package/dist/compare/replace-runtime-module-name.js +71 -0
  55. package/dist/compiler.d.ts +28 -0
  56. package/dist/compiler.js +111 -0
  57. package/dist/helper/directory.d.ts +12 -0
  58. package/dist/helper/directory.js +81 -0
  59. package/dist/helper/expect/diff.d.ts +3 -0
  60. package/dist/helper/expect/diff.js +21 -0
  61. package/dist/helper/expect/error.d.ts +5 -0
  62. package/dist/helper/expect/error.js +51 -0
  63. package/dist/helper/expect/placeholder.d.ts +1 -0
  64. package/dist/helper/expect/placeholder.js +41 -0
  65. package/dist/helper/expect/rspack.d.ts +3 -0
  66. package/dist/helper/expect/rspack.js +14 -0
  67. package/dist/helper/expect/to-be-typeof.d.ts +4 -0
  68. package/dist/helper/expect/to-be-typeof.js +12 -0
  69. package/dist/helper/expect/to-end-with.d.ts +4 -0
  70. package/dist/helper/expect/to-end-with.js +11 -0
  71. package/dist/helper/expect/to-match-file-snapshot.d.ts +23 -0
  72. package/dist/helper/expect/to-match-file-snapshot.js +108 -0
  73. package/dist/helper/hot-update/index.d.ts +1 -0
  74. package/dist/helper/hot-update/index.js +5 -0
  75. package/dist/helper/hot-update/loader.d.ts +1 -0
  76. package/dist/helper/hot-update/loader.js +32 -0
  77. package/dist/helper/hot-update/plugin.d.ts +17 -0
  78. package/dist/helper/hot-update/plugin.js +133 -0
  79. package/dist/helper/index.d.ts +7 -0
  80. package/dist/helper/index.js +23 -0
  81. package/dist/helper/legacy/EventSourceForNode.d.ts +8 -0
  82. package/dist/helper/legacy/EventSourceForNode.js +40 -0
  83. package/dist/helper/legacy/FakeDocument.d.ts +54 -0
  84. package/dist/helper/legacy/FakeDocument.js +278 -0
  85. package/dist/helper/legacy/asModule.d.ts +3 -0
  86. package/dist/helper/legacy/asModule.js +25 -0
  87. package/dist/helper/legacy/captureStdio.d.ts +8 -0
  88. package/dist/helper/legacy/captureStdio.js +32 -0
  89. package/dist/helper/legacy/checkArrayExpectation.d.ts +2 -0
  90. package/dist/helper/legacy/checkArrayExpectation.js +111 -0
  91. package/dist/helper/legacy/copyDiff.d.ts +2 -0
  92. package/dist/helper/legacy/copyDiff.js +33 -0
  93. package/dist/helper/legacy/createFakeWorker.d.ts +13 -0
  94. package/dist/helper/legacy/createFakeWorker.js +80 -0
  95. package/dist/helper/legacy/createLazyTestEnv.d.ts +10 -0
  96. package/dist/helper/legacy/createLazyTestEnv.js +116 -0
  97. package/dist/helper/legacy/createLogger.d.ts +23 -0
  98. package/dist/helper/legacy/createLogger.js +20 -0
  99. package/dist/helper/legacy/currentScript.d.ts +6 -0
  100. package/dist/helper/legacy/currentScript.js +8 -0
  101. package/dist/helper/legacy/fakeSystem.d.ts +9 -0
  102. package/dist/helper/legacy/fakeSystem.js +124 -0
  103. package/dist/helper/legacy/parseResource.d.ts +6 -0
  104. package/dist/helper/legacy/parseResource.js +15 -0
  105. package/dist/helper/legacy/supportsImportFn.d.ts +1 -0
  106. package/dist/helper/legacy/supportsImportFn.js +15 -0
  107. package/dist/helper/legacy/supportsWorker.d.ts +2 -0
  108. package/dist/helper/legacy/supportsWorker.js +17 -0
  109. package/dist/helper/legacy/urlToRelativePath.d.ts +2 -0
  110. package/dist/helper/legacy/urlToRelativePath.js +7 -0
  111. package/dist/helper/legacy/walkCssTokens.d.ts +40 -0
  112. package/dist/helper/legacy/walkCssTokens.js +761 -0
  113. package/dist/helper/legacy/warmup-webpack.d.ts +1 -0
  114. package/dist/helper/legacy/warmup-webpack.js +26 -0
  115. package/dist/helper/loaders/hot-update.d.ts +1 -0
  116. package/dist/helper/loaders/hot-update.js +40 -0
  117. package/dist/helper/parse-modules.d.ts +7 -0
  118. package/dist/helper/parse-modules.js +73 -0
  119. package/dist/helper/plugins/hot-update.d.ts +7 -0
  120. package/dist/helper/plugins/hot-update.js +40 -0
  121. package/dist/helper/plugins/index.d.ts +1 -0
  122. package/dist/helper/plugins/index.js +17 -0
  123. package/dist/helper/read-config-file.d.ts +2 -0
  124. package/dist/helper/read-config-file.js +13 -0
  125. package/dist/helper/serializers.d.ts +2 -0
  126. package/dist/helper/serializers.js +52 -0
  127. package/dist/helper/setup-env.d.ts +1 -0
  128. package/dist/helper/setup-env.js +80 -0
  129. package/dist/helper/setup-expect.d.ts +1 -0
  130. package/dist/helper/setup-expect.js +16 -0
  131. package/dist/helper/update-snapshot.d.ts +1 -0
  132. package/dist/helper/update-snapshot.js +6 -0
  133. package/dist/helper/util/checkSourceMap.d.ts +1 -0
  134. package/dist/helper/util/checkSourceMap.js +96 -0
  135. package/dist/helper/util/checkStats.d.ts +2 -0
  136. package/dist/helper/util/checkStats.js +43 -0
  137. package/dist/helper/util/currentWatchStep.d.ts +1 -0
  138. package/dist/helper/util/currentWatchStep.js +2 -0
  139. package/dist/helper/util/expectWarningFactory.d.ts +2 -0
  140. package/dist/helper/util/expectWarningFactory.js +21 -0
  141. package/dist/helper/util/filterUtil.d.ts +8 -0
  142. package/dist/helper/util/filterUtil.js +50 -0
  143. package/dist/helper/util/identifier.d.ts +76 -0
  144. package/dist/helper/util/identifier.js +339 -0
  145. package/dist/helper/util/replaceMitteDiagnostic.d.ts +2 -0
  146. package/dist/helper/util/replaceMitteDiagnostic.js +17 -0
  147. package/dist/helper/win.d.ts +1 -0
  148. package/dist/helper/win.js +10 -0
  149. package/dist/index.d.ts +12 -0
  150. package/dist/index.js +28 -0
  151. package/dist/plugin/index.d.ts +4 -0
  152. package/dist/plugin/index.js +20 -0
  153. package/dist/plugin/lazy-compilation-test-plugin.d.ts +4 -0
  154. package/dist/plugin/lazy-compilation-test-plugin.js +67 -0
  155. package/dist/plugin/rspack-diff-config-plugin.d.ts +7 -0
  156. package/dist/plugin/rspack-diff-config-plugin.js +42 -0
  157. package/dist/plugin/webpack-diff-config-plugin.d.ts +7 -0
  158. package/dist/plugin/webpack-diff-config-plugin.js +41 -0
  159. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +3 -0
  160. package/dist/plugin/webpack-module-placeholder-plugin.js +107 -0
  161. package/dist/processor/basic.d.ts +24 -0
  162. package/dist/processor/basic.js +146 -0
  163. package/dist/processor/builtin.d.ts +9 -0
  164. package/dist/processor/builtin.js +171 -0
  165. package/dist/processor/cache.d.ts +20 -0
  166. package/dist/processor/cache.js +127 -0
  167. package/dist/processor/config.d.ts +11 -0
  168. package/dist/processor/config.js +81 -0
  169. package/dist/processor/defaults.d.ts +30 -0
  170. package/dist/processor/defaults.js +72 -0
  171. package/dist/processor/diagnostic.d.ts +15 -0
  172. package/dist/processor/diagnostic.js +102 -0
  173. package/dist/processor/diff.d.ts +30 -0
  174. package/dist/processor/diff.js +140 -0
  175. package/dist/processor/error.d.ts +23 -0
  176. package/dist/processor/error.js +95 -0
  177. package/dist/processor/hash.d.ts +10 -0
  178. package/dist/processor/hash.js +63 -0
  179. package/dist/processor/hook.d.ts +44 -0
  180. package/dist/processor/hook.js +204 -0
  181. package/dist/processor/hot-new-incremental.d.ts +14 -0
  182. package/dist/processor/hot-new-incremental.js +43 -0
  183. package/dist/processor/hot-step.d.ts +18 -0
  184. package/dist/processor/hot-step.js +299 -0
  185. package/dist/processor/hot.d.ts +17 -0
  186. package/dist/processor/hot.js +138 -0
  187. package/dist/processor/index.d.ts +20 -0
  188. package/dist/processor/index.js +36 -0
  189. package/dist/processor/multi.d.ts +17 -0
  190. package/dist/processor/multi.js +73 -0
  191. package/dist/processor/normal.d.ts +12 -0
  192. package/dist/processor/normal.js +150 -0
  193. package/dist/processor/simple.d.ts +23 -0
  194. package/dist/processor/simple.js +49 -0
  195. package/dist/processor/snapshot.d.ts +12 -0
  196. package/dist/processor/snapshot.js +62 -0
  197. package/dist/processor/stats-api.d.ts +18 -0
  198. package/dist/processor/stats-api.js +48 -0
  199. package/dist/processor/stats.d.ts +18 -0
  200. package/dist/processor/stats.js +206 -0
  201. package/dist/processor/treeshaking.d.ts +10 -0
  202. package/dist/processor/treeshaking.js +33 -0
  203. package/dist/processor/watch.d.ts +29 -0
  204. package/dist/processor/watch.js +234 -0
  205. package/dist/reporter/diff-html.d.ts +15 -0
  206. package/dist/reporter/diff-html.js +69 -0
  207. package/dist/reporter/diff-stats.d.ts +24 -0
  208. package/dist/reporter/diff-stats.js +131 -0
  209. package/dist/reporter/index.d.ts +2 -0
  210. package/dist/reporter/index.js +18 -0
  211. package/dist/runner/basic.d.ts +10 -0
  212. package/dist/runner/basic.js +63 -0
  213. package/dist/runner/cache.d.ts +5 -0
  214. package/dist/runner/cache.js +90 -0
  215. package/dist/runner/hot-step.d.ts +5 -0
  216. package/dist/runner/hot-step.js +87 -0
  217. package/dist/runner/hot.d.ts +5 -0
  218. package/dist/runner/hot.js +83 -0
  219. package/dist/runner/index.d.ts +9 -0
  220. package/dist/runner/index.js +25 -0
  221. package/dist/runner/multiple.d.ts +11 -0
  222. package/dist/runner/multiple.js +38 -0
  223. package/dist/runner/normal.d.ts +5 -0
  224. package/dist/runner/normal.js +20 -0
  225. package/dist/runner/runner/basic.d.ts +30 -0
  226. package/dist/runner/runner/basic.js +107 -0
  227. package/dist/runner/runner/cjs.d.ts +14 -0
  228. package/dist/runner/runner/cjs.js +151 -0
  229. package/dist/runner/runner/esm.d.ts +7 -0
  230. package/dist/runner/runner/esm.js +125 -0
  231. package/dist/runner/runner/index.d.ts +8 -0
  232. package/dist/runner/runner/index.js +24 -0
  233. package/dist/runner/runner/normal.d.ts +9 -0
  234. package/dist/runner/runner/normal.js +23 -0
  235. package/dist/runner/runner/watch.d.ts +16 -0
  236. package/dist/runner/runner/watch.js +27 -0
  237. package/dist/runner/runner/web/fake.d.ts +18 -0
  238. package/dist/runner/runner/web/fake.js +143 -0
  239. package/dist/runner/runner/web/jsdom.d.ts +26 -0
  240. package/dist/runner/runner/web/jsdom.js +219 -0
  241. package/dist/runner/runner/web.d.ts +15 -0
  242. package/dist/runner/runner/web.js +32 -0
  243. package/dist/runner/type.d.ts +42 -0
  244. package/dist/runner/type.js +9 -0
  245. package/dist/runner/watch.d.ts +7 -0
  246. package/dist/runner/watch.js +60 -0
  247. package/dist/test/context.d.ts +26 -0
  248. package/dist/test/context.js +108 -0
  249. package/dist/test/creator.d.ts +46 -0
  250. package/dist/test/creator.js +310 -0
  251. package/dist/test/simple.d.ts +5 -0
  252. package/dist/test/simple.js +43 -0
  253. package/dist/test/tester.d.ts +17 -0
  254. package/dist/test/tester.js +88 -0
  255. package/dist/type.d.ts +168 -0
  256. package/dist/type.js +22 -0
  257. package/jest.d.ts +25 -0
  258. package/package.json +116 -0
  259. package/template/diff.bundle.css +1 -0
  260. package/template/diff.bundle.js +144 -0
  261. package/template/diff.html +14 -0
  262. package/template/editor.worker.js +1 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ describe("warmup", () => {
4
+ it("should warmup webpack", done => {
5
+ let webpack = require("@rspack/core");
6
+ const END = new Error("end warmup");
7
+ webpack({
8
+ entry: "data:text/javascript,import 'data:text/javascript,'",
9
+ plugins: [
10
+ c => c.hooks.emit.tap("Warmup", () => {
11
+ throw END;
12
+ })
13
+ ]
14
+ }, err => {
15
+ webpack = undefined;
16
+ try {
17
+ // CHANGE: rspack will format error into diagnostic.
18
+ expect(err.message).toContain("end warmup");
19
+ done();
20
+ }
21
+ catch (e) {
22
+ done(e);
23
+ }
24
+ });
25
+ }, 300000);
26
+ });
@@ -0,0 +1 @@
1
+ export default function (this: any, c: string): string;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ function default_1(c) {
5
+ let content = c;
6
+ if (content.includes("NEXT_HMR")) {
7
+ content = `
8
+ ${content}
9
+ let __hmr_children__ = [...module.children];
10
+ let __hmr_used_exports__ = __hmr_children__.reduce((res, child) => {
11
+ if (__webpack_module_cache__[child]) {
12
+ res[child] = __webpack_module_cache__[child].exports;
13
+ }
14
+ return res;
15
+ }, {});
16
+ module.hot.accept(__hmr_children__, () => {
17
+ __hmr_children__.forEach((child) => {
18
+ const reexports = __webpack_require__(child);
19
+ for (let key in reexports) {
20
+ if (!__hmr_used_exports__[child]) { continue; }
21
+ Object.defineProperty(__hmr_used_exports__[child], key, {
22
+ configurable: true,
23
+ enumerable: true,
24
+ get: () => reexports[key]
25
+ });
26
+ }
27
+ });
28
+ });
29
+ `;
30
+ }
31
+ content = content.replace(/NEXT_HMR/g, "NEXT_HMR.bind(null, module)");
32
+ const options = this.getOptions();
33
+ const items = content.split(/---+\r?\n/g);
34
+ if (items.length <= 1) {
35
+ return content;
36
+ }
37
+ options.totalUpdates = Math.max(options.totalUpdates, items.length);
38
+ options.changedFiles.push(this.resourcePath);
39
+ return items[options.updateIndex];
40
+ }
@@ -0,0 +1,7 @@
1
+ export declare function parseModules(content: string, options?: {
2
+ bootstrap?: boolean;
3
+ renameModule?: (name: string) => string;
4
+ }): {
5
+ modules: Record<string, string>;
6
+ runtimeModules: Record<string, string>;
7
+ };
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseModules = parseModules;
4
+ const BOOTSTRAP_SPLIT_LINE = "/************************************************************************/";
5
+ const MODULE_START_FLAG = "/* start::";
6
+ const MODULE_END_FLAG = "/* end::";
7
+ const MODULE_FLAG_END = " */";
8
+ function getStringBetween(raw, position, start, end) {
9
+ const startFlagIndex = raw.indexOf(start, position);
10
+ if (startFlagIndex === -1) {
11
+ return {
12
+ result: null,
13
+ remain: position
14
+ };
15
+ }
16
+ const endFlagIndex = raw.indexOf(end, startFlagIndex + start.length);
17
+ if (endFlagIndex === -1) {
18
+ return {
19
+ result: null,
20
+ remain: position
21
+ };
22
+ }
23
+ return {
24
+ result: raw.slice(startFlagIndex + start.length, endFlagIndex),
25
+ remain: endFlagIndex + end.length
26
+ };
27
+ }
28
+ function isValidModule(name) {
29
+ if (name.startsWith("data:")) {
30
+ return false;
31
+ }
32
+ if (name.startsWith("https:")) {
33
+ return false;
34
+ }
35
+ return true;
36
+ }
37
+ function parseModules(content, options = {}) {
38
+ const modules = {};
39
+ const runtimeModules = {};
40
+ let currentPosition = 0;
41
+ if (options.bootstrap) {
42
+ // parse bootstrap code
43
+ const bootstrap = getStringBetween(content, 0, BOOTSTRAP_SPLIT_LINE, BOOTSTRAP_SPLIT_LINE);
44
+ if (bootstrap.result) {
45
+ runtimeModules["webpack/runtime/bootstrap"] = bootstrap.result;
46
+ }
47
+ }
48
+ // parse module & runtime module code
49
+ let moduleName = getStringBetween(content, currentPosition, MODULE_START_FLAG, MODULE_FLAG_END).result;
50
+ while (moduleName) {
51
+ const moduleContent = getStringBetween(content, currentPosition, `${MODULE_START_FLAG}${moduleName}${MODULE_FLAG_END}`, `${MODULE_END_FLAG}${moduleName}${MODULE_FLAG_END}`);
52
+ if (!moduleContent.result) {
53
+ throw new Error(`Module code parsed error: ${moduleName}`);
54
+ }
55
+ const renamedModuleName = typeof options.renameModule === "function"
56
+ ? options.renameModule(moduleName)
57
+ : moduleName;
58
+ if (moduleName.startsWith("webpack/runtime")) {
59
+ runtimeModules[renamedModuleName] = moduleContent.result;
60
+ }
61
+ else {
62
+ if (isValidModule(moduleName)) {
63
+ modules[renamedModuleName] = moduleContent.result;
64
+ }
65
+ }
66
+ currentPosition = moduleContent.remain;
67
+ moduleName = getStringBetween(content, currentPosition, MODULE_START_FLAG, MODULE_FLAG_END).result;
68
+ }
69
+ return {
70
+ modules,
71
+ runtimeModules
72
+ };
73
+ }
@@ -0,0 +1,7 @@
1
+ import type { Compiler } from "@rspack/core";
2
+ import type { TUpdateOptions } from "../../type";
3
+ export declare class TestHotUpdatePlugin {
4
+ private updateOptions;
5
+ constructor(updateOptions: TUpdateOptions);
6
+ apply(compiler: Compiler): void;
7
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestHotUpdatePlugin = void 0;
4
+ class TestHotUpdatePlugin {
5
+ constructor(updateOptions) {
6
+ this.updateOptions = updateOptions;
7
+ }
8
+ apply(compiler) {
9
+ let isRebuild = false;
10
+ compiler.hooks.beforeRun.tap("TestHotUpdatePlugin", () => {
11
+ if (isRebuild) {
12
+ compiler.modifiedFiles = new Set(this.updateOptions.changedFiles);
13
+ }
14
+ else {
15
+ compiler.modifiedFiles = new Set();
16
+ }
17
+ this.updateOptions.changedFiles = [];
18
+ isRebuild = true;
19
+ });
20
+ compiler.hooks.compilation.tap("TestHotUpdatePlugin", compilation => {
21
+ compilation.hooks.additionalTreeRuntimeRequirements.tap("HMR_TEST_PLUGIN", (_chunk, set) => {
22
+ set.add(compiler.webpack.RuntimeGlobals.moduleCache);
23
+ });
24
+ compilation.hooks.runtimeModule.tap("HMR_TEST_PLUGIN", (module, _set) => {
25
+ if (module.constructorName === "DefinePropertyGettersRuntimeModule") {
26
+ module.source.source = Buffer.from(`
27
+ __webpack_require__.d = function (exports, definition) {
28
+ for (var key in definition) {
29
+ if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
30
+ Object.defineProperty(exports, key, { configurable: true, enumerable: true, get: definition[key] });
31
+ }
32
+ }
33
+ };
34
+ `, "utf-8");
35
+ }
36
+ });
37
+ });
38
+ }
39
+ }
40
+ exports.TestHotUpdatePlugin = TestHotUpdatePlugin;
@@ -0,0 +1 @@
1
+ export * from "./hot-update";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./hot-update"), exports);
@@ -0,0 +1,2 @@
1
+ import type { ECompilerType, TCompilerOptions } from "../type";
2
+ export declare function readConfigFile<T extends ECompilerType>(files: string[], functionApply?: (config: (TCompilerOptions<T> | ((...args: unknown[]) => TCompilerOptions<T>))[]) => TCompilerOptions<T>[]): TCompilerOptions<T>[];
@@ -0,0 +1,13 @@
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.readConfigFile = readConfigFile;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ function readConfigFile(files, functionApply) {
9
+ const existsFile = files.find(i => fs_extra_1.default.existsSync(i));
10
+ const fileConfig = existsFile ? require(existsFile) : {};
11
+ const configArr = Array.isArray(fileConfig) ? fileConfig : [fileConfig];
12
+ return functionApply ? functionApply(configArr) : configArr;
13
+ }
@@ -0,0 +1,2 @@
1
+ import type { Plugins } from "pretty-format";
2
+ export declare const serializers: Plugins;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializers = void 0;
4
+ const diff_1 = require("./expect/diff");
5
+ const error_1 = require("./expect/error");
6
+ const placeholder_1 = require("./expect/placeholder");
7
+ const rspack_1 = require("./expect/rspack");
8
+ exports.serializers = [
9
+ {
10
+ test(received) {
11
+ return typeof received === "string";
12
+ },
13
+ print(received) {
14
+ return (0, placeholder_1.normalizePlaceholder)(received.trim());
15
+ }
16
+ },
17
+ // for diff
18
+ {
19
+ test(received) {
20
+ return received?.constructor?.name === "RspackTestDiff";
21
+ },
22
+ print(received, next) {
23
+ return next((0, diff_1.normalizeDiff)(received));
24
+ }
25
+ },
26
+ // for errors
27
+ {
28
+ test(received) {
29
+ return received?.constructor?.name === "RspackStatsDiagnostics";
30
+ },
31
+ print(received, next) {
32
+ return next((0, error_1.normalizeDignostics)(received));
33
+ }
34
+ },
35
+ {
36
+ test(received) {
37
+ return typeof received?.message === "string";
38
+ },
39
+ print(received, next) {
40
+ return next((0, error_1.normalizeError)(received));
41
+ }
42
+ },
43
+ // for stats
44
+ {
45
+ test(received) {
46
+ return received?.constructor?.name === "RspackStats";
47
+ },
48
+ print(received, next) {
49
+ return next((0, rspack_1.normalizeStats)(received));
50
+ }
51
+ }
52
+ ];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ if (process.env.ALTERNATIVE_SORT) {
5
+ const oldSort = Array.prototype.sort;
6
+ Array.prototype.sort = function (cmp) {
7
+ oldSort.call(this, cmp);
8
+ if (cmp) {
9
+ for (let i = 1; i < this.length; i++) {
10
+ if (cmp(this[i - 1], this[i]) === 0) {
11
+ let j = i + 1;
12
+ for (; j < this.length; j++) {
13
+ if (cmp(this[j - 1], this[j]) !== 0) {
14
+ break;
15
+ }
16
+ }
17
+ for (let x = i - 1, y = j - 1; x < y; x++, y--) {
18
+ const temp = this[x];
19
+ this[x] = this[y];
20
+ this[y] = temp;
21
+ }
22
+ i = j;
23
+ }
24
+ }
25
+ }
26
+ return this;
27
+ };
28
+ }
29
+ // Setup debugging info for tests
30
+ if (process.env.DEBUG_INFO) {
31
+ const addDebugInfo = it => {
32
+ return (name, fn, timeout) => {
33
+ if (fn.length === 0) {
34
+ it(name, () => {
35
+ process.stdout.write(`START1 ${name}\n`);
36
+ try {
37
+ const promise = fn();
38
+ if (promise?.then) {
39
+ return promise.then(r => {
40
+ process.stdout.write(`DONE OK ${name}\n`);
41
+ return r;
42
+ }, e => {
43
+ process.stdout.write(`DONE FAIL ${name}\n`);
44
+ throw e;
45
+ });
46
+ }
47
+ process.stdout.write(`DONE OK ${name}\n`);
48
+ }
49
+ catch (e) {
50
+ process.stdout.write(`DONE FAIL ${name}\n`);
51
+ throw e;
52
+ }
53
+ }, timeout);
54
+ }
55
+ else {
56
+ it(name, done => {
57
+ process.stdout.write(`START2 ${name}\n`);
58
+ return fn(err => {
59
+ if (err) {
60
+ process.stdout.write(`DONE FAIL ${name}\n`);
61
+ }
62
+ else {
63
+ process.stdout.write(`DONE OK ${name}\n`);
64
+ }
65
+ return done(err);
66
+ });
67
+ }, timeout);
68
+ }
69
+ };
70
+ };
71
+ // eslint-disable-next-line no-global-assign
72
+ it = addDebugInfo(it);
73
+ }
74
+ // cspell:word wabt
75
+ // Workaround for a memory leak in wabt
76
+ // It leaks an Error object on construction
77
+ // so it leaks the whole stack trace
78
+ require("wast-loader");
79
+ process.removeAllListeners("uncaughtException");
80
+ process.removeAllListeners("unhandledRejection");
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const to_be_typeof_1 = require("./expect/to-be-typeof");
4
+ const to_end_with_1 = require("./expect/to-end-with");
5
+ const to_match_file_snapshot_1 = require("./expect/to-match-file-snapshot");
6
+ const serializers_1 = require("./serializers");
7
+ expect.extend({
8
+ // CHANGE: new test matcher for `rspack-test-tools`
9
+ // @ts-ignore
10
+ toMatchFileSnapshot: to_match_file_snapshot_1.toMatchFileSnapshot,
11
+ toBeTypeOf: to_be_typeof_1.toBeTypeOf,
12
+ toEndWith: to_end_with_1.toEndWith
13
+ });
14
+ for (const serializer of serializers_1.serializers) {
15
+ expect.addSnapshotSerializer(serializer);
16
+ }
@@ -0,0 +1 @@
1
+ export declare function isUpdateSnapshot(): boolean;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isUpdateSnapshot = isUpdateSnapshot;
4
+ function isUpdateSnapshot() {
5
+ return global.updateSnapshot || process.env.UPDATE_SNAPSHOT === "true";
6
+ }
@@ -0,0 +1 @@
1
+ export default function checkSourceMap(out: any, outCodeMap: any, toSearch: any, _checkColumn?: boolean): Promise<boolean>;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = checkSourceMap;
4
+ // @ts-nocheck
5
+ // Check the mapping of various key locations back to the original source
6
+ async function checkSourceMap(out, outCodeMap, toSearch, _checkColumn = true // passing `false` indicating it's an `OriginalSource`.
7
+ ) {
8
+ let failed = false;
9
+ const recordCheck = (success, message) => {
10
+ if (!success) {
11
+ failed = true;
12
+ console.error(`❌ ${message}`);
13
+ }
14
+ };
15
+ const sourceMap = require("source-map");
16
+ const path = require("node:path");
17
+ const sources = JSON.parse(outCodeMap).sources;
18
+ for (const source of sources) {
19
+ if (sources.filter(s => s === source).length > 1) {
20
+ throw new Error(`Duplicate source ${JSON.stringify(source)} found in source map`);
21
+ }
22
+ }
23
+ const map = await new sourceMap.SourceMapConsumer(outCodeMap);
24
+ for (const id in toSearch) {
25
+ const isSearchConfig = typeof toSearch[id] === "object" && toSearch[id] !== null;
26
+ const outId = isSearchConfig ? (toSearch[id].outId ?? id) : id;
27
+ const checkColumn = isSearchConfig
28
+ ? (toSearch[id].checkColumn ?? _checkColumn)
29
+ : _checkColumn;
30
+ const inSource = isSearchConfig ? toSearch[id].inSource : toSearch[id];
31
+ const outIndex = out.indexOf(outId);
32
+ if (outIndex < 0)
33
+ throw new Error(`Failed to find "${outId}" in output ${out}`);
34
+ const outLines = out.slice(0, outIndex).split("\n");
35
+ const outLine = outLines.length;
36
+ const outLastLine = outLines[outLines.length - 1];
37
+ let outColumn = outLastLine.length;
38
+ const { source, line, column } = map.originalPositionFor({
39
+ line: outLine,
40
+ column: outColumn
41
+ });
42
+ recordCheck(source === inSource, `expected source: ${inSource}, observed source: ${source}@${line}:${column}, {out_source}@${outLine}:${outColumn}. ${checkColumn ? "" : "(column ignored)"}`);
43
+ const inCode = map.sourceContentFor(source);
44
+ let inIndex = inCode.indexOf(id);
45
+ if (inIndex < 0)
46
+ inIndex = inCode.indexOf(`'${id}'`);
47
+ if (inIndex < 0)
48
+ throw new Error(`Failed to find "${id}" in input ${inCode}`);
49
+ const inLines = inCode.slice(0, inIndex).split("\n");
50
+ const inLine = inLines.length;
51
+ const inLastLine = inLines[inLines.length - 1];
52
+ let inColumn = inLastLine.length;
53
+ if (path.extname(source) === "css") {
54
+ const outMatch = /\s*content:\s*$/.exec(outLastLine);
55
+ const inMatch = /\bcontent:\s*$/.exec(inLastLine);
56
+ if (outMatch)
57
+ outColumn -= outMatch[0].length;
58
+ if (inMatch)
59
+ inColumn -= inMatch[0].length;
60
+ }
61
+ const expected = JSON.stringify({
62
+ source,
63
+ line: inLine,
64
+ column: checkColumn ? inColumn : 0
65
+ });
66
+ const observed = JSON.stringify({ source, line, column });
67
+ recordCheck(expected === observed, `expected original position: ${expected}, observed original position: ${observed}, out: ${`${outLine},${outColumn},${outIndex}:${outId}`}, ${checkColumn ? "" : "(column ignored)"}`);
68
+ // Also check the reverse mapping
69
+ const positions = map.allGeneratedPositionsFor({
70
+ source,
71
+ line: inLine,
72
+ column: checkColumn ? inColumn : 0
73
+ });
74
+ recordCheck(positions.length > 0, `expected generated positions: 1, observed generated positions: ${positions.length} ${checkColumn ? "" : "(column ignored)"}`);
75
+ let found = false;
76
+ for (const { line, column } of positions) {
77
+ if (line === outLine) {
78
+ if (!checkColumn && column === 0) {
79
+ found = true;
80
+ break;
81
+ }
82
+ if (checkColumn && column === outColumn) {
83
+ found = true;
84
+ break;
85
+ }
86
+ }
87
+ }
88
+ const expectedPosition = JSON.stringify({
89
+ line: outLine,
90
+ column: outColumn
91
+ });
92
+ const observedPositions = JSON.stringify(positions);
93
+ recordCheck(found, `expected generated position: ${expectedPosition}, observed generated positions: ${observedPositions} ${checkColumn ? "" : "(column ignored)"}`);
94
+ }
95
+ return !failed;
96
+ }
@@ -0,0 +1,2 @@
1
+ export function checkChunkModules(statsJson: any, chunkModulesMap: any, strict?: boolean): boolean;
2
+ export function checkChunkRuntime(statsJson: any, chunkModulesMap: any, strict?: boolean): boolean;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ exports.checkChunkModules = function checkChunkModules(statsJson, chunkModulesMap, strict = true) {
4
+ for (const chunkId of Reflect.ownKeys(chunkModulesMap)) {
5
+ const chunk = getChunk(statsJson, chunkId);
6
+ const expectedModules = chunkModulesMap[chunkId];
7
+ const chunkModules = chunk.modules.map(m => m.identifier);
8
+ if (strict && expectedModules.length !== chunkModules.length) {
9
+ throw new Error(`expect chunk ${chunkId} has ${chunkModules.length} modules: ${chunkModules}\nbut received ${chunkModules.length} modules`);
10
+ }
11
+ for (const module of expectedModules) {
12
+ if (!chunkModules.find(moduleId => moduleId.includes(module))) {
13
+ throw new Error(`chunk ${chunkId} has no module contains id: ${module}`);
14
+ }
15
+ }
16
+ }
17
+ return true;
18
+ };
19
+ exports.checkChunkRuntime = function checkChunkModules(statsJson, chunkModulesMap, strict = true) {
20
+ for (const chunkId of Reflect.ownKeys(chunkModulesMap)) {
21
+ const chunk = getChunk(statsJson, chunkId);
22
+ const expectedRuntime = chunkModulesMap[chunkId];
23
+ const chunkRuntime = chunk.runtime;
24
+ if (strict) {
25
+ expectedRuntime.length === chunkRuntime.length;
26
+ }
27
+ for (let i = 0; i < expectedRuntime.length; i++) {
28
+ const expected = expectedRuntime[i];
29
+ const rt = chunkRuntime[i];
30
+ if (expected !== rt) {
31
+ throw new Error(`chunk ${chunkId} runtime not equal, expected: ${expectedRuntime}, but got: ${chunkRuntime}`);
32
+ }
33
+ }
34
+ }
35
+ return true;
36
+ };
37
+ function getChunk(statsJson, id) {
38
+ const chunk = statsJson.chunks.find(chunk => chunk.id.includes(id));
39
+ if (!chunk) {
40
+ throw new Error(`cannot find chunk with id: ${id}`);
41
+ }
42
+ return chunk;
43
+ }
@@ -0,0 +1 @@
1
+ export const step: {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ exports.step = {};
@@ -0,0 +1,2 @@
1
+ declare function _exports(): (...regexp: any[]) => void;
2
+ export = _exports;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ module.exports = () => {
4
+ const warnings = [];
5
+ let oldWarn;
6
+ beforeEach(done => {
7
+ oldWarn = console.warn;
8
+ console.warn = m => warnings.push(m);
9
+ done();
10
+ });
11
+ afterEach(done => {
12
+ expectWarning();
13
+ console.warn = oldWarn;
14
+ done();
15
+ });
16
+ const expectWarning = (...regexp) => {
17
+ expect(warnings).toEqual(regexp.map(r => expect.stringMatching(r)));
18
+ warnings.length = 0;
19
+ };
20
+ return expectWarning;
21
+ };
@@ -0,0 +1,8 @@
1
+ export namespace FilteredStatus {
2
+ let TODO: string;
3
+ let PARTIAL_PASS: string;
4
+ let FAILED: string;
5
+ let NO_PLAN: string;
6
+ }
7
+ export function decodeFilteredTest(encoded: any): any;
8
+ export function normalizeFilteredTestName(flag: any, testName: any): string;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ const FilteredStatus = {
4
+ TODO: "TODO",
5
+ PARTIAL_PASS: "PARTIAL_PASS",
6
+ FAILED: "FAILED",
7
+ NO_PLAN: "NO_PLAN"
8
+ };
9
+ function validateFilteredStatus(status) {
10
+ return Object.values(FilteredStatus).includes(status);
11
+ }
12
+ function normalizeFilterFlag(flag, testName) {
13
+ if (flag === false) {
14
+ return { status: FilteredStatus.TODO, reason: "TODO" };
15
+ }
16
+ if (flag === -1) {
17
+ return { status: FilteredStatus.NO_PLAN, reason: "No plan" };
18
+ }
19
+ if (typeof flag === "string") {
20
+ return { status: FilteredStatus.FAILED, reason: flag };
21
+ }
22
+ if (Array.isArray(flag)) {
23
+ const [status, reason = "empty"] = flag;
24
+ if (validateFilteredStatus(status)) {
25
+ return { status, reason };
26
+ }
27
+ }
28
+ throw new Error(`Unvalidate filter flag "${flag}" for "${testName}"`);
29
+ }
30
+ function encodeFilteredTest(status, reason) {
31
+ return `{{ status = ${status}, reason = ${reason} }}`;
32
+ }
33
+ function decodeFilteredTest(encoded) {
34
+ const regex = /(.*) {{ status = (.*), reason = (.*) }}$/;
35
+ const result = encoded.match(regex);
36
+ if (result === null) {
37
+ return result;
38
+ }
39
+ const [, fullName, status, reason] = result;
40
+ return { fullName, status, reason };
41
+ }
42
+ function normalizeFilteredTestName(flag, testName) {
43
+ const { status, reason } = normalizeFilterFlag(flag, testName);
44
+ return encodeFilteredTest(status, reason);
45
+ }
46
+ module.exports = {
47
+ FilteredStatus,
48
+ decodeFilteredTest,
49
+ normalizeFilteredTestName
50
+ };