@rspack-canary/test-tools 1.5.6-canary-e598f284-20250921173624 → 1.5.8-canary-e350b761-20250924173613

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 (122) hide show
  1. package/dist/case/builtin.d.ts +2 -0
  2. package/dist/case/builtin.js +173 -13
  3. package/dist/case/cache.d.ts +1 -1
  4. package/dist/case/cache.js +210 -11
  5. package/dist/case/common.d.ts +10 -0
  6. package/dist/case/common.js +237 -0
  7. package/dist/case/compiler.d.ts +7 -4
  8. package/dist/case/compiler.js +144 -109
  9. package/dist/case/config.d.ts +5 -1
  10. package/dist/case/config.js +102 -16
  11. package/dist/case/defaults.d.ts +12 -4
  12. package/dist/case/defaults.js +67 -12
  13. package/dist/case/diagnostic.d.ts +6 -0
  14. package/dist/case/diagnostic.js +123 -14
  15. package/dist/case/diff.d.ts +17 -1
  16. package/dist/case/diff.js +170 -22
  17. package/dist/case/error.d.ts +14 -4
  18. package/dist/case/error.js +117 -10
  19. package/dist/case/hash.d.ts +1 -1
  20. package/dist/case/hash.js +70 -9
  21. package/dist/case/hook.d.ts +35 -4
  22. package/dist/case/hook.js +210 -21
  23. package/dist/case/hot-step.js +307 -9
  24. package/dist/case/hot.d.ts +8 -1
  25. package/dist/case/hot.js +235 -8
  26. package/dist/case/incremental.d.ts +1 -1
  27. package/dist/case/incremental.js +39 -41
  28. package/dist/case/index.d.ts +20 -20
  29. package/dist/case/index.js +44 -34
  30. package/dist/case/native-watcher.js +10 -23
  31. package/dist/case/normal.js +174 -12
  32. package/dist/case/runner.d.ts +18 -0
  33. package/dist/case/runner.js +108 -0
  34. package/dist/case/serial.d.ts +1 -1
  35. package/dist/case/serial.js +8 -12
  36. package/dist/case/stats-api.d.ts +0 -5
  37. package/dist/case/stats-api.js +71 -10
  38. package/dist/case/stats-output.js +197 -11
  39. package/dist/case/treeshaking.js +34 -7
  40. package/dist/case/watch.d.ts +27 -0
  41. package/dist/case/watch.js +321 -21
  42. package/dist/helper/plugins/hot-update.d.ts +2 -2
  43. package/dist/index.d.ts +0 -2
  44. package/dist/index.js +0 -2
  45. package/dist/runner/index.d.ts +2 -7
  46. package/dist/runner/index.js +2 -7
  47. package/dist/runner/{runner/node → node}/index.d.ts +1 -2
  48. package/dist/runner/{runner/node → node}/index.js +2 -2
  49. package/dist/runner/{runner/web → web}/fake.d.ts +1 -2
  50. package/dist/runner/{runner/web → web}/fake.js +7 -7
  51. package/dist/runner/{runner/web → web}/index.d.ts +2 -2
  52. package/dist/runner/{runner/web → web}/index.js +1 -1
  53. package/dist/runner/{runner/web → web}/jsdom.d.ts +1 -2
  54. package/dist/runner/{runner/web → web}/jsdom.js +4 -4
  55. package/dist/test/context.d.ts +3 -5
  56. package/dist/test/context.js +22 -12
  57. package/dist/test/creator.d.ts +13 -12
  58. package/dist/test/creator.js +52 -43
  59. package/dist/test/tester.js +4 -1
  60. package/dist/type.d.ts +42 -11
  61. package/dist/type.js +7 -1
  62. package/package.json +5 -5
  63. package/dist/processor/basic.d.ts +0 -24
  64. package/dist/processor/basic.js +0 -147
  65. package/dist/processor/builtin.d.ts +0 -9
  66. package/dist/processor/builtin.js +0 -171
  67. package/dist/processor/cache.d.ts +0 -20
  68. package/dist/processor/cache.js +0 -131
  69. package/dist/processor/config.d.ts +0 -11
  70. package/dist/processor/config.js +0 -88
  71. package/dist/processor/defaults.d.ts +0 -30
  72. package/dist/processor/defaults.js +0 -72
  73. package/dist/processor/diagnostic.d.ts +0 -15
  74. package/dist/processor/diagnostic.js +0 -104
  75. package/dist/processor/diff.d.ts +0 -30
  76. package/dist/processor/diff.js +0 -140
  77. package/dist/processor/error.d.ts +0 -23
  78. package/dist/processor/error.js +0 -95
  79. package/dist/processor/hash.d.ts +0 -10
  80. package/dist/processor/hash.js +0 -65
  81. package/dist/processor/hook.d.ts +0 -44
  82. package/dist/processor/hook.js +0 -206
  83. package/dist/processor/hot-incremental.d.ts +0 -14
  84. package/dist/processor/hot-incremental.js +0 -43
  85. package/dist/processor/hot-step.d.ts +0 -18
  86. package/dist/processor/hot-step.js +0 -307
  87. package/dist/processor/hot.d.ts +0 -17
  88. package/dist/processor/hot.js +0 -147
  89. package/dist/processor/index.d.ts +0 -20
  90. package/dist/processor/index.js +0 -36
  91. package/dist/processor/multi.d.ts +0 -17
  92. package/dist/processor/multi.js +0 -73
  93. package/dist/processor/normal.d.ts +0 -12
  94. package/dist/processor/normal.js +0 -170
  95. package/dist/processor/simple.d.ts +0 -24
  96. package/dist/processor/simple.js +0 -51
  97. package/dist/processor/snapshot.d.ts +0 -12
  98. package/dist/processor/snapshot.js +0 -66
  99. package/dist/processor/stats-api.d.ts +0 -18
  100. package/dist/processor/stats-api.js +0 -48
  101. package/dist/processor/stats.d.ts +0 -18
  102. package/dist/processor/stats.js +0 -206
  103. package/dist/processor/treeshaking.d.ts +0 -10
  104. package/dist/processor/treeshaking.js +0 -33
  105. package/dist/processor/watch.d.ts +0 -30
  106. package/dist/processor/watch.js +0 -252
  107. package/dist/runner/basic.d.ts +0 -10
  108. package/dist/runner/basic.js +0 -64
  109. package/dist/runner/cache.d.ts +0 -5
  110. package/dist/runner/cache.js +0 -92
  111. package/dist/runner/hot.d.ts +0 -5
  112. package/dist/runner/hot.js +0 -91
  113. package/dist/runner/multiple.d.ts +0 -11
  114. package/dist/runner/multiple.js +0 -52
  115. package/dist/runner/runner/index.d.ts +0 -2
  116. package/dist/runner/runner/index.js +0 -18
  117. package/dist/runner/type.d.ts +0 -42
  118. package/dist/runner/type.js +0 -9
  119. package/dist/runner/watch.d.ts +0 -7
  120. package/dist/runner/watch.js +0 -71
  121. package/dist/test/simple.d.ts +0 -5
  122. package/dist/test/simple.js +0 -43
