@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,100 @@
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.createHotNewIncrementalCase = createHotNewIncrementalCase;
7
+ exports.createWatchNewIncrementalCase = createWatchNewIncrementalCase;
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const hot_new_incremental_1 = require("../processor/hot-new-incremental");
11
+ const watch_1 = require("../processor/watch");
12
+ const runner_1 = require("../runner");
13
+ const creator_1 = require("../test/creator");
14
+ const type_1 = require("../type");
15
+ const hotCreators = new Map();
16
+ function getHotCreator(target, webpackCases) {
17
+ const key = JSON.stringify({ target, webpackCases });
18
+ if (!hotCreators.has(key)) {
19
+ hotCreators.set(key, new creator_1.BasicCaseCreator({
20
+ clean: true,
21
+ describe: true,
22
+ target,
23
+ steps: ({ name, target }) => [
24
+ new hot_new_incremental_1.HotNewIncrementalProcessor({
25
+ name,
26
+ target: target,
27
+ compilerType: type_1.ECompilerType.Rspack,
28
+ configFiles: ["rspack.config.js", "webpack.config.js"],
29
+ webpackCases
30
+ })
31
+ ],
32
+ runner: runner_1.HotRunnerFactory,
33
+ concurrent: true
34
+ }));
35
+ }
36
+ return hotCreators.get(key);
37
+ }
38
+ function createHotNewIncrementalCase(name, src, dist, target, webpackCases) {
39
+ const creator = getHotCreator(target, webpackCases);
40
+ creator.create(name, src, dist);
41
+ }
42
+ const watchCreators = new Map();
43
+ function getWatchCreator(options) {
44
+ const key = JSON.stringify(options);
45
+ if (!watchCreators.has(key)) {
46
+ watchCreators.set(key, new creator_1.BasicCaseCreator({
47
+ clean: true,
48
+ runner: runner_1.WatchRunnerFactory,
49
+ description: (name, index) => {
50
+ return index === 0
51
+ ? `${name} should compile`
52
+ : `should compile step ${index}`;
53
+ },
54
+ describe: false,
55
+ steps: ({ name, src, temp }) => {
56
+ const watchState = {};
57
+ const runs = node_fs_1.default
58
+ .readdirSync(src)
59
+ .sort()
60
+ .filter(name => {
61
+ return node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory();
62
+ })
63
+ .map(name => ({ name }));
64
+ return runs.map((run, index) => index === 0
65
+ ? new watch_1.WatchProcessor({
66
+ name,
67
+ stepName: run.name,
68
+ tempDir: temp,
69
+ runable: true,
70
+ compilerType: type_1.ECompilerType.Rspack,
71
+ configFiles: ["rspack.config.js", "webpack.config.js"],
72
+ defaultOptions(index, context) {
73
+ return {
74
+ experiments: {
75
+ incremental: "advance"
76
+ },
77
+ ignoreWarnings: options.ignoreNotFriendlyForIncrementalWarnings
78
+ ? [/is not friendly for incremental/]
79
+ : undefined
80
+ };
81
+ }
82
+ }, watchState)
83
+ : new watch_1.WatchStepProcessor({
84
+ name,
85
+ stepName: run.name,
86
+ tempDir: temp,
87
+ runable: true,
88
+ compilerType: type_1.ECompilerType.Rspack,
89
+ configFiles: ["rspack.config.js", "webpack.config.js"]
90
+ }, watchState));
91
+ },
92
+ concurrent: true
93
+ }));
94
+ }
95
+ return watchCreators.get(key);
96
+ }
97
+ function createWatchNewIncrementalCase(name, src, dist, temp, options = {}) {
98
+ const creator = getWatchCreator(options);
99
+ creator.create(name, src, dist, temp);
100
+ }
@@ -0,0 +1 @@
1
+ export declare function createNormalCase(name: string, src: string, dist: string): void;
@@ -0,0 +1,29 @@
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.createNormalCase = createNormalCase;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const normal_1 = require("../processor/normal");
9
+ const runner_1 = require("../runner");
10
+ const creator_1 = require("../test/creator");
11
+ const type_1 = require("../type");
12
+ const creator = new creator_1.BasicCaseCreator({
13
+ clean: true,
14
+ describe: false,
15
+ steps: ({ name }) => [
16
+ new normal_1.NormalProcessor({
17
+ name,
18
+ root: node_path_1.default.resolve(__dirname, "../../tests/normalCases"),
19
+ compilerOptions: {}, // do not used in rspack
20
+ runable: true,
21
+ compilerType: type_1.ECompilerType.Rspack
22
+ })
23
+ ],
24
+ runner: runner_1.NormalRunnerFactory,
25
+ concurrent: true
26
+ });
27
+ function createNormalCase(name, src, dist) {
28
+ creator.create(name, src, dist);
29
+ }
@@ -0,0 +1,3 @@
1
+ import { ECompilerType, type TTestConfig } from "../type";
2
+ export type TSerialCaseConfig = Omit<TTestConfig<ECompilerType.Rspack>, "validate">;
3
+ export declare function createSerialCase(name: string, src: string, dist: string): void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSerialCase = createSerialCase;
4
+ const config_1 = require("../processor/config");
5
+ const runner_1 = require("../runner");
6
+ const creator_1 = require("../test/creator");
7
+ const type_1 = require("../type");
8
+ const creator = new creator_1.BasicCaseCreator({
9
+ clean: true,
10
+ describe: false,
11
+ testConfig: testConfig => {
12
+ const oldModuleScope = testConfig.moduleScope;
13
+ testConfig.moduleScope = (ms, stats) => {
14
+ let res = ms;
15
+ // TODO: modify runner module scope based on stats here
16
+ if (typeof oldModuleScope === "function") {
17
+ res = oldModuleScope(ms, stats);
18
+ }
19
+ return res;
20
+ };
21
+ },
22
+ steps: ({ name }) => [
23
+ new config_1.ConfigProcessor({
24
+ name,
25
+ runable: true,
26
+ compilerType: type_1.ECompilerType.Rspack,
27
+ configFiles: ["rspack.config.js", "webpack.config.js"]
28
+ })
29
+ ],
30
+ runner: runner_1.MultipleRunnerFactory
31
+ });
32
+ function createSerialCase(name, src, dist) {
33
+ creator.create(name, src, dist);
34
+ }
@@ -0,0 +1,6 @@
1
+ import { type IStatsAPIProcessorOptions } from "../processor";
2
+ import { ECompilerType } from "../type";
3
+ export type TStatsAPICaseConfig = Omit<IStatsAPIProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
4
+ description: string;
5
+ };
6
+ export declare function createStatsAPICase(name: string, src: string, dist: string, testConfig: string): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStatsAPICase = createStatsAPICase;
4
+ const processor_1 = require("../processor");
5
+ const simple_1 = require("../test/simple");
6
+ const type_1 = require("../type");
7
+ let addedSerializer = false;
8
+ function createStatsAPICase(name, src, dist, testConfig) {
9
+ if (!addedSerializer) {
10
+ addedSerializer = true;
11
+ }
12
+ const caseConfig = require(testConfig);
13
+ const runner = (0, simple_1.getSimpleProcessorRunner)(src, dist);
14
+ it(caseConfig.description, async () => {
15
+ await runner(name, new processor_1.StatsAPIProcessor({
16
+ name: name,
17
+ compilerType: type_1.ECompilerType.Rspack,
18
+ ...caseConfig
19
+ }));
20
+ });
21
+ }
@@ -0,0 +1 @@
1
+ export declare function createStatsOutputCase(name: string, src: string, dist: string): void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStatsOutputCase = createStatsOutputCase;
4
+ const stats_1 = require("../processor/stats");
5
+ const creator_1 = require("../test/creator");
6
+ const type_1 = require("../type");
7
+ const creator = new creator_1.BasicCaseCreator({
8
+ clean: true,
9
+ describe: false,
10
+ steps: ({ name }) => [
11
+ new stats_1.StatsProcessor({
12
+ name,
13
+ writeStatsOuptut: false,
14
+ compilerType: type_1.ECompilerType.Rspack,
15
+ configFiles: ["rspack.config.js", "webpack.config.js"]
16
+ })
17
+ ],
18
+ description: () => "should print correct stats for"
19
+ });
20
+ function createStatsOutputCase(name, src, dist) {
21
+ creator.create(name, src, dist);
22
+ }
@@ -0,0 +1 @@
1
+ export declare function createTreeShakingCase(name: string, src: string, dist: string): void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTreeShakingCase = createTreeShakingCase;
4
+ const treeshaking_1 = require("../processor/treeshaking");
5
+ const creator_1 = require("../test/creator");
6
+ const type_1 = require("../type");
7
+ const creator = new creator_1.BasicCaseCreator({
8
+ clean: true,
9
+ describe: false,
10
+ description(name, step) {
11
+ return `${name} with newTreeshaking should match snapshot`;
12
+ },
13
+ steps: ({ name }) => [
14
+ new treeshaking_1.TreeShakingProcessor({
15
+ name,
16
+ snapshot: "treeshaking.snap.txt",
17
+ compilerType: type_1.ECompilerType.Rspack
18
+ })
19
+ ]
20
+ });
21
+ function createTreeShakingCase(name, src, dist) {
22
+ creator.create(name, src, dist);
23
+ }
@@ -0,0 +1 @@
1
+ export declare function createWatchCase(name: string, src: string, dist: string, temp: string): void;
@@ -0,0 +1,53 @@
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.createWatchCase = createWatchCase;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const watch_1 = require("../processor/watch");
10
+ const runner_1 = require("../runner");
11
+ const creator_1 = require("../test/creator");
12
+ const type_1 = require("../type");
13
+ const creator = new creator_1.BasicCaseCreator({
14
+ clean: true,
15
+ runner: runner_1.WatchRunnerFactory,
16
+ description: (name, index) => {
17
+ return index === 0
18
+ ? `${name} should compile`
19
+ : `should compile step ${index}`;
20
+ },
21
+ describe: false,
22
+ steps: ({ name, src, temp }) => {
23
+ const watchState = {};
24
+ const runs = node_fs_1.default
25
+ .readdirSync(src)
26
+ .sort()
27
+ .filter(name => {
28
+ return node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory();
29
+ })
30
+ .map(name => ({ name }));
31
+ return runs.map((run, index) => index === 0
32
+ ? new watch_1.WatchProcessor({
33
+ name,
34
+ stepName: run.name,
35
+ tempDir: temp,
36
+ runable: true,
37
+ compilerType: type_1.ECompilerType.Rspack,
38
+ configFiles: ["rspack.config.js", "webpack.config.js"]
39
+ }, watchState)
40
+ : new watch_1.WatchStepProcessor({
41
+ name,
42
+ stepName: run.name,
43
+ tempDir: temp,
44
+ runable: true,
45
+ compilerType: type_1.ECompilerType.Rspack,
46
+ configFiles: ["rspack.config.js", "webpack.config.js"]
47
+ }, watchState));
48
+ },
49
+ concurrent: true
50
+ });
51
+ function createWatchCase(name, src, dist, temp) {
52
+ creator.create(name, src, dist, temp);
53
+ }
@@ -0,0 +1,17 @@
1
+ import type { ITestReporter, TCompareModules } from "../type";
2
+ import type { IFormatCodeOptions } from "./format-code";
3
+ export interface IDiffComparatorOptions {
4
+ rspackDist: string;
5
+ webpackDist: string;
6
+ files: string[];
7
+ modules?: TCompareModules;
8
+ runtimeModules?: TCompareModules;
9
+ reporters: ITestReporter<unknown>[];
10
+ formatOptions?: IFormatCodeOptions;
11
+ bootstrap?: boolean;
12
+ }
13
+ export declare class DiffComparator {
14
+ private options;
15
+ constructor(options: IDiffComparatorOptions);
16
+ compare(): Promise<void>;
17
+ }
@@ -0,0 +1,52 @@
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.DiffComparator = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const deepmerge_1 = __importDefault(require("deepmerge"));
9
+ const compare_1 = require("./compare");
10
+ const replace_runtime_module_name_1 = require("./replace-runtime-module-name");
11
+ class DiffComparator {
12
+ constructor(options) {
13
+ this.options = options;
14
+ }
15
+ async compare() {
16
+ for (const file of this.options.files) {
17
+ try {
18
+ const result = (0, compare_1.compareFile)(node_path_1.default.join(this.options.rspackDist, file), node_path_1.default.join(this.options.webpackDist, file), {
19
+ modules: this.options.modules,
20
+ runtimeModules: this.options.runtimeModules,
21
+ format: (0, deepmerge_1.default)({
22
+ replacements: {},
23
+ ignorePropertyQuotationMark: true,
24
+ ignoreModuleId: true,
25
+ ignoreModuleArguments: true,
26
+ ignoreBlockOnlyStatement: true,
27
+ ignoreIfCertainCondition: true,
28
+ ignoreSwcHelpersPath: true,
29
+ ignoreObjectPropertySequence: true,
30
+ ignoreCssFilePath: true
31
+ }, this.options.formatOptions || {}),
32
+ renameModule: replace_runtime_module_name_1.replaceRuntimeModuleName,
33
+ bootstrap: this.options.bootstrap
34
+ });
35
+ for (const reporter of this.options.reporters) {
36
+ reporter.increment(file, result.modules.modules || []);
37
+ }
38
+ for (const reporter of this.options.reporters) {
39
+ reporter.increment(file, result.modules.runtimeModules || []);
40
+ }
41
+ }
42
+ catch (e) {
43
+ console.error(e);
44
+ for (const reporter of this.options.reporters) {
45
+ reporter.failure(file);
46
+ }
47
+ }
48
+ }
49
+ await Promise.all(this.options.reporters.map(r => r.output()));
50
+ }
51
+ }
52
+ exports.DiffComparator = DiffComparator;
@@ -0,0 +1,17 @@
1
+ import { type TCompareModules, type TCompareResult, type TFileCompareResult, type TModuleCompareResult } from "../type";
2
+ import { type IFormatCodeOptions } from "./format-code";
3
+ declare global {
4
+ var updateSnapshot: boolean;
5
+ }
6
+ export interface ICompareOptions {
7
+ modules?: TCompareModules;
8
+ runtimeModules?: TCompareModules;
9
+ format: IFormatCodeOptions;
10
+ renameModule?: (name: string) => string;
11
+ bootstrap?: boolean;
12
+ detail?: boolean;
13
+ snapshot?: string;
14
+ }
15
+ export declare function compareFile(sourceFile: string, distFile: string, compareOptions: ICompareOptions): TFileCompareResult;
16
+ export declare function compareModules(modules: string[], sourceModules: Record<string, string>, distModules: Record<string, string>, compareOptions: ICompareOptions): TModuleCompareResult[];
17
+ export declare function compareContent(sourceContent: string | false, distContent: string | false, compareOptions: ICompareOptions): TCompareResult;
@@ -0,0 +1,175 @@
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.compareFile = compareFile;
7
+ exports.compareModules = compareModules;
8
+ exports.compareContent = compareContent;
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const jest_diff_1 = require("jest-diff");
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ const helper_1 = require("../helper");
13
+ const type_1 = require("../type");
14
+ const format_code_1 = require("./format-code");
15
+ const replace_runtime_module_name_1 = require("./replace-runtime-module-name");
16
+ const WORKSPACE = node_path_1.default.resolve(__dirname, "../../../..");
17
+ function compareFile(sourceFile, distFile, compareOptions) {
18
+ const result = {
19
+ type: type_1.ECompareResultType.Same,
20
+ file: {
21
+ source: sourceFile,
22
+ dist: distFile
23
+ },
24
+ modules: {}
25
+ };
26
+ const sourceExists = fs_extra_1.default.existsSync(sourceFile);
27
+ const distExists = compareOptions.snapshot
28
+ ? fs_extra_1.default.existsSync(compareOptions.snapshot)
29
+ : fs_extra_1.default.existsSync(distFile);
30
+ if (!sourceExists && !distExists) {
31
+ result.type = type_1.ECompareResultType.Missing;
32
+ return result;
33
+ }
34
+ if (!sourceExists && distExists) {
35
+ result.type = type_1.ECompareResultType.OnlyDist;
36
+ return result;
37
+ }
38
+ if (sourceExists && !distExists) {
39
+ result.type = type_1.ECompareResultType.OnlySource;
40
+ return result;
41
+ }
42
+ function formatModules(modules) {
43
+ const res = {};
44
+ for (const [name, content] of Object.entries(modules)) {
45
+ const renamed = name.replaceAll(node_path_1.default.win32.sep, node_path_1.default.posix.sep);
46
+ if (!renamed.includes("node_modules/css-loader/dist")) {
47
+ res[renamed] = (0, format_code_1.formatCode)(renamed, content, compareOptions.format);
48
+ }
49
+ }
50
+ return res;
51
+ }
52
+ const sourceContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default.readFileSync(sourceFile, "utf-8").replaceAll(WORKSPACE, "__WORKSPACE__"));
53
+ const sourceModules = (0, helper_1.parseModules)(sourceContent, {
54
+ bootstrap: compareOptions.bootstrap,
55
+ renameModule: compareOptions.renameModule
56
+ });
57
+ sourceModules.modules = formatModules(sourceModules.modules);
58
+ sourceModules.runtimeModules = formatModules(sourceModules.runtimeModules);
59
+ let distModules = {
60
+ modules: {},
61
+ runtimeModules: {}
62
+ };
63
+ if (!global.updateSnapshot &&
64
+ compareOptions.snapshot &&
65
+ fs_extra_1.default.existsSync(compareOptions.snapshot)) {
66
+ distModules = JSON.parse(fs_extra_1.default.readFileSync(compareOptions.snapshot, "utf-8"));
67
+ }
68
+ else {
69
+ const distContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default.readFileSync(distFile, "utf-8").replaceAll(WORKSPACE, "__WORKSPACE__"));
70
+ distModules = (0, helper_1.parseModules)(distContent, {
71
+ bootstrap: compareOptions.bootstrap,
72
+ renameModule: compareOptions.renameModule
73
+ });
74
+ distModules.modules = formatModules(distModules.modules);
75
+ distModules.runtimeModules = formatModules(distModules.runtimeModules);
76
+ if (compareOptions.snapshot) {
77
+ fs_extra_1.default.ensureDirSync(node_path_1.default.dirname(compareOptions.snapshot));
78
+ fs_extra_1.default.writeFileSync(compareOptions.snapshot, JSON.stringify(distModules, null, 2));
79
+ }
80
+ }
81
+ result.type = type_1.ECompareResultType.Different;
82
+ for (const type of ["modules", "runtimeModules"]) {
83
+ const t = type;
84
+ let moduleList = [];
85
+ if (compareOptions[t] === true) {
86
+ moduleList = [
87
+ ...Object.keys(sourceModules[t]),
88
+ ...Object.keys(distModules[t])
89
+ ].filter((i, idx, arr) => arr.indexOf(i) === idx);
90
+ }
91
+ else if (Array.isArray(compareOptions[t])) {
92
+ moduleList = compareOptions[t];
93
+ }
94
+ else {
95
+ continue;
96
+ }
97
+ result.modules[t] = compareModules(moduleList, sourceModules[t], distModules[t], compareOptions);
98
+ }
99
+ return result;
100
+ }
101
+ function compareModules(modules, sourceModules, distModules, compareOptions) {
102
+ const compareResults = [];
103
+ for (const name of modules) {
104
+ const renamed = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(name).replaceAll(node_path_1.default.win32.sep, node_path_1.default.posix.sep);
105
+ const sourceContent = sourceModules[renamed];
106
+ const distContent = distModules[renamed];
107
+ compareResults.push({
108
+ ...compareContent(sourceContent, distContent, compareOptions),
109
+ name
110
+ });
111
+ }
112
+ return compareResults;
113
+ }
114
+ function compareContent(sourceContent, distContent, compareOptions) {
115
+ if (sourceContent) {
116
+ if (distContent) {
117
+ if (sourceContent === distContent) {
118
+ const lines = sourceContent.trim().split("\n").length;
119
+ return {
120
+ type: type_1.ECompareResultType.Same,
121
+ source: sourceContent,
122
+ dist: distContent,
123
+ lines: {
124
+ source: 0,
125
+ common: lines,
126
+ dist: 0
127
+ }
128
+ };
129
+ }
130
+ const difference = compareOptions.detail
131
+ ? (0, jest_diff_1.diffStringsUnified)(sourceContent.trim(), distContent.trim())
132
+ : undefined;
133
+ const diffLines = (0, jest_diff_1.diffLinesRaw)(sourceContent.trim().split("\n"), distContent.trim().split("\n"));
134
+ return {
135
+ type: type_1.ECompareResultType.Different,
136
+ detail: difference,
137
+ source: sourceContent,
138
+ dist: distContent,
139
+ lines: {
140
+ source: diffLines.filter(l => l[0] < 0).length,
141
+ common: diffLines.filter(l => l[0] === 0).length,
142
+ dist: diffLines.filter(l => l[0] > 0).length
143
+ }
144
+ };
145
+ }
146
+ return {
147
+ type: type_1.ECompareResultType.OnlySource,
148
+ source: sourceContent,
149
+ lines: {
150
+ source: sourceContent.trim().split("\n").length,
151
+ common: 0,
152
+ dist: 0
153
+ }
154
+ };
155
+ }
156
+ if (distContent) {
157
+ return {
158
+ type: type_1.ECompareResultType.OnlyDist,
159
+ dist: distContent,
160
+ lines: {
161
+ source: 0,
162
+ common: 0,
163
+ dist: distContent.trim().split("\n").length
164
+ }
165
+ };
166
+ }
167
+ return {
168
+ type: type_1.ECompareResultType.Missing,
169
+ lines: {
170
+ source: 0,
171
+ common: 0,
172
+ dist: 0
173
+ }
174
+ };
175
+ }
@@ -0,0 +1,16 @@
1
+ export interface IFormatCodeOptions {
2
+ replacements?: IFormatCodeReplacement[];
3
+ ignorePropertyQuotationMark: boolean;
4
+ ignoreModuleId: boolean;
5
+ ignoreModuleArguments: boolean;
6
+ ignoreBlockOnlyStatement: boolean;
7
+ ignoreSwcHelpersPath: boolean;
8
+ ignoreObjectPropertySequence: boolean;
9
+ ignoreCssFilePath: boolean;
10
+ ignoreIfCertainCondition: boolean;
11
+ }
12
+ export interface IFormatCodeReplacement {
13
+ from: string | RegExp;
14
+ to: string;
15
+ }
16
+ export declare function formatCode(name: string, raw: string, options: IFormatCodeOptions): string;