@rspack-debug/test-tools 1.4.11 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/README.md +1 -1
  2. package/dist/case/builtin.d.ts +3 -0
  3. package/dist/case/builtin.js +152 -14
  4. package/dist/case/cache.d.ts +2 -2
  5. package/dist/case/cache.js +214 -12
  6. package/dist/case/common.d.ts +11 -0
  7. package/dist/case/common.js +249 -0
  8. package/dist/case/compiler.d.ts +17 -4
  9. package/dist/case/compiler.js +149 -12
  10. package/dist/case/config.d.ts +7 -2
  11. package/dist/case/config.js +106 -18
  12. package/dist/case/defaults.d.ts +13 -4
  13. package/dist/case/defaults.js +73 -18
  14. package/dist/case/diagnostic.d.ts +6 -0
  15. package/dist/case/diagnostic.js +121 -14
  16. package/dist/case/error.d.ts +15 -4
  17. package/dist/case/error.js +137 -12
  18. package/dist/case/esm-output.d.ts +1 -0
  19. package/dist/case/esm-output.js +117 -0
  20. package/dist/case/example.d.ts +1 -0
  21. package/dist/case/example.js +57 -0
  22. package/dist/case/hash.d.ts +2 -2
  23. package/dist/case/hash.js +72 -9
  24. package/dist/case/hook.d.ts +36 -4
  25. package/dist/case/hook.js +209 -20
  26. package/dist/case/hot-step.d.ts +2 -2
  27. package/dist/case/hot-step.js +309 -13
  28. package/dist/case/hot.d.ts +11 -2
  29. package/dist/case/hot.js +217 -12
  30. package/dist/case/incremental.d.ts +2 -2
  31. package/dist/case/incremental.js +24 -45
  32. package/dist/case/index.d.ts +31 -20
  33. package/dist/case/index.js +50 -34
  34. package/dist/case/multi-compiler.d.ts +19 -0
  35. package/dist/case/multi-compiler.js +97 -0
  36. package/dist/case/{nativeWatcher.js → native-watcher.js} +11 -23
  37. package/dist/case/normal.d.ts +3 -0
  38. package/dist/case/normal.js +202 -18
  39. package/dist/case/runner.d.ts +19 -0
  40. package/dist/case/runner.js +113 -0
  41. package/dist/case/serial.d.ts +2 -2
  42. package/dist/case/serial.js +10 -14
  43. package/dist/case/stats-api.d.ts +8 -3
  44. package/dist/case/stats-api.js +69 -10
  45. package/dist/case/stats-output.d.ts +11 -0
  46. package/dist/case/stats-output.js +199 -8
  47. package/dist/case/treeshaking.js +34 -7
  48. package/dist/case/watch.d.ts +27 -0
  49. package/dist/case/watch.js +318 -22
  50. package/dist/compiler.d.ts +16 -16
  51. package/dist/compiler.js +120 -15
  52. package/dist/helper/directory.d.ts +1 -1
  53. package/dist/helper/directory.js +6 -2
  54. package/dist/helper/disable-iconv-lite-warning.d.ts +1 -0
  55. package/dist/helper/disable-iconv-lite-warning.js +12 -0
  56. package/dist/helper/expect/error.js +1 -1
  57. package/dist/helper/expect/placeholder.js +7 -7
  58. package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
  59. package/dist/helper/expect/to-match-file-snapshot.js +3 -3
  60. package/dist/helper/hot-update/loader.d.ts +2 -1
  61. package/dist/helper/hot-update/loader.js +5 -30
  62. package/dist/helper/hot-update/plugin.d.ts +1 -1
  63. package/dist/helper/hot-update/plugin.js +14 -13
  64. package/dist/helper/index.d.ts +2 -1
  65. package/dist/helper/index.js +2 -1
  66. package/dist/helper/is.d.ts +2 -0
  67. package/dist/helper/is.js +15 -0
  68. package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
  69. package/dist/helper/legacy/LogTestPlugin.js +35 -0
  70. package/dist/helper/legacy/asModule.js +0 -2
  71. package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
  72. package/dist/helper/legacy/checkArrayExpectation.js +8 -8
  73. package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
  74. package/dist/helper/legacy/createFakeWorker.js +44 -20
  75. package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
  76. package/dist/helper/legacy/createLazyTestEnv.js +3 -3
  77. package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
  78. package/dist/helper/legacy/deprecationTracking.js +41 -0
  79. package/dist/helper/legacy/expectSource.d.ts +10 -0
  80. package/dist/helper/legacy/expectSource.js +23 -0
  81. package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
  82. package/dist/helper/legacy/findOutputFiles.js +14 -0
  83. package/dist/helper/legacy/regexEscape.d.ts +2 -0
  84. package/dist/helper/legacy/regexEscape.js +5 -0
  85. package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
  86. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  87. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  88. package/dist/helper/legacy/supportsUsing.d.ts +2 -0
  89. package/dist/helper/legacy/supportsUsing.js +26 -0
  90. package/dist/helper/legacy/urlToRelativePath.js +5 -2
  91. package/dist/helper/read-config-file.d.ts +3 -2
  92. package/dist/helper/read-config-file.js +12 -2
  93. package/dist/helper/setup-env.js +26 -4
  94. package/dist/helper/setup-expect.js +2 -2
  95. package/dist/helper/setup-wasm.js +2 -2
  96. package/dist/helper/stringify-config.d.ts +2 -0
  97. package/dist/helper/stringify-config.js +43 -0
  98. package/dist/helper/util/checkStats.d.ts +0 -1
  99. package/dist/helper/util/checkStats.js +0 -18
  100. package/dist/helper/util/expectWarningFactory.js +2 -4
  101. package/dist/index.d.ts +0 -4
  102. package/dist/index.js +1 -4
  103. package/dist/plugin/index.d.ts +0 -3
  104. package/dist/plugin/index.js +0 -3
  105. package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
  106. package/dist/runner/index.d.ts +2 -9
  107. package/dist/runner/index.js +2 -9
  108. package/dist/runner/node/index.d.ts +41 -0
  109. package/dist/runner/node/index.js +450 -0
  110. package/dist/runner/web/index.d.ts +30 -0
  111. package/dist/runner/web/index.js +343 -0
  112. package/dist/test/context.d.ts +15 -18
  113. package/dist/test/context.js +52 -57
  114. package/dist/test/creator.d.ts +20 -19
  115. package/dist/test/creator.js +69 -57
  116. package/dist/test/debug.d.ts +15 -0
  117. package/dist/test/debug.js +205 -0
  118. package/dist/test/tester.d.ts +1 -0
  119. package/dist/test/tester.js +44 -6
  120. package/dist/type.d.ts +94 -64
  121. package/dist/type.js +8 -12
  122. package/package.json +22 -61
  123. package/rstest.d.ts +24 -0
  124. package/dist/case/diff.d.ts +0 -3
  125. package/dist/case/diff.js +0 -126
  126. package/dist/compare/comparator.d.ts +0 -17
  127. package/dist/compare/comparator.js +0 -52
  128. package/dist/compare/compare.d.ts +0 -17
  129. package/dist/compare/compare.js +0 -175
  130. package/dist/compare/format-code.d.ts +0 -16
  131. package/dist/compare/format-code.js +0 -239
  132. package/dist/compare/index.d.ts +0 -5
  133. package/dist/compare/index.js +0 -21
  134. package/dist/compare/replace-module-argument.d.ts +0 -1
  135. package/dist/compare/replace-module-argument.js +0 -8
  136. package/dist/compare/replace-runtime-module-name.d.ts +0 -1
  137. package/dist/compare/replace-runtime-module-name.js +0 -71
  138. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  139. package/dist/helper/legacy/FakeDocument.js +0 -278
  140. package/dist/helper/legacy/createLogger.d.ts +0 -23
  141. package/dist/helper/legacy/createLogger.js +0 -20
  142. package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
  143. package/dist/helper/legacy/supportsImportFn.js +0 -15
  144. package/dist/helper/legacy/supportsWorker.js +0 -17
  145. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  146. package/dist/helper/legacy/walkCssTokens.js +0 -761
  147. package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
  148. package/dist/helper/legacy/warmup-webpack.js +0 -26
  149. package/dist/helper/loaders/hot-update.d.ts +0 -1
  150. package/dist/helper/loaders/hot-update.js +0 -40
  151. package/dist/helper/plugins/hot-update.d.ts +0 -7
  152. package/dist/helper/plugins/hot-update.js +0 -40
  153. package/dist/helper/plugins/index.d.ts +0 -1
  154. package/dist/helper/plugins/index.js +0 -17
  155. package/dist/helper/util/currentWatchStep.d.ts +0 -1
  156. package/dist/helper/util/currentWatchStep.js +0 -2
  157. package/dist/helper/util/identifier.d.ts +0 -76
  158. package/dist/helper/util/identifier.js +0 -339
  159. package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
  160. package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
  161. package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
  162. package/dist/plugin/rspack-diff-config-plugin.js +0 -42
  163. package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
  164. package/dist/plugin/webpack-diff-config-plugin.js +0 -41
  165. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
  166. package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
  167. package/dist/processor/basic.d.ts +0 -24
  168. package/dist/processor/basic.js +0 -146
  169. package/dist/processor/builtin.d.ts +0 -9
  170. package/dist/processor/builtin.js +0 -171
  171. package/dist/processor/cache.d.ts +0 -20
  172. package/dist/processor/cache.js +0 -128
  173. package/dist/processor/config.d.ts +0 -11
  174. package/dist/processor/config.js +0 -81
  175. package/dist/processor/defaults.d.ts +0 -30
  176. package/dist/processor/defaults.js +0 -72
  177. package/dist/processor/diagnostic.d.ts +0 -15
  178. package/dist/processor/diagnostic.js +0 -102
  179. package/dist/processor/diff.d.ts +0 -30
  180. package/dist/processor/diff.js +0 -140
  181. package/dist/processor/error.d.ts +0 -23
  182. package/dist/processor/error.js +0 -95
  183. package/dist/processor/hash.d.ts +0 -10
  184. package/dist/processor/hash.js +0 -63
  185. package/dist/processor/hook.d.ts +0 -44
  186. package/dist/processor/hook.js +0 -204
  187. package/dist/processor/hot-incremental.d.ts +0 -14
  188. package/dist/processor/hot-incremental.js +0 -43
  189. package/dist/processor/hot-step.d.ts +0 -18
  190. package/dist/processor/hot-step.js +0 -304
  191. package/dist/processor/hot.d.ts +0 -17
  192. package/dist/processor/hot.js +0 -140
  193. package/dist/processor/index.d.ts +0 -20
  194. package/dist/processor/index.js +0 -36
  195. package/dist/processor/multi.d.ts +0 -17
  196. package/dist/processor/multi.js +0 -73
  197. package/dist/processor/normal.d.ts +0 -12
  198. package/dist/processor/normal.js +0 -150
  199. package/dist/processor/simple.d.ts +0 -23
  200. package/dist/processor/simple.js +0 -49
  201. package/dist/processor/snapshot.d.ts +0 -12
  202. package/dist/processor/snapshot.js +0 -66
  203. package/dist/processor/stats-api.d.ts +0 -18
  204. package/dist/processor/stats-api.js +0 -48
  205. package/dist/processor/stats.d.ts +0 -18
  206. package/dist/processor/stats.js +0 -206
  207. package/dist/processor/treeshaking.d.ts +0 -10
  208. package/dist/processor/treeshaking.js +0 -33
  209. package/dist/processor/watch.d.ts +0 -30
  210. package/dist/processor/watch.js +0 -241
  211. package/dist/reporter/diff-html.d.ts +0 -15
  212. package/dist/reporter/diff-html.js +0 -69
  213. package/dist/reporter/diff-stats.d.ts +0 -24
  214. package/dist/reporter/diff-stats.js +0 -131
  215. package/dist/reporter/index.d.ts +0 -2
  216. package/dist/reporter/index.js +0 -18
  217. package/dist/runner/basic.d.ts +0 -10
  218. package/dist/runner/basic.js +0 -63
  219. package/dist/runner/cache.d.ts +0 -5
  220. package/dist/runner/cache.js +0 -90
  221. package/dist/runner/hot-step.d.ts +0 -5
  222. package/dist/runner/hot-step.js +0 -87
  223. package/dist/runner/hot.d.ts +0 -5
  224. package/dist/runner/hot.js +0 -83
  225. package/dist/runner/multiple.d.ts +0 -11
  226. package/dist/runner/multiple.js +0 -38
  227. package/dist/runner/normal.d.ts +0 -5
  228. package/dist/runner/normal.js +0 -20
  229. package/dist/runner/runner/basic.d.ts +0 -30
  230. package/dist/runner/runner/basic.js +0 -107
  231. package/dist/runner/runner/cjs.d.ts +0 -14
  232. package/dist/runner/runner/cjs.js +0 -151
  233. package/dist/runner/runner/esm.d.ts +0 -7
  234. package/dist/runner/runner/esm.js +0 -125
  235. package/dist/runner/runner/index.d.ts +0 -8
  236. package/dist/runner/runner/index.js +0 -24
  237. package/dist/runner/runner/normal.d.ts +0 -9
  238. package/dist/runner/runner/normal.js +0 -23
  239. package/dist/runner/runner/watch.d.ts +0 -16
  240. package/dist/runner/runner/watch.js +0 -27
  241. package/dist/runner/runner/web/fake.d.ts +0 -18
  242. package/dist/runner/runner/web/fake.js +0 -143
  243. package/dist/runner/runner/web/jsdom.d.ts +0 -26
  244. package/dist/runner/runner/web/jsdom.js +0 -219
  245. package/dist/runner/runner/web.d.ts +0 -15
  246. package/dist/runner/runner/web.js +0 -32
  247. package/dist/runner/type.d.ts +0 -42
  248. package/dist/runner/type.js +0 -9
  249. package/dist/runner/watch.d.ts +0 -7
  250. package/dist/runner/watch.js +0 -60
  251. package/dist/test/simple.d.ts +0 -5
  252. package/dist/test/simple.js +0 -43
  253. package/jest.d.ts +0 -25
  254. package/template/diff.bundle.css +0 -1
  255. package/template/diff.bundle.js +0 -144
  256. package/template/diff.html +0 -14
  257. package/template/editor.worker.js +0 -1
  258. /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
  259. /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
