@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,44 +0,0 @@
1
- import { TestContext, type TTestContextOptions } from "../test/context";
2
- import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions } from "../type";
3
- import { type ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot";
4
- export declare class HookCasesContext extends TestContext {
5
- protected src: string;
6
- protected testName: string;
7
- protected options: TTestContextOptions;
8
- protected promises: Promise<void>[];
9
- protected count: number;
10
- protected snapshots: Record<string | number, Array<[string | Buffer, string]>>;
11
- protected snapshotsList: Array<string | number>;
12
- constructor(src: string, testName: string, options: TTestContextOptions);
13
- /**
14
- * Snapshot function arguments and return value.
15
- * Generated snapshot is located in the same directory with the test source.
16
- * @example
17
- * compiler.hooks.compilation("name", context.snapped((...args) => { ... }))
18
- */
19
- snapped(cb: (...args: unknown[]) => Promise<unknown>, prefix?: string): (this: any, ...args: unknown[]) => Promise<unknown>;
20
- /**
21
- * @internal
22
- */
23
- _addSnapshot(content: unknown, name: string, group: string | number): void;
24
- /**
25
- * @internal
26
- */
27
- collectSnapshots(env: ITestEnv, options?: {
28
- diff: {};
29
- }): Promise<void>;
30
- }
31
- export interface IHookProcessorOptions<T extends ECompilerType> extends ISnapshotProcessorOptions<T> {
32
- options?: (context: ITestContext) => TCompilerOptions<T>;
33
- compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
34
- check?: (context: ITestContext) => Promise<void>;
35
- }
36
- export declare class HookTaskProcessor<T extends ECompilerType> extends SnapshotProcessor<T> {
37
- protected _hookOptions: IHookProcessorOptions<T>;
38
- constructor(_hookOptions: IHookProcessorOptions<T>);
39
- config(context: ITestContext): Promise<void>;
40
- compiler(context: ITestContext): Promise<void>;
41
- check(env: ITestEnv, context: HookCasesContext): Promise<void>;
42
- static defaultOptions<T extends ECompilerType>(context: ITestContext): TCompilerOptions<T>;
43
- static overrideOptions<T extends ECompilerType>(options: TCompilerOptions<T>): void;
44
- }
@@ -1,204 +0,0 @@
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.HookTaskProcessor = exports.HookCasesContext = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const core_1 = require("@rspack/core");
9
- const jest_snapshot_1 = require("jest-snapshot");
10
- const path_serializer_1 = require("path-serializer");
11
- const pretty_format_1 = require("pretty-format");
12
- const context_1 = require("../test/context");
13
- const snapshot_1 = require("./snapshot");
14
- const srcDir = node_path_1.default.resolve(__dirname, "../../tests/fixtures");
15
- const distDir = node_path_1.default.resolve(__dirname, "../../tests/js/hook");
16
- const sourceSerializer = {
17
- test(val) {
18
- return val instanceof core_1.sources.Source;
19
- },
20
- print(val) {
21
- return val.source();
22
- }
23
- };
24
- const internalSerializer = {
25
- test(val) {
26
- return val instanceof core_1.Compiler || val instanceof core_1.Compilation;
27
- },
28
- print(val) {
29
- return JSON.stringify(`${val.constructor.name}(internal ignored)`);
30
- }
31
- };
32
- const testPathSerializer = (0, path_serializer_1.createSnapshotSerializer)({
33
- replace: [
34
- {
35
- match: srcDir,
36
- mark: "<HOOK_SRC_DIR>"
37
- },
38
- {
39
- match: distDir,
40
- mark: "<HOOK_DIST_DIR>"
41
- }
42
- ]
43
- });
44
- const escapeRegex = true;
45
- const printFunctionName = false;
46
- const normalizeNewlines = (str) => str.replace(/\r\n|\r/g, "\n");
47
- const serialize = (val, indent = 2, formatOverrides = {}) => normalizeNewlines((0, pretty_format_1.format)(val, {
48
- escapeRegex,
49
- indent,
50
- plugins: [
51
- ...(0, jest_snapshot_1.getSerializers)(),
52
- sourceSerializer,
53
- internalSerializer,
54
- testPathSerializer
55
- ],
56
- printFunctionName,
57
- ...formatOverrides
58
- }));
59
- class HookCasesContext extends context_1.TestContext {
60
- constructor(src, testName, options) {
61
- super(options);
62
- this.src = src;
63
- this.testName = testName;
64
- this.options = options;
65
- this.promises = [];
66
- this.count = 0;
67
- this.snapshots = {};
68
- this.snapshotsList = [];
69
- this.snapped = this.snapped.bind(this);
70
- }
71
- /**
72
- * Snapshot function arguments and return value.
73
- * Generated snapshot is located in the same directory with the test source.
74
- * @example
75
- * compiler.hooks.compilation("name", context.snapped((...args) => { ... }))
76
- */
77
- snapped(cb, prefix = "") {
78
- // eslint-disable-next-line
79
- const context = this;
80
- return function SNAPPED_HOOK(...args) {
81
- const group = prefix ? prefix : context.count++;
82
- context._addSnapshot(args, "input", group);
83
- const output = cb.apply(this, args);
84
- if (output && typeof output.then === "function") {
85
- let resolve;
86
- context.promises.push(new Promise(r => (resolve = r)));
87
- return output
88
- .then((o) => {
89
- context._addSnapshot(o, "output (Promise resolved)", group);
90
- return o;
91
- })
92
- .catch((o) => {
93
- context._addSnapshot(o, "output (Promise rejected)", group);
94
- return o;
95
- })
96
- .finally(resolve);
97
- }
98
- context._addSnapshot(output, "output", group);
99
- return output;
100
- };
101
- }
102
- /**
103
- * @internal
104
- */
105
- _addSnapshot(content, name, group) {
106
- const normalizedContent = Buffer.isBuffer(content)
107
- ? content
108
- : serialize(content, undefined, {
109
- escapeString: true,
110
- printBasicPrototype: true
111
- }).replace(/\r\n/g, "\n");
112
- (this.snapshots[group] = this.snapshots[group] || []).push([
113
- normalizedContent,
114
- name
115
- ]);
116
- if (!this.snapshotsList.includes(group)) {
117
- this.snapshotsList.push(group);
118
- }
119
- }
120
- /**
121
- * @internal
122
- */
123
- async collectSnapshots(env, options = {
124
- diff: {}
125
- }) {
126
- await Promise.allSettled(this.promises);
127
- if (!this.snapshotsList.length)
128
- return;
129
- const snapshots = this.snapshotsList.reduce((acc, group, index) => {
130
- const block = this.snapshots[group || index].reduce((acc, [content, name]) => {
131
- name = `## ${name || `test: ${index}`}\n\n`;
132
- const block = `\`\`\`javascript\n${content}\n\`\`\`\n`;
133
- return `${acc}${name + block}\n`;
134
- }, "");
135
- return `${acc}# ${Number.isInteger(group) ? `Group: ${index}` : group}\n\n${block}`;
136
- }, "");
137
- env
138
- .expect(snapshots)
139
- .toMatchFileSnapshot(node_path_1.default.join(this.src, "hooks.snap.txt"), options);
140
- }
141
- }
142
- exports.HookCasesContext = HookCasesContext;
143
- class HookTaskProcessor extends snapshot_1.SnapshotProcessor {
144
- constructor(_hookOptions) {
145
- super({
146
- defaultOptions: (HookTaskProcessor.defaultOptions),
147
- ..._hookOptions
148
- });
149
- this._hookOptions = _hookOptions;
150
- }
151
- async config(context) {
152
- await super.config(context);
153
- const compiler = this.getCompiler(context);
154
- if (typeof this._hookOptions.options === "function") {
155
- compiler.mergeOptions(this._hookOptions.options(context));
156
- }
157
- }
158
- async compiler(context) {
159
- await super.compiler(context);
160
- if (typeof this._hookOptions.compiler === "function") {
161
- const compiler = this.getCompiler(context);
162
- await this._hookOptions.compiler(context, compiler.getCompiler());
163
- }
164
- }
165
- async check(env, context) {
166
- await context.collectSnapshots(env);
167
- await super.check(env, context);
168
- if (typeof this._hookOptions.check === "function") {
169
- await this._hookOptions.check(context);
170
- }
171
- }
172
- static defaultOptions(context) {
173
- return {
174
- context: context.getSource(),
175
- mode: "production",
176
- target: "async-node",
177
- devtool: false,
178
- cache: false,
179
- entry: "./hook",
180
- output: {
181
- path: context.getDist()
182
- },
183
- optimization: {
184
- minimize: false
185
- },
186
- experiments: {
187
- css: true,
188
- rspackFuture: {
189
- bundlerInfo: {
190
- force: false
191
- }
192
- }
193
- }
194
- };
195
- }
196
- static overrideOptions(options) {
197
- if (!global.printLogger) {
198
- options.infrastructureLogging = {
199
- level: "error"
200
- };
201
- }
202
- }
203
- }
204
- exports.HookTaskProcessor = HookTaskProcessor;
@@ -1,14 +0,0 @@
1
- import { ECompilerType, type ITestContext, type ITestEnv, type TCompilerOptions } from "../type";
2
- import type { IBasicProcessorOptions } from "./basic";
3
- import { HotProcessor } from "./hot";
4
- export interface IHotIncrementalProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
5
- target: TCompilerOptions<T>["target"];
6
- webpackCases: boolean;
7
- }
8
- export declare class HotIncrementalProcessor<T extends ECompilerType> extends HotProcessor<T> {
9
- protected _hotOptions: IHotIncrementalProcessorOptions<T>;
10
- constructor(_hotOptions: IHotIncrementalProcessorOptions<T>);
11
- run(env: ITestEnv, context: ITestContext): Promise<void>;
12
- afterAll(context: ITestContext): Promise<void>;
13
- static defaultOptions<T extends ECompilerType>(this: HotIncrementalProcessor<T>, context: ITestContext): TCompilerOptions<T>;
14
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HotIncrementalProcessor = void 0;
4
- const type_1 = require("../type");
5
- const hot_1 = require("./hot");
6
- class HotIncrementalProcessor extends hot_1.HotProcessor {
7
- constructor(_hotOptions) {
8
- super({
9
- defaultOptions: HotIncrementalProcessor.defaultOptions,
10
- ..._hotOptions
11
- });
12
- this._hotOptions = _hotOptions;
13
- }
14
- async run(env, context) {
15
- context.setValue(this._options.name, "documentType", this._hotOptions.webpackCases ? type_1.EDocumentType.Fake : type_1.EDocumentType.JSDOM);
16
- await super.run(env, context);
17
- }
18
- async afterAll(context) {
19
- try {
20
- await super.afterAll(context);
21
- }
22
- catch (e) {
23
- const isFake = context.getValue(this._options.name, "documentType") ===
24
- type_1.EDocumentType.Fake;
25
- if (isFake && /Should run all hot steps/.test(e.message))
26
- return;
27
- throw e;
28
- }
29
- }
30
- static defaultOptions(context) {
31
- const options = super.defaultOptions(context);
32
- if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
33
- const rspackOptions = options;
34
- rspackOptions.experiments ??= {};
35
- rspackOptions.experiments.incremental ??= "advance-silent";
36
- }
37
- else {
38
- throw new Error("HotIncrementalProcessor should only used for Rspack.");
39
- }
40
- return options;
41
- }
42
- }
43
- exports.HotIncrementalProcessor = HotIncrementalProcessor;
@@ -1,18 +0,0 @@
1
- import type { THotStepRuntimeData } from "../runner";
2
- import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions, TCompilerStatsCompilation } from "../type";
3
- import { HotProcessor, type IHotProcessorOptions } from "./hot";
4
- type TModuleGetHandler = (file: string, options: TCompilerOptions<ECompilerType>) => string[];
5
- export interface IHotSnapshotProcessorOptions<T extends ECompilerType> extends IHotProcessorOptions<T> {
6
- getModuleHandler?: TModuleGetHandler;
7
- snapshot?: string;
8
- }
9
- export declare class HotSnapshotProcessor<T extends ECompilerType> extends HotProcessor<T> {
10
- protected _hotOptions: IHotSnapshotProcessorOptions<T>;
11
- private hashes;
12
- private entries;
13
- constructor(_hotOptions: IHotSnapshotProcessorOptions<T>);
14
- run(env: ITestEnv, context: ITestContext): Promise<void>;
15
- check(env: ITestEnv, context: ITestContext): Promise<void>;
16
- protected matchStepSnapshot(env: ITestEnv, context: ITestContext, step: number, stats: TCompilerStatsCompilation<T>, runtime?: THotStepRuntimeData): void;
17
- }
18
- export {};
@@ -1,304 +0,0 @@
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.HotSnapshotProcessor = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const placeholder_1 = require("../helper/expect/placeholder");
10
- const win_1 = require("../helper/win");
11
- const hot_1 = require("./hot");
12
- const NOOP_SET = new Set();
13
- const escapeLocalName = (str) => str.split(/[-<>:"/|?*.]/).join("_");
14
- const SELF_HANDLER = (file, options) => {
15
- let res = [];
16
- const hotUpdateGlobal = (_, modules) => {
17
- res = Object.keys(modules);
18
- };
19
- const hotUpdateGlobalKey = escapeLocalName(`${options.output?.hotUpdateGlobal || "webpackHotUpdate"}${options.output?.uniqueName || ""}`);
20
- global.self ??= {};
21
- global.self[hotUpdateGlobalKey] = hotUpdateGlobal;
22
- require(file);
23
- delete global.self[hotUpdateGlobalKey];
24
- if (!Object.keys(global.self).length) {
25
- delete global.self;
26
- }
27
- return res;
28
- };
29
- const NODE_HANDLER = (file) => {
30
- return Object.keys(require(file).modules) || [];
31
- };
32
- const GET_MODULE_HANDLER = {
33
- web: SELF_HANDLER,
34
- webworker: SELF_HANDLER,
35
- "async-node": NODE_HANDLER,
36
- node: NODE_HANDLER
37
- };
38
- class HotSnapshotProcessor extends hot_1.HotProcessor {
39
- constructor(_hotOptions) {
40
- super(_hotOptions);
41
- this._hotOptions = _hotOptions;
42
- this.hashes = [];
43
- this.entries = {};
44
- }
45
- async run(env, context) {
46
- context.setValue(this._options.name, "hotUpdateStepChecker", (hotUpdateContext, stats, runtime) => {
47
- const statsJson = stats.toJson({
48
- assets: true,
49
- chunks: true
50
- });
51
- const chunks = Array.from(
52
- // Some chunk fields are missing from rspack
53
- stats?.compilation.chunks || NOOP_SET);
54
- for (const entry of chunks.filter(i => i.hasRuntime())) {
55
- if (!this.entries[entry.id] && entry.runtime) {
56
- this.entries[entry.id] =
57
- // Webpack uses `string | SortableSet<string>` for `entry.runtime`
58
- typeof entry.runtime === "string"
59
- ? [entry.runtime]
60
- : Array.from(entry.runtime);
61
- }
62
- }
63
- this.matchStepSnapshot(env, context, hotUpdateContext.updateIndex, statsJson, runtime);
64
- this.hashes.push(stats.hash);
65
- });
66
- context.setValue(this._options.name, "hotUpdateStepErrorChecker", (_, stats, runtime) => {
67
- this.hashes.push(stats.hash);
68
- });
69
- await super.run(env, context);
70
- }
71
- async check(env, context) {
72
- const compiler = this.getCompiler(context);
73
- const stats = compiler.getStats();
74
- if (!stats || !stats.hash) {
75
- env.expect(false);
76
- return;
77
- }
78
- const statsJson = stats.toJson({ assets: true, chunks: true });
79
- const chunks = Array.from(
80
- // Some chunk fields are missing from rspack
81
- stats?.compilation.chunks || NOOP_SET);
82
- for (const entry of chunks.filter(i => i.hasRuntime())) {
83
- if (entry.runtime) {
84
- this.entries[entry.id] =
85
- // Webpack uses `string | SortableSet<string>` for `entry.runtime`
86
- typeof entry.runtime === "string"
87
- ? [entry.runtime]
88
- : Array.from(entry.runtime);
89
- }
90
- }
91
- let matchFailed = null;
92
- try {
93
- this.matchStepSnapshot(env, context, 0, statsJson);
94
- }
95
- catch (e) {
96
- matchFailed = e;
97
- }
98
- this.hashes.push(stats.hash);
99
- if (matchFailed) {
100
- throw matchFailed;
101
- }
102
- }
103
- matchStepSnapshot(env, context, step, stats, runtime) {
104
- const compiler = this.getCompiler(context);
105
- const compilerOptions = compiler.getOptions();
106
- const getModuleHandler = this._hotOptions.getModuleHandler ||
107
- GET_MODULE_HANDLER[compilerOptions.target];
108
- env.expect(typeof getModuleHandler).toBe("function");
109
- const lastHash = this.hashes[this.hashes.length - 1];
110
- const snapshotPath = context.getSource(`${this._hotOptions.snapshot || `__snapshots__/${compilerOptions.target}`}/${step}.snap.txt`);
111
- const title = `Case ${node_path_1.default.basename(this._options.name)}: Step ${step}`;
112
- const hotUpdateFile = [];
113
- const hotUpdateManifest = [];
114
- const changedFiles = this.updateOptions.updateIndex === 0
115
- ? []
116
- : this.updateOptions.changedFiles.map((i) => (0, win_1.escapeSep)(node_path_1.default.relative(context.getSource(), i)));
117
- changedFiles.sort();
118
- const hashes = {
119
- [lastHash || "LAST_HASH"]: "LAST_HASH",
120
- [stats.hash]: "CURRENT_HASH"
121
- };
122
- // TODO: find a better way
123
- // replace [runtime] to [runtime of id] to prevent worker hash
124
- const runtimes = {};
125
- for (const [id, runtime] of Object.entries(this.entries)) {
126
- if (typeof runtime === "string") {
127
- if (runtime !== id) {
128
- runtimes[runtime] = `[runtime of ${id}]`;
129
- }
130
- }
131
- else if (Array.isArray(runtime)) {
132
- for (const r of runtime) {
133
- if (r !== id) {
134
- runtimes[r] = `[runtime of ${id}]`;
135
- }
136
- }
137
- }
138
- }
139
- const replaceContent = (rawStr) => {
140
- let str = rawStr;
141
- const replaceContentConfig = context.getTestConfig().snapshotContent;
142
- if (replaceContentConfig) {
143
- str = replaceContentConfig(str);
144
- }
145
- return (0, placeholder_1.normalizePlaceholder)(Object.entries(hashes)
146
- .reduce((str, [raw, replacement]) => {
147
- return str.split(raw).join(replacement);
148
- }, str)
149
- .replace(/\/\/ (\d+)\s+(?=var cssReload)/, ""));
150
- };
151
- const replaceFileName = (str) => {
152
- return Object.entries({
153
- ...hashes,
154
- ...runtimes
155
- }).reduce((str, [raw, replacement]) => {
156
- return str.split(raw).join(replacement);
157
- }, str);
158
- };
159
- const fileList = stats
160
- .assets.map(i => {
161
- const fileName = i.name;
162
- const renderName = replaceFileName(fileName);
163
- const content = replaceContent(fs_extra_1.default.readFileSync(context.getDist(fileName), "utf-8"));
164
- if (fileName.endsWith("hot-update.js")) {
165
- const modules = getModuleHandler(context.getDist(fileName), compilerOptions);
166
- const runtime = [];
167
- for (const i of content.matchAll(/\/\/ (webpack\/runtime\/[\w_-]+)\s*\n/g)) {
168
- runtime.push(i[1]);
169
- }
170
- modules.sort();
171
- runtime.sort();
172
- hotUpdateFile.push({
173
- name: renderName,
174
- content,
175
- modules,
176
- runtime
177
- });
178
- return `- Update: ${renderName}, size: ${content.length}`;
179
- }
180
- if (fileName.endsWith("hot-update.json")) {
181
- const manifest = JSON.parse(content);
182
- manifest.c?.sort();
183
- manifest.r?.sort();
184
- manifest.m?.sort();
185
- hotUpdateManifest.push({
186
- name: renderName,
187
- content: JSON.stringify(manifest)
188
- });
189
- return `- Manifest: ${renderName}, size: ${i.size}`;
190
- }
191
- if (fileName.endsWith(".js")) {
192
- return `- Bundle: ${renderName}`;
193
- }
194
- })
195
- .filter(Boolean);
196
- fileList.sort();
197
- hotUpdateManifest.sort((a, b) => (a.name > b.name ? 1 : -1));
198
- hotUpdateFile.sort((a, b) => (a.name > b.name ? 1 : -1));
199
- if (runtime?.javascript) {
200
- runtime.javascript.outdatedModules.sort();
201
- runtime.javascript.updatedModules.sort();
202
- runtime.javascript.updatedRuntime.sort();
203
- runtime.javascript.acceptedModules.sort();
204
- runtime.javascript.disposedModules.sort();
205
- for (const value of Object.values(runtime.javascript.outdatedDependencies)) {
206
- value.sort();
207
- }
208
- }
209
- const content = `
210
- # ${title}
211
-
212
- ## Changed Files
213
- ${changedFiles.map(i => `- ${i}`).join("\n")}
214
-
215
- ## Asset Files
216
- ${fileList.join("\n")}
217
-
218
- ## Manifest
219
- ${hotUpdateManifest
220
- .map(i => `
221
- ### ${i.name}
222
-
223
- \`\`\`json
224
- ${i.content}
225
- \`\`\`
226
- `)
227
- .join("\n\n")}
228
-
229
- ## Update
230
-
231
- ${hotUpdateFile
232
- .map(i => `
233
- ### ${i.name}
234
-
235
- #### Changed Modules
236
- ${i.modules.map(i => `- ${i}`).join("\n")}
237
-
238
- #### Changed Runtime Modules
239
- ${i.runtime.map(i => `- ${i}`).join("\n")}
240
-
241
- #### Changed Content
242
- \`\`\`js
243
- ${i.content}
244
- \`\`\`
245
- `)
246
- .join("\n\n")}
247
-
248
-
249
- ${runtime
250
- ? `
251
- ## Runtime
252
- ### Status
253
-
254
- \`\`\`txt
255
- ${runtime.statusPath.join(" => ")}
256
- \`\`\`
257
-
258
- ${runtime.javascript
259
- ? `
260
-
261
- ### JavaScript
262
-
263
- #### Outdated
264
-
265
- Outdated Modules:
266
- ${runtime.javascript.outdatedModules.map(i => `- ${i}`).join("\n")}
267
-
268
-
269
- Outdated Dependencies:
270
- \`\`\`json
271
- ${JSON.stringify(runtime.javascript.outdatedDependencies || {}, null, 2)}
272
- \`\`\`
273
-
274
- #### Updated
275
-
276
- Updated Modules:
277
- ${runtime.javascript.updatedModules.map(i => `- ${i}`).join("\n")}
278
-
279
- Updated Runtime:
280
- ${runtime.javascript.updatedRuntime.map(i => `- \`${i}\``).join("\n")}
281
-
282
-
283
- #### Callback
284
-
285
- Accepted Callback:
286
- ${runtime.javascript.acceptedModules.map(i => `- ${i}`).join("\n")}
287
-
288
- Disposed Callback:
289
- ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
290
- `
291
- : ""}
292
-
293
- `
294
- : ""}
295
-
296
- `
297
- .replaceAll(/%3A(\d+)%2F/g, (match, capture) => {
298
- return match.replace(capture, "PORT");
299
- })
300
- .trim();
301
- env.expect(content).toMatchFileSnapshot(snapshotPath);
302
- }
303
- }
304
- exports.HotSnapshotProcessor = HotSnapshotProcessor;
@@ -1,17 +0,0 @@
1
- import { ECompilerType, type ITestContext, type ITestEnv, type ITestRunner, type TCompilerOptions, type TUpdateOptions } from "../type";
2
- import { BasicProcessor, type IBasicProcessorOptions } from "./basic";
3
- export interface IHotProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
4
- target: TCompilerOptions<T>["target"];
5
- checkSteps?: boolean;
6
- }
7
- export declare class HotProcessor<T extends ECompilerType> extends BasicProcessor<T> {
8
- protected _hotOptions: IHotProcessorOptions<T>;
9
- protected updateOptions: TUpdateOptions;
10
- protected runner: ITestRunner | null;
11
- constructor(_hotOptions: IHotProcessorOptions<T>);
12
- run(env: ITestEnv, context: ITestContext): Promise<void>;
13
- static findBundle<T extends ECompilerType>(this: HotProcessor<T>, context: ITestContext): string[];
14
- afterAll(context: ITestContext): Promise<void>;
15
- static defaultOptions<T extends ECompilerType>(this: HotProcessor<T>, context: ITestContext): TCompilerOptions<T>;
16
- static overrideOptions<T extends ECompilerType>(this: HotProcessor<T>, context: ITestContext, options: TCompilerOptions<T>): void;
17
- }