@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,81 +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.ConfigProcessor = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const parseResource_1 = require("../helper/legacy/parseResource");
10
- const multi_1 = require("./multi");
11
- class ConfigProcessor extends multi_1.MultiTaskProcessor {
12
- constructor(_configOptions) {
13
- super({
14
- defaultOptions: (ConfigProcessor.defaultOptions),
15
- overrideOptions: (ConfigProcessor.overrideOptions),
16
- findBundle: (ConfigProcessor.findBundle),
17
- ..._configOptions
18
- });
19
- this._configOptions = _configOptions;
20
- }
21
- static findBundle(index, context, options) {
22
- const testConfig = context.getTestConfig();
23
- if (typeof testConfig.findBundle === "function") {
24
- return testConfig.findBundle(index, options);
25
- }
26
- const ext = node_path_1.default.extname((0, parseResource_1.parseResource)(options.output?.filename).path);
27
- const bundlePath = [];
28
- if (options.output?.path &&
29
- node_fs_1.default.existsSync(node_path_1.default.join(options.output.path, `bundle${index}${ext}`))) {
30
- if (options.experiments?.css) {
31
- const cssOutputPath = node_path_1.default.join(options.output.path, (typeof options.output?.cssFilename === "string" &&
32
- options.output?.cssFilename) ||
33
- `bundle${index}.css`);
34
- if (node_fs_1.default.existsSync(cssOutputPath)) {
35
- bundlePath.push(`./bundle${index}.css`);
36
- }
37
- }
38
- bundlePath.push(`./bundle${index}${ext}`);
39
- }
40
- return bundlePath;
41
- }
42
- static defaultOptions(index, context) {
43
- return {
44
- context: context.getSource(),
45
- mode: "production",
46
- target: "async-node",
47
- devtool: false,
48
- cache: false,
49
- output: {
50
- path: context.getDist()
51
- },
52
- optimization: {
53
- minimize: false
54
- },
55
- experiments: {
56
- css: true,
57
- rspackFuture: {
58
- bundlerInfo: {
59
- force: false
60
- }
61
- }
62
- }
63
- };
64
- }
65
- static overrideOptions(index, context, options) {
66
- if (!options.entry) {
67
- options.entry = "./index.js";
68
- }
69
- if (!options.output?.filename) {
70
- const outputModule = options.experiments?.outputModule;
71
- options.output ??= {};
72
- options.output.filename = `bundle${index}${outputModule ? ".mjs" : ".js"}`;
73
- }
74
- if (!global.printLogger) {
75
- options.infrastructureLogging = {
76
- level: "error"
77
- };
78
- }
79
- }
80
- }
81
- exports.ConfigProcessor = ConfigProcessor;
@@ -1,30 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
2
- import { SimpleTaskProcessor } from "./simple";
3
- declare class RspackTestDiff {
4
- value: string;
5
- constructor(value: string);
6
- }
7
- export interface IDefaultsConfigProcessorOptions<T extends ECompilerType> {
8
- options?: (context: ITestContext) => TCompilerOptions<T>;
9
- cwd?: string;
10
- name: string;
11
- diff: (diff: jest.JestMatchers<RspackTestDiff>, defaults: jest.JestMatchers<TCompilerOptions<T>>) => Promise<void>;
12
- compilerType: T;
13
- }
14
- export declare class DefaultsConfigProcessor<T extends ECompilerType> extends SimpleTaskProcessor<T> {
15
- protected _defaultsConfigOptions: IDefaultsConfigProcessorOptions<T>;
16
- private defaultConfig;
17
- constructor(_defaultsConfigOptions: IDefaultsConfigProcessorOptions<T>);
18
- compiler(context: ITestContext): Promise<void>;
19
- build(context: ITestContext): Promise<void>;
20
- run(env: ITestEnv, context: ITestContext): Promise<void>;
21
- check(env: ITestEnv, context: ITestContext): Promise<void>;
22
- before(context: ITestContext): Promise<void>;
23
- after(context: ITestContext): Promise<void>;
24
- beforeAll(context: ITestContext): Promise<void>;
25
- afterAll(context: ITestContext): Promise<void>;
26
- protected getCompiler(context: ITestContext): import("../type").ITestCompilerManager<T>;
27
- static getDefaultConfig(cwd: string, config: TCompilerOptions<ECompilerType>): TCompilerOptions<ECompilerType>;
28
- static overrideOptions<T extends ECompilerType>(options: TCompilerOptions<T>): void;
29
- }
30
- export {};
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultsConfigProcessor = void 0;
4
- const node_util_1 = require("node:util");
5
- const jest_diff_1 = require("jest-diff");
6
- const simple_1 = require("./simple");
7
- const CURRENT_CWD = process.cwd();
8
- class RspackTestDiff {
9
- constructor(value) {
10
- this.value = value;
11
- }
12
- }
13
- class DefaultsConfigProcessor extends simple_1.SimpleTaskProcessor {
14
- constructor(_defaultsConfigOptions) {
15
- super({
16
- options: context => {
17
- let res;
18
- if (typeof _defaultsConfigOptions.options === "function") {
19
- res = _defaultsConfigOptions.options(context);
20
- }
21
- else {
22
- res = {};
23
- }
24
- if (!("mode" in res)) {
25
- res.mode = "none";
26
- }
27
- return res;
28
- },
29
- compilerType: _defaultsConfigOptions.compilerType,
30
- name: _defaultsConfigOptions.name
31
- });
32
- this._defaultsConfigOptions = _defaultsConfigOptions;
33
- this.defaultConfig = DefaultsConfigProcessor.getDefaultConfig(CURRENT_CWD, {
34
- mode: "none"
35
- });
36
- }
37
- async compiler(context) { }
38
- async build(context) { }
39
- async run(env, context) { }
40
- async check(env, context) {
41
- const compiler = this.getCompiler(context);
42
- const config = DefaultsConfigProcessor.getDefaultConfig(this._defaultsConfigOptions.cwd || CURRENT_CWD, compiler.getOptions());
43
- const diff = (0, node_util_1.stripVTControlCharacters)((0, jest_diff_1.diff)(this.defaultConfig, config, { expand: false, contextLines: 0 }));
44
- await this._defaultsConfigOptions.diff(env.expect(new RspackTestDiff(diff)), env.expect(this.defaultConfig));
45
- }
46
- async before(context) { }
47
- async after(context) { }
48
- async beforeAll(context) { }
49
- async afterAll(context) { }
50
- getCompiler(context) {
51
- return context.getCompiler(this._options.name, this._options.compilerType);
52
- }
53
- static getDefaultConfig(cwd, config) {
54
- process.chdir(cwd);
55
- const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = require("@rspack/core").config;
56
- const normalizedConfig = getNormalizedWebpackOptions(config);
57
- applyWebpackOptionsDefaults(normalizedConfig);
58
- // make snapshot stable
59
- normalizedConfig.experiments.rspackFuture.bundlerInfo.version =
60
- "$version$";
61
- process.chdir(CURRENT_CWD);
62
- return normalizedConfig;
63
- }
64
- static overrideOptions(options) {
65
- if (!global.printLogger) {
66
- options.infrastructureLogging = {
67
- level: "error"
68
- };
69
- }
70
- }
71
- }
72
- exports.DefaultsConfigProcessor = DefaultsConfigProcessor;
@@ -1,15 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
2
- import { BasicProcessor, type IBasicProcessorOptions } from "./basic";
3
- export interface IDiagnosticProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
4
- snapshot: string;
5
- snapshotErrors: string;
6
- snapshotWarning: string;
7
- format?: (output: string) => string;
8
- }
9
- export declare class DiagnosticProcessor<T extends ECompilerType> extends BasicProcessor<T> {
10
- protected _diagnosticOptions: IDiagnosticProcessorOptions<T>;
11
- constructor(_diagnosticOptions: IDiagnosticProcessorOptions<T>);
12
- check(env: ITestEnv, context: ITestContext): Promise<void>;
13
- static defaultOptions<T extends ECompilerType>(context: ITestContext): TCompilerOptions<T>;
14
- static overrideOptions<T extends ECompilerType>(options: TCompilerOptions<T>): void;
15
- }
@@ -1,102 +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.DiagnosticProcessor = void 0;
7
- const node_assert_1 = __importDefault(require("node:assert"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const placeholder_1 = require("../helper/expect/placeholder");
10
- const basic_1 = require("./basic");
11
- class DiagnosticProcessor extends basic_1.BasicProcessor {
12
- constructor(_diagnosticOptions) {
13
- super({
14
- defaultOptions: (DiagnosticProcessor.defaultOptions),
15
- runable: false,
16
- ..._diagnosticOptions
17
- });
18
- this._diagnosticOptions = _diagnosticOptions;
19
- }
20
- async check(env, context) {
21
- const compiler = this.getCompiler(context);
22
- const stats = compiler.getStats();
23
- if (!stats) {
24
- throw new Error("Stats should exists");
25
- }
26
- (0, node_assert_1.default)(stats.hasErrors() || stats.hasWarnings());
27
- let output = (0, placeholder_1.normalizePlaceholder)(stats.toString({
28
- all: false,
29
- errors: true,
30
- warnings: true
31
- })).replaceAll("\\", "/"); // stats has some win32 paths that path-serializer can not handle
32
- const statsJson = stats.toJson({
33
- all: false,
34
- errors: true,
35
- warnings: true
36
- });
37
- const errors = (statsJson.errors || []).map(e => {
38
- // @ts-expect-error error message is already serialized in `stats.err`
39
- delete e.message;
40
- delete e.stack;
41
- return e;
42
- });
43
- const warnings = (statsJson.warnings || []).map(e => {
44
- // @ts-expect-error error message is already serialized in `stats.err`
45
- delete e.message;
46
- delete e.stack;
47
- return e;
48
- });
49
- if (typeof this._diagnosticOptions.format === "function") {
50
- output = this._diagnosticOptions.format(output);
51
- }
52
- env.expect.addSnapshotSerializer({
53
- test(received) {
54
- return typeof received === "string";
55
- },
56
- serialize(received) {
57
- return (0, placeholder_1.normalizePlaceholder)(received.trim());
58
- }
59
- });
60
- const errorOutputPath = node_path_1.default.resolve(context.getSource(this._diagnosticOptions.snapshot));
61
- const errorStatsOutputPath = node_path_1.default.resolve(context.getSource(this._diagnosticOptions.snapshotErrors));
62
- const warningStatsOutputPath = node_path_1.default.resolve(context.getSource(this._diagnosticOptions.snapshotWarning));
63
- env.expect(output).toMatchFileSnapshot(errorOutputPath);
64
- env.expect(errors).toMatchFileSnapshot(errorStatsOutputPath);
65
- env.expect(warnings).toMatchFileSnapshot(warningStatsOutputPath);
66
- }
67
- static defaultOptions(context) {
68
- return {
69
- target: "node",
70
- context: context.getSource(),
71
- entry: {
72
- main: "./"
73
- },
74
- mode: "development",
75
- devServer: {
76
- hot: false
77
- },
78
- infrastructureLogging: {
79
- debug: false
80
- },
81
- output: {
82
- path: context.getDist()
83
- },
84
- experiments: {
85
- css: true,
86
- rspackFuture: {
87
- bundlerInfo: {
88
- force: false
89
- }
90
- }
91
- }
92
- };
93
- }
94
- static overrideOptions(options) {
95
- if (!global.printLogger) {
96
- options.infrastructureLogging = {
97
- level: "error"
98
- };
99
- }
100
- }
101
- }
102
- exports.DiagnosticProcessor = DiagnosticProcessor;
@@ -1,30 +0,0 @@
1
- import { type IFormatCodeOptions, type IFormatCodeReplacement } from "../compare";
2
- import { type ITestContext, type ITestEnv, type ITestProcessor, type TCompareModules, type TFileCompareResult, type TModuleCompareResult } from "../type";
3
- export interface IDiffProcessorOptions extends IFormatCodeOptions {
4
- webpackPath: string;
5
- rspackPath: string;
6
- files?: string[];
7
- modules?: TCompareModules;
8
- runtimeModules?: TCompareModules;
9
- bootstrap?: boolean;
10
- detail?: boolean;
11
- errors?: boolean;
12
- replacements?: IFormatCodeReplacement[];
13
- renameModule?: (file: string) => string;
14
- onCompareFile?: (file: string, result: TFileCompareResult) => void;
15
- onCompareModules?: (file: string, results: TModuleCompareResult[]) => void;
16
- onCompareRuntimeModules?: (file: string, results: TModuleCompareResult[]) => void;
17
- }
18
- export declare class DiffProcessor implements ITestProcessor {
19
- private options;
20
- private hashes;
21
- private webpack;
22
- private rspack;
23
- constructor(options: IDiffProcessorOptions);
24
- config(context: ITestContext): Promise<void>;
25
- compiler(context: ITestContext): Promise<void>;
26
- build(context: ITestContext): Promise<void>;
27
- check(env: ITestEnv, context: ITestContext): Promise<void>;
28
- private getDefaultOptions;
29
- private createFormatOptions;
30
- }
@@ -1,140 +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.DiffProcessor = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const compare_1 = require("../compare");
9
- const plugin_1 = require("../plugin");
10
- const type_1 = require("../type");
11
- const basic_1 = require("./basic");
12
- class DiffProcessor {
13
- constructor(options) {
14
- this.options = options;
15
- this.hashes = [];
16
- this.webpack = null;
17
- if (global.updateSnapshot) {
18
- this.webpack = new basic_1.BasicProcessor({
19
- defaultOptions: context => this.getDefaultOptions(type_1.ECompilerType.Webpack, context.getSource(), node_path_1.default.join(context.getDist(), type_1.ECompilerType.Webpack)),
20
- compilerType: type_1.ECompilerType.Webpack,
21
- name: type_1.ECompilerType.Webpack,
22
- configFiles: ["webpack.config.js", "rspack.config.js"],
23
- runable: false
24
- });
25
- }
26
- this.rspack = new basic_1.BasicProcessor({
27
- defaultOptions: context => this.getDefaultOptions(type_1.ECompilerType.Rspack, context.getSource(), node_path_1.default.join(context.getDist(), type_1.ECompilerType.Rspack)),
28
- compilerType: type_1.ECompilerType.Rspack,
29
- name: type_1.ECompilerType.Rspack,
30
- configFiles: ["rspack.config.js", "webpack.config.js"],
31
- runable: false
32
- });
33
- }
34
- async config(context) {
35
- if (this.webpack) {
36
- await this.webpack.config(context);
37
- }
38
- await this.rspack.config(context);
39
- }
40
- async compiler(context) {
41
- if (this.webpack) {
42
- await this.webpack.compiler(context);
43
- }
44
- await this.rspack.compiler(context);
45
- }
46
- async build(context) {
47
- if (this.webpack) {
48
- await this.webpack.build(context);
49
- }
50
- await this.rspack.build(context);
51
- }
52
- async check(env, context) {
53
- if (this.webpack) {
54
- const webpackCompiler = context.getCompiler(type_1.ECompilerType.Webpack);
55
- const webpackStats = webpackCompiler.getStats();
56
- //TODO: handle chunk hash and content hash
57
- webpackStats?.hash && this.hashes.push(webpackStats?.hash);
58
- if (!this.options.errors) {
59
- env.expect(webpackStats?.hasErrors()).toBe(false);
60
- }
61
- }
62
- const rspackCompiler = context.getCompiler(type_1.ECompilerType.Rspack);
63
- const rspackStats = rspackCompiler.getStats();
64
- //TODO: handle chunk hash and content hash
65
- rspackStats?.hash && this.hashes.push(rspackStats?.hash);
66
- if (!this.options.errors) {
67
- env.expect(rspackStats?.hasErrors()).toBe(false);
68
- }
69
- const dist = context.getDist();
70
- const snapshot = context.getSource("__snapshot__");
71
- for (const file of this.options.files) {
72
- const rspackDist = node_path_1.default.join(dist, type_1.ECompilerType.Rspack, file);
73
- const webpackDist = node_path_1.default.join(dist, type_1.ECompilerType.Webpack, file);
74
- const snapshotDist = node_path_1.default.join(snapshot, file.replace(/\.js$/, ".json"));
75
- const result = (0, compare_1.compareFile)(rspackDist, webpackDist, {
76
- modules: this.options.modules,
77
- runtimeModules: this.options.runtimeModules,
78
- format: this.createFormatOptions(),
79
- renameModule: this.options.renameModule,
80
- bootstrap: this.options.bootstrap,
81
- detail: this.options.detail,
82
- snapshot: snapshotDist
83
- });
84
- if (typeof this.options.onCompareFile === "function") {
85
- this.options.onCompareFile(file, result);
86
- }
87
- if (typeof this.options.onCompareModules === "function" &&
88
- result.modules.modules) {
89
- this.options.onCompareModules(file, result.modules.modules);
90
- }
91
- if (typeof this.options.onCompareRuntimeModules === "function" &&
92
- result.modules.runtimeModules) {
93
- this.options.onCompareRuntimeModules(file, result.modules.runtimeModules);
94
- }
95
- }
96
- }
97
- getDefaultOptions(type, src, dist) {
98
- return {
99
- entry: node_path_1.default.join(src, "./src/index.js"),
100
- context: src,
101
- output: {
102
- path: dist,
103
- filename: "bundle.js",
104
- chunkFilename: "[name].chunk.js"
105
- },
106
- plugins: [
107
- type === type_1.ECompilerType.Webpack && new plugin_1.WebpackDiffConfigPlugin(),
108
- type === type_1.ECompilerType.Rspack && new plugin_1.RspackDiffConfigPlugin()
109
- ].filter(Boolean),
110
- experiments: type === type_1.ECompilerType.Rspack
111
- ? {
112
- css: true,
113
- rspackFuture: {
114
- bundlerInfo: {
115
- force: false
116
- }
117
- }
118
- }
119
- : {}
120
- };
121
- }
122
- createFormatOptions() {
123
- const formatOptions = {
124
- ignoreModuleArguments: this.options.ignoreModuleArguments,
125
- ignoreModuleId: this.options.ignoreModuleId,
126
- ignorePropertyQuotationMark: this.options.ignorePropertyQuotationMark,
127
- ignoreBlockOnlyStatement: this.options.ignoreBlockOnlyStatement,
128
- ignoreIfCertainCondition: this.options.ignoreIfCertainCondition,
129
- ignoreSwcHelpersPath: this.options.ignoreSwcHelpersPath,
130
- ignoreObjectPropertySequence: this.options.ignoreObjectPropertySequence,
131
- ignoreCssFilePath: this.options.ignoreCssFilePath,
132
- replacements: this.options.replacements || []
133
- };
134
- for (const hash of this.hashes) {
135
- formatOptions.replacements.push({ from: hash, to: "fullhash" });
136
- }
137
- return formatOptions;
138
- }
139
- }
140
- exports.DiffProcessor = DiffProcessor;
@@ -1,23 +0,0 @@
1
- import type { StatsError } from "@rspack/core";
2
- import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions } from "../type";
3
- import { SimpleTaskProcessor } from "./simple";
4
- declare class RspackStatsDiagnostics {
5
- errors: StatsError[];
6
- warnings: StatsError[];
7
- constructor(errors: StatsError[], warnings: StatsError[]);
8
- }
9
- export interface IErrorProcessorOptions<T extends ECompilerType> {
10
- name: string;
11
- compilerType: T;
12
- options?: (options: TCompilerOptions<T>, context: ITestContext) => TCompilerOptions<T>;
13
- build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
14
- check?: (stats: RspackStatsDiagnostics) => Promise<void>;
15
- }
16
- export declare class ErrorProcessor<T extends ECompilerType> extends SimpleTaskProcessor<T> {
17
- protected _errorOptions: IErrorProcessorOptions<T>;
18
- constructor(_errorOptions: IErrorProcessorOptions<T>);
19
- compiler(context: ITestContext): Promise<void>;
20
- run(env: ITestEnv, context: ITestContext): Promise<void>;
21
- check(env: ITestEnv, context: ITestContext): Promise<void>;
22
- }
23
- export {};
@@ -1,95 +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.ErrorProcessor = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const webpack_merge_1 = __importDefault(require("webpack-merge"));
9
- const simple_1 = require("./simple");
10
- class RspackStatsDiagnostics {
11
- constructor(errors, warnings) {
12
- this.errors = errors;
13
- this.warnings = warnings;
14
- }
15
- }
16
- class ErrorProcessor extends simple_1.SimpleTaskProcessor {
17
- constructor(_errorOptions) {
18
- super({
19
- options: (context) => {
20
- let options = {
21
- context: node_path_1.default.resolve(__dirname, "../../tests/fixtures/errors"),
22
- mode: "none",
23
- devtool: false,
24
- optimization: {
25
- minimize: false,
26
- moduleIds: "named",
27
- chunkIds: "named"
28
- },
29
- experiments: {
30
- css: true,
31
- rspackFuture: {
32
- bundlerInfo: {
33
- force: false
34
- }
35
- }
36
- }
37
- };
38
- if (typeof _errorOptions.options === "function") {
39
- options = (0, webpack_merge_1.default)(options, _errorOptions.options(options, context));
40
- }
41
- if (options.mode === "production") {
42
- if (options.optimization)
43
- options.optimization.minimize = true;
44
- else
45
- options.optimization = { minimize: true };
46
- }
47
- return options;
48
- },
49
- build: _errorOptions.build,
50
- compilerType: _errorOptions.compilerType,
51
- name: _errorOptions.name
52
- });
53
- this._errorOptions = _errorOptions;
54
- }
55
- async compiler(context) {
56
- await super.compiler(context);
57
- const compiler = this.getCompiler(context).getCompiler();
58
- if (compiler) {
59
- compiler.outputFileSystem = {
60
- // CHANGE: rspack outputFileSystem `mkdirp` uses option `{ recursive: true }`, webpack's second parameter is alway a callback
61
- mkdir(dir, maybeOptionOrCallback, maybeCallback) {
62
- if (typeof maybeOptionOrCallback === "function") {
63
- maybeOptionOrCallback();
64
- }
65
- else if (typeof maybeCallback === "function") {
66
- maybeCallback();
67
- }
68
- },
69
- writeFile(file, content, callback) {
70
- callback();
71
- },
72
- stat(file, callback) {
73
- callback(new Error("ENOENT"));
74
- },
75
- mkdirSync() { },
76
- writeFileSync() { }
77
- };
78
- }
79
- }
80
- async run(env, context) {
81
- // do nothing
82
- }
83
- async check(env, context) {
84
- const compiler = this.getCompiler(context);
85
- const stats = compiler.getStats();
86
- env.expect(typeof stats).toBe("object");
87
- const statsResult = stats.toJson({ errorDetails: false });
88
- env.expect(typeof statsResult).toBe("object");
89
- const { errors, warnings } = statsResult;
90
- env.expect(Array.isArray(errors)).toBe(true);
91
- env.expect(Array.isArray(warnings)).toBe(true);
92
- await this._errorOptions.check?.(new RspackStatsDiagnostics(errors, warnings));
93
- }
94
- }
95
- exports.ErrorProcessor = ErrorProcessor;
@@ -1,10 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
2
- import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";
3
- export interface IHashProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {
4
- }
5
- export declare class HashProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
6
- constructor(_hashOptions: IHashProcessorOptions<T>);
7
- check(env: ITestEnv, context: ITestContext): Promise<void>;
8
- static defaultOptions<T extends ECompilerType>(index: number, context: ITestContext): TCompilerOptions<T>;
9
- static overrideOptions<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): void;
10
- }
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HashProcessor = void 0;
4
- const multi_1 = require("./multi");
5
- const REG_ERROR_CASE = /error$/;
6
- class HashProcessor extends multi_1.MultiTaskProcessor {
7
- constructor(_hashOptions) {
8
- super({
9
- defaultOptions: (HashProcessor.defaultOptions),
10
- overrideOptions: (HashProcessor.overrideOptions),
11
- runable: false,
12
- ..._hashOptions
13
- });
14
- }
15
- async check(env, context) {
16
- const compiler = this.getCompiler(context);
17
- const testConfig = context.getTestConfig();
18
- const stats = compiler.getStats();
19
- if (!stats) {
20
- env.expect(false);
21
- return;
22
- }
23
- if (REG_ERROR_CASE.test(this._options.name)) {
24
- env.expect(stats.hasErrors());
25
- }
26
- else {
27
- env.expect(!stats.hasErrors());
28
- }
29
- if (typeof testConfig.validate === "function") {
30
- testConfig.validate(stats);
31
- }
32
- else {
33
- throw new Error("HashTestCases should have test.config.js and a validate method");
34
- }
35
- }
36
- static defaultOptions(index, context) {
37
- return {
38
- context: context.getSource(),
39
- output: {
40
- path: context.getDist()
41
- },
42
- experiments: {
43
- css: true,
44
- rspackFuture: {
45
- bundlerInfo: {
46
- force: false
47
- }
48
- }
49
- }
50
- };
51
- }
52
- static overrideOptions(index, context, options) {
53
- if (!options.entry) {
54
- options.entry = "./index.js";
55
- }
56
- if (!global.printLogger) {
57
- options.infrastructureLogging = {
58
- level: "error"
59
- };
60
- }
61
- }
62
- }
63
- exports.HashProcessor = HashProcessor;