@rspack-debug/test-tools 1.4.11 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/README.md +1 -1
  2. package/dist/case/builtin.d.ts +3 -0
  3. package/dist/case/builtin.js +152 -14
  4. package/dist/case/cache.d.ts +2 -2
  5. package/dist/case/cache.js +214 -12
  6. package/dist/case/common.d.ts +11 -0
  7. package/dist/case/common.js +249 -0
  8. package/dist/case/compiler.d.ts +17 -4
  9. package/dist/case/compiler.js +149 -12
  10. package/dist/case/config.d.ts +7 -2
  11. package/dist/case/config.js +106 -18
  12. package/dist/case/defaults.d.ts +13 -4
  13. package/dist/case/defaults.js +73 -18
  14. package/dist/case/diagnostic.d.ts +6 -0
  15. package/dist/case/diagnostic.js +121 -14
  16. package/dist/case/error.d.ts +15 -4
  17. package/dist/case/error.js +137 -12
  18. package/dist/case/esm-output.d.ts +1 -0
  19. package/dist/case/esm-output.js +117 -0
  20. package/dist/case/example.d.ts +1 -0
  21. package/dist/case/example.js +57 -0
  22. package/dist/case/hash.d.ts +2 -2
  23. package/dist/case/hash.js +72 -9
  24. package/dist/case/hook.d.ts +36 -4
  25. package/dist/case/hook.js +209 -20
  26. package/dist/case/hot-step.d.ts +2 -2
  27. package/dist/case/hot-step.js +309 -13
  28. package/dist/case/hot.d.ts +11 -2
  29. package/dist/case/hot.js +217 -12
  30. package/dist/case/incremental.d.ts +2 -2
  31. package/dist/case/incremental.js +24 -45
  32. package/dist/case/index.d.ts +31 -20
  33. package/dist/case/index.js +50 -34
  34. package/dist/case/multi-compiler.d.ts +19 -0
  35. package/dist/case/multi-compiler.js +97 -0
  36. package/dist/case/{nativeWatcher.js → native-watcher.js} +11 -23
  37. package/dist/case/normal.d.ts +3 -0
  38. package/dist/case/normal.js +202 -18
  39. package/dist/case/runner.d.ts +19 -0
  40. package/dist/case/runner.js +113 -0
  41. package/dist/case/serial.d.ts +2 -2
  42. package/dist/case/serial.js +10 -14
  43. package/dist/case/stats-api.d.ts +8 -3
  44. package/dist/case/stats-api.js +69 -10
  45. package/dist/case/stats-output.d.ts +11 -0
  46. package/dist/case/stats-output.js +199 -8
  47. package/dist/case/treeshaking.js +34 -7
  48. package/dist/case/watch.d.ts +27 -0
  49. package/dist/case/watch.js +318 -22
  50. package/dist/compiler.d.ts +16 -16
  51. package/dist/compiler.js +120 -15
  52. package/dist/helper/directory.d.ts +1 -1
  53. package/dist/helper/directory.js +6 -2
  54. package/dist/helper/disable-iconv-lite-warning.d.ts +1 -0
  55. package/dist/helper/disable-iconv-lite-warning.js +12 -0
  56. package/dist/helper/expect/error.js +1 -1
  57. package/dist/helper/expect/placeholder.js +7 -7
  58. package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
  59. package/dist/helper/expect/to-match-file-snapshot.js +3 -3
  60. package/dist/helper/hot-update/loader.d.ts +2 -1
  61. package/dist/helper/hot-update/loader.js +5 -30
  62. package/dist/helper/hot-update/plugin.d.ts +1 -1
  63. package/dist/helper/hot-update/plugin.js +14 -13
  64. package/dist/helper/index.d.ts +2 -1
  65. package/dist/helper/index.js +2 -1
  66. package/dist/helper/is.d.ts +2 -0
  67. package/dist/helper/is.js +15 -0
  68. package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
  69. package/dist/helper/legacy/LogTestPlugin.js +35 -0
  70. package/dist/helper/legacy/asModule.js +0 -2
  71. package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
  72. package/dist/helper/legacy/checkArrayExpectation.js +8 -8
  73. package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
  74. package/dist/helper/legacy/createFakeWorker.js +44 -20
  75. package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
  76. package/dist/helper/legacy/createLazyTestEnv.js +3 -3
  77. package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
  78. package/dist/helper/legacy/deprecationTracking.js +41 -0
  79. package/dist/helper/legacy/expectSource.d.ts +10 -0
  80. package/dist/helper/legacy/expectSource.js +23 -0
  81. package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
  82. package/dist/helper/legacy/findOutputFiles.js +14 -0
  83. package/dist/helper/legacy/regexEscape.d.ts +2 -0
  84. package/dist/helper/legacy/regexEscape.js +5 -0
  85. package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
  86. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  87. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  88. package/dist/helper/legacy/supportsUsing.d.ts +2 -0
  89. package/dist/helper/legacy/supportsUsing.js +26 -0
  90. package/dist/helper/legacy/urlToRelativePath.js +5 -2
  91. package/dist/helper/read-config-file.d.ts +3 -2
  92. package/dist/helper/read-config-file.js +12 -2
  93. package/dist/helper/setup-env.js +26 -4
  94. package/dist/helper/setup-expect.js +2 -2
  95. package/dist/helper/setup-wasm.js +2 -2
  96. package/dist/helper/stringify-config.d.ts +2 -0
  97. package/dist/helper/stringify-config.js +43 -0
  98. package/dist/helper/util/checkStats.d.ts +0 -1
  99. package/dist/helper/util/checkStats.js +0 -18
  100. package/dist/helper/util/expectWarningFactory.js +2 -4
  101. package/dist/index.d.ts +0 -4
  102. package/dist/index.js +1 -4
  103. package/dist/plugin/index.d.ts +0 -3
  104. package/dist/plugin/index.js +0 -3
  105. package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
  106. package/dist/runner/index.d.ts +2 -9
  107. package/dist/runner/index.js +2 -9
  108. package/dist/runner/node/index.d.ts +41 -0
  109. package/dist/runner/node/index.js +450 -0
  110. package/dist/runner/web/index.d.ts +30 -0
  111. package/dist/runner/web/index.js +343 -0
  112. package/dist/test/context.d.ts +15 -18
  113. package/dist/test/context.js +52 -57
  114. package/dist/test/creator.d.ts +20 -19
  115. package/dist/test/creator.js +69 -57
  116. package/dist/test/debug.d.ts +15 -0
  117. package/dist/test/debug.js +205 -0
  118. package/dist/test/tester.d.ts +1 -0
  119. package/dist/test/tester.js +44 -6
  120. package/dist/type.d.ts +94 -64
  121. package/dist/type.js +8 -12
  122. package/package.json +22 -61
  123. package/rstest.d.ts +24 -0
  124. package/dist/case/diff.d.ts +0 -3
  125. package/dist/case/diff.js +0 -126
  126. package/dist/compare/comparator.d.ts +0 -17
  127. package/dist/compare/comparator.js +0 -52
  128. package/dist/compare/compare.d.ts +0 -17
  129. package/dist/compare/compare.js +0 -175
  130. package/dist/compare/format-code.d.ts +0 -16
  131. package/dist/compare/format-code.js +0 -239
  132. package/dist/compare/index.d.ts +0 -5
  133. package/dist/compare/index.js +0 -21
  134. package/dist/compare/replace-module-argument.d.ts +0 -1
  135. package/dist/compare/replace-module-argument.js +0 -8
  136. package/dist/compare/replace-runtime-module-name.d.ts +0 -1
  137. package/dist/compare/replace-runtime-module-name.js +0 -71
  138. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  139. package/dist/helper/legacy/FakeDocument.js +0 -278
  140. package/dist/helper/legacy/createLogger.d.ts +0 -23
  141. package/dist/helper/legacy/createLogger.js +0 -20
  142. package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
  143. package/dist/helper/legacy/supportsImportFn.js +0 -15
  144. package/dist/helper/legacy/supportsWorker.js +0 -17
  145. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  146. package/dist/helper/legacy/walkCssTokens.js +0 -761
  147. package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
  148. package/dist/helper/legacy/warmup-webpack.js +0 -26
  149. package/dist/helper/loaders/hot-update.d.ts +0 -1
  150. package/dist/helper/loaders/hot-update.js +0 -40
  151. package/dist/helper/plugins/hot-update.d.ts +0 -7
  152. package/dist/helper/plugins/hot-update.js +0 -40
  153. package/dist/helper/plugins/index.d.ts +0 -1
  154. package/dist/helper/plugins/index.js +0 -17
  155. package/dist/helper/util/currentWatchStep.d.ts +0 -1
  156. package/dist/helper/util/currentWatchStep.js +0 -2
  157. package/dist/helper/util/identifier.d.ts +0 -76
  158. package/dist/helper/util/identifier.js +0 -339
  159. package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
  160. package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
  161. package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
  162. package/dist/plugin/rspack-diff-config-plugin.js +0 -42
  163. package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
  164. package/dist/plugin/webpack-diff-config-plugin.js +0 -41
  165. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
  166. package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
  167. package/dist/processor/basic.d.ts +0 -24
  168. package/dist/processor/basic.js +0 -146
  169. package/dist/processor/builtin.d.ts +0 -9
  170. package/dist/processor/builtin.js +0 -171
  171. package/dist/processor/cache.d.ts +0 -20
  172. package/dist/processor/cache.js +0 -128
  173. package/dist/processor/config.d.ts +0 -11
  174. package/dist/processor/config.js +0 -81
  175. package/dist/processor/defaults.d.ts +0 -30
  176. package/dist/processor/defaults.js +0 -72
  177. package/dist/processor/diagnostic.d.ts +0 -15
  178. package/dist/processor/diagnostic.js +0 -102
  179. package/dist/processor/diff.d.ts +0 -30
  180. package/dist/processor/diff.js +0 -140
  181. package/dist/processor/error.d.ts +0 -23
  182. package/dist/processor/error.js +0 -95
  183. package/dist/processor/hash.d.ts +0 -10
  184. package/dist/processor/hash.js +0 -63
  185. package/dist/processor/hook.d.ts +0 -44
  186. package/dist/processor/hook.js +0 -204
  187. package/dist/processor/hot-incremental.d.ts +0 -14
  188. package/dist/processor/hot-incremental.js +0 -43
  189. package/dist/processor/hot-step.d.ts +0 -18
  190. package/dist/processor/hot-step.js +0 -304
  191. package/dist/processor/hot.d.ts +0 -17
  192. package/dist/processor/hot.js +0 -140
  193. package/dist/processor/index.d.ts +0 -20
  194. package/dist/processor/index.js +0 -36
  195. package/dist/processor/multi.d.ts +0 -17
  196. package/dist/processor/multi.js +0 -73
  197. package/dist/processor/normal.d.ts +0 -12
  198. package/dist/processor/normal.js +0 -150
  199. package/dist/processor/simple.d.ts +0 -23
  200. package/dist/processor/simple.js +0 -49
  201. package/dist/processor/snapshot.d.ts +0 -12
  202. package/dist/processor/snapshot.js +0 -66
  203. package/dist/processor/stats-api.d.ts +0 -18
  204. package/dist/processor/stats-api.js +0 -48
  205. package/dist/processor/stats.d.ts +0 -18
  206. package/dist/processor/stats.js +0 -206
  207. package/dist/processor/treeshaking.d.ts +0 -10
  208. package/dist/processor/treeshaking.js +0 -33
  209. package/dist/processor/watch.d.ts +0 -30
  210. package/dist/processor/watch.js +0 -241
  211. package/dist/reporter/diff-html.d.ts +0 -15
  212. package/dist/reporter/diff-html.js +0 -69
  213. package/dist/reporter/diff-stats.d.ts +0 -24
  214. package/dist/reporter/diff-stats.js +0 -131
  215. package/dist/reporter/index.d.ts +0 -2
  216. package/dist/reporter/index.js +0 -18
  217. package/dist/runner/basic.d.ts +0 -10
  218. package/dist/runner/basic.js +0 -63
  219. package/dist/runner/cache.d.ts +0 -5
  220. package/dist/runner/cache.js +0 -90
  221. package/dist/runner/hot-step.d.ts +0 -5
  222. package/dist/runner/hot-step.js +0 -87
  223. package/dist/runner/hot.d.ts +0 -5
  224. package/dist/runner/hot.js +0 -83
  225. package/dist/runner/multiple.d.ts +0 -11
  226. package/dist/runner/multiple.js +0 -38
  227. package/dist/runner/normal.d.ts +0 -5
  228. package/dist/runner/normal.js +0 -20
  229. package/dist/runner/runner/basic.d.ts +0 -30
  230. package/dist/runner/runner/basic.js +0 -107
  231. package/dist/runner/runner/cjs.d.ts +0 -14
  232. package/dist/runner/runner/cjs.js +0 -151
  233. package/dist/runner/runner/esm.d.ts +0 -7
  234. package/dist/runner/runner/esm.js +0 -125
  235. package/dist/runner/runner/index.d.ts +0 -8
  236. package/dist/runner/runner/index.js +0 -24
  237. package/dist/runner/runner/normal.d.ts +0 -9
  238. package/dist/runner/runner/normal.js +0 -23
  239. package/dist/runner/runner/watch.d.ts +0 -16
  240. package/dist/runner/runner/watch.js +0 -27
  241. package/dist/runner/runner/web/fake.d.ts +0 -18
  242. package/dist/runner/runner/web/fake.js +0 -143
  243. package/dist/runner/runner/web/jsdom.d.ts +0 -26
  244. package/dist/runner/runner/web/jsdom.js +0 -219
  245. package/dist/runner/runner/web.d.ts +0 -15
  246. package/dist/runner/runner/web.js +0 -32
  247. package/dist/runner/type.d.ts +0 -42
  248. package/dist/runner/type.js +0 -9
  249. package/dist/runner/watch.d.ts +0 -7
  250. package/dist/runner/watch.js +0 -60
  251. package/dist/test/simple.d.ts +0 -5
  252. package/dist/test/simple.js +0 -43
  253. package/jest.d.ts +0 -25
  254. package/template/diff.bundle.css +0 -1
  255. package/template/diff.bundle.js +0 -144
  256. package/template/diff.html +0 -14
  257. package/template/editor.worker.js +0 -1
  258. /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
  259. /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StatsAPIProcessor = void 0;
