@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
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-present Bytedance, Inc. and its affiliates.
4
+
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ <picture>
2
+ <img alt="Rspack Banner" src="https://assets.rspack.rs/rspack/rspack-banner.png">
3
+ </picture>
4
+
5
+ # @rspack/test-tools
6
+
7
+ > Rspack's internal test tools, don't use it directly in your project, it may contain breaking change in minor & patch release right now.
8
+
9
+ Test tools for rspack.
10
+
11
+ ## Documentation
12
+
13
+ See [https://rspack.rs](https://rspack.rs) for details.
14
+
15
+ ## License
16
+
17
+ Rspack is [MIT licensed](https://github.com/web-infra-dev/rspack/blob/main/LICENSE).
@@ -0,0 +1 @@
1
+ export declare function createBuiltinCase(name: string, src: string, dist: string): void;
@@ -0,0 +1,39 @@
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.createBuiltinCase = createBuiltinCase;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const processor_1 = require("../processor");
9
+ const creator_1 = require("../test/creator");
10
+ const type_1 = require("../type");
11
+ const FILTERS = {
12
+ "plugin-css": (file) => file.endsWith(".css"),
13
+ "plugin-css-modules": (file) => file.endsWith(".css") ||
14
+ (file.endsWith(".js") && !file.includes("runtime")),
15
+ "plugin-html": (file) => file.endsWith(".html")
16
+ };
17
+ const creator = new creator_1.BasicCaseCreator({
18
+ clean: true,
19
+ describe: false,
20
+ description(name) {
21
+ return `${name} should match snapshot`;
22
+ },
23
+ steps: ({ name, src }) => {
24
+ const cat = node_path_1.default.basename(node_path_1.default.dirname(src));
25
+ const filter = FILTERS[cat];
26
+ return [
27
+ new processor_1.BuiltinProcessor({
28
+ name,
29
+ snapshot: "output.snap.txt",
30
+ snapshotFileFilter: filter,
31
+ compilerType: type_1.ECompilerType.Rspack
32
+ })
33
+ ];
34
+ },
35
+ concurrent: true
36
+ });
37
+ function createBuiltinCase(name, src, dist) {
38
+ creator.create(name, src, dist);
39
+ }
@@ -0,0 +1,2 @@
1
+ import { ECompilerType, type TCompilerOptions } from "../type";
2
+ export declare function createCacheCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], temp: string): void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCacheCase = createCacheCase;
4
+ const cache_1 = require("../processor/cache");
5
+ const runner_1 = require("../runner");
6
+ const creator_1 = require("../test/creator");
7
+ const type_1 = require("../type");
8
+ const creators = new Map();
9
+ function getCreator(target) {
10
+ if (!creators.has(target)) {
11
+ creators.set(target, new creator_1.BasicCaseCreator({
12
+ clean: true,
13
+ describe: true,
14
+ target,
15
+ steps: ({ name, src, target, temp }) => [
16
+ new cache_1.CacheProcessor({
17
+ name,
18
+ sourceDir: src,
19
+ tempDir: temp,
20
+ target: target,
21
+ compilerType: type_1.ECompilerType.Rspack,
22
+ configFiles: ["rspack.config.js", "webpack.config.js"]
23
+ })
24
+ ],
25
+ runner: runner_1.CacheRunnerFactory,
26
+ concurrent: true
27
+ }));
28
+ }
29
+ return creators.get(target);
30
+ }
31
+ function createCacheCase(name, src, dist, target, temp) {
32
+ const creator = getCreator(target);
33
+ creator.create(name, src, dist, temp);
34
+ }
@@ -0,0 +1,6 @@
1
+ import { type ISimpleProcessorOptions } from "../processor";
2
+ import { ECompilerType } from "../type";
3
+ export type TCompilerCaseConfig = Omit<ISimpleProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
4
+ description: string;
5
+ };
6
+ export declare function createCompilerCase(name: string, src: string, dist: string, testConfig: string): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCompilerCase = createCompilerCase;
4
+ const processor_1 = require("../processor");
5
+ const simple_1 = require("../test/simple");
6
+ const type_1 = require("../type");
7
+ function createCompilerCase(name, src, dist, testConfig) {
8
+ const caseConfig = require(testConfig);
9
+ const runner = (0, simple_1.getSimpleProcessorRunner)(src, dist);
10
+ it(caseConfig.description, async () => {
11
+ await runner(name, new processor_1.SimpleTaskProcessor({
12
+ name: name,
13
+ compilerType: type_1.ECompilerType.Rspack,
14
+ ...caseConfig
15
+ }));
16
+ });
17
+ }
@@ -0,0 +1,3 @@
1
+ import { ECompilerType, type TTestConfig } from "../type";
2
+ export type TConfigCaseConfig = Omit<TTestConfig<ECompilerType.Rspack>, "validate">;
3
+ export declare function createConfigCase(name: string, src: string, dist: string): void;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConfigCase = createConfigCase;
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: [
28
+ "rspack.config.cjs",
29
+ "rspack.config.js",
30
+ "webpack.config.js"
31
+ ]
32
+ })
33
+ ],
34
+ runner: runner_1.MultipleRunnerFactory,
35
+ concurrent: true
36
+ });
37
+ function createConfigCase(name, src, dist) {
38
+ creator.create(name, src, dist);
39
+ }
@@ -0,0 +1,6 @@
1
+ import { type IDefaultsConfigProcessorOptions } from "../processor";
2
+ import { ECompilerType } from "../type";
3
+ export type TDefaultsCaseConfig = Omit<IDefaultsConfigProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
4
+ description: string;
5
+ };
6
+ export declare function createDefaultsCase(name: string, src: string): void;
@@ -0,0 +1,39 @@
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.createDefaultsCase = createDefaultsCase;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const processor_1 = require("../processor");
9
+ const context_1 = require("../test/context");
10
+ const type_1 = require("../type");
11
+ const srcDir = node_path_1.default.resolve(__dirname, "../../tests/fixtures");
12
+ const distDir = node_path_1.default.resolve(__dirname, "../../tests/js/defaults");
13
+ const context = new context_1.TestContext({
14
+ src: srcDir,
15
+ dist: distDir
16
+ });
17
+ async function run(name, processor) {
18
+ try {
19
+ await processor.before?.(context);
20
+ await processor.config?.(context);
21
+ }
22
+ catch (e) {
23
+ context.emitError(name, e);
24
+ }
25
+ finally {
26
+ await processor.check?.({ expect, it, beforeEach, afterEach, jest }, context);
27
+ await processor.after?.(context);
28
+ }
29
+ }
30
+ function createDefaultsCase(name, src) {
31
+ const caseConfig = require(src);
32
+ it(`should generate the correct defaults from ${caseConfig.description}`, async () => {
33
+ await run(name, new processor_1.DefaultsConfigProcessor({
34
+ name,
35
+ compilerType: type_1.ECompilerType.Rspack,
36
+ ...caseConfig
37
+ }));
38
+ });
39
+ }
@@ -0,0 +1 @@
1
+ export declare function createDiagnosticCase(name: string, src: string, dist: string): void;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDiagnosticCase = createDiagnosticCase;
4
+ const processor_1 = require("../processor");
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 processor_1.DiagnosticProcessor({
12
+ name,
13
+ snapshot: "./stats.err",
14
+ snapshotErrors: "./raw-error.err",
15
+ snapshotWarning: "./raw-warning.err",
16
+ configFiles: ["rspack.config.js", "webpack.config.js"],
17
+ compilerType: type_1.ECompilerType.Rspack,
18
+ format: (output) => {
19
+ // TODO: change to stats.errorStack
20
+ // TODO: add `errorStack: false`
21
+ return output.replace(/(│.* at ).*/g, "$1xxx");
22
+ }
23
+ })
24
+ ],
25
+ concurrent: true
26
+ });
27
+ function createDiagnosticCase(name, src, dist) {
28
+ creator.create(name, src, dist);
29
+ }
@@ -0,0 +1,3 @@
1
+ import { type IDiffProcessorOptions } from "../processor";
2
+ export type TDiffCaseConfig = IDiffProcessorOptions;
3
+ export declare function createDiffCase(name: string, src: string, dist: string): void;
@@ -0,0 +1,126 @@
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.createDiffCase = createDiffCase;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const rimraf_1 = require("rimraf");
10
+ const createLazyTestEnv_1 = __importDefault(require("../helper/legacy/createLazyTestEnv"));
11
+ const processor_1 = require("../processor");
12
+ const tester_1 = require("../test/tester");
13
+ const type_1 = require("../type");
14
+ const DEFAULT_CASE_CONFIG = {
15
+ webpackPath: require.resolve("webpack"),
16
+ rspackPath: require.resolve("@rspack/core"),
17
+ files: ["bundle.js"],
18
+ bootstrap: true,
19
+ detail: true,
20
+ errors: false
21
+ };
22
+ function createDiffCase(name, src, dist) {
23
+ const caseConfigFile = node_path_1.default.join(src, "test.config.js");
24
+ if (!fs_extra_1.default.existsSync(caseConfigFile)) {
25
+ return;
26
+ }
27
+ const caseConfig = Object.assign({}, DEFAULT_CASE_CONFIG, require(caseConfigFile));
28
+ const [processor, compareMap] = createDiffProcessor(caseConfig);
29
+ const tester = new tester_1.Tester({
30
+ name,
31
+ src,
32
+ dist,
33
+ steps: [processor]
34
+ });
35
+ (0, rimraf_1.rimrafSync)(dist);
36
+ const prefix = node_path_1.default.basename(name);
37
+ describe(`${prefix}:check`, () => {
38
+ beforeAll(async () => {
39
+ await tester.compile();
40
+ compareMap.clear();
41
+ await tester.check(env);
42
+ });
43
+ for (const file of caseConfig.files) {
44
+ describe(`Comparing "${file}"`, () => {
45
+ let moduleResults = [];
46
+ let runtimeResults = [];
47
+ beforeAll(() => {
48
+ const fileResult = compareMap.get(file);
49
+ if (!fileResult) {
50
+ throw new Error(`File ${file} has no results`);
51
+ }
52
+ moduleResults = fileResult.modules;
53
+ runtimeResults = fileResult.runtimeModules;
54
+ });
55
+ if (caseConfig.modules) {
56
+ checkCompareResults("modules", () => moduleResults);
57
+ }
58
+ if (caseConfig.runtimeModules) {
59
+ checkCompareResults("runtime modules", () => runtimeResults);
60
+ }
61
+ });
62
+ }
63
+ const env = (0, createLazyTestEnv_1.default)(1000);
64
+ });
65
+ }
66
+ function createDiffProcessor(config) {
67
+ const fileCompareMap = new Map();
68
+ const createCompareResultHandler = (type) => {
69
+ return (file, results) => {
70
+ const fileResult = fileCompareMap.get(file) || {
71
+ modules: [],
72
+ runtimeModules: []
73
+ };
74
+ fileResult[type] = results;
75
+ fileCompareMap.set(file, fileResult);
76
+ };
77
+ };
78
+ const processor = new processor_1.DiffProcessor({
79
+ webpackPath: config.webpackPath,
80
+ rspackPath: config.rspackPath,
81
+ files: config.files,
82
+ modules: config.modules,
83
+ runtimeModules: config.runtimeModules,
84
+ renameModule: config.renameModule,
85
+ ignoreModuleId: config.ignoreModuleId ?? true,
86
+ ignoreModuleArguments: config.ignoreModuleArguments ?? true,
87
+ ignorePropertyQuotationMark: config.ignorePropertyQuotationMark ?? true,
88
+ ignoreBlockOnlyStatement: config.ignoreBlockOnlyStatement ?? true,
89
+ ignoreIfCertainCondition: config.ignoreIfCertainCondition ?? true,
90
+ ignoreSwcHelpersPath: config.ignoreSwcHelpersPath ?? true,
91
+ ignoreObjectPropertySequence: config.ignoreObjectPropertySequence ?? true,
92
+ ignoreCssFilePath: config.ignoreCssFilePath ?? true,
93
+ onCompareModules: createCompareResultHandler("modules"),
94
+ onCompareRuntimeModules: createCompareResultHandler("runtimeModules"),
95
+ bootstrap: config.bootstrap ?? true,
96
+ detail: config.detail ?? true,
97
+ errors: config.errors ?? false,
98
+ replacements: config.replacements
99
+ });
100
+ return [processor, fileCompareMap];
101
+ }
102
+ function checkCompareResults(name, getResults) {
103
+ describe(`Comparing ${name}`, () => {
104
+ it("should not miss any module", () => {
105
+ expect(getResults()
106
+ .filter(i => i.type === type_1.ECompareResultType.Missing)
107
+ .map(i => i.name)).toEqual([]);
108
+ });
109
+ it("should not have any rspack-only module", () => {
110
+ expect(getResults()
111
+ .filter(i => i.type === type_1.ECompareResultType.OnlySource)
112
+ .map(i => i.name)).toEqual([]);
113
+ });
114
+ it("should not have any webpack-only module", () => {
115
+ expect(getResults()
116
+ .filter(i => i.type === type_1.ECompareResultType.OnlyDist)
117
+ .map(i => i.name)).toEqual([]);
118
+ });
119
+ it("all modules should be the same", () => {
120
+ for (const result of getResults().filter(i => i.type === type_1.ECompareResultType.Different)) {
121
+ console.log(`${result.name}:\n${result.detail}`);
122
+ }
123
+ expect(getResults().every(i => i.type === type_1.ECompareResultType.Same)).toEqual(true);
124
+ });
125
+ });
126
+ }
@@ -0,0 +1,6 @@
1
+ import { type IErrorProcessorOptions } from "../processor";
2
+ import { ECompilerType } from "../type";
3
+ export type TErrorCaseConfig = Omit<IErrorProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
4
+ description: string;
5
+ };
6
+ export declare function createErrorCase(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.createErrorCase = createErrorCase;
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 createErrorCase(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.ErrorProcessor({
16
+ name: name,
17
+ compilerType: type_1.ECompilerType.Rspack,
18
+ ...caseConfig
19
+ }));
20
+ });
21
+ }
@@ -0,0 +1,3 @@
1
+ import { ECompilerType, type TTestConfig } from "../type";
2
+ export type THashCaseConfig = Pick<TTestConfig<ECompilerType.Rspack>, "validate">;
3
+ export declare function createHashCase(name: string, src: string, dist: string): void;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHashCase = createHashCase;
4
+ const processor_1 = require("../processor");
5
+ const creator_1 = require("../test/creator");
6
+ const type_1 = require("../type");
7
+ class HashCaseCreator extends creator_1.BasicCaseCreator {
8
+ describe(name, tester, testConfig) {
9
+ it(`should print correct hash for ${name}`, async () => {
10
+ await tester.prepare();
11
+ await tester.compile();
12
+ await tester.check(this.createEnv(testConfig));
13
+ await tester.resume();
14
+ }, 30000);
15
+ }
16
+ }
17
+ const creator = new HashCaseCreator({
18
+ clean: true,
19
+ describe: false,
20
+ steps: ({ name }) => [
21
+ new processor_1.HashProcessor({
22
+ name,
23
+ compilerType: type_1.ECompilerType.Rspack,
24
+ configFiles: ["rspack.config.js", "webpack.config.js"]
25
+ })
26
+ ]
27
+ });
28
+ function createHashCase(name, src, dist) {
29
+ creator.create(name, src, dist);
30
+ }
@@ -0,0 +1,6 @@
1
+ import { type IHookProcessorOptions } from "../processor";
2
+ import { ECompilerType } from "../type";
3
+ export type THookCaseConfig = Omit<IHookProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType" | "runable"> & {
4
+ description: string;
5
+ };
6
+ export declare function createHookCase(name: string, src: string, dist: string, source: string): void;
@@ -0,0 +1,35 @@
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.createHookCase = createHookCase;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const createLazyTestEnv_1 = __importDefault(require("../helper/legacy/createLazyTestEnv"));
9
+ const processor_1 = require("../processor");
10
+ const runner_1 = require("../runner");
11
+ const simple_1 = require("../test/simple");
12
+ const type_1 = require("../type");
13
+ function createHookCase(name, src, dist, source) {
14
+ const caseConfig = require(node_path_1.default.join(src, "test.js"));
15
+ const testName = node_path_1.default.basename(name.slice(0, name.indexOf(node_path_1.default.extname(name))));
16
+ const runner = (0, simple_1.getSimpleProcessorRunner)(source, dist, {
17
+ env: () => env,
18
+ context: () => new processor_1.HookCasesContext(src, testName, {
19
+ src: source,
20
+ dist: dist,
21
+ runnerFactory: runner_1.BasicRunnerFactory
22
+ })
23
+ });
24
+ it(caseConfig.description, async () => {
25
+ await runner(name, new processor_1.HookTaskProcessor({
26
+ name,
27
+ compilerType: type_1.ECompilerType.Rspack,
28
+ findBundle: () => ["main.js"],
29
+ snapshot: node_path_1.default.join(src, "output.snap.txt"),
30
+ runable: true,
31
+ ...caseConfig
32
+ }));
33
+ });
34
+ const env = (0, createLazyTestEnv_1.default)(10000);
35
+ }
@@ -0,0 +1,2 @@
1
+ import { ECompilerType, type TCompilerOptions } from "../type";
2
+ export declare function createHotStepCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHotStepCase = createHotStepCase;
4
+ const hot_step_1 = require("../processor/hot-step");
5
+ const runner_1 = require("../runner");
6
+ const creator_1 = require("../test/creator");
7
+ const type_1 = require("../type");
8
+ const creators = new Map();
9
+ function getCreator(target) {
10
+ if (!creators.has(target)) {
11
+ creators.set(target, new creator_1.BasicCaseCreator({
12
+ clean: true,
13
+ describe: false,
14
+ target,
15
+ steps: ({ name, target }) => [
16
+ new hot_step_1.HotSnapshotProcessor({
17
+ name,
18
+ target: target,
19
+ compilerType: type_1.ECompilerType.Rspack,
20
+ configFiles: ["rspack.config.js", "webpack.config.js"]
21
+ })
22
+ ],
23
+ runner: runner_1.HotStepRunnerFactory,
24
+ concurrent: true
25
+ }));
26
+ }
27
+ return creators.get(target);
28
+ }
29
+ function createHotStepCase(name, src, dist, target) {
30
+ const creator = getCreator(target);
31
+ creator.create(name, src, dist);
32
+ }
@@ -0,0 +1,2 @@
1
+ import { ECompilerType, type TCompilerOptions } from "../type";
2
+ export declare function createHotCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHotCase = createHotCase;
4
+ const hot_1 = require("../processor/hot");
5
+ const runner_1 = require("../runner");
6
+ const creator_1 = require("../test/creator");
7
+ const type_1 = require("../type");
8
+ const creators = new Map();
9
+ function getCreator(target) {
10
+ if (!creators.has(target)) {
11
+ creators.set(target, new creator_1.BasicCaseCreator({
12
+ clean: true,
13
+ describe: true,
14
+ target,
15
+ steps: ({ name, target }) => [
16
+ new hot_1.HotProcessor({
17
+ name,
18
+ target: target,
19
+ compilerType: type_1.ECompilerType.Rspack,
20
+ configFiles: ["rspack.config.js", "webpack.config.js"]
21
+ })
22
+ ],
23
+ runner: runner_1.HotRunnerFactory,
24
+ concurrent: true
25
+ }));
26
+ }
27
+ return creators.get(target);
28
+ }
29
+ function createHotCase(name, src, dist, target) {
30
+ const creator = getCreator(target);
31
+ creator.create(name, src, dist);
32
+ }
@@ -0,0 +1,19 @@
1
+ export * from "./builtin";
2
+ export * from "./compiler";
3
+ export * from "./config";
4
+ export * from "./defaults";
5
+ export * from "./diagnostic";
6
+ export * from "./diff";
7
+ export * from "./error";
8
+ export * from "./hash";
9
+ export * from "./hook";
10
+ export * from "./hot";
11
+ export * from "./hot-step";
12
+ export * from "./normal";
13
+ export * from "./stats-api";
14
+ export * from "./stats-output";
15
+ export * from "./treeshaking";
16
+ export * from "./watch";
17
+ export * from "./new-incremental";
18
+ export * from "./cache";
19
+ export * from "./serial";
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./builtin"), exports);
18
+ __exportStar(require("./compiler"), exports);
19
+ __exportStar(require("./config"), exports);
20
+ __exportStar(require("./defaults"), exports);
21
+ __exportStar(require("./diagnostic"), exports);
22
+ __exportStar(require("./diff"), exports);
23
+ __exportStar(require("./error"), exports);
24
+ __exportStar(require("./hash"), exports);
25
+ __exportStar(require("./hook"), exports);
26
+ __exportStar(require("./hot"), exports);
27
+ __exportStar(require("./hot-step"), exports);
28
+ __exportStar(require("./normal"), exports);
29
+ __exportStar(require("./stats-api"), exports);
30
+ __exportStar(require("./stats-output"), exports);
31
+ __exportStar(require("./treeshaking"), exports);
32
+ __exportStar(require("./watch"), exports);
33
+ __exportStar(require("./new-incremental"), exports);
34
+ __exportStar(require("./cache"), exports);
35
+ __exportStar(require("./serial"), exports);
@@ -0,0 +1,6 @@
1
+ import { ECompilerType, type TCompilerOptions } from "../type";
2
+ export declare function createHotNewIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], webpackCases: boolean): void;
3
+ export type WatchNewIncrementalOptions = {
4
+ ignoreNotFriendlyForIncrementalWarnings?: boolean;
5
+ };
6
+ export declare function createWatchNewIncrementalCase(name: string, src: string, dist: string, temp: string, options?: WatchNewIncrementalOptions): void;