@@ -0,0 +1,19 @@
1
+ import type { StatsCompilation } from "@rspack/core";
2
+ import type { ITestContext, ITestEnv, ITestRunner } from "../type";
3
+ export type THotStepRuntimeLangData = {
4
+ outdatedModules: string[];
5
+ outdatedDependencies: Record<string, string[]>;
6
+ updatedModules: string[];
7
+ updatedRuntime: string[];
8
+ acceptedModules: string[];
9
+ disposedModules: string[];
10
+ };
11
+ export type THotStepRuntimeData = {
12
+ javascript: THotStepRuntimeLangData;
13
+ css: THotStepRuntimeLangData;
14
+ statusPath: string[];
15
+ };
16
+ export declare function cachedStats(context: ITestContext, name: string): () => StatsCompilation;
17
+ export declare function createRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
18
+ export declare function getMultiCompilerRunnerKey(context: ITestContext, name: string, file: string): string;
19
+ export declare function createMultiCompilerRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cachedStats = cachedStats;
4
+ exports.createRunner = createRunner;
5
+ exports.getMultiCompilerRunnerKey = getMultiCompilerRunnerKey;
6
+ exports.createMultiCompilerRunner = createMultiCompilerRunner;
7
+ const runner_1 = require("../runner");
8
+ const debug_1 = require("../test/debug");
9
+ function cachedStats(context, name) {
10
+ const compiler = context.getCompiler();
11
+ const statsGetter = (() => {
12
+ let cached = null;
13
+ return () => {
14
+ if (cached) {
15
+ return cached;
16
+ }
17
+ cached = compiler.getStats().toJson({
18
+ errorDetails: true
19
+ });
20
+ return cached;
21
+ };
22
+ })();
23
+ return statsGetter;
24
+ }
25
+ function createRunner(context, name, file, env) {
26
+ const compiler = context.getCompiler();
27
+ const testConfig = context.getTestConfig();
28
+ const compilerOptions = compiler.getOptions();
29
+ const runnerOptions = {
30
+ runInNewContext: false,
31
+ cachable: true,
32
+ env,
33
+ stats: cachedStats(context, name),
34
+ name,
35
+ testConfig: context.getTestConfig(),
36
+ source: context.getSource(),
37
+ dist: context.getDist(),
38
+ compilerOptions
39
+ };
40
+ if (compilerOptions.target === "web" ||
41
+ compilerOptions.target === "webworker") {
42
+ return new runner_1.WebRunner({
43
+ ...runnerOptions,
44
+ runInNewContext: true,
45
+ location: testConfig.location || "https://test.cases/path/index.html"
46
+ });
47
+ }
48
+ return new runner_1.NodeRunner(runnerOptions);
49
+ }
50
+ function getFileIndexHandler(context, name, file) {
51
+ const multiFileIndexMap = context.getValue("multiFileIndexMap") || {};
52
+ const runned = context.getValue("runned") || new Set();
53
+ if (typeof multiFileIndexMap[file] === "undefined") {
54
+ throw new Error("Unexpect file in multiple runner");
55
+ }
56
+ const indexList = multiFileIndexMap[file];
57
+ const seq = indexList.findIndex((index, n) => !runned.has(`${name}:${file}[${n}]`));
58
+ if (seq === -1) {
59
+ throw new Error(`File ${file} should run only ${indexList.length} times`);
60
+ }
61
+ const getIndex = () => [indexList[seq], seq];
62
+ const flagIndex = () => runned.add(`${name}:${file}[${seq}]`);
63
+ context.setValue("runned", runned);
64
+ return { getIndex, flagIndex };
65
+ }
66
+ function getMultiCompilerRunnerKey(context, name, file) {
67
+ const { getIndex } = getFileIndexHandler(context, name, file);
68
+ const [index, seq] = getIndex();
69
+ return `${name}-${index}[${seq}]`;
70
+ }
71
+ function createMultiCompilerRunner(context, name, file, env) {
72
+ const testConfig = context.getTestConfig();
73
+ const { getIndex, flagIndex } = getFileIndexHandler(context, name, file);
74
+ const multiCompilerOptions = context.getValue("multiCompilerOptions") || [];
75
+ const [index] = getIndex();
76
+ const compilerOptions = multiCompilerOptions[index];
77
+ const logs = context.getValue(debug_1.DEBUG_SCOPES.RunLogs);
78
+ const errors = context.getValue(debug_1.DEBUG_SCOPES.RunErrors);
79
+ let runner;
80
+ const runnerOptions = {
81
+ runInNewContext: false,
82
+ cachable: true,
83
+ env,
84
+ stats: () => {
85
+ const s = cachedStats(context, name)();
86
+ if (s.children?.length && s.children.length > 1) {
87
+ s.__index__ = index;
88
+ return s;
89
+ }
90
+ return s.children[index];
91
+ },
92
+ name,
93
+ testConfig: context.getTestConfig(),
94
+ source: context.getSource(),
95
+ dist: context.getDist(),
96
+ compilerOptions,
97
+ logs,
98
+ errors
99
+ };
100
+ if (compilerOptions.target === "web" ||
101
+ compilerOptions.target === "webworker") {
102
+ runner = new runner_1.WebRunner({
103
+ ...runnerOptions,
104
+ runInNewContext: true,
105
+ location: testConfig.location || "https://test.cases/path/index.html"
106
+ });
107
+ }
108
+ else {
109
+ runner = new runner_1.NodeRunner(runnerOptions);
110
+ }
111
+ flagIndex();
112
+ return runner;
113
+ }
@@ -1,3 +1,3 @@
1
- import { ECompilerType, type TTestConfig } from "../type";
2
- export type TSerialCaseConfig = Omit<TTestConfig<ECompilerType.Rspack>, "validate">;
1
+ import type { TTestConfig } from "../type";
2
+ export type TSerialCaseConfig = Omit<TTestConfig, "validate">;
3
3
  export declare function createSerialCase(name: string, src: string, dist: string): void;
