@rspack-canary/test-tools 1.5.7-canary-a3406c0a-20250922173625 → 1.5.8-canary-6c1a40e3-20250925175235

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 (89) hide show
  1. package/dist/case/builtin.d.ts +2 -2
  2. package/dist/case/builtin.js +37 -28
  3. package/dist/case/cache.d.ts +1 -1
  4. package/dist/case/cache.js +135 -42
  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 +3 -2
  10. package/dist/case/config.js +47 -39
  11. package/dist/case/defaults.d.ts +2 -2
  12. package/dist/case/defaults.js +28 -18
  13. package/dist/case/diagnostic.d.ts +1 -1
  14. package/dist/case/diagnostic.js +52 -43
  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 +51 -21
  19. package/dist/case/hash.d.ts +1 -1
  20. package/dist/case/hash.js +41 -34
  21. package/dist/case/hook.d.ts +4 -5
  22. package/dist/case/hook.js +78 -70
  23. package/dist/case/hot-step.d.ts +1 -1
  24. package/dist/case/hot-step.js +9 -5
  25. package/dist/case/hot.d.ts +5 -5
  26. package/dist/case/hot.js +142 -55
  27. package/dist/case/incremental.d.ts +1 -1
  28. package/dist/case/incremental.js +19 -34
  29. package/dist/case/native-watcher.js +10 -23
  30. package/dist/case/normal.js +46 -31
  31. package/dist/case/runner.d.ts +18 -0
  32. package/dist/case/runner.js +108 -0
  33. package/dist/case/serial.d.ts +1 -1
  34. package/dist/case/serial.js +7 -15
  35. package/dist/case/stats-api.js +52 -22
  36. package/dist/case/stats-output.js +133 -137
  37. package/dist/case/treeshaking.js +33 -22
  38. package/dist/case/watch.d.ts +27 -0
  39. package/dist/case/watch.js +321 -21
  40. package/dist/index.d.ts +0 -2
  41. package/dist/index.js +0 -2
  42. package/dist/runner/index.d.ts +2 -7
  43. package/dist/runner/index.js +2 -7
  44. package/dist/runner/{runner/node → node}/index.d.ts +1 -2
  45. package/dist/runner/{runner/node → node}/index.js +2 -2
  46. package/dist/runner/{runner/web → web}/fake.d.ts +1 -2
  47. package/dist/runner/{runner/web → web}/fake.js +7 -7
  48. package/dist/runner/{runner/web → web}/index.d.ts +2 -2
  49. package/dist/runner/{runner/web → web}/index.js +1 -1
  50. package/dist/runner/{runner/web → web}/jsdom.d.ts +1 -2
  51. package/dist/runner/{runner/web → web}/jsdom.js +4 -4
  52. package/dist/test/context.d.ts +3 -5
  53. package/dist/test/context.js +22 -12
  54. package/dist/test/creator.d.ts +13 -12
  55. package/dist/test/creator.js +52 -43
  56. package/dist/test/tester.js +4 -1
  57. package/dist/type.d.ts +41 -10
  58. package/dist/type.js +7 -1
  59. package/package.json +6 -6
  60. package/dist/processor/basic.d.ts +0 -27
  61. package/dist/processor/basic.js +0 -157
  62. package/dist/processor/diff.d.ts +0 -30
  63. package/dist/processor/diff.js +0 -140
  64. package/dist/processor/index.d.ts +0 -6
  65. package/dist/processor/index.js +0 -22
  66. package/dist/processor/multi.d.ts +0 -19
  67. package/dist/processor/multi.js +0 -75
  68. package/dist/processor/simple.d.ts +0 -24
  69. package/dist/processor/simple.js +0 -51
  70. package/dist/processor/snapshot.d.ts +0 -12
  71. package/dist/processor/snapshot.js +0 -67
  72. package/dist/processor/watch.d.ts +0 -30
  73. package/dist/processor/watch.js +0 -252
  74. package/dist/runner/basic.d.ts +0 -10
  75. package/dist/runner/basic.js +0 -64
  76. package/dist/runner/cache.d.ts +0 -5
  77. package/dist/runner/cache.js +0 -92
  78. package/dist/runner/hot.d.ts +0 -5
  79. package/dist/runner/hot.js +0 -91
  80. package/dist/runner/multiple.d.ts +0 -11
  81. package/dist/runner/multiple.js +0 -52
  82. package/dist/runner/runner/index.d.ts +0 -2
  83. package/dist/runner/runner/index.js +0 -18
  84. package/dist/runner/type.d.ts +0 -42
  85. package/dist/runner/type.js +0 -9
  86. package/dist/runner/watch.d.ts +0 -7
  87. package/dist/runner/watch.js +0 -71
  88. package/dist/test/simple.d.ts +0 -5
  89. package/dist/test/simple.js +0 -43