@@ -1,6 +1,14 @@
1
- import { type IDefaultsConfigProcessorOptions } from "../processor";
2
- import { ECompilerType } from "../type";
3
- export type TDefaultsCaseConfig = Omit<IDefaultsConfigProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
1
+ import type { ECompilerType, ITestContext, TCompilerOptions } from "../type";
2
+ export declare function createDefaultsCase(name: string, src: string): void;
3
+ export declare function getRspackDefaultConfig(cwd: string, config: TCompilerOptions<ECompilerType>): TCompilerOptions<ECompilerType>;
4
+ export type TDefaultsCaseConfig = {
5
+ options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
6
+ cwd?: string;
7
+ diff: (diff: jest.JestMatchers<RspackTestDiff>, defaults: jest.JestMatchers<TCompilerOptions<ECompilerType.Rspack>>) => Promise<void>;
4
8
  description: string;
5
9
  };
6
- export declare function createDefaultsCase(name: string, src: string): void;
10
+ declare class RspackTestDiff {
11
+ value: string;
12
+ constructor(value: string);
13
+ }
14
+ export {};
@@ -4,16 +4,81 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createDefaultsCase = createDefaultsCase;
7
+ exports.getRspackDefaultConfig = getRspackDefaultConfig;
7
8
  const node_path_1 = __importDefault(require("node:path"));
