@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 declare const normalizePlaceholder: (val: any) => string;
@@ -0,0 +1,41 @@
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.normalizePlaceholder = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const path_serializer_1 = require("path-serializer");
9
+ // 1. escapeEOL \r\n -> \n
10
+ // 2. replace <RSPACK_ROOT> etc
11
+ // 3. transform win32 sep
12
+ const placeholderSerializer = (0, path_serializer_1.createSnapshotSerializer)({
13
+ root: __dirname.includes("node_modules")
14
+ ? // Use `process.cwd()` when using outside Rspack
15
+ process.cwd()
16
+ : node_path_1.default.resolve(__dirname, "../../../../../"),
17
+ replace: [
18
+ {
19
+ match: node_path_1.default.resolve(__dirname, "../../../"),
20
+ mark: "test_tools_root"
21
+ },
22
+ {
23
+ match: node_path_1.default.resolve(__dirname, "../../../../rspack"),
24
+ mark: "rspack_root"
25
+ },
26
+ {
27
+ match: /:\d+:\d+-\d+:\d+/g,
28
+ mark: "line_col_range"
29
+ },
30
+ {
31
+ match: /:\d+:\d+/g,
32
+ mark: "line_col"
33
+ }
34
+ ],
35
+ features: {
36
+ replaceWorkspace: false,
37
+ addDoubleQuotes: false,
38
+ escapeDoubleQuotes: false
39
+ }
40
+ });
41
+ exports.normalizePlaceholder = placeholderSerializer.serialize;
@@ -0,0 +1,3 @@
1
+ export declare const normalizeStats: (stats: {
2
+ value: string;
3
+ }) => string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeStats = void 0;
4
+ const normalizeStats = (stats) => {
5
+ return (stats.value
6
+ // CHANGE: Remove potential line break and "|" caused by long text
7
+ .replace(/((ERROR|WARNING)([\s\S](?!╭|├))*?)(\n {2}│ )/g, "$1")
8
+ // CHANGE: Update the regular expression to replace the 'Rspack' version string
9
+ .replace(/Rspack [^ )]+(\)?) compiled/g, "Rspack x.x.x$1 compiled")
10
+ .replace(/(\w)\\(\w)/g, "$1/$2")
11
+ .replace(/, additional resolving: X ms/g, "")
12
+ .replace(/Unexpected identifier '.+?'/g, "Unexpected identifier"));
13
+ };
14
+ exports.normalizeStats = normalizeStats;
@@ -0,0 +1,4 @@
1
+ export declare function toBeTypeOf(received: any, expected: any): {
2
+ message: () => string;
3
+ pass: boolean;
4
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBeTypeOf = toBeTypeOf;
4
+ // @ts-nocheck
5
+ function toBeTypeOf(received, expected) {
6
+ const objType = typeof received;
7
+ const pass = objType === expected;
8
+ const message = pass
9
+ ? () => `${this.utils.matcherHint(".not.toBeTypeOf")}\n\nExpected value to not be (using typeof):\n ${this.utils.printExpected(expected)}\nReceived:\n ${this.utils.printReceived(objType)}`
10
+ : () => `${this.utils.matcherHint(".toBeTypeOf")}\n\nExpected value to be (using typeof):\n ${this.utils.printExpected(expected)}\nReceived:\n ${this.utils.printReceived(objType)}`;
11
+ return { message, pass };
12
+ }
@@ -0,0 +1,4 @@
1
+ export declare function toEndWith(received: any, expected: any): {
2
+ message: () => string;
3
+ pass: boolean;
4
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toEndWith = toEndWith;
4
+ // @ts-nocheck
5
+ function toEndWith(received, expected) {
6
+ const pass = typeof received === "string" && received.endsWith(expected);
7
+ const message = pass
8
+ ? () => `${this.utils.matcherHint(".not.toEndWith")}\n\nExpected value to not end with:\n ${this.utils.printExpected(expected)}\nReceived:\n ${this.utils.printReceived(received)}`
9
+ : () => `${this.utils.matcherHint(".toEndWith")}\n\nExpected value to end with:\n ${this.utils.printExpected(expected)}\nReceived:\n ${this.utils.printReceived(received)}`;
10
+ return { message, pass };
11
+ }
@@ -0,0 +1,23 @@
1
+ import type { FileMatcherOptions } from "../../../jest";
2
+ /**
3
+ * Match given content against content of the specified file.
4
+ *
5
+ * @param content Output content to match
6
+ * @param filepath Path to the file to match against
7
+ * @param options Additional options for matching
8
+ */
9
+ export declare function toMatchFileSnapshot(this: {
10
+ testPath: string;
11
+ currentTestName: string;
12
+ assertionCalls: number;
13
+ isNot: boolean;
14
+ snapshotState: {
15
+ added: number;
16
+ updated: number;
17
+ unmatched: number;
18
+ _updateSnapshot: "none" | "new" | "all";
19
+ };
20
+ }, rawContent: string | Buffer, filepath: string, options?: FileMatcherOptions): {
21
+ pass: boolean;
22
+ message: () => string;
23
+ };
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.toMatchFileSnapshot = toMatchFileSnapshot;
8
+ /* istanbul ignore file */
9
+ const node_fs_1 = __importDefault(require("node:fs"));
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const chalk_1 = __importDefault(require("chalk"));
12
+ const filenamify_1 = __importDefault(require("filenamify"));
13
+ const jest_diff_1 = require("jest-diff");
14
+ const serializers_1 = require("../serializers");
15
+ const { serialize } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve("jest-snapshot")), "./utils.js"));
16
+ // get jest builtin serializers
17
+ const { getSerializers } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve("jest-snapshot")), "./plugins.js"));
18
+ /**
19
+ * Check if 2 strings or buffer are equal
20
+ */
21
+ const isEqual = (a, b) => {
22
+ // @ts-ignore: TypeScript gives error if we pass string to buffer.equals
23
+ return Buffer.isBuffer(a) ? a.equals(b) : a === b;
24
+ };
25
+ /**
26
+ * Match given content against content of the specified file.
27
+ *
28
+ * @param content Output content to match
29
+ * @param filepath Path to the file to match against
30
+ * @param options Additional options for matching
31
+ */
32
+ function toMatchFileSnapshot(rawContent, filepath, options = {}) {
33
+ const content = Buffer.isBuffer(rawContent)
34
+ ? rawContent
35
+ : serialize(rawContent, /* ident */ 2, {
36
+ plugins: [
37
+ ...getSerializers(),
38
+ // Rspack serializers
39
+ ...serializers_1.serializers
40
+ ]
41
+ });
42
+ const { isNot, snapshotState } = this;
43
+ const filename = filepath === undefined
44
+ ? // If file name is not specified, generate one from the test title
45
+ node_path_1.default.join(node_path_1.default.dirname(this.testPath), "__file_snapshots__", `${(0, filenamify_1.default)(this.currentTestName, {
46
+ replacement: "-"
47
+ }).replace(/\s/g, "-")}-${this.assertionCalls}`)
48
+ : filepath;
49
+ if (snapshotState._updateSnapshot === "none" && !node_fs_1.default.existsSync(filename)) {
50
+ // We're probably running in CI environment
51
+ snapshotState.unmatched++;
52
+ return {
53
+ pass: isNot,
54
+ message: () => `New output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} was ${chalk_1.default.bold.red("not written")}.\n\nThe update flag must be explicitly passed to write a new snapshot.\n\nThis is likely because this test is run in a ${chalk_1.default.blue("continuous integration (CI) environment")} in which snapshots are not written by default.\n\n`
55
+ };
56
+ }
57
+ if (node_fs_1.default.existsSync(filename)) {
58
+ const output = node_fs_1.default
59
+ .readFileSync(filename, Buffer.isBuffer(content) ? null : "utf8")
60
+ .replace(/\r\n/g, "\n");
61
+ if (isNot) {
62
+ // The matcher is being used with `.not`
63
+ if (!isEqual(content, output)) {
64
+ // The value of `pass` is reversed when used with `.not`
65
+ return { pass: false, message: () => "" };
66
+ }
67
+ snapshotState.unmatched++;
68
+ return {
69
+ pass: true,
70
+ message: () => `Expected received content ${chalk_1.default.red("to not match")} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.`
71
+ };
72
+ }
73
+ if (isEqual(content, output)) {
74
+ return { pass: true, message: () => "" };
75
+ }
76
+ if (snapshotState._updateSnapshot === "all") {
77
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(filename), { recursive: true });
78
+ node_fs_1.default.writeFileSync(filename, content);
79
+ snapshotState.updated++;
80
+ return { pass: true, message: () => "" };
81
+ }
82
+ snapshotState.unmatched++;
83
+ const difference = Buffer.isBuffer(content) || Buffer.isBuffer(output)
84
+ ? ""
85
+ : `\n\n${(0, jest_diff_1.diff)(output, content, Object.assign({
86
+ expand: false,
87
+ contextLines: 5,
88
+ aAnnotation: "Snapshot"
89
+ }, options.diff || {}))}`;
90
+ return {
91
+ pass: false,
92
+ message: () => `Received content ${chalk_1.default.red("doesn't match")} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.${difference}`
93
+ };
94
+ }
95
+ if (!isNot &&
96
+ (snapshotState._updateSnapshot === "new" ||
97
+ snapshotState._updateSnapshot === "all")) {
98
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(filename), { recursive: true });
99
+ node_fs_1.default.writeFileSync(filename, content);
100
+ snapshotState.added++;
101
+ return { pass: true, message: () => "" };
102
+ }
103
+ snapshotState.unmatched++;
104
+ return {
105
+ pass: true,
106
+ message: () => `The output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} ${chalk_1.default.bold.red("doesn't exist")}.`
107
+ };
108
+ }
@@ -0,0 +1 @@
1
+ export { HotUpdatePlugin } from "./plugin";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HotUpdatePlugin = void 0;
4
+ var plugin_1 = require("./plugin");
5
+ Object.defineProperty(exports, "HotUpdatePlugin", { enumerable: true, get: function () { return plugin_1.HotUpdatePlugin; } });
@@ -0,0 +1 @@
1
+ export default function (c: string): string;
@@ -0,0 +1,32 @@
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
+ return content.replace(/NEXT_HMR/g, "NEXT_HMR.bind(null, module)");
32
+ }
@@ -0,0 +1,17 @@
1
+ import type { Compiler } from "@rspack/core";
2
+ export declare class HotUpdatePlugin {
3
+ private projectDir;
4
+ private tempDir;
5
+ private initialized;
6
+ private updateIndex;
7
+ private files;
8
+ constructor(projectDir: string, tempDir: string);
9
+ private getModifiedFiles;
10
+ private getContent;
11
+ private updateFiles;
12
+ initialize(): Promise<void>;
13
+ getUpdateIndex(): number;
14
+ getTotalUpdates(): number;
15
+ goNext(): Promise<void>;
16
+ apply(compiler: Compiler): void;
17
+ }
@@ -0,0 +1,133 @@
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.HotUpdatePlugin = void 0;
7
+ const promises_1 = __importDefault(require("node:fs/promises"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ async function loopFile(dir, callback) {
10
+ const children = await promises_1.default.readdir(dir);
11
+ await Promise.all(children.map(async (filename) => {
12
+ const filePath = node_path_1.default.join(dir, filename);
13
+ const stat = await promises_1.default.stat(filePath);
14
+ if (stat.isFile()) {
15
+ const content = await promises_1.default.readFile(filePath);
16
+ callback(filePath, content.toString());
17
+ }
18
+ else if (stat.isDirectory()) {
19
+ return loopFile(filePath, callback);
20
+ }
21
+ }));
22
+ }
23
+ const PLUGIN_NAME = "HotUpdatePlugin";
24
+ class HotUpdatePlugin {
25
+ constructor(projectDir, tempDir) {
26
+ this.projectDir = projectDir;
27
+ this.tempDir = tempDir;
28
+ this.initialized = false;
29
+ this.updateIndex = 0;
30
+ this.files = {};
31
+ }
32
+ getModifiedFiles() {
33
+ return Object.keys(this.files);
34
+ }
35
+ getContent(filePath, index) {
36
+ const contents = this.files[filePath] || [];
37
+ let content = contents[index] === undefined ? contents.at(-1) || "" : contents[index];
38
+ let command = "";
39
+ const matchResult = content.match(/^<(.+?)>([\w\W]*)$/);
40
+ if (matchResult) {
41
+ command = matchResult[1];
42
+ content = matchResult[2];
43
+ }
44
+ return {
45
+ content,
46
+ command
47
+ };
48
+ }
49
+ async updateFiles() {
50
+ await Promise.all(this.getModifiedFiles().map(async (filePath) => {
51
+ const { content, command } = this.getContent(filePath, this.updateIndex);
52
+ // match command
53
+ if (command === "delete") {
54
+ await promises_1.default.unlink(filePath);
55
+ return;
56
+ }
57
+ if (command === "force_write") {
58
+ await promises_1.default.writeFile(filePath, content);
59
+ return;
60
+ }
61
+ // default
62
+ const { content: oldContent } = this.getContent(filePath, this.updateIndex - 1);
63
+ if (content === oldContent) {
64
+ return;
65
+ }
66
+ await promises_1.default.writeFile(filePath, content);
67
+ }));
68
+ }
69
+ async initialize() {
70
+ if (this.initialized) {
71
+ return;
72
+ }
73
+ this.initialized = true;
74
+ await promises_1.default.rmdir(this.tempDir, { recursive: true });
75
+ await promises_1.default.cp(this.projectDir, this.tempDir, { recursive: true });
76
+ await loopFile(this.tempDir, (filePath, content) => {
77
+ const contents = content.split(/---+\r?\n/g);
78
+ if (contents.length > 1) {
79
+ this.files[filePath] = contents;
80
+ }
81
+ });
82
+ await this.updateFiles();
83
+ }
84
+ getUpdateIndex() {
85
+ return this.updateIndex;
86
+ }
87
+ getTotalUpdates() {
88
+ return Object.values(this.files).reduce((max, item) => {
89
+ return Math.max(max, item.length);
90
+ }, 0);
91
+ }
92
+ async goNext() {
93
+ this.updateIndex++;
94
+ await this.updateFiles();
95
+ }
96
+ apply(compiler) {
97
+ const options = compiler.options;
98
+ options.context = this.tempDir;
99
+ options.module.rules ??= [];
100
+ options.module.rules.push({
101
+ test: /\.(js|css|json)/,
102
+ use: [
103
+ {
104
+ loader: node_path_1.default.resolve(__dirname, "./loader.js")
105
+ }
106
+ ]
107
+ });
108
+ let isRebuild = false;
109
+ compiler.hooks.beforeRun.tap(PLUGIN_NAME, () => {
110
+ compiler.modifiedFiles = new Set(isRebuild ? this.getModifiedFiles() : []);
111
+ isRebuild = true;
112
+ });
113
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
114
+ compilation.hooks.additionalTreeRuntimeRequirements.tap(PLUGIN_NAME, (_chunk, set) => {
115
+ set.add(compiler.webpack.RuntimeGlobals.moduleCache);
116
+ });
117
+ compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module, _set) => {
118
+ if (module.constructorName === "DefinePropertyGettersRuntimeModule") {
119
+ module.source.source = Buffer.from(`
120
+ __webpack_require__.d = function (exports, definition) {
121
+ for (var key in definition) {
122
+ if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
123
+ Object.defineProperty(exports, key, { configurable: true, enumerable: true, get: definition[key] });
124
+ }
125
+ }
126
+ };
127
+ `, "utf-8");
128
+ }
129
+ });
130
+ });
131
+ }
132
+ }
133
+ exports.HotUpdatePlugin = HotUpdatePlugin;
@@ -0,0 +1,7 @@
1
+ export * from "./directory";
2
+ export * from "./parse-modules";
3
+ export * from "./read-config-file";
4
+ export * from "./update-snapshot";
5
+ export * from "./win";
6
+ export * from "./util/checkStats";
7
+ export * from "./legacy/supportsImportFn";
@@ -0,0 +1,23 @@
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("./directory"), exports);
18
+ __exportStar(require("./parse-modules"), exports);
19
+ __exportStar(require("./read-config-file"), exports);
20
+ __exportStar(require("./update-snapshot"), exports);
21
+ __exportStar(require("./win"), exports);
22
+ __exportStar(require("./util/checkStats"), exports);
23
+ __exportStar(require("./legacy/supportsImportFn"), exports);
@@ -0,0 +1,8 @@
1
+ export = EventSource;
2
+ declare class EventSource {
3
+ constructor(url: any);
4
+ response: import("http").IncomingMessage | undefined;
5
+ close(): void;
6
+ set onopen(value: any);
7
+ set onmessage(value: any);
8
+ }
@@ -0,0 +1,40 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * The following code is modified based on
4
+ * https://github.com/webpack/webpack/blob/4b4ca3b/test/helpers/EventSourceForNode.js
5
+ *
6
+ * MIT Licensed
7
+ * Author Tobias Koppers @sokra
8
+ * Copyright (c) JS Foundation and other contributors
9
+ * https://github.com/webpack/webpack/blob/main/LICENSE
10
+ */
11
+ "use strict";
12
+ module.exports = class EventSource {
13
+ constructor(url) {
14
+ this.response = undefined;
15
+ const request = (url.startsWith("https:") ? require("node:https") : require("node:http")).request(url, {
16
+ agent: false,
17
+ headers: { accept: "text/event-stream" }
18
+ }, res => {
19
+ this.response = res;
20
+ res.on("error", err => {
21
+ if (this.onerror)
22
+ this.onerror(err);
23
+ });
24
+ });
25
+ request.on("error", err => {
26
+ if (this.onerror)
27
+ this.onerror({ message: err });
28
+ });
29
+ request.end();
30
+ }
31
+ close() {
32
+ this.response.destroy();
33
+ }
34
+ set onopen(value) {
35
+ throw new Error("not implemented");
36
+ }
37
+ set onmessage(value) {
38
+ throw new Error("not implemented");
39
+ }
40
+ };
@@ -0,0 +1,54 @@
1
+ export default class FakeDocument {
2
+ constructor(basePath: any, options?: {});
3
+ head: FakeElement;
4
+ body: FakeElement;
5
+ baseURI: string;
6
+ _elementsByTagName: Map<string, FakeElement[]>;
7
+ _basePath: any;
8
+ currentScript: any;
9
+ _options: {};
10
+ createElement(type: any): FakeElement;
11
+ _onElementAttached(element: any): void;
12
+ _onElementRemoved(element: any): void;
13
+ getElementsByTagName(name: any): FakeElement[];
14
+ querySelectorAll(name: any): FakeElement[];
15
+ getComputedStyle(element: any): {
16
+ getPropertyValue: (property: any) => any;
17
+ };
18
+ }
19
+ export class FakeElement {
20
+ constructor(document: any, type: any, basePath: any);
21
+ _document: any;
22
+ _type: any;
23
+ _basePath: any;
24
+ _children: any[];
25
+ _attributes: any;
26
+ _src: any;
27
+ _href: any;
28
+ rel: any;
29
+ parentNode: any;
30
+ sheet: FakeSheet | undefined;
31
+ cloneNode(): FakeElement;
32
+ addEventListener(): void;
33
+ insertBefore(node: any, before: any): void;
34
+ appendChild(node: any): void;
35
+ removeChild(node: any): void;
36
+ setAttribute(name: any, value: any): void;
37
+ removeAttribute(name: any): void;
38
+ getAttribute(name: any): any;
39
+ _toRealUrl(value: any): any;
40
+ set src(value: any);
41
+ get src(): any;
42
+ get children(): any[];
43
+ set href(value: any);
44
+ get href(): any;
45
+ }
46
+ export class FakeSheet {
47
+ constructor(element: any, basePath: any);
48
+ _element: any;
49
+ _basePath: any;
50
+ cachedCss: string | undefined;
51
+ cachedCssRules: any[] | undefined;
52
+ get css(): string;
53
+ get cssRules(): any[];
54
+ }