@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,18 @@
1
+ import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
2
+ import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";
3
+ export interface IStatsProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {
4
+ snapshotName?: string;
5
+ writeStatsOuptut?: boolean;
6
+ }
7
+ export declare class StatsProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
8
+ private stderr;
9
+ private snapshotName?;
10
+ private writeStatsOuptut?;
11
+ constructor(_statsOptions: IStatsProcessorOptions<T>);
12
+ before(context: ITestContext): Promise<void>;
13
+ after(context: ITestContext): Promise<void>;
14
+ compiler(context: ITestContext): Promise<void>;
15
+ check(env: ITestEnv, context: ITestContext): Promise<void>;
16
+ static defaultOptions<T extends ECompilerType>(index: number, context: ITestContext): TCompilerOptions<T>;
17
+ static overrideOptions<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): void;
18
+ }
@@ -0,0 +1,206 @@
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.StatsProcessor = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const placeholder_1 = require("../helper/expect/placeholder");
10
+ const captureStdio_1 = __importDefault(require("../helper/legacy/captureStdio"));
11
+ const multi_1 = require("./multi");
12
+ const REG_ERROR_CASE = /error$/;
13
+ class RspackStats {
14
+ constructor(value) {
15
+ this.value = value;
16
+ }
17
+ }
18
+ class StatsProcessor extends multi_1.MultiTaskProcessor {
19
+ constructor(_statsOptions) {
20
+ super({
21
+ defaultOptions: (StatsProcessor.defaultOptions),
22
+ overrideOptions: (StatsProcessor.overrideOptions),
23
+ runable: false,
24
+ ..._statsOptions
25
+ });
26
+ this.snapshotName = _statsOptions.snapshotName;
27
+ this.writeStatsOuptut = _statsOptions.writeStatsOuptut;
28
+ }
29
+ async before(context) {
30
+ this.stderr = (0, captureStdio_1.default)(process.stderr, true);
31
+ }
32
+ async after(context) {
33
+ this.stderr.restore();
34
+ }
35
+ async compiler(context) {
36
+ await super.compiler(context);
37
+ const instance = this.getCompiler(context).getCompiler();
38
+ const compilers = instance.compilers
39
+ ? instance.compilers
40
+ : [instance];
41
+ for (const compiler of compilers) {
42
+ if (!compiler.inputFileSystem) {
43
+ continue;
44
+ }
45
+ const ifs = compiler.inputFileSystem;
46
+ const inputFileSystem = Object.create(ifs);
47
+ compiler.inputFileSystem = inputFileSystem;
48
+ inputFileSystem.readFile = (...args) => {
49
+ const callback = args.pop();
50
+ ifs.readFile.apply(ifs, args.concat([
51
+ (err, result) => {
52
+ if (err)
53
+ return callback(err);
54
+ if (!/\.(js|json|txt)$/.test(args[0]))
55
+ return callback(null, result);
56
+ callback(null, (0, placeholder_1.normalizePlaceholder)(result.toString("utf-8")));
57
+ }
58
+ ]));
59
+ };
60
+ // CHANGE: The checkConstraints() function is currently not implemented in rspack
61
+ // compiler.hooks.compilation.tap("StatsTestCasesTest", compilation => {
62
+ // [
63
+ // "optimize",
64
+ // "optimizeModules",
65
+ // "optimizeChunks",
66
+ // "afterOptimizeTree",
67
+ // "afterOptimizeAssets",
68
+ // "beforeHash"
69
+ // ].forEach(hook => {
70
+ // compilation.hooks[hook].tap("TestCasesTest", () =>
71
+ // compilation.checkConstraints()
72
+ // );
73
+ // });
74
+ // });
75
+ }
76
+ }
77
+ async check(env, context) {
78
+ const compiler = this.getCompiler(context);
79
+ const stats = compiler.getStats();
80
+ const c = compiler.getCompiler();
81
+ if (!stats || !c)
82
+ return;
83
+ for (const compilation of []
84
+ .concat(stats.stats || stats)
85
+ .map((s) => s.compilation)) {
86
+ compilation.logging.delete("webpack.Compilation.ModuleProfile");
87
+ }
88
+ if (REG_ERROR_CASE.test(this._options.name)) {
89
+ env.expect(stats.hasErrors()).toBe(true);
90
+ }
91
+ else if (stats.hasErrors()) {
92
+ throw new Error(stats.toString({
93
+ all: false,
94
+ errors: true
95
+ // errorStack: true,
96
+ // errorDetails: true
97
+ }));
98
+ }
99
+ else if (this.writeStatsOuptut) {
100
+ node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
101
+ preset: "verbose",
102
+ // context: context.getSource(),
103
+ colors: false
104
+ }), "utf-8");
105
+ }
106
+ let toStringOptions = {
107
+ context: context.getSource(),
108
+ colors: false
109
+ };
110
+ let hasColorSetting = false;
111
+ if (typeof c.options.stats !== "undefined") {
112
+ toStringOptions = c.options.stats;
113
+ if (toStringOptions === null || typeof toStringOptions !== "object")
114
+ toStringOptions = { preset: toStringOptions };
115
+ if (!toStringOptions.context)
116
+ toStringOptions.context = context.getSource();
117
+ hasColorSetting = typeof toStringOptions.colors !== "undefined";
118
+ }
119
+ if (Array.isArray(c.options) && !toStringOptions.children) {
120
+ toStringOptions.children = c.options.map(o => o.stats);
121
+ }
122
+ // mock timestamps
123
+ for (const { compilation: s } of [].concat(stats.stats || stats)) {
124
+ env.expect(s.startTime).toBeGreaterThan(0);
125
+ env.expect(s.endTime).toBeGreaterThan(0);
126
+ s.endTime = new Date("04/20/1970, 12:42:42 PM").getTime();
127
+ s.startTime = s.endTime - 1234;
128
+ }
129
+ let actual = stats.toString(toStringOptions);
130
+ env.expect(typeof actual).toBe("string");
131
+ actual = this.stderr.toString() + actual;
132
+ if (!hasColorSetting) {
133
+ actual = actual
134
+ .replace(/\u001b\[[0-9;]*m/g, "")
135
+ // CHANGE: The time unit display in Rspack is second
136
+ .replace(/[.0-9]+(\s?s)/g, "X$1")
137
+ // CHANGE: Replace bundle size, since bundle sizes may differ between platforms
138
+ .replace(/[0-9]+\.?[0-9]+ KiB/g, "xx KiB");
139
+ }
140
+ if (this.snapshotName) {
141
+ env.expect(new RspackStats(actual)).toMatchSnapshot(this.snapshotName);
142
+ }
143
+ else {
144
+ env.expect(new RspackStats(actual)).toMatchSnapshot();
145
+ }
146
+ const testConfig = context.getTestConfig();
147
+ if (typeof testConfig?.validate === "function") {
148
+ testConfig.validate(stats, this.stderr.toString());
149
+ }
150
+ }
151
+ static defaultOptions(index, context) {
152
+ if (node_fs_1.default.existsSync(node_path_1.default.join(context.getSource(), "rspack.config.js"))) {
153
+ return {
154
+ experiments: {
155
+ css: true,
156
+ rspackFuture: {
157
+ bundlerInfo: {
158
+ force: false
159
+ }
160
+ }
161
+ }
162
+ };
163
+ }
164
+ return {
165
+ context: context.getSource(),
166
+ mode: "development",
167
+ entry: "./index.js",
168
+ output: {
169
+ filename: "bundle.js",
170
+ path: context.getDist()
171
+ },
172
+ optimization: {
173
+ minimize: false
174
+ },
175
+ experiments: {
176
+ css: true,
177
+ rspackFuture: {
178
+ bundlerInfo: {
179
+ force: false
180
+ }
181
+ }
182
+ }
183
+ };
184
+ }
185
+ static overrideOptions(index, context, options) {
186
+ if (!options.context)
187
+ options.context = context.getSource();
188
+ if (!options.output)
189
+ options.output = options.output || {};
190
+ if (!options.output.path)
191
+ options.output.path = context.getDist();
192
+ if (!options.plugins)
193
+ options.plugins = [];
194
+ if (!options.optimization)
195
+ options.optimization = {};
196
+ if (options.optimization.minimize === undefined) {
197
+ options.optimization.minimize = false;
198
+ }
199
+ if (!global.printLogger) {
200
+ options.infrastructureLogging = {
201
+ level: "error"
202
+ };
203
+ }
204
+ }
205
+ }
206
+ exports.StatsProcessor = StatsProcessor;
@@ -0,0 +1,10 @@
1
+ import type { ECompilerType, ITestContext, TCompilerOptions } from "../type";
2
+ import { type ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot";
3
+ export interface ITreeShakingProcessorOptions<T extends ECompilerType> extends Omit<ISnapshotProcessorOptions<T>, "runable"> {
4
+ }
5
+ export declare class TreeShakingProcessor<T extends ECompilerType> extends SnapshotProcessor<T> {
6
+ protected _treeShakingOptions: ITreeShakingProcessorOptions<T>;
7
+ constructor(_treeShakingOptions: ITreeShakingProcessorOptions<T>);
8
+ static overrideOptions<T extends ECompilerType>(context: ITestContext, options: TCompilerOptions<T>): void;
9
+ serializeEachFile(content: string): string;
10
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TreeShakingProcessor = void 0;
4
+ const placeholder_1 = require("../helper/expect/placeholder");
5
+ const builtin_1 = require("./builtin");
6
+ const snapshot_1 = require("./snapshot");
7
+ class TreeShakingProcessor extends snapshot_1.SnapshotProcessor {
8
+ constructor(_treeShakingOptions) {
9
+ super({
10
+ defaultOptions: builtin_1.BuiltinProcessor.defaultOptions,
11
+ overrideOptions: (TreeShakingProcessor.overrideOptions),
12
+ runable: false,
13
+ ..._treeShakingOptions
14
+ });
15
+ this._treeShakingOptions = _treeShakingOptions;
16
+ }
17
+ static overrideOptions(context, options) {
18
+ options.target = options.target || ["web", "es2022"];
19
+ options.optimization ??= {};
20
+ options.optimization.providedExports = true;
21
+ options.optimization.innerGraph = true;
22
+ options.optimization.usedExports = true;
23
+ if (!global.printLogger) {
24
+ options.infrastructureLogging = {
25
+ level: "error"
26
+ };
27
+ }
28
+ }
29
+ serializeEachFile(content) {
30
+ return (0, placeholder_1.normalizePlaceholder)(content);
31
+ }
32
+ }
33
+ exports.TreeShakingProcessor = TreeShakingProcessor;
@@ -0,0 +1,29 @@
1
+ import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
2
+ import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";
3
+ export interface IWatchProcessorOptions<T extends ECompilerType> extends IMultiTaskProcessorOptions<T> {
4
+ stepName: string;
5
+ tempDir: string;
6
+ }
7
+ export declare class WatchProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
8
+ protected _watchOptions: IWatchProcessorOptions<T>;
9
+ protected _watchState: Record<string, any>;
10
+ protected currentTriggerFilename: string | null;
11
+ protected lastHash: string | null;
12
+ constructor(_watchOptions: IWatchProcessorOptions<T>, _watchState: Record<string, any>);
13
+ compiler(context: ITestContext): Promise<void>;
14
+ build(context: ITestContext): Promise<void>;
15
+ run(env: ITestEnv, context: ITestContext): Promise<void>;
16
+ check(env: ITestEnv, context: ITestContext): Promise<void>;
17
+ config(context: ITestContext): Promise<void>;
18
+ static overrideOptions<T extends ECompilerType>({ tempDir, name }: IWatchProcessorOptions<T>): (index: number, context: ITestContext, options: TCompilerOptions<ECompilerType>) => void;
19
+ static findBundle<T extends ECompilerType>(this: IWatchProcessorOptions<T>, index: number, context: ITestContext, options: TCompilerOptions<T>): string | string[];
20
+ }
21
+ export interface IWatchStepProcessorOptions<T extends ECompilerType> extends Omit<IWatchProcessorOptions<T>, "experiments" | "optimization"> {
22
+ }
23
+ export declare class WatchStepProcessor<T extends ECompilerType> extends WatchProcessor<T> {
24
+ protected _watchOptions: IWatchStepProcessorOptions<T>;
25
+ protected _watchState: Record<string, any>;
26
+ constructor(_watchOptions: IWatchStepProcessorOptions<T>, _watchState: Record<string, any>);
27
+ compiler(context: ITestContext): Promise<void>;
28
+ build(context: ITestContext): Promise<void>;
29
+ }
@@ -0,0 +1,234 @@
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.WatchStepProcessor = exports.WatchProcessor = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const webpack_merge_1 = require("webpack-merge");
10
+ const compiler_1 = require("../compiler");
11
+ const helper_1 = require("../helper");
12
+ const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
13
+ const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
14
+ const multi_1 = require("./multi");
15
+ // This file is used to port step number to rspack.config.js/webpack.config.js
16
+ const currentWatchStepModulePath = node_path_1.default.resolve(__dirname, "../helper/util/currentWatchStep");
17
+ class WatchProcessor extends multi_1.MultiTaskProcessor {
18
+ constructor(_watchOptions, _watchState) {
19
+ super({
20
+ overrideOptions: WatchProcessor.overrideOptions(_watchOptions),
21
+ findBundle: (WatchProcessor.findBundle),
22
+ ..._watchOptions
23
+ });
24
+ this._watchOptions = _watchOptions;
25
+ this._watchState = _watchState;
26
+ this.currentTriggerFilename = null;
27
+ this.lastHash = null;
28
+ }
29
+ async compiler(context) {
30
+ await super.compiler(context);
31
+ const compiler = this.getCompiler(context).getCompiler();
32
+ compiler.hooks.invalid.tap("WatchTestCasesTest", (filename, mtime) => {
33
+ this.currentTriggerFilename = filename;
34
+ });
35
+ }
36
+ async build(context) {
37
+ const compiler = this.getCompiler(context);
38
+ const currentWatchStepModule = require(currentWatchStepModulePath);
39
+ currentWatchStepModule.step[this._options.name] =
40
+ this._watchOptions.stepName;
41
+ node_fs_1.default.mkdirSync(this._watchOptions.tempDir, { recursive: true });
42
+ (0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), this._watchOptions.tempDir, true);
43
+ const task = new Promise((resolve, reject) => {
44
+ compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
45
+ if (e)
46
+ return reject(e);
47
+ resolve(stats);
48
+ });
49
+ });
50
+ compiler.watch();
51
+ await task;
52
+ }
53
+ async run(env, context) {
54
+ context.setValue(this._options.name, "watchStepName", this._watchOptions.stepName);
55
+ context.setValue(this._options.name, "watchState", this._watchState);
56
+ await super.run(env, context);
57
+ }
58
+ async check(env, context) {
59
+ const testConfig = context.getTestConfig();
60
+ if (testConfig.noTest)
61
+ return;
62
+ const errors = (context.getError(this._options.name) || []).map(e => ({
63
+ message: e.message,
64
+ stack: e.stack
65
+ }));
66
+ const warnings = [];
67
+ const compiler = this.getCompiler(context);
68
+ const stats = compiler.getStats();
69
+ const checkStats = testConfig.checkStats || (() => true);
70
+ if (stats) {
71
+ if (testConfig.writeStatsOuptut) {
72
+ node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
73
+ preset: "verbose",
74
+ colors: false
75
+ }), "utf-8");
76
+ }
77
+ const getJsonStats = (() => {
78
+ let cached = null;
79
+ return () => {
80
+ if (!cached) {
81
+ cached = stats.toJson({
82
+ errorDetails: true
83
+ });
84
+ }
85
+ return cached;
86
+ };
87
+ })();
88
+ const getStringStats = (() => {
89
+ let cached = null;
90
+ return () => {
91
+ if (!cached) {
92
+ cached = stats.toString({
93
+ logging: "verbose"
94
+ });
95
+ }
96
+ return cached;
97
+ };
98
+ })();
99
+ if (checkStats.length > 1) {
100
+ if (!checkStats(this._watchOptions.stepName, getJsonStats(), getStringStats())) {
101
+ throw new Error("stats check failed");
102
+ }
103
+ }
104
+ else {
105
+ // @ts-expect-error only one param
106
+ if (!checkStats(this._watchOptions.stepName)) {
107
+ throw new Error("stats check failed");
108
+ }
109
+ }
110
+ if (testConfig.writeStatsJson) {
111
+ node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.json"), JSON.stringify(getJsonStats(), null, 2), "utf-8");
112
+ }
113
+ if (node_fs_1.default.existsSync(context.getSource(`${this._watchOptions.stepName}/errors.js`)) ||
114
+ node_fs_1.default.existsSync(context.getSource(`${this._watchOptions.stepName}/warnings.js`)) ||
115
+ stats.hasErrors() ||
116
+ stats.hasWarnings()) {
117
+ const statsJson = stats.toJson({
118
+ errorDetails: true
119
+ });
120
+ if (statsJson.errors) {
121
+ errors.push(...statsJson.errors);
122
+ }
123
+ if (statsJson.warnings) {
124
+ warnings.push(...statsJson.warnings);
125
+ }
126
+ }
127
+ }
128
+ await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { errors }, "error", "errors", "Error");
129
+ await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { warnings }, "warning", "warnings", "Warning");
130
+ // clear error if checked
131
+ if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
132
+ context.clearError(this._options.name);
133
+ }
134
+ // check hash
135
+ if (testConfig.writeStatsOuptut) {
136
+ node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.txt"), node_path_1.default.join(context.getDist(), `stats.${this._watchOptions.stepName}.txt`));
137
+ }
138
+ if (testConfig.writeStatsJson) {
139
+ node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.json"), node_path_1.default.join(context.getDist(), `stats.${this._watchOptions.stepName}.json`));
140
+ }
141
+ }
142
+ async config(context) {
143
+ this.multiCompilerOptions = [];
144
+ const caseOptions = Array.isArray(this._multiOptions.configFiles)
145
+ ? (0, helper_1.readConfigFile)(this._multiOptions.configFiles.map(i => context.getSource(i)))
146
+ : [{}];
147
+ for (const [index, options] of caseOptions.entries()) {
148
+ const compilerOptions = (0, webpack_merge_1.merge)(typeof this._multiOptions.defaultOptions === "function"
149
+ ? this._multiOptions.defaultOptions(index, context)
150
+ : {}, options);
151
+ if (typeof this._multiOptions.overrideOptions === "function") {
152
+ this._multiOptions.overrideOptions(index, context, compilerOptions);
153
+ }
154
+ this.multiCompilerOptions.push(compilerOptions);
155
+ }
156
+ const compilerOptions = this.multiCompilerOptions.length === 1
157
+ ? this.multiCompilerOptions[0]
158
+ : this.multiCompilerOptions;
159
+ const compiler = this.getCompiler(context);
160
+ compiler.setOptions(compilerOptions);
161
+ }
162
+ static overrideOptions({ tempDir, name }) {
163
+ return (index, context, options) => {
164
+ if (!options.mode)
165
+ options.mode = "development";
166
+ if (!options.context)
167
+ options.context = tempDir;
168
+ if (!options.entry)
169
+ options.entry = "./index.js";
170
+ if (!options.target)
171
+ options.target = "async-node";
172
+ if (!options.devtool)
173
+ options.devtool = false;
174
+ if (!options.output)
175
+ options.output = {};
176
+ if (!options.output.path)
177
+ options.output.path = context.getDist();
178
+ if (typeof options.output.pathinfo === "undefined")
179
+ options.output.pathinfo = false;
180
+ if (!options.output.filename)
181
+ options.output.filename = "bundle.js";
182
+ if (options.cache && options.cache.type === "filesystem") {
183
+ const cacheDirectory = node_path_1.default.join(tempDir, ".cache");
184
+ options.cache.cacheDirectory = cacheDirectory;
185
+ options.cache.name = `config-${index}`;
186
+ }
187
+ options.optimization ??= {};
188
+ options.experiments ??= {};
189
+ options.experiments.css ??= true;
190
+ options.experiments.rspackFuture ??= {};
191
+ options.experiments.rspackFuture.bundlerInfo ??= {};
192
+ options.experiments.rspackFuture.bundlerInfo.force ??= false;
193
+ if (!global.printLogger) {
194
+ options.infrastructureLogging = {
195
+ level: "error"
196
+ };
197
+ }
198
+ };
199
+ }
200
+ static findBundle(index, context, options) {
201
+ const testConfig = context.getTestConfig();
202
+ if (typeof testConfig.findBundle === "function") {
203
+ return testConfig.findBundle(index, options, this.stepName);
204
+ }
205
+ return "./bundle.js";
206
+ }
207
+ }
208
+ exports.WatchProcessor = WatchProcessor;
209
+ class WatchStepProcessor extends WatchProcessor {
210
+ constructor(_watchOptions, _watchState) {
211
+ super(_watchOptions, _watchState);
212
+ this._watchOptions = _watchOptions;
213
+ this._watchState = _watchState;
214
+ }
215
+ async compiler(context) {
216
+ // do nothing
217
+ }
218
+ async build(context) {
219
+ const compiler = this.getCompiler(context);
220
+ const currentWatchStepModule = require(currentWatchStepModulePath);
221
+ currentWatchStepModule.step[this._options.name] =
222
+ this._watchOptions.stepName;
223
+ const task = new Promise((resolve, reject) => {
224
+ compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
225
+ if (e)
226
+ return reject(e);
227
+ resolve(stats);
228
+ });
229
+ });
230
+ (0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), this._watchOptions.tempDir, false);
231
+ await task;
232
+ }
233
+ }
234
+ exports.WatchStepProcessor = WatchStepProcessor;
@@ -0,0 +1,15 @@
1
+ import type { ITestReporter, TModuleCompareResult } from "../type";
2
+ export interface IDiffHtmlReporterOptions {
3
+ dist: string;
4
+ ignore?: RegExp;
5
+ }
6
+ export declare class DiffHtmlReporter implements ITestReporter<TModuleCompareResult[]> {
7
+ private options;
8
+ private failed;
9
+ private results;
10
+ constructor(options: IDiffHtmlReporterOptions);
11
+ init(data?: TModuleCompareResult[]): Promise<void>;
12
+ failure(id: string): Promise<void>;
13
+ increment(id: string, data: TModuleCompareResult[]): Promise<void>;
14
+ output(): Promise<void>;
15
+ }
@@ -0,0 +1,69 @@
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.DiffHtmlReporter = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const VIEWER_DIR = node_path_1.default.join(__dirname, "../../template");
10
+ const DIFF_STATS_PLACEHOLDER = "$$RSPACK_DIFF_STATS_PLACEHOLDER$$";
11
+ const DEFAULT_IGNORE = /node_modules/;
12
+ class DiffHtmlReporter {
13
+ constructor(options) {
14
+ this.options = options;
15
+ this.failed = new Set();
16
+ this.results = new Map();
17
+ }
18
+ async init(data = []) { }
19
+ async failure(id) {
20
+ this.failed.add(id);
21
+ this.results.delete(id);
22
+ }
23
+ async increment(id, data) {
24
+ if (this.failed.has(id))
25
+ return;
26
+ if (!this.results.has(id)) {
27
+ this.results.set(id, []);
28
+ }
29
+ const ignore = this.options.ignore || DEFAULT_IGNORE;
30
+ const current = this.results.get(id);
31
+ for (const i of data) {
32
+ if (!ignore.test(i.name)) {
33
+ current.push({
34
+ name: i.name,
35
+ source: i.source || "",
36
+ dist: i.dist || "",
37
+ type: i.type
38
+ });
39
+ }
40
+ }
41
+ }
42
+ async output() {
43
+ fs_extra_1.default.ensureDirSync(this.options.dist);
44
+ for (const viewerFile of fs_extra_1.default
45
+ .readdirSync(VIEWER_DIR)
46
+ .filter(file => file.startsWith("diff"))) {
47
+ const sourceFile = node_path_1.default.join(VIEWER_DIR, viewerFile);
48
+ if (node_path_1.default.extname(viewerFile) === ".html") {
49
+ const template = fs_extra_1.default.readFileSync(sourceFile, "utf-8");
50
+ for (const [id, items] of this.results.entries()) {
51
+ const data = {
52
+ root: id,
53
+ data: items
54
+ };
55
+ const casename = node_path_1.default.basename(id);
56
+ const extname = node_path_1.default.extname(viewerFile);
57
+ const filename = node_path_1.default.basename(viewerFile, extname);
58
+ const content = template.replace(`<script id="${DIFF_STATS_PLACEHOLDER}"></script>`, `<script src="${filename}_${casename}.js"></script>`);
59
+ fs_extra_1.default.writeFileSync(node_path_1.default.join(this.options.dist, `${filename}_${casename}${extname}`), content, "utf-8");
60
+ fs_extra_1.default.writeFileSync(node_path_1.default.join(this.options.dist, `${filename}_${casename}.js`), `window.$$diff_detail$$ = ${JSON.stringify(data)}`, "utf-8");
61
+ }
62
+ }
63
+ else {
64
+ fs_extra_1.default.copyFileSync(sourceFile, node_path_1.default.join(this.options.dist, viewerFile));
65
+ }
66
+ }
67
+ }
68
+ }
69
+ exports.DiffHtmlReporter = DiffHtmlReporter;
@@ -0,0 +1,24 @@
1
+ import { ECompilerType, type ITestReporter, type TModuleCompareResult } from "../type";
2
+ export interface IDiffStatsReporterOptions {
3
+ header?: string[];
4
+ footer?: string[];
5
+ file: string;
6
+ report?: boolean;
7
+ }
8
+ export type TCompilerTypeId = ECompilerType.Rspack | ECompilerType.Webpack | "common";
9
+ export type TModuleTypeId = "normal" | "runtime";
10
+ export type TDimenTypeId = "modules" | "lines" | "lines-in-common";
11
+ export type TCaseSummaryId = `${TCompilerTypeId}|${TModuleTypeId}|${TDimenTypeId}`;
12
+ export type TCaseSummary = Record<TCaseSummaryId, number>;
13
+ export declare class DiffStatsReporter implements ITestReporter<TModuleCompareResult[]> {
14
+ private options;
15
+ private summary;
16
+ private failed;
17
+ constructor(options: IDiffStatsReporterOptions);
18
+ init(data?: TModuleCompareResult[]): Promise<void>;
19
+ failure(id: string): Promise<void>;
20
+ increment(id: string, data: TModuleCompareResult[]): Promise<void>;
21
+ output(): Promise<void>;
22
+ private stringifySummary;
23
+ private createSummary;
24
+ }