@@ -1,33 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSerialCase = createSerialCase;
4
- const config_1 = require("../processor/config");
5
- const runner_1 = require("../runner");
6
4
  const creator_1 = require("../test/creator");
7
- const type_1 = require("../type");
5
+ const config_1 = require("./config");
6
+ const runner_1 = require("./runner");
8
7
  const creator = new creator_1.BasicCaseCreator({
9
8
  clean: true,
10
9
  describe: false,
11
10
  testConfig: testConfig => {
12
11
  const oldModuleScope = testConfig.moduleScope;
13
- testConfig.moduleScope = (ms, stats) => {
12
+ testConfig.moduleScope = (ms, stats, compilerOptions) => {
14
13
  let res = ms;
15
14
  // TODO: modify runner module scope based on stats here
16
15
  if (typeof oldModuleScope === "function") {
17
- res = oldModuleScope(ms, stats);
16
+ res = oldModuleScope(ms, stats, compilerOptions);
18
17
  }
19
18
  return res;
20
19
  };
21
20
  },
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
21
+ steps: ({ name }) => [(0, config_1.createConfigProcessor)(name)],
22
+ runner: {
23
+ key: runner_1.getMultiCompilerRunnerKey,
24
+ runner: runner_1.createMultiCompilerRunner
25
+ },
26
+ concurrent: 1
31
27
  });
32
28
  function createSerialCase(name, src, dist) {
33
29
  creator.create(name, src, dist);
@@ -1,6 +1,11 @@
1
- import { type IStatsAPIProcessorOptions } from "../processor";
2
- import { ECompilerType } from "../type";
3
- export type TStatsAPICaseConfig = Omit<IStatsAPIProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
1
+ import type { Compiler, RspackOptions, Stats } from "@rspack/core";
2
+ import type { ITestContext } from "../type";
3
+ export type TStatsAPICaseConfig = {
4
4
  description: string;
5
+ options?: (context: ITestContext) => RspackOptions;
6
+ snapshotName?: string;
7
+ compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
8
+ build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
9
+ check?: (stats: Stats, compiler: Compiler) => Promise<void>;
5
10
  };
6
11
  export declare function createStatsAPICase(name: string, src: string, dist: string, testConfig: string): void;
@@ -1,21 +1,80 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createStatsAPICase = createStatsAPICase;
4
- const processor_1 = require("../processor");
5
- const simple_1 = require("../test/simple");
6
- const type_1 = require("../type");
4
+ const memfs_1 = require("memfs");
5
+ const creator_1 = require("../test/creator");
7
6
  let addedSerializer = false;
7
+ const creator = new creator_1.BasicCaseCreator({
8
+ clean: true,
9
+ describe: true,
10
+ steps: ({ name, caseConfig }) => {
11
+ const config = caseConfig;
12
+ return [
13
+ {
14
+ config: async (context) => {
15
+ const compiler = context.getCompiler();
16
+ compiler.setOptions(options(context, config.options));
17
+ },
18
+ compiler: async (context) => {
19
+ const compilerManager = context.getCompiler();
20
+ compilerManager.createCompiler();
21
+ compiler(context, compilerManager.getCompiler(), config.compiler);
22
+ },
23
+ build: async (context) => {
24
+ const compiler = context.getCompiler();
25
+ if (typeof config.build === "function") {
26
+ await config.build(context, compiler.getCompiler());
27
+ }
28
+ else {
29
+ await compiler.build();
30
+ }
31
+ },
32
+ run: async (env, context) => {
33
+ // no need to run, just check the snapshot of diagnostics
34
+ },
35
+ check: async (env, context) => {
36
+ await check(env, context, name, config.check);
37
+ }
38
+ }
39
+ ];
40
+ },
41
+ concurrent: true
42
+ });
8
43
  function createStatsAPICase(name, src, dist, testConfig) {
9
44
  if (!addedSerializer) {
10
45
  addedSerializer = true;
11
46
  }
12
47
  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
- }));
48
+ creator.create(name, src, dist, undefined, {
49
+ caseConfig,
50
+ description: () => caseConfig.description
20
51
  });