8
- const processor_1 = require("../processor");
9
+ const node_util_1 = require("node:util");
10
+ const jest_diff_1 = require("jest-diff");
9
11
  const context_1 = require("../test/context");
10
- const type_1 = require("../type");
12
+ const common_1 = require("./common");
13
+ const CURRENT_CWD = process.cwd();
14
+ function createDefaultsCase(name, src) {
15
+ const caseConfig = require(src);
16
+ it(`should generate the correct defaults from ${caseConfig.description}`, async () => {
17
+ await run(name, {
18
+ config: async (context) => {
19
+ const compiler = (0, common_1.getCompiler)(context, name);
20
+ compiler.setOptions(options(context, caseConfig.options));
21
+ },
22
+ compiler: async (context) => {
23
+ const compiler = (0, common_1.getCompiler)(context, name);
24
+ compiler.createCompiler();
25
+ },
26
+ build: async (context) => {
27
+ // no need to build, just check the snapshot of compiler options
28
+ },
29
+ run: async (env, context) => {
30
+ // no need to run, just check the snapshot of compiler options
31
+ },
32
+ check: async (env, context) => {
33
+ await check(env, context, name, caseConfig);
34
+ }
35
+ });
36
+ });
37
+ }
38
+ function getRspackDefaultConfig(cwd, config) {
39
+ process.chdir(cwd);
40
+ const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = require("@rspack/core").config;
41
+ const normalizedConfig = getNormalizedWebpackOptions(config);
42
+ applyWebpackOptionsDefaults(normalizedConfig);
43
+ // make snapshot stable
44
+ normalizedConfig.experiments.rspackFuture.bundlerInfo.version =
45
+ "$version$";
46
+ process.chdir(CURRENT_CWD);
47
+ return normalizedConfig;
48
+ }
11
49
  const srcDir = node_path_1.default.resolve(__dirname, "../../tests/fixtures");
12
50
  const distDir = node_path_1.default.resolve(__dirname, "../../tests/js/defaults");
13
51
  const context = new context_1.TestContext({
14
52
  src: srcDir,
15
53
  dist: distDir
16
54
  });
55
+ function options(context, custom) {
56
+ let res;
57
+ if (typeof custom === "function") {
58
+ res = custom(context);
59
+ }
60
+ else {
61
+ res = {};
62
+ }
63
+ if (!("mode" in res)) {
64
+ res.mode = "none";
65
+ }
66
+ return res;
67
+ }
68
+ class RspackTestDiff {
69
+ constructor(value) {
70
+ this.value = value;
71
+ }
72
+ }
73
+ async function check(env, context, name, options) {
74
+ const compiler = (0, common_1.getCompiler)(context, name);
75
+ const config = getRspackDefaultConfig(options.cwd || CURRENT_CWD, compiler.getOptions());
76
+ const defaultConfig = getRspackDefaultConfig(options.cwd || CURRENT_CWD, {
77
+ mode: "none"
78
+ });
79
+ const diff = (0, node_util_1.stripVTControlCharacters)((0, jest_diff_1.diff)(defaultConfig, config, { expand: false, contextLines: 0 }));
80
+ await options.diff(env.expect(new RspackTestDiff(diff)), env.expect(defaultConfig));
81
+ }
17
82
  async function run(name, processor) {
18
83
  try {
19
84
  await processor.before?.(context);
@@ -27,13 +92,3 @@ async function run(name, processor) {
27
92
  await processor.after?.(context);
28
93
  }
29
94
  }
30
- function createDefaultsCase(name, src) {
31
- const caseConfig = require(src);
32
- it(`should generate the correct defaults from ${caseConfig.description}`, async () => {
33
- await run(name, new processor_1.DefaultsConfigProcessor({
34
- name,
35
- compilerType: type_1.ECompilerType.Rspack,
36
- ...caseConfig
37
- }));
38
- });
39
- }
@@ -1 +1,7 @@
1
1
  export declare function createDiagnosticCase(name: string, src: string, dist: string): void;
2
+ export interface IDiagnosticOptions {
3
+ snapshot: string;
4
+ snapshotErrors: string;
5
+ snapshotWarning: string;
6
+ format?: (output: string) => string;
7
+ }
@@ -1,29 +1,138 @@
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 });
3
6
  exports.createDiagnosticCase = createDiagnosticCase;
