@rspack-canary/test-tools 1.5.7-canary-a3406c0a-20250922173625 → 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 (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 +5 -5
  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
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 ISimpleProcessorOptions } from "../processor";
2
- import { ECompilerType } from "../type";
3
- export type TErrorCaseConfig = Omit<ISimpleProcessorOptions<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 {};
@@ -6,10 +6,55 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createErrorCase = createErrorCase;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const webpack_merge_1 = __importDefault(require("webpack-merge"));
9
- const processor_1 = require("../processor");
10
- const simple_1 = require("../test/simple");
11
- const type_1 = require("../type");
9
+ const creator_1 = require("../test/creator");
10
+ const common_1 = require("./common");
12
11
  let addedSerializer = false;
12
+ const creator = new creator_1.BasicCaseCreator({
13
+ clean: true,
14
+ describe: true,
15
+ steps: ({ name, caseConfig }) => {
16
+ const config = caseConfig;
17
+ return [
18
+ {
19
+ config: async (context) => {
20
+ const compiler = (0, common_1.getCompiler)(context, name);
21
+ compiler.setOptions(options(context, config.options));
22
+ },
23
+ compiler: async (context) => {
24
+ const compilerManager = (0, common_1.getCompiler)(context, name);
25
+ compilerManager.createCompiler();
26
+ compiler(context, compilerManager.getCompiler(), config.compiler);
27
+ },
28
+ build: async (context) => {
29
+ const compiler = (0, common_1.getCompiler)(context, name);
30
+ if (typeof config.build === "function") {
31
+ await config.build(context, compiler.getCompiler());
32
+ }
33
+ else {
34
+ await compiler.build();
35
+ }
36
+ },
37
+ run: async (env, context) => {
38
+ // no need to run, just check the snapshot of diagnostics
39
+ },
40
+ check: async (env, context) => {
41
+ await check(env, context, name, config.check);
42
+ }
43
+ }
44
+ ];
45
+ },
46
+ concurrent: true
47
+ });
48
+ function createErrorCase(name, src, dist, testConfig) {
49
+ if (!addedSerializer) {
50
+ addedSerializer = true;
51
+ }
52
+ const caseConfig = require(testConfig);
53
+ creator.create(name, src, dist, undefined, {
54
+ caseConfig,
55
+ description: () => caseConfig.description
56
+ });
57
+ }
13
58
  function options(context, custom) {
14
59
  let options = {
15
60
  context: node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/fixtures/errors"),
@@ -70,7 +115,9 @@ class RspackStatsDiagnostics {
70
115
  this.warnings = warnings;
71
116
  }
72
117
  }
73
- async function check(env, context, _, stats, check) {
118
+ async function check(env, context, name, check) {
119
+ const compiler = (0, common_1.getCompiler)(context, name);
120
+ const stats = compiler.getStats();
74
121
  env.expect(typeof stats).toBe("object");
75
122
  const statsResult = stats.toJson({ errorDetails: false });
76
123
  env.expect(typeof statsResult).toBe("object");
@@ -79,20 +126,3 @@ async function check(env, context, _, stats, check) {
79
126
  env.expect(Array.isArray(warnings)).toBe(true);
80
127
  await check?.(new RspackStatsDiagnostics(errors, warnings));
81
128
  }
82
- function createErrorCase(name, src, dist, testConfig) {
83
- if (!addedSerializer) {
84
- addedSerializer = true;
85
- }
86
- const caseConfig = require(testConfig);
87
- const runner = (0, simple_1.getSimpleProcessorRunner)(src, dist);
88
- it(caseConfig.description, async () => {
89
- await runner(name, new processor_1.SimpleTaskProcessor({
90
- name: name,
91
- compilerType: type_1.ECompilerType.Rspack,
92
- options: context => options(context, caseConfig.options),
93
- compiler: (context, c) => compiler(context, c, caseConfig.compiler),
94
- build: caseConfig.build,
95
- check: (env, context, compiler, stats) => check(env, context, compiler, stats, caseConfig.check)
96
- }));
97
- });
98
- }
@@ -1,3 +1,3 @@
1
- import { ECompilerType, type TTestConfig } from "../type";
1
+ import type { ECompilerType, TTestConfig } from "../type";
2
2
  export type THashCaseConfig = Pick<TTestConfig<ECompilerType.Rspack>, "validate">;
3
3
  export declare function createHashCase(name: string, src: string, dist: string): void;
package/dist/case/hash.js CHANGED
@@ -1,10 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createHashCase = createHashCase;
4
- const processor_1 = require("../processor");
5
4
  const creator_1 = require("../test/creator");
6
- const type_1 = require("../type");
5
+ const common_1 = require("./common");
7
6
  const REG_ERROR_CASE = /error$/;
7
+ class HashCaseCreator extends creator_1.BasicCaseCreator {
8
+ describe(name, tester, testConfig, options) {
9
+ it(`should print correct hash for ${name}`, async () => {
10
+ await tester.prepare();
11
+ await tester.compile();
12
+ await tester.check(this.createEnv(testConfig, options));
13
+ await tester.resume();
14
+ }, 30000);
15
+ }
16
+ }
17
+ const creator = new HashCaseCreator({
18
+ clean: true,
19
+ describe: false,
20
+ steps: ({ name }) => [
21
+ {
22
+ config: async (context) => {
23
+ (0, common_1.configMultiCompiler)(context, name, ["rspack.config.js", "webpack.config.js"], defaultOptions, overrideOptions);
24
+ },
25
+ compiler: async (context) => {
26
+ await (0, common_1.compiler)(context, name);
27
+ },
28
+ build: async (context) => {
29
+ await (0, common_1.build)(context, name);
30
+ },
31
+ run: async (env, context) => {
32
+ // no need to run, just check snapshot
33
+ },
34
+ check: async (env, context) => {
35
+ await check(env, context, name);
36
+ }
37
+ }
38
+ ]
39
+ });
40
+ function createHashCase(name, src, dist) {
41
+ creator.create(name, src, dist);
42
+ }
8
43
  function defaultOptions(index, context) {
9
44
  return {
10
45
  context: context.getSource(),
@@ -33,23 +68,15 @@ function overrideOptions(index, context, options) {
33
68
  };
34
69
  }
35
70
  }
36
- class HashCaseCreator extends creator_1.BasicCaseCreator {
37
- describe(name, tester, testConfig) {
38
- it(`should print correct hash for ${name}`, async () => {
39
- await tester.prepare();
40
- await tester.compile();
41
- await tester.check(this.createEnv(testConfig));
42
- await tester.resume();
43
- }, 30000);
44
- }
45
- }
46
- async function check(env, context, compiler, stats) {
71
+ async function check(env, context, name) {
72
+ const compiler = (0, common_1.getCompiler)(context, name);
73
+ const stats = compiler.getStats();
47
74
  const testConfig = context.getTestConfig();
48
75
  if (!stats) {
49
76
  env.expect(false);
50
77
  return;
51
78
  }
52
- if (REG_ERROR_CASE.test(this._options.name)) {
79
+ if (REG_ERROR_CASE.test(name)) {
53
80
  env.expect(stats.hasErrors());
54
81
  }
55
82
  else {
@@ -62,23 +89,3 @@ async function check(env, context, compiler, stats) {
62
89
  throw new Error("HashTestCases should have test.config.js and a validate method");
63
90
  }
64
91
  }
65
- function createHashProcessor(name) {
66
- const processor = new processor_1.MultiTaskProcessor({
67
- name,
68
- compilerType: type_1.ECompilerType.Rspack,
69
- configFiles: ["rspack.config.js", "webpack.config.js"],
70
- runable: false,
71
- defaultOptions,
72
- overrideOptions,
73
- check
74
- });
75
- return processor;
76
- }
77
- const creator = new HashCaseCreator({
78
- clean: true,
79
- describe: false,
80
- steps: ({ name }) => [createHashProcessor(name)]
81
- });
82
- function createHashCase(name, src, dist) {
83
- creator.create(name, src, dist);
84
- }
@@ -1,7 +1,6 @@
1
- import { type ISnapshotProcessorOptions } from "../processor";
2
1
  import { TestContext, type TTestContextOptions } from "../test/context";
3
- import type { ITestEnv } from "../type";
4
- import { ECompilerType, type ITestContext, type TCompiler, type TCompilerOptions } from "../type";
2
+ import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions } from "../type";
3
+ export declare function createHookCase(name: string, src: string, dist: string, source: string): void;
5
4
  export declare class HookCasesContext extends TestContext {
6
5
  protected src: string;
7
6
  protected testName: string;
@@ -29,10 +28,10 @@ export declare class HookCasesContext extends TestContext {
29
28
  diff: {};
30
29
  }): Promise<void>;
31
30
  }
32
- export type THookCaseConfig = Omit<ISnapshotProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType" | "runable"> & {
31
+ export type THookCaseConfig = {
33
32
  options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
34
33
  compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
35
34
  check?: (context: ITestContext) => Promise<void>;
35
+ snapshotFileFilter?: (file: string) => boolean;
36
36
  description: string;
37
37
  };
38
- export declare function createHookCase(name: string, src: string, dist: string, source: string): void;
package/dist/case/hook.js CHANGED
@@ -11,14 +11,60 @@ const jest_snapshot_1 = require("jest-snapshot");
11
11
  const path_serializer_1 = require("path-serializer");
12
12
  const pretty_format_1 = require("pretty-format");
13
13
  const webpack_merge_1 = __importDefault(require("webpack-merge"));
14
- const createLazyTestEnv_1 = __importDefault(require("../helper/legacy/createLazyTestEnv"));
15
- const processor_1 = require("../processor");
16
- const runner_1 = require("../runner");
17
14
  const context_1 = require("../test/context");
18
- const simple_1 = require("../test/simple");
19
- const type_1 = require("../type");
15
+ const creator_1 = require("../test/creator");
16
+ const common_1 = require("./common");
20
17
  const srcDir = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/fixtures");
21
18
  const distDir = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/js/hook");
19
+ const creator = new creator_1.BasicCaseCreator({
20
+ clean: true,
21
+ describe: true,
22
+ createContext: (config) => new HookCasesContext(config.src, config.name, config),
23
+ steps: ({ name, caseConfig: _caseConfig, src }) => {
24
+ const caseConfig = _caseConfig;
25
+ return [
26
+ {
27
+ config: async (context) => {
28
+ const compiler = (0, common_1.getCompiler)(context, name);
29
+ const options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"], defaultOptions(context, caseConfig.options));
30
+ if (!global.printLogger) {
31
+ options.infrastructureLogging = {
32
+ level: "error"
33
+ };
34
+ }
35
+ compiler.setOptions(options);
36
+ },
37
+ compiler: async (context) => {
38
+ const c = await (0, common_1.compiler)(context, name);
39
+ if (caseConfig.compiler) {
40
+ await caseConfig.compiler(context, c);
41
+ }
42
+ },
43
+ build: async (context) => {
44
+ await (0, common_1.build)(context, name);
45
+ },
46
+ run: async (env, context) => {
47
+ // no need to run, just check snapshot
48
+ },
49
+ check: async (env, context) => {
50
+ await (0, common_1.checkSnapshot)(env, context, name, node_path_1.default.join(src, "output.snap.txt"), caseConfig.snapshotFileFilter);
51
+ }
52
+ }
53
+ ];
54
+ }
55
+ });
56
+ function createHookCase(name, src, dist, source) {
57
+ const caseConfig = require(node_path_1.default.join(src, "test.js"));
58
+ const testName = node_path_1.default.basename(name.slice(0, name.indexOf(node_path_1.default.extname(name))));
59
+ creator.create(name, src, dist, undefined, {
60
+ caseConfig,
61
+ description: () => caseConfig.description,
62
+ createContext: (config) => new HookCasesContext(src, testName, {
63
+ src: source,
64
+ dist: dist
65
+ })
66
+ });
67
+ }
22
68
  const sourceSerializer = {
23
69
  test(val) {
24
70
  return val instanceof core_1.sources.Source;
@@ -146,71 +192,33 @@ class HookCasesContext extends context_1.TestContext {
146
192
  }
147
193
  }
148
194
  exports.HookCasesContext = HookCasesContext;
149
- function createHookCase(name, src, dist, source) {
150
- const caseConfig = require(node_path_1.default.join(src, "test.js"));
151
- const testName = node_path_1.default.basename(name.slice(0, name.indexOf(node_path_1.default.extname(name))));
152
- const runner = (0, simple_1.getSimpleProcessorRunner)(source, dist, {
153
- env: () => env,
154
- context: () => new HookCasesContext(src, testName, {
155
- src: source,
156
- dist: dist,
157
- runnerFactory: runner_1.BasicRunnerFactory
158
- })
159
- });
160
- it(caseConfig.description, async () => {
161
- await runner(name, new processor_1.SnapshotProcessor({
162
- name,
163
- compilerType: type_1.ECompilerType.Rspack,
164
- findBundle: () => ["main.js"],
165
- snapshot: node_path_1.default.join(src, "output.snap.txt"),
166
- runable: false,
167
- defaultOptions: context => {
168
- let defaultOptions = {
169
- context: context.getSource(),
170
- mode: "production",
171
- target: "async-node",
172
- devtool: false,
173
- cache: false,
174
- entry: "./hook",
175
- output: {
176
- path: context.getDist()
177
- },
178
- optimization: {
179
- minimize: false
180
- },
181
- experiments: {
182
- css: true,
183
- rspackFuture: {
184
- bundlerInfo: {
185
- force: false
186
- }
187
- },
188
- inlineConst: true,
189
- lazyBarrel: true
190
- }
191
- };
192
- if (caseConfig.options) {
193
- defaultOptions = (0, webpack_merge_1.default)(defaultOptions, caseConfig.options(context));
194
- }
195
- return defaultOptions;
196
- },
197
- overrideOptions: (context, options) => {
198
- if (!global.printLogger) {
199
- options.infrastructureLogging = {
200
- level: "error"
201
- };
202
- }
203
- },
204
- compiler: caseConfig.compiler,
205
- check: async function (env, context, compiler, stats) {
206
- await context.collectSnapshots(env);
207
- await processor_1.SnapshotProcessor.prototype.check.call(this, env, context);
208
- if (typeof caseConfig.check === "function") {
209
- await caseConfig.check(context);
195
+ function defaultOptions(context, custom) {
196
+ let defaultOptions = {
197
+ context: context.getSource(),
198
+ mode: "production",
199
+ target: "async-node",
200
+ devtool: false,
201
+ cache: false,
202
+ entry: "./hook",
203
+ output: {
204
+ path: context.getDist()
205
+ },
206
+ optimization: {
207
+ minimize: false
208
+ },
209
+ experiments: {
210
+ css: true,
211
+ rspackFuture: {
212
+ bundlerInfo: {
213
+ force: false
210
214
  }
211
215
  },
212
- snapshotFileFilter: caseConfig.snapshotFileFilter
213
- }));
214
- });
215
- const env = (0, createLazyTestEnv_1.default)(10000);
216
+ inlineConst: true,
217
+ lazyBarrel: true
218
+ }
219
+ };
220
+ if (custom) {
221
+ defaultOptions = (0, webpack_merge_1.default)(defaultOptions, custom(context));
222
+ }
223
+ return defaultOptions;
216
224
  }
@@ -1,2 +1,2 @@
1
- import type { ECompilerType, TCompilerOptions } from "../type";
1
+ import { ECompilerType, type TCompilerOptions } from "../type";
2
2
  export declare function createHotStepCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;