21
52
  }
53
+ function options(context, custom) {
54
+ const res = (custom?.(context) || {});
55
+ res.experiments ??= {};
56
+ res.experiments.css ??= true;
57
+ res.experiments.rspackFuture ??= {};
58
+ res.experiments.rspackFuture.bundlerInfo ??= {};
59
+ res.experiments.rspackFuture.bundlerInfo.force ??= false;
60
+ if (!global.printLogger) {
61
+ res.infrastructureLogging = {
62
+ level: "error"
63
+ };
64
+ }
65
+ return res;
66
+ }
67
+ async function compiler(context, compiler, custom) {
68
+ if (custom) {
69
+ await custom(context, compiler);
70
+ }
71
+ if (compiler) {
72
+ compiler.outputFileSystem = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
73
+ }
74
+ }
75
+ async function check(env, context, name, custom) {
76
+ const manager = context.getCompiler();
77
+ const stats = manager.getStats();
78
+ env.expect(typeof stats).toBe("object");
79
+ await custom?.(stats, manager.getCompiler());
80
+ }
@@ -1 +1,12 @@
1
+ import type { RspackOptions } from "@rspack/core";
2
+ import type { ITestContext, ITestEnv } from "../type";
3
+ export declare function createStatsProcessor(name: string, defaultOptions: (index: number, context: ITestContext) => RspackOptions, overrideOptions: (index: number, context: ITestContext, options: RspackOptions) => void): {
4
+ before: (context: ITestContext) => Promise<void>;
5
+ config: (context: ITestContext) => Promise<void>;
6
+ compiler: (context: ITestContext) => Promise<void>;
7
+ build: (context: ITestContext) => Promise<void>;
8
+ run: (env: ITestEnv, context: ITestContext) => Promise<void>;
9
+ check: (env: ITestEnv, context: ITestContext) => Promise<void>;
10
+ after: (context: ITestContext) => Promise<void>;
11
+ };
1
12
  export declare function createStatsOutputCase(name: string, src: string, dist: string): void;