4
- const processor_1 = require("../processor");
7
+ const node_assert_1 = __importDefault(require("node:assert"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const webpack_merge_1 = __importDefault(require("webpack-merge"));
10
+ const helper_1 = require("../helper");
11
+ const placeholder_1 = require("../helper/expect/placeholder");
5
12
  const creator_1 = require("../test/creator");
6
- const type_1 = require("../type");
13
+ const common_1 = require("./common");
7
14
  const creator = new creator_1.BasicCaseCreator({
8
15
  clean: true,
9
16
  describe: false,
10
17
  steps: ({ name }) => [
11
- new processor_1.DiagnosticProcessor({
12
- name,
13
- snapshot: "./stats.err",
14
- snapshotErrors: "./raw-error.err",
15
- snapshotWarning: "./raw-warning.err",
16
- configFiles: ["rspack.config.js", "webpack.config.js"],
17
- compilerType: type_1.ECompilerType.Rspack,
18
- format: (output) => {
19
- // TODO: change to stats.errorStack
20
- // TODO: add `errorStack: false`
21
- return output.replace(/(│.* at ).*/g, "$1xxx");
18
+ {
19
+ config: async (context) => {
20
+ const compiler = (0, common_1.getCompiler)(context, name);
21
+ let options = defaultOptions(context);
22
+ const custom = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)))[0];
23
+ if (custom) {
24
+ options = (0, webpack_merge_1.default)(options, custom);
25
+ }
26
+ if (!global.printLogger) {
27
+ options.infrastructureLogging = {
28
+ level: "error"
29
+ };
30
+ }
31
+ compiler.setOptions(options);
32
+ },
33
+ compiler: async (context) => {
34
+ const compiler = (0, common_1.getCompiler)(context, name);
35
+ compiler.createCompiler();
36
+ },
37
+ build: async (context) => {
38
+ const compiler = (0, common_1.getCompiler)(context, name);
39
+ await compiler.build();
40
+ },
41
+ run: async (env, context) => {
42
+ // no need to run, just check the snapshot of diagnostics
43
+ },
44
+ check: async (env, context) => {
45
+ await check(env, context, name, {
46
+ snapshot: "./stats.err",
47
+ snapshotErrors: "./raw-error.err",
48
+ snapshotWarning: "./raw-warning.err",
49
+ format: (output) => {
50
+ // TODO: change to stats.errorStack
51
+ // TODO: add `errorStack: false`
52
+ return output.replace(/(│.* at ).*/g, "$1xxx");
53
+ }
54
+ });
22
55
  }
23
- })
56
+ }
24
57
  ],
25
58
  concurrent: true
26
59
  });
27
60
  function createDiagnosticCase(name, src, dist) {
28
61
  creator.create(name, src, dist);
29
62
  }