4
- const memfs_1 = require("memfs");
5
- const simple_1 = require("./simple");
6
- class StatsAPIProcessor extends simple_1.SimpleTaskProcessor {
7
- constructor(_statsAPIOptions) {
8
- super({
9
- options: context => {
10
- const res = (_statsAPIOptions.options?.(context) ||
11
- {});
12
- res.experiments ??= {};
13
- res.experiments.css ??= true;
14
- res.experiments.rspackFuture ??= {};
15
- res.experiments.rspackFuture.bundlerInfo ??= {};
16
- res.experiments.rspackFuture.bundlerInfo.force ??= false;
17
- if (!global.printLogger) {
18
- res.infrastructureLogging = {
19
- level: "error"
20
- };
21
- }
22
- return res;
23
- },
24
- build: _statsAPIOptions.build,
25
- compilerType: _statsAPIOptions.compilerType,
26
- name: _statsAPIOptions.name,
27
- compiler: _statsAPIOptions.compiler
28
- });
29
- this._statsAPIOptions = _statsAPIOptions;
30
- }
31
- async compiler(context) {
32
- await super.compiler(context);
33
- const compiler = this.getCompiler(context).getCompiler();
34
- if (compiler) {
35
- compiler.outputFileSystem = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
36
- }
37
- }
38
- async run(env, context) {
39
- // do nothing
40
- }
41
- async check(env, context) {
42
- const compiler = this.getCompiler(context);
43
- const stats = compiler.getStats();
44
- env.expect(typeof stats).toBe("object");
45
- await this._statsAPIOptions.check?.(stats, compiler.getCompiler());
46
- }
47
- }
48
- exports.StatsAPIProcessor = StatsAPIProcessor;
@@ -1,18 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
2
- import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";
3
- export interface IStatsProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {
4
- snapshotName?: string;
5
- writeStatsOuptut?: boolean;
6
- }
7
- export declare class StatsProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
8
- private stderr;
9
- private snapshotName?;
10
- private writeStatsOuptut?;
11
- constructor(_statsOptions: IStatsProcessorOptions<T>);
12
- before(context: ITestContext): Promise<void>;
13
- after(context: ITestContext): Promise<void>;
14
- compiler(context: ITestContext): Promise<void>;
15
- check(env: ITestEnv, context: ITestContext): Promise<void>;
16
- static defaultOptions<T extends ECompilerType>(index: number, context: ITestContext): TCompilerOptions<T>;
17
- static overrideOptions<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): void;
18
- }
@@ -1,206 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.StatsProcessor = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const placeholder_1 = require("../helper/expect/placeholder");
10
- const captureStdio_1 = __importDefault(require("../helper/legacy/captureStdio"));
11
- const multi_1 = require("./multi");
12
- const REG_ERROR_CASE = /error$/;
13
- class RspackStats {
14
- constructor(value) {
15
- this.value = value;
16
- }
17
- }
18
- class StatsProcessor extends multi_1.MultiTaskProcessor {
19
- constructor(_statsOptions) {
20
- super({
21
- defaultOptions: (StatsProcessor.defaultOptions),
22
- overrideOptions: (StatsProcessor.overrideOptions),
23
- runable: false,
24
- ..._statsOptions
25
- });
26
- this.snapshotName = _statsOptions.snapshotName;
27
- this.writeStatsOuptut = _statsOptions.writeStatsOuptut;
28
- }
29
- async before(context) {
30
- this.stderr = (0, captureStdio_1.default)(process.stderr, true);
31
- }
32
- async after(context) {
33
- this.stderr.restore();
34
- }
35
- async compiler(context) {
36
- await super.compiler(context);
37
- const instance = this.getCompiler(context).getCompiler();
38
- const compilers = instance.compilers
39
- ? instance.compilers
40
- : [instance];
41
- for (const compiler of compilers) {
42
- if (!compiler.inputFileSystem) {
43
- continue;
44
- }
45
- const ifs = compiler.inputFileSystem;
46
- const inputFileSystem = Object.create(ifs);
47
- compiler.inputFileSystem = inputFileSystem;
48
- inputFileSystem.readFile = (...args) => {
49
- const callback = args.pop();
50
- ifs.readFile.apply(ifs, args.concat([
51
- (err, result) => {
52
- if (err)
53
- return callback(err);
54
- if (!/\.(js|json|txt)$/.test(args[0]))
55
- return callback(null, result);
56
- callback(null, (0, placeholder_1.normalizePlaceholder)(result.toString("utf-8")));
57
- }
58
- ]));
59
- };
60
- // CHANGE: The checkConstraints() function is currently not implemented in rspack
61
- // compiler.hooks.compilation.tap("StatsTestCasesTest", compilation => {
62
- // [
63
- // "optimize",
64
- // "optimizeModules",
65
- // "optimizeChunks",
66
- // "afterOptimizeTree",
67
- // "afterOptimizeAssets",
68
- // "beforeHash"
69
- // ].forEach(hook => {
70
- // compilation.hooks[hook].tap("TestCasesTest", () =>
71
- // compilation.checkConstraints()
72
- // );
73
- // });
74
- // });
75
- }
76
- }
77
- async check(env, context) {
78
- const compiler = this.getCompiler(context);
79
- const stats = compiler.getStats();
80
- const c = compiler.getCompiler();
81
- if (!stats || !c)
82
- return;
83
- for (const compilation of []
84
- .concat(stats.stats || stats)
85
- .map((s) => s.compilation)) {
86
- compilation.logging.delete("webpack.Compilation.ModuleProfile");
87
- }
88
- if (REG_ERROR_CASE.test(this._options.name)) {
89
- env.expect(stats.hasErrors()).toBe(true);
90
- }
91
- else if (stats.hasErrors()) {
92
- throw new Error(stats.toString({
93
- all: false,
94
- errors: true
95
- // errorStack: true,
96
- // errorDetails: true
97
- }));
98
- }
99
- else if (this.writeStatsOuptut) {
100
- node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
101
- preset: "verbose",
102
- // context: context.getSource(),
103
- colors: false
104
- }), "utf-8");
105
- }
106
- let toStringOptions = {
107
- context: context.getSource(),
108
- colors: false
109
- };
110
- let hasColorSetting = false;
111
- if (typeof c.options.stats !== "undefined") {
112
- toStringOptions = c.options.stats;
113
- if (toStringOptions === null || typeof toStringOptions !== "object")
114
- toStringOptions = { preset: toStringOptions };
115
- if (!toStringOptions.context)
116
- toStringOptions.context = context.getSource();
117
- hasColorSetting = typeof toStringOptions.colors !== "undefined";
118
- }
119
- if (Array.isArray(c.options) && !toStringOptions.children) {
120
- toStringOptions.children = c.options.map(o => o.stats);
121
- }
122
- // mock timestamps
123
- for (const { compilation: s } of [].concat(stats.stats || stats)) {
124
- env.expect(s.startTime).toBeGreaterThan(0);
125
- env.expect(s.endTime).toBeGreaterThan(0);
126
- s.endTime = new Date("04/20/1970, 12:42:42 PM").getTime();
127
- s.startTime = s.endTime - 1234;
128
- }
129
- let actual = stats.toString(toStringOptions);
130
- env.expect(typeof actual).toBe("string");
131
- actual = this.stderr.toString() + actual;
132
- if (!hasColorSetting) {
133
- actual = actual
134
- .replace(/\u001b\[[0-9;]*m/g, "")
135
- // CHANGE: The time unit display in Rspack is second
136
- .replace(/[.0-9]+(\s?s)/g, "X$1")
137
- // CHANGE: Replace bundle size, since bundle sizes may differ between platforms
138
- .replace(/[0-9]+\.?[0-9]+ KiB/g, "xx KiB");
139
- }
140
- if (this.snapshotName) {
141
- env.expect(new RspackStats(actual)).toMatchSnapshot(this.snapshotName);
142
- }
143
- else {
144
- env.expect(new RspackStats(actual)).toMatchSnapshot();
145
- }
146
- const testConfig = context.getTestConfig();
147
- if (typeof testConfig?.validate === "function") {
148
- testConfig.validate(stats, this.stderr.toString());
149
- }
150
- }
151
- static defaultOptions(index, context) {
152
- if (node_fs_1.default.existsSync(node_path_1.default.join(context.getSource(), "rspack.config.js"))) {
153
- return {
154
- experiments: {
155
- css: true,
156
- rspackFuture: {
157
- bundlerInfo: {
158
- force: false
159
- }
160
- }
161
- }
162
- };
163
- }
164
- return {
165
- context: context.getSource(),
166
- mode: "development",
167
- entry: "./index.js",
168
- output: {
169
- filename: "bundle.js",
170
- path: context.getDist()
171
- },
172
- optimization: {
173
- minimize: false
174
- },
175
- experiments: {
176
- css: true,
177
- rspackFuture: {
178
- bundlerInfo: {
179
- force: false
180
- }
181
- }
182
- }
183
- };
184
- }
185
- static overrideOptions(index, context, options) {
186
- if (!options.context)
187
- options.context = context.getSource();
188
- if (!options.output)
189
- options.output = options.output || {};
190
- if (!options.output.path)
191
- options.output.path = context.getDist();
192
- if (!options.plugins)
193
- options.plugins = [];
194
- if (!options.optimization)
195
- options.optimization = {};
196
- if (options.optimization.minimize === undefined) {
197
- options.optimization.minimize = false;
198
- }
199
- if (!global.printLogger) {
200
- options.infrastructureLogging = {
201
- level: "error"
202
- };
203
- }
204
- }
205
- }
206
- exports.StatsProcessor = StatsProcessor;
@@ -1,10 +0,0 @@
1
- import type { ECompilerType, ITestContext, TCompilerOptions } from "../type";
2
- import { type ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot";
3
- export interface ITreeShakingProcessorOptions<T extends ECompilerType> extends Omit<ISnapshotProcessorOptions<T>, "runable"> {
4
- }
5
- export declare class TreeShakingProcessor<T extends ECompilerType> extends SnapshotProcessor<T> {
6
- protected _treeShakingOptions: ITreeShakingProcessorOptions<T>;
7
- constructor(_treeShakingOptions: ITreeShakingProcessorOptions<T>);
8
- static overrideOptions<T extends ECompilerType>(context: ITestContext, options: TCompilerOptions<T>): void;
9
- serializeEachFile(content: string): string;
10
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TreeShakingProcessor = void 0;
4
- const placeholder_1 = require("../helper/expect/placeholder");
5
- const builtin_1 = require("./builtin");
6
- const snapshot_1 = require("./snapshot");
7
- class TreeShakingProcessor extends snapshot_1.SnapshotProcessor {
8
- constructor(_treeShakingOptions) {
9
- super({
10
- defaultOptions: builtin_1.BuiltinProcessor.defaultOptions,
11
- overrideOptions: (TreeShakingProcessor.overrideOptions),
12
- runable: false,
13
- ..._treeShakingOptions
14
- });
15
- this._treeShakingOptions = _treeShakingOptions;
16
- }
17
- static overrideOptions(context, options) {
18
- options.target = options.target || ["web", "es2022"];
19
- options.optimization ??= {};
20
- options.optimization.providedExports = true;
21
- options.optimization.innerGraph = true;
22
- options.optimization.usedExports = true;
23
- if (!global.printLogger) {
24
- options.infrastructureLogging = {
25
- level: "error"
26
- };
27
- }
28
- }
29
- serializeEachFile(content) {
30
- return (0, placeholder_1.normalizePlaceholder)(content);
31
- }
32
- }
33
- exports.TreeShakingProcessor = TreeShakingProcessor;
@@ -1,30 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
2
- import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";
3
- export interface IWatchProcessorOptions<T extends ECompilerType> extends IMultiTaskProcessorOptions<T> {
4
- stepName: string;
5
- tempDir: string;
6
- nativeWatcher?: boolean;
7
- }
8
- export declare class WatchProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
9
- protected _watchOptions: IWatchProcessorOptions<T>;
10
- protected _watchState: Record<string, any>;
11
- protected currentTriggerFilename: string | null;
12
- protected lastHash: string | null;
13
- constructor(_watchOptions: IWatchProcessorOptions<T>, _watchState: Record<string, any>);
14
- compiler(context: ITestContext): Promise<void>;
15
- build(context: ITestContext): Promise<void>;
16
- run(env: ITestEnv, context: ITestContext): Promise<void>;
17
- check(env: ITestEnv, context: ITestContext): Promise<void>;
18
- config(context: ITestContext): Promise<void>;
19
- static overrideOptions<T extends ECompilerType>({ tempDir, nativeWatcher }: IWatchProcessorOptions<T>): (index: number, context: ITestContext, options: TCompilerOptions<ECompilerType>) => void;
20
- static findBundle<T extends ECompilerType>(this: IWatchProcessorOptions<T>, index: number, context: ITestContext, options: TCompilerOptions<T>): string | string[];
21
- }
22
- export interface IWatchStepProcessorOptions<T extends ECompilerType> extends Omit<IWatchProcessorOptions<T>, "experiments" | "optimization"> {
23
- }
24
- export declare class WatchStepProcessor<T extends ECompilerType> extends WatchProcessor<T> {
25
- protected _watchOptions: IWatchStepProcessorOptions<T>;
26
- protected _watchState: Record<string, any>;
27
- constructor(_watchOptions: IWatchStepProcessorOptions<T>, _watchState: Record<string, any>);
28
- compiler(context: ITestContext): Promise<void>;
29
- build(context: ITestContext): Promise<void>;
30
- }
@@ -1,241 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WatchStepProcessor = exports.WatchProcessor = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const webpack_merge_1 = require("webpack-merge");
10
- const compiler_1 = require("../compiler");
11
- const helper_1 = require("../helper");
12
- const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
13
- const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
14
- const multi_1 = require("./multi");
15
- // This file is used to port step number to rspack.config.js/webpack.config.js
16
- const currentWatchStepModulePath = node_path_1.default.resolve(__dirname, "../helper/util/currentWatchStep");
17
- class WatchProcessor extends multi_1.MultiTaskProcessor {
18
- constructor(_watchOptions, _watchState) {
19
- super({
20
- overrideOptions: WatchProcessor.overrideOptions(_watchOptions),
21
- findBundle: (WatchProcessor.findBundle),
22
- ..._watchOptions
23
- });
24
- this._watchOptions = _watchOptions;
25
- this._watchState = _watchState;
26
- this.currentTriggerFilename = null;
27
- this.lastHash = null;
28
- }
29
- async compiler(context) {
30
- await super.compiler(context);
31
- const compiler = this.getCompiler(context).getCompiler();
32
- compiler.hooks.invalid.tap("WatchTestCasesTest", (filename, mtime) => {
33
- this.currentTriggerFilename = filename;
34
- });
35
- }
36
- async build(context) {
37
- const compiler = this.getCompiler(context);
38
- const currentWatchStepModule = require(currentWatchStepModulePath);
39
- currentWatchStepModule.step[this._options.name] =
40
- this._watchOptions.stepName;
41
- node_fs_1.default.mkdirSync(this._watchOptions.tempDir, { recursive: true });
42
- (0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), this._watchOptions.tempDir, true);
43
- const task = new Promise((resolve, reject) => {
44
- compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
45
- if (e)
46
- return reject(e);
47
- resolve(stats);
48
- });
49
- });
50
- compiler.watch();
51
- await task;
52
- }
53
- async run(env, context) {
54
- context.setValue(this._options.name, "watchStepName", this._watchOptions.stepName);
55
- context.setValue(this._options.name, "watchState", this._watchState);
56
- await super.run(env, context);
57
- }
58
- async check(env, context) {
59
- const testConfig = context.getTestConfig();
60
- if (testConfig.noTest)
61
- return;
62
- const errors = (context.getError(this._options.name) || []).map(e => ({
63
- message: e.message,
64
- stack: e.stack
65
- }));
66
- const warnings = [];
67
- const compiler = this.getCompiler(context);
68
- const stats = compiler.getStats();
69
- const checkStats = testConfig.checkStats || (() => true);
70
- if (stats) {
71
- if (testConfig.writeStatsOuptut) {
72
- node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
73
- preset: "verbose",
74
- colors: false
75
- }), "utf-8");
76
- }
77
- const getJsonStats = (() => {
78
- let cached = null;
79
- return () => {
80
- if (!cached) {
81
- cached = stats.toJson({
82
- errorDetails: true
83
- });
84
- }
85
- return cached;
86
- };
87
- })();
88
- const getStringStats = (() => {
89
- let cached = null;
90
- return () => {
91
- if (!cached) {
92
- cached = stats.toString({
93
- logging: "verbose"
94
- });
95
- }
96
- return cached;
97
- };
98
- })();
99
- if (checkStats.length > 1) {
100
- if (!checkStats(this._watchOptions.stepName, getJsonStats(), getStringStats())) {
101
- throw new Error("stats check failed");
102
- }
103
- }
104
- else {
105
- // @ts-expect-error only one param
106
- if (!checkStats(this._watchOptions.stepName)) {
107
- throw new Error("stats check failed");
108
- }
109
- }
110
- if (testConfig.writeStatsJson) {
111
- node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.json"), JSON.stringify(getJsonStats(), null, 2), "utf-8");
112
- }
113
- if (node_fs_1.default.existsSync(context.getSource(`${this._watchOptions.stepName}/errors.js`)) ||
114
- node_fs_1.default.existsSync(context.getSource(`${this._watchOptions.stepName}/warnings.js`)) ||
115
- stats.hasErrors() ||
116
- stats.hasWarnings()) {
117
- const statsJson = stats.toJson({
118
- errorDetails: true
119
- });
120
- if (statsJson.errors) {
121
- errors.push(...statsJson.errors);
122
- }
123
- if (statsJson.warnings) {
124
- warnings.push(...statsJson.warnings);
125
- }
126
- }
127
- }
128
- await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { errors }, "error", "errors", "Error");
129
- await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { warnings }, "warning", "warnings", "Warning");
130
- // clear error if checked
131
- if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
132
- context.clearError(this._options.name);
133
- }
134
- // check hash
135
- if (testConfig.writeStatsOuptut) {
136
- node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.txt"), node_path_1.default.join(context.getDist(), `stats.${this._watchOptions.stepName}.txt`));
137
- }
138
- if (testConfig.writeStatsJson) {
139
- node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.json"), node_path_1.default.join(context.getDist(), `stats.${this._watchOptions.stepName}.json`));
140
- }
141
- }
142
- async config(context) {
143
- this.multiCompilerOptions = [];
144
- const caseOptions = Array.isArray(this._multiOptions.configFiles)
145
- ? (0, helper_1.readConfigFile)(this._multiOptions.configFiles.map(i => context.getSource(i)))
146
- : [{}];
147
- for (const [index, options] of caseOptions.entries()) {
148
- const compilerOptions = (0, webpack_merge_1.merge)(typeof this._multiOptions.defaultOptions === "function"
149
- ? this._multiOptions.defaultOptions(index, context)
150
- : {}, options);
151
- if (typeof this._multiOptions.overrideOptions === "function") {
152
- this._multiOptions.overrideOptions(index, context, compilerOptions);
153
- }
154
- this.multiCompilerOptions.push(compilerOptions);
155
- }
156
- const compilerOptions = this.multiCompilerOptions.length === 1
157
- ? this.multiCompilerOptions[0]
158
- : this.multiCompilerOptions;
159
- const compiler = this.getCompiler(context);
160
- compiler.setOptions(compilerOptions);
161
- }
162
- static overrideOptions({ tempDir, nativeWatcher }) {
163
- return (index, context, options) => {
164
- if (!options.mode)
165
- options.mode = "development";
166
- if (!options.context)
167
- options.context = tempDir;
168
- if (!options.entry)
169
- options.entry = "./index.js";
170
- if (!options.target)
171
- options.target = "async-node";
172
- if (!options.devtool)
173
- options.devtool = false;
174
- if (!options.output)
175
- options.output = {};
176
- if (!options.output.path)
177
- options.output.path = context.getDist();
178
- if (typeof options.output.pathinfo === "undefined")
179
- options.output.pathinfo = false;
180
- if (!options.output.filename)
181
- options.output.filename = "bundle.js";
182
- if (options.cache && options.cache.type === "filesystem") {
183
- const cacheDirectory = node_path_1.default.join(tempDir, ".cache");
184
- options.cache.cacheDirectory = cacheDirectory;
185
- options.cache.name = `config-${index}`;
186
- }
187
- options.optimization ??= {};
188
- options.experiments ??= {};
189
- options.experiments.css ??= true;
190
- if (nativeWatcher) {
191
- options.experiments.nativeWatcher ??= true;
192
- }
193
- options.experiments.rspackFuture ??= {};
194
- options.experiments.rspackFuture.bundlerInfo ??= {};
195
- options.experiments.rspackFuture.bundlerInfo.force ??= false;
196
- // test incremental: "safe" here, we test default incremental in Incremental-*.test.js
197
- options.experiments.incremental ??= "safe";
198
- if (!global.printLogger) {
199
- options.infrastructureLogging = {
200
- level: "error"
201
- };
202
- }
203
- };
204
- }
205
- static findBundle(index, context, options) {
206
- const testConfig = context.getTestConfig();
207
- if (typeof testConfig.findBundle === "function") {
208
- return testConfig.findBundle(index, options, this.stepName);
209
- }
210
- return "./bundle.js";
211
- }
212
- }
213
- exports.WatchProcessor = WatchProcessor;
214
- class WatchStepProcessor extends WatchProcessor {
215
- constructor(_watchOptions, _watchState) {
216
- super(_watchOptions, _watchState);
217
- this._watchOptions = _watchOptions;
218
- this._watchState = _watchState;
219
- }
220
- async compiler(context) {
221
- // do nothing
222
- }
223
- async build(context) {
224
- const compiler = this.getCompiler(context);
225
- const currentWatchStepModule = require(currentWatchStepModulePath);
226
- currentWatchStepModule.step[this._options.name] =
227
- this._watchOptions.stepName;
228
- const task = new Promise((resolve, reject) => {
229
- compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
230
- if (e)
231
- return reject(e);
232
- resolve(stats);
233
- });
234
- });
235
- // wait compiler to ready watch the files and diretories
236
- await new Promise(resolve => setTimeout(resolve, 100));
237
- (0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), this._watchOptions.tempDir, false);
238
- await task;
239
- }
240
- }
241
- exports.WatchStepProcessor = WatchStepProcessor;
@@ -1,15 +0,0 @@
1
- import type { ITestReporter, TModuleCompareResult } from "../type";
2
- export interface IDiffHtmlReporterOptions {
3
- dist: string;
4
- ignore?: RegExp;
5
- }
6
- export declare class DiffHtmlReporter implements ITestReporter<TModuleCompareResult[]> {
7
- private options;
8
- private failed;
9
- private results;
10
- constructor(options: IDiffHtmlReporterOptions);
11
- init(data?: TModuleCompareResult[]): Promise<void>;
12
- failure(id: string): Promise<void>;
13
- increment(id: string, data: TModuleCompareResult[]): Promise<void>;
14
- output(): Promise<void>;
15
- }
@@ -1,69 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DiffHtmlReporter = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const VIEWER_DIR = node_path_1.default.join(__dirname, "../../template");
10
- const DIFF_STATS_PLACEHOLDER = "$$RSPACK_DIFF_STATS_PLACEHOLDER$$";
11
- const DEFAULT_IGNORE = /node_modules/;
12
- class DiffHtmlReporter {
13
- constructor(options) {
14
- this.options = options;
15
- this.failed = new Set();
16
- this.results = new Map();
17
- }
18
- async init(data = []) { }
19
- async failure(id) {
20
- this.failed.add(id);
21
- this.results.delete(id);
22
- }
23
- async increment(id, data) {
24
- if (this.failed.has(id))
25
- return;
26
- if (!this.results.has(id)) {
27
- this.results.set(id, []);
28
- }
29
- const ignore = this.options.ignore || DEFAULT_IGNORE;
30
- const current = this.results.get(id);
31
- for (const i of data) {
32
- if (!ignore.test(i.name)) {
33
- current.push({
34
- name: i.name,
35
- source: i.source || "",
36
- dist: i.dist || "",
37
- type: i.type
38
- });
39
- }
40
- }
41
- }
42
- async output() {
43
- fs_extra_1.default.ensureDirSync(this.options.dist);
44
- for (const viewerFile of fs_extra_1.default
45
- .readdirSync(VIEWER_DIR)
46
- .filter(file => file.startsWith("diff"))) {
47
- const sourceFile = node_path_1.default.join(VIEWER_DIR, viewerFile);
48
- if (node_path_1.default.extname(viewerFile) === ".html") {
49
- const template = fs_extra_1.default.readFileSync(sourceFile, "utf-8");
50
- for (const [id, items] of this.results.entries()) {
51
- const data = {
52
- root: id,
53
- data: items
54
- };
55
- const casename = node_path_1.default.basename(id);
56
- const extname = node_path_1.default.extname(viewerFile);
57
- const filename = node_path_1.default.basename(viewerFile, extname);
58
- const content = template.replace(`<script id="${DIFF_STATS_PLACEHOLDER}"></script>`, `<script src="${filename}_${casename}.js"></script>`);
59
- fs_extra_1.default.writeFileSync(node_path_1.default.join(this.options.dist, `${filename}_${casename}${extname}`), content, "utf-8");
60
- fs_extra_1.default.writeFileSync(node_path_1.default.join(this.options.dist, `${filename}_${casename}.js`), `window.$$diff_detail$$ = ${JSON.stringify(data)}`, "utf-8");
61
- }
62
- }
63
- else {
64
- fs_extra_1.default.copyFileSync(sourceFile, node_path_1.default.join(this.options.dist, viewerFile));
65
- }
66
- }
67
- }
68
- }
69
- exports.DiffHtmlReporter = DiffHtmlReporter;