@@ -1,22 +1,213 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createStatsProcessor = createStatsProcessor;
3
7
  exports.createStatsOutputCase = createStatsOutputCase;
4
- const stats_1 = require("../processor/stats");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const placeholder_1 = require("../helper/expect/placeholder");
11
+ const captureStdio_1 = __importDefault(require("../helper/legacy/captureStdio"));
5
12
  const creator_1 = require("../test/creator");
6
- const type_1 = require("../type");
13
+ const common_1 = require("./common");
14
+ const REG_ERROR_CASE = /error$/;
15
+ function createStatsProcessor(name, defaultOptions, overrideOptions) {
16
+ const writeStatsOuptut = false;
17
+ const snapshotName = "stats.txt";
18
+ let stderr = null;
19
+ return {
20
+ before: async (context) => {
21
+ stderr = (0, captureStdio_1.default)(process.stderr, true);
22
+ },
23
+ config: async (context) => {
24
+ (0, common_1.configMultiCompiler)(context, name, ["rspack.config.js", "webpack.config.js"], defaultOptions, overrideOptions);
25
+ },
26
+ compiler: async (context) => {
27
+ const c = await (0, common_1.compiler)(context, name);
28
+ await statsCompiler(context, c);
29
+ },
30
+ build: async (context) => {
31
+ await (0, common_1.build)(context, name);
32
+ },
33
+ run: async (env, context) => {
34
+ // no need to run, just check snapshot
35
+ },
36
+ check: async (env, context) => {
37
+ await check(env, context, name, writeStatsOuptut, snapshotName, stderr);
38
+ },
39
+ after: async (context) => {
40
+ stderr.restore();
41
+ }
42
+ };
43
+ }
7
44
  const creator = new creator_1.BasicCaseCreator({
8
45
  clean: true,
9
46
  describe: false,
10
47
  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
- })
48
+ createStatsProcessor(name, defaultOptions, overrideOptions)
17
49
  ],