63
+ function defaultOptions(context) {
64
+ return {
65
+ target: "node",
66
+ context: context.getSource(),
67
+ entry: {
68
+ main: "./"
69
+ },
70
+ mode: "development",
71
+ devServer: {
72
+ hot: false
73
+ },
74
+ infrastructureLogging: {
75
+ debug: false
76
+ },
77
+ output: {
78
+ path: context.getDist()
79
+ },
80
+ experiments: {
81
+ css: true,
82
+ rspackFuture: {
83
+ bundlerInfo: {
84
+ force: false
85
+ }
86
+ },
87
+ inlineConst: true,
88
+ lazyBarrel: true
89
+ }
90
+ };
91
+ }
92
+ async function check(env, context, name, options) {
93
+ const compiler = (0, common_1.getCompiler)(context, name);
94
+ const stats = compiler.getStats();
95
+ if (!stats) {
96
+ throw new Error("Stats should exists");
97
+ }
98
+ (0, node_assert_1.default)(stats.hasErrors() || stats.hasWarnings());
99
+ let output = (0, placeholder_1.normalizePlaceholder)(stats.toString({
100
+ all: false,
101
+ errors: true,
102
+ warnings: true
103
+ })).replaceAll("\\", "/");
104
+ const statsJson = stats.toJson({
105
+ all: false,
106
+ errors: true,
107
+ warnings: true
108
+ });
109
+ const errors = (statsJson.errors || []).map(e => {
110
+ // @ts-expect-error error message is already serialized in `stats.err`
111
+ delete e.message;
112
+ delete e.stack;
113
+ return e;
114
+ });
115
+ const warnings = (statsJson.warnings || []).map(e => {
116
+ // @ts-expect-error error message is already serialized in `stats.err`
117
+ delete e.message;
118
+ delete e.stack;
119
+ return e;
120
+ });
121
+ if (typeof options.format === "function") {
122
+ output = options.format(output);
123
+ }
124
+ env.expect.addSnapshotSerializer({
125
+ test(received) {
126
+ return typeof received === "string";
127
+ },
128
+ serialize(received) {
129
+ return (0, placeholder_1.normalizePlaceholder)(received.trim());
130
+ }
131
+ });
132
+ const errorOutputPath = node_path_1.default.resolve(context.getSource(options.snapshot));
133
+ const errorStatsOutputPath = node_path_1.default.resolve(context.getSource(options.snapshotErrors));
134
+ const warningStatsOutputPath = node_path_1.default.resolve(context.getSource(options.snapshotWarning));
135
+ env.expect(output).toMatchFileSnapshot(errorOutputPath);
136
+ env.expect(errors).toMatchFileSnapshot(errorStatsOutputPath);
137
+ env.expect(warnings).toMatchFileSnapshot(warningStatsOutputPath);
138
+ }
@@ -1,3 +1,19 @@
1
- import { type IDiffProcessorOptions } from "../processor";
1
+ import { type IFormatCodeOptions, type IFormatCodeReplacement } from "../compare";
2
+ import { type TCompareModules, type TFileCompareResult, type TModuleCompareResult } from "../type";
2
3
  export type TDiffCaseConfig = IDiffProcessorOptions;
3
4
  export declare function createDiffCase(name: string, src: string, dist: string): void;
5
+ export interface IDiffProcessorOptions extends IFormatCodeOptions {
6
+ webpackPath: string;
7
+ rspackPath: string;
8
+ files?: string[];
9
+ modules?: TCompareModules;
10
+ runtimeModules?: TCompareModules;
11
+ bootstrap?: boolean;
12
+ detail?: boolean;
13
+ errors?: boolean;
14
+ replacements?: IFormatCodeReplacement[];
15
+ renameModule?: (file: string) => string;
16
+ onCompareFile?: (file: string, result: TFileCompareResult) => void;
17
+ onCompareModules?: (file: string, results: TModuleCompareResult[]) => void;
18
+ onCompareRuntimeModules?: (file: string, results: TModuleCompareResult[]) => void;
19
+ }
package/dist/case/diff.js CHANGED
@@ -7,10 +7,12 @@ exports.createDiffCase = createDiffCase;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const rimraf_1 = require("rimraf");
10
+ const compare_1 = require("../compare");
10
11
  const createLazyTestEnv_1 = __importDefault(require("../helper/legacy/createLazyTestEnv"));