@@ -1,120 +1,155 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCompilerCase = createCompilerCase;
4
- const processor_1 = require("../processor");
5
- const simple_1 = require("../test/simple");
6
- const type_1 = require("../type");
4
+ const creator_1 = require("../test/creator");
5
+ const common_1 = require("./common");
6
+ function createCompilerProcessor(name, caseConfig) {
7
+ const logs = {
8
+ mkdir: [],
9
+ writeFile: []
10
+ };
11
+ const files = {};
12
+ return {
13
+ config: async (context) => {
14
+ const compiler = (0, common_1.getCompiler)(context, name);
15
+ const options = caseConfig.options?.(context) || {};
16
+ options.mode ??= "production";
17
+ options.context ??= context.getSource();
18
+ options.entry ??= "./a.js";
19
+ options.output ??= {};
20
+ options.output.path ??= "/";
21
+ options.output.pathinfo ??= true;
22
+ options.optimization ??= {};
23
+ options.optimization.minimize ??= false;
24
+ compiler.setOptions(options);
25
+ },
26
+ compiler: async (context) => {
27
+ const compiler = (0, common_1.getCompiler)(context, name);
28
+ if (caseConfig.compilerCallback) {
29
+ compiler.createCompilerWithCallback(caseConfig.compilerCallback);
30
+ }
31
+ else {
32
+ compiler.createCompiler();
33
+ }
34
+ const c = compiler.getCompiler();
35
+ c.outputFileSystem = {
36
+ // CHANGE: Added support for the `options` parameter to enable recursive directory creation,
37
+ // accommodating Rspack's requirement that differs from webpack's usage
38
+ mkdir(path, callback) {
39
+ const recursive = false;
40
+ // if (typeof options === "function") {
41
+ // callback = options;
42
+ // } else if (options) {
43
+ // if (options.recursive !== undefined) recursive = options.recursive;
44
+ // }
45
+ logs.mkdir.push(path);
46
+ if (recursive) {
47
+ callback();
48
+ }
49
+ else {
50
+ const err = new Error();
51
+ err.code = "EEXIST";
52
+ callback(err);
53
+ }
54
+ },
55
+ writeFile(name, content, callback) {
56
+ logs.writeFile.push(name, content);
57
+ files[name] = content.toString("utf-8");
58
+ callback();
59
+ },
60
+ stat(path, callback) {
61
+ callback(new Error("ENOENT"));
62
+ }
63
+ };
64
+ c.hooks.compilation.tap("CompilerTest", compilation => (compilation.bail = true));
65
+ await caseConfig.compiler?.(context, c);
66
+ },
67
+ build: async (context) => {
68
+ const compiler = (0, common_1.getCompiler)(context, name);
69
+ if (typeof caseConfig.build === "function") {
70
+ await caseConfig.build?.(context, compiler.getCompiler());
71
+ }
72
+ else {
73
+ await compiler.build();
74
+ }
75
+ },
76
+ run: async (env, context) => { },
77
+ check: async (env, context) => {
78
+ const compiler = (0, common_1.getCompiler)(context, name);
79
+ const c = compiler.getCompiler();
80
+ const stats = compiler.getStats();
81
+ if (caseConfig.error) {
82
+ const statsJson = stats?.toJson({
83
+ modules: true,
84
+ reasons: true
85
+ });
86
+ const compilation = stats?.compilation;
87
+ await caseConfig.check?.({
88
+ context,
89
+ compiler: c,
90
+ stats: statsJson,
91
+ compilation,
92
+ files
93
+ });
94
+ }
95
+ else if (stats) {
96
+ expect(typeof stats).toBe("object");
97
+ const compilation = stats.compilation;
98
+ const statsJson = stats.toJson({
99
+ modules: true,
100
+ reasons: true
101
+ });
102
+ expect(typeof statsJson).toBe("object");
103
+ expect(statsJson).toHaveProperty("errors");
104
+ expect(Array.isArray(statsJson.errors)).toBe(true);
105
+ if (statsJson.errors.length > 0) {
106
+ expect(statsJson.errors[0]).toBeInstanceOf(Object);
107
+ throw statsJson.errors[0];
108
+ }
109
+ statsJson.logs = logs;
110
+ await caseConfig.check?.({
111
+ context,
112
+ stats: statsJson,
113
+ files,
114
+ compiler: c,
115
+ compilation
116
+ });
117
+ }
118
+ else {
119
+ await caseConfig.check?.({
120
+ context,
121
+ files,
122
+ compiler: c
123
+ });
124
+ }
125
+ },
126
+ after: async (context) => {
127
+ await context.closeCompiler(name);
128
+ }
129
+ };
130
+ }
131
+ const creator = new creator_1.BasicCaseCreator({
132
+ clean: true,
133
+ describe: false,
134
+ steps: ({ name, caseConfig }) => {
135
+ return [createCompilerProcessor(name, caseConfig)];
136
+ },
137
+ concurrent: false
138
+ });
7
139
  function createCompilerCase(name, src, dist, testConfig) {
8
140
  let caseConfigList = require(testConfig);
9
141
  if (!Array.isArray(caseConfigList)) {
10
142
  caseConfigList = [caseConfigList];
11
143
  }
12
- const runner = (0, simple_1.getSimpleProcessorRunner)(src, dist);
13
- for (const caseConfig of caseConfigList) {
14
- const testFn = caseConfig.skip ? it.skip : it;
15
- testFn(caseConfig.description, async () => {
16
- const logs = {
17
- mkdir: [],
18
- writeFile: []
19
- };
20
- const files = {};
21
- await runner(name, new processor_1.SimpleTaskProcessor({
22
- name: name,
23
- compilerType: type_1.ECompilerType.Rspack,
24
- compilerCallback: caseConfig.compilerCallback,
25
- build: caseConfig.build,
26
- options: context => {
27
- const options = caseConfig.options?.(context) || {};
28
- options.mode ??= "production";
29
- options.context ??= context.getSource();
30
- options.entry ??= "./a.js";
31
- options.output ??= {};
32
- options.output.path ??= "/";
33
- options.output.pathinfo ??= true;
34
- options.optimization ??= {};
35
- options.optimization.minimize ??= false;
36
- return options;
37
- },
38
- async compiler(context, compiler) {
39
- compiler.outputFileSystem = {
40
- // CHANGE: Added support for the `options` parameter to enable recursive directory creation,
41
- // accommodating Rspack's requirement that differs from webpack's usage
42
- mkdir(path, callback) {
43
- const recursive = false;
44
- // if (typeof options === "function") {
45
- // callback = options;
46
- // } else if (options) {
47
- // if (options.recursive !== undefined) recursive = options.recursive;
48
- // }
49
- logs.mkdir.push(path);
50
- if (recursive) {
51
- callback();
52
- }
53
- else {
54
- const err = new Error();
55
- err.code = "EEXIST";
56
- callback(err);
57
- }
58
- },
59
- writeFile(name, content, callback) {
60
- logs.writeFile.push(name, content);
61
- files[name] = content.toString("utf-8");
62
- callback();
63
- },
64
- stat(path, callback) {
65
- callback(new Error("ENOENT"));
66
- }
67
- };
68
- compiler.hooks.compilation.tap("CompilerTest", compilation => (compilation.bail = true));
69
- await caseConfig.compiler?.(context, compiler);
70
- },
71
- async check(env, context, compiler, stats) {
72
- if (caseConfig.error) {
73
- const statsJson = stats?.toJson({
74
- modules: true,
75
- reasons: true
76
- });
77
- const compilation = stats?.compilation;
78
- await caseConfig.check?.({
79
- context,
80
- compiler,
81
- stats: statsJson,
82
- compilation,
83
- files
84
- });
85
- }
86
- else if (stats) {
87
- expect(typeof stats).toBe("object");
88
- const compilation = stats.compilation;
89
- const statsJson = stats.toJson({
90
- modules: true,
91
- reasons: true
92
- });
93
- expect(typeof statsJson).toBe("object");
94
- expect(statsJson).toHaveProperty("errors");
95
- expect(Array.isArray(statsJson.errors)).toBe(true);
96
- if (statsJson.errors.length > 0) {
97
- expect(statsJson.errors[0]).toBeInstanceOf(Object);
98
- throw statsJson.errors[0];
99
- }
100
- statsJson.logs = logs;
101
- await caseConfig.check?.({
102
- context,
103
- stats: statsJson,
104
- files,
105
- compiler,
106
- compilation
107
- });
108
- }
109
- else {
110
- await caseConfig.check?.({
111
- context,
112
- files,
113
- compiler
114
- });
115
- }
116
- }
117
- }));
144
+ for (let i = 0; i < caseConfigList.length; i++) {
145
+ const caseConfig = caseConfigList[i];
146
+ if (caseConfig.skip) {
147
+ it.skip(`${name}[${i}]`, () => { });
148
+ continue;
149
+ }
150
+ creator.create(`${name}[${i}]`, src, dist, undefined, {
151
+ caseConfig,
152
+ description: () => caseConfig.description
118
153
  });
119
154
  }
120
155
  }
@@ -1,6 +1,7 @@
1
- import { ECompilerType, type ITestContext, type TCompilerOptions, type TTestConfig } from "../type";
1
+ import type { ECompilerType, ITestContext, ITestProcessor, TCompilerOptions, TTestConfig } from "../type";
2
2
  export type TConfigCaseConfig = Omit<TTestConfig<ECompilerType.Rspack>, "validate">;
3
+ export declare function createConfigProcessor(name: string): ITestProcessor;
4
+ export declare function createConfigCase(name: string, src: string, dist: string): void;
3
5
  export declare function defaultOptions(index: number, context: ITestContext): TCompilerOptions<ECompilerType.Rspack>;
4
6
  export declare function overrideOptions(index: number, context: ITestContext, options: TCompilerOptions<ECompilerType.Rspack>): void;
5
7
  export declare function findBundle(index: number, context: ITestContext, options: TCompilerOptions<ECompilerType.Rspack>): string | string[];
6
- export declare function createConfigCase(name: string, src: string, dist: string): void;
@@ -3,17 +3,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createConfigProcessor = createConfigProcessor;
7
+ exports.createConfigCase = createConfigCase;
6
8
  exports.defaultOptions = defaultOptions;
7
9
  exports.overrideOptions = overrideOptions;
8
10
  exports.findBundle = findBundle;
9
- exports.createConfigCase = createConfigCase;
10
11
  const fs_extra_1 = __importDefault(require("fs-extra"));
11
12
  const path_1 = __importDefault(require("path"));
12
13
  const parseResource_1 = require("../helper/legacy/parseResource");
13
- const processor_1 = require("../processor");
14
- const runner_1 = require("../runner");
15
14
  const creator_1 = require("../test/creator");
16
- const type_1 = require("../type");
15
+ const common_1 = require("./common");
16
+ const runner_1 = require("./runner");
17
+ function createConfigProcessor(name) {
18
+ return {
19
+ config: async (context) => {
20
+ (0, common_1.configMultiCompiler)(context, name, ["rspack.config.cjs", "rspack.config.js", "webpack.config.js"], defaultOptions, overrideOptions);
21
+ },
22
+ compiler: async (context) => {
23
+ await (0, common_1.compiler)(context, name);
24
+ },
25
+ build: async (context) => {
26
+ await (0, common_1.build)(context, name);
27
+ },
28
+ run: async (env, context) => {
29
+ await (0, common_1.run)(env, context, name, (context) => (0, common_1.findMultiCompilerBundle)(context, name, findBundle));
30
+ },
31
+ check: async (env, context) => {
32
+ await (0, common_1.check)(env, context, name);
33
+ }
34
+ };
35
+ }
36
+ const creator = new creator_1.BasicCaseCreator({
37
+ clean: true,
38
+ describe: false,
39
+ testConfig: testConfig => {
40
+ const oldModuleScope = testConfig.moduleScope;
41
+ testConfig.moduleScope = (ms, stats, compilerOptions) => {
42
+ let res = ms;
43
+ // TODO: modify runner module scope based on stats here
44
+ if (typeof oldModuleScope === "function") {
45
+ res = oldModuleScope(ms, stats, compilerOptions);
46
+ }
47
+ return res;
48
+ };
49
+ },
50
+ steps: ({ name }) => [createConfigProcessor(name)],
51
+ runner: {
52
+ key: runner_1.getMultiCompilerRunnerKey,
53
+ runner: runner_1.createMultiCompilerRunner
54
+ },
55
+ concurrent: true
56
+ });
57
+ function createConfigCase(name, src, dist) {
58
+ creator.create(name, src, dist);
59
+ }
17
60
  function defaultOptions(index, context) {
18
61
  return {
19
62
  context: context.getSource(),
@@ -80,38 +123,3 @@ function findBundle(index, context, options) {
80
123
  }
81
124
  return bundlePath;
82
125
  }
83
- const creator = new creator_1.BasicCaseCreator({
84
- clean: true,
85
- describe: false,
86
- testConfig: testConfig => {
87
- const oldModuleScope = testConfig.moduleScope;
88
- testConfig.moduleScope = (ms, stats, compilerOptions) => {
89
- let res = ms;
90
- // TODO: modify runner module scope based on stats here
91
- if (typeof oldModuleScope === "function") {
92
- res = oldModuleScope(ms, stats, compilerOptions);
93
- }
94
- return res;
95
- };
96
- },
97
- steps: ({ name }) => [
98
- new processor_1.MultiTaskProcessor({
99
- name,
100
- runable: true,
101
- compilerType: type_1.ECompilerType.Rspack,
102
- defaultOptions,
103
- overrideOptions,
104
- findBundle,
105
- configFiles: [
106
- "rspack.config.cjs",
107
- "rspack.config.js",
108
- "webpack.config.js"
109
- ]
110
- })
111
- ],
112
- runner: runner_1.MultipleRunnerFactory,
113
- concurrent: true
114
- });
115
- function createConfigCase(name, src, dist) {
116
- creator.create(name, src, dist);
117
- }
@@ -1,4 +1,5 @@
1
- import { ECompilerType, type ITestContext, type TCompilerOptions } from "../type";
1
+ import type { ECompilerType, ITestContext, TCompilerOptions } from "../type";
2
+ export declare function createDefaultsCase(name: string, src: string): void;
2
3
  export declare function getRspackDefaultConfig(cwd: string, config: TCompilerOptions<ECompilerType>): TCompilerOptions<ECompilerType>;
3
4
  export type TDefaultsCaseConfig = {
4
5
  options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
@@ -10,5 +11,4 @@ declare class RspackTestDiff {
10
11
  value: string;
11
12
  constructor(value: string);
12
13
  }
13
- export declare function createDefaultsCase(name: string, src: string): void;
14
14
  export {};
@@ -3,15 +3,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getRspackDefaultConfig = getRspackDefaultConfig;
7
6
  exports.createDefaultsCase = createDefaultsCase;
7
+ exports.getRspackDefaultConfig = getRspackDefaultConfig;
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const node_util_1 = require("node:util");
10
10
  const jest_diff_1 = require("jest-diff");
11
- const processor_1 = require("../processor");
12
11
  const context_1 = require("../test/context");
13
- const type_1 = require("../type");
12
+ const common_1 = require("./common");
14
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
+ }
15
38
  function getRspackDefaultConfig(cwd, config) {
16
39
  process.chdir(cwd);
17
40
  const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = require("@rspack/core").config;
@@ -47,8 +70,8 @@ class RspackTestDiff {
47
70
  this.value = value;
48
71
  }
49
72
  }
50
- async function check(env, context, options) {
51
- const compiler = this.getCompiler(context);
73
+ async function check(env, context, name, options) {
74
+ const compiler = (0, common_1.getCompiler)(context, name);
52
75
  const config = getRspackDefaultConfig(options.cwd || CURRENT_CWD, compiler.getOptions());
53
76
  const defaultConfig = getRspackDefaultConfig(options.cwd || CURRENT_CWD, {
54
77
  mode: "none"
@@ -69,16 +92,3 @@ async function run(name, processor) {
69
92
  await processor.after?.(context);
70
93
  }
71
94
  }
72
- function createDefaultsCase(name, src) {
73
- const caseConfig = require(src);
74
- it(`should generate the correct defaults from ${caseConfig.description}`, async () => {
75
- await run(name, new processor_1.SimpleTaskProcessor({
76
- name,
77
- compilerType: type_1.ECompilerType.Rspack,
78
- options: (context) => options(context, caseConfig.options),
79
- check(env, context, _compiler, _stats) {
80
- return check.call(this, env, context, caseConfig);
81
- }
82
- }));
83
- });
84
- }
@@ -1,7 +1,7 @@
1
+ export declare function createDiagnosticCase(name: string, src: string, dist: string): void;
1
2
  export interface IDiagnosticOptions {
2
3
  snapshot: string;
3
4
  snapshotErrors: string;
4
5
  snapshotWarning: string;
5
6
  format?: (output: string) => string;
6
7
  }
7
- export declare function createDiagnosticCase(name: string, src: string, dist: string): void;
@@ -9,9 +9,57 @@ const node_path_1 = __importDefault(require("node:path"));
9
9
  const webpack_merge_1 = __importDefault(require("webpack-merge"));
10
10
  const helper_1 = require("../helper");
11
11
  const placeholder_1 = require("../helper/expect/placeholder");
12
- const processor_1 = require("../processor");
13
12
  const creator_1 = require("../test/creator");
14
- const type_1 = require("../type");
13
+ const common_1 = require("./common");
14
+ const creator = new creator_1.BasicCaseCreator({
15
+ clean: true,
16
+ describe: false,
17
+ steps: ({ name }) => [
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
+ });
55
+ }
56
+ }
57
+ ],
58
+ concurrent: true
59
+ });
60
+ function createDiagnosticCase(name, src, dist) {
61
+ creator.create(name, src, dist);
62
+ }
15
63
  function defaultOptions(context) {
16
64
  return {
17
65
  target: "node",
@@ -41,8 +89,8 @@ function defaultOptions(context) {
41
89
  }
42
90
  };
43
91
  }
44
- async function check(env, context, options) {
45
- const compiler = this.getCompiler(context);
92
+ async function check(env, context, name, options) {
93
+ const compiler = (0, common_1.getCompiler)(context, name);
46
94
  const stats = compiler.getStats();
47
95
  if (!stats) {
48
96
  throw new Error("Stats should exists");
@@ -88,42 +136,3 @@ async function check(env, context, options) {
88
136
  env.expect(errors).toMatchFileSnapshot(errorStatsOutputPath);
89
137
  env.expect(warnings).toMatchFileSnapshot(warningStatsOutputPath);
90
138
  }
91
- const creator = new creator_1.BasicCaseCreator({
92
- clean: true,
93
- describe: false,
94
- steps: ({ name }) => [
95
- new processor_1.SimpleTaskProcessor({
96
- name,
97
- compilerType: type_1.ECompilerType.Rspack,
98
- options: context => {
99
- let options = defaultOptions(context);
100
- const custom = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)))[0];
101
- if (custom) {
102
- options = (0, webpack_merge_1.default)(options, custom);
103
- }
104
- if (!global.printLogger) {
105
- options.infrastructureLogging = {
106
- level: "error"
107
- };
108
- }
109
- return options;
110
- },
111
- check: function (env, context, compiler, stats) {
112
- return check.call(this, env, context, {
113
- snapshot: "./stats.err",
114
- snapshotErrors: "./raw-error.err",
115
- snapshotWarning: "./raw-warning.err",
116
- format: (output) => {
117
- // TODO: change to stats.errorStack
118
- // TODO: add `errorStack: false`
119
- return output.replace(/(│.* at ).*/g, "$1xxx");
120
- }
121
- });
122
- }
123
- })
124
- ],
125
- concurrent: true
126
- });
127
- function createDiagnosticCase(name, src, dist) {
128
- creator.create(name, src, dist);
129
- }
@@ -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
+ }