18
50
  description: () => "should print correct stats for"
19
51
  });
20
52
  function createStatsOutputCase(name, src, dist) {
21
53
  creator.create(name, src, dist);
22
54
  }
55
+ function defaultOptions(index, context) {
56
+ if (fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), "rspack.config.js")) ||
57
+ fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), "webpack.config.js"))) {
58
+ return {
59
+ experiments: {
60
+ css: true,
61
+ rspackFuture: {
62
+ bundlerInfo: {
63
+ force: false
64
+ }
65
+ }
66
+ }
67
+ };
68
+ }
69
+ return {
70
+ context: context.getSource(),
71
+ mode: "development",
72
+ entry: "./index.js",
73
+ output: {
74
+ filename: "bundle.js",
75
+ path: context.getDist()
76
+ },
77
+ optimization: {
78
+ minimize: false
79
+ },
80
+ experiments: {
81
+ css: true,
82
+ rspackFuture: {
83
+ bundlerInfo: {
84
+ force: false
85
+ }
86
+ },
87
+ inlineConst: true
88
+ }
89
+ };
90
+ }
91
+ function overrideOptions(index, context, options) {
92
+ if (!options.context)
93
+ options.context = context.getSource();
94
+ if (!options.output)
95
+ options.output = options.output || {};
96
+ if (!options.output.path)
97
+ options.output.path = context.getDist();
98
+ if (!options.plugins)
99
+ options.plugins = [];
100
+ if (!options.optimization)
101
+ options.optimization = {};
102
+ if (options.optimization.minimize === undefined) {
103
+ options.optimization.minimize = false;
104
+ }
105
+ if (!global.printLogger) {
106
+ options.infrastructureLogging = {
107
+ level: "error"
108
+ };
109
+ }
110
+ }
111
+ class RspackStats {
112
+ constructor(value) {
113
+ this.value = value;
114
+ }
115
+ }
116
+ async function check(env, context, name, writeStatsOuptut, snapshot, stderr) {
117
+ const compiler = context.getCompiler();
118
+ const options = compiler.getOptions();
119
+ const stats = compiler.getStats();
120
+ if (!stats || !compiler)
121
+ return;
122
+ for (const compilation of []
123
+ .concat(stats.stats || stats)
124
+ .map((s) => s.compilation)) {
125
+ compilation.logging.delete("webpack.Compilation.ModuleProfile");
126
+ }
127
+ if (REG_ERROR_CASE.test(name)) {
128
+ env.expect(stats.hasErrors()).toBe(true);
129
+ }
130
+ else if (stats.hasErrors()) {
131
+ throw new Error(stats.toString({
132
+ all: false,
133
+ errors: true
134
+ // errorStack: true,
135
+ // errorDetails: true
136
+ }));
137
+ }
138
+ else if (writeStatsOuptut) {
139
+ fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
140
+ preset: "verbose",
141
+ // context: context.getSource(),
142
+ colors: false
143
+ }), "utf-8");
144
+ }
145
+ let toStringOptions = {
146
+ context: context.getSource(),
147
+ colors: false
148
+ };
149
+ let hasColorSetting = false;
150
+ if (typeof options.stats !== "undefined") {
151
+ toStringOptions = options.stats;
152
+ if (toStringOptions === null || typeof toStringOptions !== "object")
153
+ toStringOptions = { preset: toStringOptions };
154
+ if (!toStringOptions.context)
155
+ toStringOptions.context = context.getSource();
156
+ hasColorSetting = typeof toStringOptions.colors !== "undefined";
157
+ }
158
+ if (Array.isArray(options) && !toStringOptions.children) {
159
+ toStringOptions.children = options.map(o => o.stats);
160
+ }
161
+ // mock timestamps
162
+ for (const { compilation: s } of [].concat(stats.stats || stats)) {
163
+ env.expect(s.startTime).toBeGreaterThan(0);
164
+ env.expect(s.endTime).toBeGreaterThan(0);
165
+ s.endTime = new Date("04/20/1970, 12:42:42 PM").getTime();
166
+ s.startTime = s.endTime - 1234;
167
+ }
168
+ let actual = stats.toString(toStringOptions);
169
+ env.expect(typeof actual).toBe("string");
170
+ actual = stderr.toString() + actual;
171
+ if (!hasColorSetting) {
172
+ actual = actual
173
+ .replace(/\u001b\[[0-9;]*m/g, "")
174
+ // CHANGE: The time unit display in Rspack is second
175
+ .replace(/[.0-9]+(\s?s)/g, "X$1")
176
+ // CHANGE: Replace bundle size, since bundle sizes may differ between platforms
177
+ .replace(/[0-9]+\.?[0-9]+ KiB/g, "xx KiB")
178
+ .replace(/[0-9]+ ms/g, "xx ms");
179
+ }
180
+ const snapshotPath = node_path_1.default.isAbsolute(snapshot)
181
+ ? snapshot
182
+ : node_path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshot}`);
183
+ env.expect(new RspackStats(actual)).toMatchFileSnapshotSync(snapshotPath);
184
+ const testConfig = context.getTestConfig();
185
+ if (typeof testConfig?.validate === "function") {
186
+ testConfig.validate(stats, stderr.toString());
187
+ }
188
+ }
189
+ async function statsCompiler(context, compiler) {
190
+ const compilers = compiler.compilers
191
+ ? compiler.compilers
192
+ : [compiler];
193
+ for (const compiler of compilers) {
194
+ if (!compiler.inputFileSystem) {
195
+ continue;
196
+ }
197
+ const ifs = compiler.inputFileSystem;
198
+ const inputFileSystem = Object.create(ifs);
199
+ compiler.inputFileSystem = inputFileSystem;
200
+ inputFileSystem.readFile = (...args) => {
201
+ const callback = args.pop();
202
+ ifs.readFile.apply(ifs, args.concat([
203
+ (err, result) => {
204
+ if (err)
205
+ return callback(err);
206
+ if (!/\.(js|json|txt)$/.test(args[0]))
207
+ return callback(null, result);
208
+ callback(null, (0, placeholder_1.normalizePlaceholder)(result.toString("utf-8")));
209
+ }
210
+ ]));
211
+ };
212
+ }
213
+ }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTreeShakingCase = createTreeShakingCase;
4
- const treeshaking_1 = require("../processor/treeshaking");
5
4
  const creator_1 = require("../test/creator");
6
- const type_1 = require("../type");
5
+ const builtin_1 = require("./builtin");
6
+ const common_1 = require("./common");
7
7
  const creator = new creator_1.BasicCaseCreator({
8
8
  clean: true,
9
9
  describe: false,
@@ -11,13 +11,40 @@ const creator = new creator_1.BasicCaseCreator({
11
11
  return `${name} with newTreeshaking should match snapshot`;
12
12
  },
13
13
  steps: ({ name }) => [
14
- new treeshaking_1.TreeShakingProcessor({
15
- name,
16
- snapshot: "treeshaking.snap.txt",
17
- compilerType: type_1.ECompilerType.Rspack
18
- })
14
+ {
15
+ config: async (context) => {
16
+ const compiler = context.getCompiler();
17
+ const options = (0, builtin_1.defaultOptions)(context);
18
+ overrideOptions(context, options);
19
+ compiler.setOptions(options);
20
+ },
21
+ compiler: async (context) => {
22
+ await (0, common_1.compiler)(context, name);
23
+ },
24
+ build: async (context) => {
25
+ await (0, common_1.build)(context, name);
26
+ },
27
+ run: async (env, context) => {
28
+ // no need to run, just check snapshot
29
+ },
30
+ check: async (env, context) => {
31
+ await (0, common_1.checkSnapshot)(env, context, name, "treeshaking.snap.txt");
32
+ }
33
+ }
19
34
  ]
20
35
  });
21
36
  function createTreeShakingCase(name, src, dist) {
22
37
  creator.create(name, src, dist);
23
38
  }
39
+ function overrideOptions(context, options) {
40
+ options.target = options.target || ["web", "es2022"];
41
+ options.optimization ??= {};
42
+ options.optimization.providedExports = true;
43
+ options.optimization.innerGraph = true;
44
+ options.optimization.usedExports = true;
45
+ if (!global.printLogger) {
46
+ options.infrastructureLogging = {
47
+ level: "error"
48
+ };
49
+ }
50
+ }
@@ -1 +1,28 @@
1
+ import type { ITestContext, ITestEnv, ITestRunner } from "../type";
2
+ export declare function createWatchInitialProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher }?: {
3
+ incremental?: boolean | undefined;
4
+ nativeWatcher?: boolean | undefined;
5
+ }): {
6
+ before: (context: ITestContext) => Promise<void>;
7
+ config: (context: ITestContext) => Promise<void>;
8
+ compiler: (context: ITestContext) => Promise<void>;
9
+ build: (context: ITestContext) => Promise<void>;
10
+ run: (env: ITestEnv, context: ITestContext) => Promise<void>;
11
+ check: (env: ITestEnv, context: ITestContext) => Promise<void>;
12
+ after: (context: ITestContext) => Promise<void>;
13
+ };
14
+ export declare function createWatchStepProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher }?: {
15
+ incremental?: boolean | undefined;
16
+ nativeWatcher?: boolean | undefined;
17
+ }): {
18
+ before: (context: ITestContext) => Promise<void>;
19
+ config: (context: ITestContext) => Promise<void>;
20
+ compiler: (context: ITestContext) => Promise<void>;
21
+ build: (context: ITestContext) => Promise<void>;
22
+ run: (env: ITestEnv, context: ITestContext) => Promise<void>;
23
+ check: (env: ITestEnv, context: ITestContext) => Promise<void>;
24
+ after: (context: ITestContext) => Promise<void>;
25
+ };
1
26
  export declare function createWatchCase(name: string, src: string, dist: string, temp: string): void;
27
+ export declare function getWatchRunnerKey(context: ITestContext, name: string, file: string): string;
28
+ export declare function createWatchRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;