11
- const processor_1 = require("../processor");
12
+ const plugin_1 = require("../plugin");
12
13
  const tester_1 = require("../test/tester");
13
14
  const type_1 = require("../type");
15
+ const common_1 = require("./common");
14
16
  const DEFAULT_CASE_CONFIG = {
15
17
  webpackPath: require.resolve("webpack"),
16
18
  rspackPath: require.resolve("@rspack/core"),
@@ -63,7 +65,49 @@ function createDiffCase(name, src, dist) {
63
65
  const env = (0, createLazyTestEnv_1.default)(1000);
64
66
  });
65
67
  }
66
- function createDiffProcessor(config) {
68
+ function defaultOptions(type, src, dist) {
69
+ return {
70
+ entry: node_path_1.default.join(src, "./src/index.js"),
71
+ context: src,
72
+ output: {
73
+ path: dist,
74
+ filename: "bundle.js",
75
+ chunkFilename: "[name].chunk.js"
76
+ },
77
+ plugins: [
78
+ type === type_1.ECompilerType.Webpack && new plugin_1.WebpackDiffConfigPlugin(),
79
+ type === type_1.ECompilerType.Rspack && new plugin_1.RspackDiffConfigPlugin()
80
+ ].filter(Boolean),
81
+ experiments: type === type_1.ECompilerType.Rspack
82
+ ? {
83
+ css: true,
84
+ rspackFuture: {
85
+ bundlerInfo: {
86
+ force: false
87
+ }
88
+ }
89
+ }
90
+ : {}
91
+ };
92
+ }
93
+ function createFormatOptions(options, hashes) {
94
+ const formatOptions = {
95
+ ignoreModuleArguments: options.ignoreModuleArguments,
96
+ ignoreModuleId: options.ignoreModuleId,
97
+ ignorePropertyQuotationMark: options.ignorePropertyQuotationMark,
98
+ ignoreBlockOnlyStatement: options.ignoreBlockOnlyStatement,
99
+ ignoreIfCertainCondition: options.ignoreIfCertainCondition,
100
+ ignoreSwcHelpersPath: options.ignoreSwcHelpersPath,
101
+ ignoreObjectPropertySequence: options.ignoreObjectPropertySequence,
102
+ ignoreCssFilePath: options.ignoreCssFilePath,
103
+ replacements: options.replacements || []
104
+ };
105
+ for (const hash of hashes) {
106
+ formatOptions.replacements.push({ from: hash, to: "fullhash" });
107
+ }
108
+ return formatOptions;
109
+ }
110
+ function createDiffProcessor(options) {
67
111
  const fileCompareMap = new Map();
68
112
  const createCompareResultHandler = (type) => {
69
113
  return (file, results) => {
@@ -75,28 +119,132 @@ function createDiffProcessor(config) {
75
119
  fileCompareMap.set(file, fileResult);
76
120
  };
77
121
  };
78
- const processor = new processor_1.DiffProcessor({
79
- webpackPath: config.webpackPath,
80
- rspackPath: config.rspackPath,
81
- files: config.files,
82
- modules: config.modules,
83
- runtimeModules: config.runtimeModules,
84
- renameModule: config.renameModule,
85
- ignoreModuleId: config.ignoreModuleId ?? true,
86
- ignoreModuleArguments: config.ignoreModuleArguments ?? true,
87
- ignorePropertyQuotationMark: config.ignorePropertyQuotationMark ?? true,
88
- ignoreBlockOnlyStatement: config.ignoreBlockOnlyStatement ?? true,
89
- ignoreIfCertainCondition: config.ignoreIfCertainCondition ?? true,
90
- ignoreSwcHelpersPath: config.ignoreSwcHelpersPath ?? true,
91
- ignoreObjectPropertySequence: config.ignoreObjectPropertySequence ?? true,
92
- ignoreCssFilePath: config.ignoreCssFilePath ?? true,
122
+ const diffOptions = {
123
+ webpackPath: options.webpackPath,
124
+ rspackPath: options.rspackPath,
125
+ files: options.files,
126
+ modules: options.modules,
127
+ runtimeModules: options.runtimeModules,
128
+ renameModule: options.renameModule,
129
+ ignoreModuleId: options.ignoreModuleId ?? true,
130
+ ignoreModuleArguments: options.ignoreModuleArguments ?? true,
131
+ ignorePropertyQuotationMark: options.ignorePropertyQuotationMark ?? true,
132
+ ignoreBlockOnlyStatement: options.ignoreBlockOnlyStatement ?? true,
133
+ ignoreIfCertainCondition: options.ignoreIfCertainCondition ?? true,
134
+ ignoreSwcHelpersPath: options.ignoreSwcHelpersPath ?? true,
135
+ ignoreObjectPropertySequence: options.ignoreObjectPropertySequence ?? true,
136
+ ignoreCssFilePath: options.ignoreCssFilePath ?? true,
93
137
  onCompareModules: createCompareResultHandler("modules"),
94
138
  onCompareRuntimeModules: createCompareResultHandler("runtimeModules"),
95
- bootstrap: config.bootstrap ?? true,
96
- detail: config.detail ?? true,
97
- errors: config.errors ?? false,
98
- replacements: config.replacements
99
- });
139
+ bootstrap: options.bootstrap ?? true,
140
+ detail: options.detail ?? true,
141
+ errors: options.errors ?? false,
142
+ replacements: options.replacements
143
+ };
144
+ const hashes = [];
145
+ const webpackProcessor = global.updateSnapshot &&
146
+ {
147
+ config: async (context) => {
148
+ const compiler = (0, common_1.getCompiler)(context, type_1.ECompilerType.Webpack);
149
+ let options = defaultOptions(type_1.ECompilerType.Webpack, context.getSource(), node_path_1.default.join(context.getDist(), type_1.ECompilerType.Webpack));
150
+ options = await (0, common_1.config)(context, type_1.ECompilerType.Webpack, ["webpack.config.js", "rspack.config.js"], options);
151
+ compiler.setOptions(options);
152
+ },
153
+ compiler: async (context) => {
154
+ await (0, common_1.compiler)(context, type_1.ECompilerType.Webpack);
155
+ },
156
+ build: async (context) => {
157
+ await (0, common_1.build)(context, type_1.ECompilerType.Webpack);
158
+ },
159
+ run: async (env, context) => { },
160
+ check: async (env, context) => {
161
+ await (0, common_1.check)(env, context, type_1.ECompilerType.Webpack);
162
+ }
163
+ };
164
+ const rspackProcessor = {
165
+ config: async (context) => {
166
+ const compiler = (0, common_1.getCompiler)(context, type_1.ECompilerType.Rspack);
167
+ let options = defaultOptions(type_1.ECompilerType.Rspack, context.getSource(), node_path_1.default.join(context.getDist(), type_1.ECompilerType.Rspack));
168
+ options = await (0, common_1.config)(context, type_1.ECompilerType.Rspack, ["rspack.config.js", "webpack.config.js"], options);
169
+ compiler.setOptions(options);
170
+ },
171
+ compiler: async (context) => {
172
+ await (0, common_1.compiler)(context, type_1.ECompilerType.Rspack);
173
+ },
174
+ build: async (context) => {
175
+ await (0, common_1.build)(context, type_1.ECompilerType.Rspack);
176
+ },
177
+ run: async (env, context) => { },
178
+ check: async (env, context) => {
179
+ await (0, common_1.check)(env, context, type_1.ECompilerType.Rspack);
180
+ }
181
+ };
182
+ const processor = {
183
+ config: async (context) => {
184
+ if (webpackProcessor) {
185
+ await webpackProcessor.config(context);
186
+ }
187
+ await rspackProcessor.config(context);
188
+ },
189
+ compiler: async (context) => {
190
+ if (webpackProcessor) {
191
+ await webpackProcessor.compiler(context);
192
+ }
193
+ await rspackProcessor.compiler(context);
194
+ },
195
+ build: async (context) => {
196
+ if (webpackProcessor) {
197
+ await webpackProcessor.build(context);
198
+ }
199
+ await rspackProcessor.build(context);
200
+ },
201
+ run: async (env, context) => { },
202
+ check: async (env, context) => {
203
+ if (webpackProcessor) {
204
+ const webpackCompiler = context.getCompiler(type_1.ECompilerType.Webpack);
205
+ const webpackStats = webpackCompiler.getStats();
206
+ //TODO: handle chunk hash and content hash
207
+ webpackStats?.hash && hashes.push(webpackStats?.hash);
208
+ if (!diffOptions.errors) {
209
+ env.expect(webpackStats?.hasErrors()).toBe(false);
210
+ }
211
+ }
212
+ const rspackCompiler = context.getCompiler(type_1.ECompilerType.Rspack);
213
+ const rspackStats = rspackCompiler.getStats();
214
+ //TODO: handle chunk hash and content hash
215
+ rspackStats?.hash && hashes.push(rspackStats?.hash);
216
+ if (!diffOptions.errors) {
217
+ env.expect(rspackStats?.hasErrors()).toBe(false);
218
+ }
219
+ const dist = context.getDist();
220
+ const snapshot = context.getSource("__snapshot__");
221
+ for (const file of diffOptions.files) {
222
+ const rspackDist = node_path_1.default.join(dist, type_1.ECompilerType.Rspack, file);
223
+ const webpackDist = node_path_1.default.join(dist, type_1.ECompilerType.Webpack, file);
224
+ const snapshotDist = node_path_1.default.join(snapshot, file.replace(/\.js$/, ".json"));
225
+ const result = (0, compare_1.compareFile)(rspackDist, webpackDist, {
226
+ modules: diffOptions.modules,
227
+ runtimeModules: diffOptions.runtimeModules,
228
+ format: createFormatOptions(diffOptions, hashes),
229
+ renameModule: diffOptions.renameModule,
230
+ bootstrap: diffOptions.bootstrap,
231
+ detail: diffOptions.detail,
232
+ snapshot: snapshotDist
233
+ });
234
+ if (typeof diffOptions.onCompareFile === "function") {
235
+ diffOptions.onCompareFile(file, result);
236
+ }
237
+ if (typeof diffOptions.onCompareModules === "function" &&
238
+ result.modules.modules) {
239
+ diffOptions.onCompareModules(file, result.modules.modules);
240
+ }
241
+ if (typeof diffOptions.onCompareRuntimeModules === "function" &&
242
+ result.modules.runtimeModules) {
243
+ diffOptions.onCompareRuntimeModules(file, result.modules.runtimeModules);
244
+ }
245
+ }
246
+ }
247
+ };
100
248
  return [processor, fileCompareMap];
101
249
  }
102
250
  function checkCompareResults(name, getResults) {
@@ -1,6 +1,16 @@
1
- import { type IErrorProcessorOptions } from "../processor";
2
- import { ECompilerType } from "../type";
3
- export type TErrorCaseConfig = Omit<IErrorProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
1
+ import type { StatsError } from "@rspack/core";
2
+ import type { ECompilerType, ITestContext, TCompiler, TCompilerOptions } from "../type";
3
+ export declare function createErrorCase(name: string, src: string, dist: string, testConfig: string): void;
4
+ declare class RspackStatsDiagnostics {
5
+ errors: StatsError[];
6
+ warnings: StatsError[];
7
+ constructor(errors: StatsError[], warnings: StatsError[]);
8
+ }
9
+ export type TErrorCaseConfig = {
4
10
  description: string;
11
+ options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
12
+ compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
13
+ build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
14
+ check?: (stats: RspackStatsDiagnostics) => Promise<void>;
5
15
  };
6
- export declare function createErrorCase(name: string, src: string, dist: string, testConfig: string): void;
16
+ export {};