@rspack-canary/test-tools 1.6.0-canary-6cd722f4-20251022123039 → 1.6.0-canary-4ad8b49f-20251023175711

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 (91) hide show
  1. package/dist/case/builtin.d.ts +3 -2
  2. package/dist/case/builtin.js +1 -1
  3. package/dist/case/cache.d.ts +2 -2
  4. package/dist/case/cache.js +9 -6
  5. package/dist/case/common.d.ts +10 -10
  6. package/dist/case/common.js +33 -30
  7. package/dist/case/compiler.d.ts +9 -8
  8. package/dist/case/compiler.js +5 -6
  9. package/dist/case/config.d.ts +6 -5
  10. package/dist/case/defaults.d.ts +5 -4
  11. package/dist/case/defaults.js +10 -10
  12. package/dist/case/diagnostic.js +4 -5
  13. package/dist/case/error.d.ts +5 -5
  14. package/dist/case/error.js +7 -8
  15. package/dist/case/example.js +2 -2
  16. package/dist/case/hash.d.ts +2 -2
  17. package/dist/case/hash.js +1 -1
  18. package/dist/case/hook.d.ts +4 -3
  19. package/dist/case/hook.js +3 -2
  20. package/dist/case/hot-step.d.ts +2 -2
  21. package/dist/case/hot-step.js +4 -6
  22. package/dist/case/hot.d.ts +5 -4
  23. package/dist/case/hot.js +6 -6
  24. package/dist/case/incremental.d.ts +2 -2
  25. package/dist/case/index.d.ts +0 -1
  26. package/dist/case/index.js +1 -3
  27. package/dist/case/multi-compiler.d.ts +9 -8
  28. package/dist/case/multi-compiler.js +3 -4
  29. package/dist/case/normal.js +1 -1
  30. package/dist/case/runner.d.ts +5 -4
  31. package/dist/case/runner.js +12 -8
  32. package/dist/case/serial.d.ts +2 -2
  33. package/dist/case/stats-api.d.ts +6 -5
  34. package/dist/case/stats-api.js +5 -7
  35. package/dist/case/stats-output.d.ts +3 -2
  36. package/dist/case/stats-output.js +1 -1
  37. package/dist/case/treeshaking.js +1 -1
  38. package/dist/case/watch.d.ts +6 -6
  39. package/dist/case/watch.js +15 -14
  40. package/dist/compiler.d.ts +16 -17
  41. package/dist/compiler.js +116 -16
  42. package/dist/helper/index.d.ts +1 -0
  43. package/dist/helper/index.js +1 -0
  44. package/dist/helper/legacy/checkArrayExpectation.js +1 -1
  45. package/dist/helper/read-config-file.d.ts +3 -2
  46. package/dist/helper/read-config-file.js +7 -0
  47. package/dist/helper/setup-env.js +1 -0
  48. package/dist/helper/stringify-config.d.ts +2 -0
  49. package/dist/helper/stringify-config.js +43 -0
  50. package/dist/index.d.ts +0 -1
  51. package/dist/index.js +0 -1
  52. package/dist/plugin/index.d.ts +0 -3
  53. package/dist/plugin/index.js +0 -3
  54. package/dist/runner/node/index.d.ts +13 -8
  55. package/dist/runner/node/index.js +86 -7
  56. package/dist/runner/web/index.d.ts +6 -5
  57. package/dist/runner/web/index.js +38 -50
  58. package/dist/test/context.d.ts +15 -16
  59. package/dist/test/context.js +44 -59
  60. package/dist/test/creator.d.ts +14 -14
  61. package/dist/test/creator.js +4 -5
  62. package/dist/test/debug.d.ts +15 -0
  63. package/dist/test/debug.js +205 -0
  64. package/dist/test/tester.js +13 -4
  65. package/dist/type.d.ts +37 -50
  66. package/dist/type.js +1 -6
  67. package/package.json +5 -9
  68. package/dist/case/diff.d.ts +0 -19
  69. package/dist/case/diff.js +0 -274
  70. package/dist/compare/comparator.d.ts +0 -17
  71. package/dist/compare/comparator.js +0 -52
  72. package/dist/compare/compare.d.ts +0 -17
  73. package/dist/compare/compare.js +0 -178
  74. package/dist/compare/format-code.d.ts +0 -16
  75. package/dist/compare/format-code.js +0 -244
  76. package/dist/compare/index.d.ts +0 -5
  77. package/dist/compare/index.js +0 -21
  78. package/dist/compare/replace-module-argument.d.ts +0 -1
  79. package/dist/compare/replace-module-argument.js +0 -8
  80. package/dist/compare/replace-runtime-module-name.d.ts +0 -1
  81. package/dist/compare/replace-runtime-module-name.js +0 -71
  82. package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
  83. package/dist/plugin/rspack-diff-config-plugin.js +0 -42
  84. package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
  85. package/dist/plugin/webpack-diff-config-plugin.js +0 -41
  86. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
  87. package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
  88. package/template/diff.bundle.css +0 -1
  89. package/template/diff.bundle.js +0 -144
  90. package/template/diff.html +0 -14
  91. package/template/editor.worker.js +0 -1
@@ -1,3 +1,4 @@
1
- import type { ECompilerType, ITestContext, TCompilerOptions } from "../type";
1
+ import type { RspackOptions } from "@rspack/core";
2
+ import type { ITestContext } from "../type";
2
3
  export declare function createBuiltinCase(name: string, src: string, dist: string): void;
3
- export declare function defaultOptions<T extends ECompilerType.Rspack>(context: ITestContext): TCompilerOptions<T>;
4
+ export declare function defaultOptions(context: ITestContext): RspackOptions;
@@ -23,7 +23,7 @@ const creator = new creator_1.BasicCaseCreator({
23
23
  return [
24
24
  {
25
25
  config: async (context) => {
26
- const compiler = (0, common_1.getCompiler)(context, name);
26
+ const compiler = context.getCompiler();
27
27
  compiler.setOptions(defaultOptions(context));
28
28
  },
29
29
  compiler: async (context) => {
@@ -1,2 +1,2 @@
1
- import type { ECompilerType, TCompilerOptions } from "../type";
2
- export declare function createCacheCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], temp: string): void;
1
+ import { type RspackOptions } from "@rspack/core";
2
+ export declare function createCacheCase(name: string, src: string, dist: string, target: RspackOptions["target"], temp: string): void;
@@ -19,10 +19,10 @@ function createCacheProcessor(name, src, temp, target) {
19
19
  return {
20
20
  before: async (context) => {
21
21
  await updatePlugin.initialize();
22
- context.setValue(name, "hotUpdateContext", updatePlugin);
22
+ context.setValue("hotUpdateContext", updatePlugin);
23
23
  },
24
24
  config: async (context) => {
25
- const compiler = (0, common_1.getCompiler)(context, name);
25
+ const compiler = context.getCompiler();
26
26
  let options = defaultOptions(context, temp, target);
27
27
  options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"].map(i => node_path_1.default.resolve(temp, i)), options);
28
28
  overrideOptions(options, temp, target, updatePlugin);
@@ -131,13 +131,16 @@ function overrideOptions(options, temp, target, updatePlugin) {
131
131
  function findBundle(name, target, context) {
132
132
  const files = [];
133
133
  const prefiles = [];
134
- const compiler = (0, common_1.getCompiler)(context, name);
134
+ const compiler = context.getCompiler();
135
135
  if (!compiler)
136
136
  throw new Error("Compiler should exists when find bundle");
137
137
  const stats = compiler.getStats();
138
138
  if (!stats)
139
139
  throw new Error("Stats should exists when find bundle");
140
- const info = stats.toJson({ all: false, entrypoints: true });
140
+ const info = stats.toJson({
141
+ all: false,
142
+ entrypoints: true
143
+ });
141
144
  if (target === "web" || target === "webworker") {
142
145
  for (const file of info.entrypoints.main.assets) {
143
146
  if ((0, helper_1.isJavaScript)(file.name)) {
@@ -155,13 +158,13 @@ function findBundle(name, target, context) {
155
158
  return [...prefiles, ...files];
156
159
  }
157
160
  function createRunner(context, name, file, env) {
158
- const compiler = context.getCompiler(name);
161
+ const compiler = context.getCompiler();
159
162
  const options = compiler.getOptions();
160
163
  let compilerIndex = 0;
161
164
  const testConfig = context.getTestConfig();
162
165
  const source = context.getSource();
163
166
  const dist = context.getDist();
164
- const updatePlugin = context.getValue(name, "hotUpdateContext");
167
+ const updatePlugin = context.getValue("hotUpdateContext");
165
168
  const getWebRunner = () => {
166
169
  return new runner_1.NodeRunner({
167
170
  env,
@@ -1,11 +1,11 @@
1
- import { ECompilerType, type ITestCompilerManager, type ITestContext, type ITestEnv, type TCompiler, type TCompilerOptions } from "../type";
2
- export declare function getCompiler<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string): ITestCompilerManager<T>;
3
- export declare function config<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, configFiles: string[], defaultOptions?: TCompilerOptions<T>): Promise<TCompilerOptions<T>>;
4
- export declare function compiler<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string): Promise<TCompiler<T>>;
5
- export declare function build<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string): Promise<TCompiler<T>>;
6
- export declare function run<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string, findBundle: (context: ITestContext, options: TCompilerOptions<T>) => string[] | string | void): Promise<void>;
7
- export declare function check<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string): Promise<void>;
8
- export declare function checkSnapshot<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string, snapshot: string, filter?: (file: string) => boolean): Promise<void>;
1
+ import type { Compiler, RspackOptions } from "@rspack/core";
2
+ import type { ITestContext, ITestEnv } from "../type";
3
+ export declare function config(context: ITestContext, name: string, configFiles: string[], defaultOptions?: RspackOptions): Promise<RspackOptions>;
4
+ export declare function compiler(context: ITestContext, name: string): Promise<Compiler>;
5
+ export declare function build(context: ITestContext, name: string): Promise<Compiler>;
6
+ export declare function run(env: ITestEnv, context: ITestContext, name: string, findBundle: (context: ITestContext, options: RspackOptions) => string[] | string | void): Promise<void>;
7
+ export declare function check(env: ITestEnv, context: ITestContext, name: string): Promise<void>;
8
+ export declare function checkSnapshot(env: ITestEnv, context: ITestContext, name: string, snapshot: string, filter?: (file: string) => boolean): Promise<void>;
9
9
  export declare function afterExecute(context: ITestContext, name: string): Promise<void>;
10
- export declare function findMultiCompilerBundle<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, multiFindBundle: (index: number, context: ITestContext, options: TCompilerOptions<T>) => string[] | string | void): string[];
11
- export declare function configMultiCompiler<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, configFiles: string[], defaultOptions: (index: number, context: ITestContext) => TCompilerOptions<T>, overrideOptions: (index: number, context: ITestContext, options: TCompilerOptions<T>) => void): void;
10
+ export declare function findMultiCompilerBundle(context: ITestContext, name: string, multiFindBundle: (index: number, context: ITestContext, options: RspackOptions) => string[] | string | void): string[];
11
+ export declare function configMultiCompiler(context: ITestContext, name: string, configFiles: string[], defaultOptions: (index: number, context: ITestContext) => RspackOptions, overrideOptions: (index: number, context: ITestContext, options: RspackOptions) => void): void;
@@ -3,7 +3,6 @@ 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.getCompiler = getCompiler;
7
6
  exports.config = config;
8
7
  exports.compiler = compiler;
9
8
  exports.build = build;
@@ -19,12 +18,9 @@ const webpack_merge_1 = __importDefault(require("webpack-merge"));
19
18
  const helper_1 = require("../helper");
20
19
  const placeholder_1 = require("../helper/expect/placeholder");
21
20
  const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
22
- const type_1 = require("../type");
23
- function getCompiler(context, name) {
24
- return context.getCompiler(name, type_1.ECompilerType.Rspack);
25
- }
21
+ const debug_1 = require("../test/debug");
26
22
  async function config(context, name, configFiles, defaultOptions = {}) {
27
- const compiler = getCompiler(context, name);
23
+ const compiler = context.getCompiler();
28
24
  compiler.setOptions(defaultOptions);
29
25
  if (Array.isArray(configFiles)) {
30
26
  const fileOptions = (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), context, defaultOptions)[0];
@@ -33,12 +29,12 @@ async function config(context, name, configFiles, defaultOptions = {}) {
33
29
  return compiler.getOptions();
34
30
  }
35
31
  async function compiler(context, name) {
36
- const compiler = getCompiler(context, name);
32
+ const compiler = context.getCompiler();
37
33
  compiler.createCompiler();
38
34
  return compiler.getCompiler();
39
35
  }
40
36
  async function build(context, name) {
41
- const compiler = getCompiler(context, name);
37
+ const compiler = context.getCompiler();
42
38
  await compiler.build();
43
39
  return compiler.getCompiler();
44
40
  }
@@ -46,15 +42,12 @@ async function run(env, context, name, findBundle) {
46
42
  const testConfig = context.getTestConfig();
47
43
  if (testConfig.noTests)
48
44
  return;
49
- const compiler = getCompiler(context, name);
45
+ const compiler = context.getCompiler();
50
46
  if (typeof testConfig.beforeExecute === "function") {
51
47
  testConfig.beforeExecute(compiler.getOptions());
52
48
  }
53
49
  let bundles;
54
- if (testConfig.bundlePath) {
55
- bundles = testConfig.bundlePath;
56
- }
57
- else if (typeof findBundle === "function") {
50
+ if (typeof findBundle === "function") {
58
51
  bundles = findBundle(context, compiler.getOptions());
59
52
  }
60
53
  else {
@@ -63,28 +56,39 @@ async function run(env, context, name, findBundle) {
63
56
  if (typeof bundles === "string") {
64
57
  bundles = [bundles];
65
58
  }
59
+ if (__DEBUG__) {
60
+ context.setValue(debug_1.DEBUG_SCOPES.RunFindBundle, bundles);
61
+ }
66
62
  if (!bundles || !bundles.length) {
67
63
  return;
68
64
  }
65
+ if (__DEBUG__) {
66
+ context.setValue(debug_1.DEBUG_SCOPES.RunLogs, []);
67
+ context.setValue(debug_1.DEBUG_SCOPES.RunErrors, []);
68
+ }
69
69
  for (const bundle of bundles) {
70
70
  if (!bundle) {
71
71
  continue;
72
72
  }
73
- const runner = context.getRunner(name, bundle, env);
73
+ const runner = context.getRunner(bundle, env);
74
+ if (__DEBUG__) {
75
+ const runLogs = context.getValue(debug_1.DEBUG_SCOPES.RunLogs);
76
+ runLogs?.push(`Start running entry: ${bundle} in ${runner.constructor.name}(${runner.__key__})`);
77
+ }
74
78
  const mod = runner.run(bundle);
75
- const result = context.getValue(name, "modules") || [];
79
+ const result = context.getValue("modules") || [];
76
80
  result.push(mod);
77
- context.setValue(name, "modules", result);
81
+ context.setValue("modules", result);
78
82
  }
79
- const results = context.getValue(name, "modules") || [];
83
+ const results = context.getValue("modules") || [];
80
84
  await Promise.all(results);
81
85
  }
82
86
  async function check(env, context, name) {
83
87
  const testConfig = context.getTestConfig();
84
88
  if (testConfig.noTests)
85
89
  return;
86
- const compiler = getCompiler(context, name);
87
- const errors = (context.getError(name) || []).map(e => ({
90
+ const compiler = context.getCompiler();
91
+ const errors = (context.getError() || []).map(e => ({
88
92
  message: e.message,
89
93
  stack: e.stack
90
94
  }));
@@ -123,14 +127,14 @@ async function check(env, context, name) {
123
127
  await (0, checkArrayExpectation_1.default)(context.getSource(), { warnings }, "warning", "warnings", "Warning", options);
124
128
  // clear error if checked
125
129
  if (fs_extra_1.default.existsSync(context.getSource("errors.js"))) {
126
- context.clearError(name);
130
+ context.clearError();
127
131
  }
128
132
  }
129
133
  async function checkSnapshot(env, context, name, snapshot, filter) {
130
134
  if (path_1.default.extname(snapshot) === ".snap") {
131
135
  throw new Error("Snapshot with `.snap` will be managed by jest, please use `.snap.txt` instead");
132
136
  }
133
- const compilerManager = getCompiler(context, name);
137
+ const compilerManager = context.getCompiler();
134
138
  const stats = compilerManager.getStats();
135
139
  const compiler = compilerManager.getCompiler();
136
140
  if (!stats || !compiler)
@@ -138,9 +142,7 @@ async function checkSnapshot(env, context, name, snapshot, filter) {
138
142
  const compilers = "compilers" in compiler
139
143
  ? compiler.compilers
140
144
  : [compiler];
141
- const totalStats = "stats" in stats
142
- ? stats.stats
143
- : [stats];
145
+ const totalStats = "stats" in stats ? stats.stats : [stats];
144
146
  const total = compilers.length;
145
147
  for (let i = 0; i < compilers.length; i++) {
146
148
  const c = compilers[i];
@@ -178,7 +180,7 @@ async function checkSnapshot(env, context, name, snapshot, filter) {
178
180
  }
179
181
  }
180
182
  async function afterExecute(context, name) {
181
- const compiler = getCompiler(context, name);
183
+ const compiler = context.getCompiler();
182
184
  const testConfig = context.getTestConfig();
183
185
  if (typeof testConfig.afterExecute === "function") {
184
186
  let options = compiler.getOptions();
@@ -192,9 +194,10 @@ function findMultiCompilerBundle(context, name, multiFindBundle) {
192
194
  if (typeof multiFindBundle !== "function") {
193
195
  return [];
194
196
  }
195
- const multiCompilerOptions = (context.getValue(name, "multiCompilerOptions") || []);
197
+ const multiCompilerOptions = (context.getValue("multiCompilerOptions") ||
198
+ []);
196
199
  const result = [];
197
- const multiFileIndexMap = context.getValue(name, "multiFileIndexMap") || {};
200
+ const multiFileIndexMap = context.getValue("multiFileIndexMap") || {};
198
201
  for (const [index, compilerOptions] of multiCompilerOptions.entries()) {
199
202
  const curBundles = multiFindBundle(index, context, compilerOptions);
200
203
  const bundles = Array.isArray(curBundles)
@@ -212,7 +215,7 @@ function findMultiCompilerBundle(context, name, multiFindBundle) {
212
215
  }
213
216
  result.push(...bundles);
214
217
  }
215
- context.setValue(name, "multiFileIndexMap", multiFileIndexMap);
218
+ context.setValue("multiFileIndexMap", multiFileIndexMap);
216
219
  return result;
217
220
  }
218
221
  function configMultiCompiler(context, name, configFiles, defaultOptions, overrideOptions) {
@@ -240,7 +243,7 @@ function configMultiCompiler(context, name, configFiles, defaultOptions, overrid
240
243
  }
241
244
  multiCompilerOptions.push(compilerOptions);
242
245
  }
243
- const compiler = getCompiler(context, name);
246
+ const compiler = context.getCompiler();
244
247
  compiler.setOptions(multiCompilerOptions);
245
- context.setValue(name, "multiCompilerOptions", multiCompilerOptions);
248
+ context.setValue("multiCompilerOptions", multiCompilerOptions);
246
249
  }
@@ -1,18 +1,19 @@
1
- import type { ECompilerType, ITestContext, TCompilation, TCompiler, TCompilerOptions, TCompilerStats, TCompilerStatsCompilation } from "../type";
1
+ import type { Compilation, Compiler, RspackOptions, Stats, StatsCompilation } from "@rspack/core";
2
+ import type { ITestContext } from "../type";
2
3
  export declare function createCompilerCase(name: string, src: string, dist: string, testConfig: string): void;
3
4
  export type TCompilerCaseConfig = {
4
5
  description: string;
5
6
  error?: boolean;
6
7
  skip?: boolean;
7
- options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
8
- compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
9
- build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
8
+ options?: (context: ITestContext) => RspackOptions;
9
+ compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
10
+ build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
10
11
  check?: ({ context, stats, files, compiler, compilation }: {
11
12
  context: ITestContext;
12
- stats?: TCompilerStatsCompilation<ECompilerType.Rspack>;
13
+ stats?: StatsCompilation;
13
14
  files?: Record<string, string>;
14
- compiler: TCompiler<ECompilerType.Rspack>;
15
- compilation?: TCompilation<ECompilerType.Rspack>;
15
+ compiler: Compiler;
16
+ compilation?: Compilation;
16
17
  }) => Promise<void>;
17
- compilerCallback?: (error: Error | null, stats: TCompilerStats<ECompilerType.Rspack> | null) => void;
18
+ compilerCallback?: (error: Error | null, stats: Stats | null) => void;
18
19
  };
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCompilerCase = createCompilerCase;
4
4
  const creator_1 = require("../test/creator");
5
- const common_1 = require("./common");
6
5
  function createCompilerProcessor(name, caseConfig) {
7
6
  const logs = {
8
7
  mkdir: [],
@@ -11,7 +10,7 @@ function createCompilerProcessor(name, caseConfig) {
11
10
  const files = {};
12
11
  return {
13
12
  config: async (context) => {
14
- const compiler = (0, common_1.getCompiler)(context, name);
13
+ const compiler = context.getCompiler();
15
14
  const options = caseConfig.options?.(context) || {};
16
15
  options.mode ??= "production";
17
16
  options.context ??= context.getSource();
@@ -24,7 +23,7 @@ function createCompilerProcessor(name, caseConfig) {
24
23
  compiler.setOptions(options);
25
24
  },
26
25
  compiler: async (context) => {
27
- const compiler = (0, common_1.getCompiler)(context, name);
26
+ const compiler = context.getCompiler();
28
27
  if (caseConfig.compilerCallback) {
29
28
  compiler.createCompilerWithCallback(caseConfig.compilerCallback);
30
29
  }
@@ -65,7 +64,7 @@ function createCompilerProcessor(name, caseConfig) {
65
64
  await caseConfig.compiler?.(context, c);
66
65
  },
67
66
  build: async (context) => {
68
- const compiler = (0, common_1.getCompiler)(context, name);
67
+ const compiler = context.getCompiler();
69
68
  if (typeof caseConfig.build === "function") {
70
69
  await caseConfig.build?.(context, compiler.getCompiler());
71
70
  }
@@ -75,7 +74,7 @@ function createCompilerProcessor(name, caseConfig) {
75
74
  },
76
75
  run: async (env, context) => { },
77
76
  check: async (env, context) => {
78
- const compiler = (0, common_1.getCompiler)(context, name);
77
+ const compiler = context.getCompiler();
79
78
  const c = compiler.getCompiler();
80
79
  const stats = compiler.getStats();
81
80
  if (caseConfig.error) {
@@ -124,7 +123,7 @@ function createCompilerProcessor(name, caseConfig) {
124
123
  }
125
124
  },
126
125
  after: async (context) => {
127
- await context.closeCompiler(name);
126
+ await context.closeCompiler();
128
127
  }
129
128
  };
130
129
  }
@@ -1,7 +1,8 @@
1
- import type { ECompilerType, ITestContext, ITestProcessor, TCompilerOptions, TTestConfig } from "../type";
2
- export type TConfigCaseConfig = Omit<TTestConfig<ECompilerType.Rspack>, "validate">;
1
+ import type { RspackOptions } from "@rspack/core";
2
+ import type { ITestContext, ITestProcessor, TTestConfig } from "../type";
3
+ export type TConfigCaseConfig = Omit<TTestConfig, "validate">;
3
4
  export declare function createConfigProcessor(name: string): ITestProcessor;
4
5
  export declare function createConfigCase(name: string, src: string, dist: string): void;
5
- export declare function defaultOptions(index: number, context: ITestContext): TCompilerOptions<ECompilerType.Rspack>;
6
- export declare function overrideOptions(index: number, context: ITestContext, options: TCompilerOptions<ECompilerType.Rspack>): void;
7
- export declare function findBundle(index: number, context: ITestContext, options: TCompilerOptions<ECompilerType.Rspack>): string | string[];
6
+ export declare function defaultOptions(index: number, context: ITestContext): RspackOptions;
7
+ export declare function overrideOptions(index: number, context: ITestContext, options: RspackOptions): void;
8
+ export declare function findBundle(index: number, context: ITestContext, options: RspackOptions): string | string[];
@@ -1,10 +1,11 @@
1
- import type { ECompilerType, ITestContext, TCompilerOptions } from "../type";
1
+ import type { RspackOptions } from "@rspack/core";
2
+ import type { ITestContext } from "../type";
2
3
  export declare function createDefaultsCase(name: string, src: string): void;
3
- export declare function getRspackDefaultConfig(cwd: string, config: TCompilerOptions<ECompilerType>): TCompilerOptions<ECompilerType>;
4
+ export declare function getRspackDefaultConfig(cwd: string, config: RspackOptions): RspackOptions;
4
5
  export type TDefaultsCaseConfig = {
5
- options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
6
+ options?: (context: ITestContext) => RspackOptions;
6
7
  cwd?: string;
7
- diff: (diff: jest.JestMatchers<RspackTestDiff>, defaults: jest.JestMatchers<TCompilerOptions<ECompilerType.Rspack>>) => Promise<void>;
8
+ diff: (diff: jest.JestMatchers<RspackTestDiff>, defaults: jest.JestMatchers<RspackOptions>) => Promise<void>;
8
9
  description: string;
9
10
  };
10
11
  declare class RspackTestDiff {
@@ -9,18 +9,17 @@ 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
11
  const context_1 = require("../test/context");
12
- const common_1 = require("./common");
13
12
  const CURRENT_CWD = process.cwd();
14
13
  function createDefaultsCase(name, src) {
15
14
  const caseConfig = require(src);
16
15
  it(`should generate the correct defaults from ${caseConfig.description}`, async () => {
17
16
  await run(name, {
18
17
  config: async (context) => {
19
- const compiler = (0, common_1.getCompiler)(context, name);
18
+ const compiler = context.getCompiler();
20
19
  compiler.setOptions(options(context, caseConfig.options));
21
20
  },
22
21
  compiler: async (context) => {
23
- const compiler = (0, common_1.getCompiler)(context, name);
22
+ const compiler = context.getCompiler();
24
23
  compiler.createCompiler();
25
24
  },
26
25
  build: async (context) => {
@@ -48,10 +47,6 @@ function getRspackDefaultConfig(cwd, config) {
48
47
  }
49
48
  const srcDir = node_path_1.default.resolve(__dirname, "../../tests/fixtures");
50
49
  const distDir = node_path_1.default.resolve(__dirname, "../../tests/js/defaults");
51
- const context = new context_1.TestContext({
52
- src: srcDir,
53
- dist: distDir
54
- });
55
50
  function options(context, custom) {
56
51
  let res;
57
52
  if (typeof custom === "function") {
@@ -71,7 +66,7 @@ class RspackTestDiff {
71
66
  }
72
67
  }
73
68
  async function check(env, context, name, options) {
74
- const compiler = (0, common_1.getCompiler)(context, name);
69
+ const compiler = context.getCompiler();
75
70
  const config = getRspackDefaultConfig(options.cwd || CURRENT_CWD, compiler.getOptions());
76
71
  const defaultConfig = getRspackDefaultConfig(options.cwd || CURRENT_CWD, {
77
72
  mode: "none"
@@ -80,15 +75,20 @@ async function check(env, context, name, options) {
80
75
  await options.diff(env.expect(new RspackTestDiff(diff)), env.expect(defaultConfig));
81
76
  }
82
77
  async function run(name, processor) {
78
+ const context = new context_1.TestContext({
79
+ name: name,
80
+ src: srcDir,
81
+ dist: distDir
82
+ });
83
83
  try {
84
84
  await processor.before?.(context);
85
85
  await processor.config?.(context);
86
86
  }
87
87
  catch (e) {
88
- context.emitError(name, e);
88
+ context.emitError(e);
89
89
  }
90
90
  finally {
91
- await processor.check?.({ expect, it, beforeEach, afterEach, jest }, context);
91
+ await processor.check?.({ expect, it, beforeEach, afterEach, jest: global.jest || global.rstest }, context);
92
92
  await processor.after?.(context);
93
93
  }
94
94
  }
@@ -10,14 +10,13 @@ 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
12
  const creator_1 = require("../test/creator");
13
- const common_1 = require("./common");
14
13
  const creator = new creator_1.BasicCaseCreator({
15
14
  clean: true,
16
15
  describe: false,
17
16
  steps: ({ name }) => [
18
17
  {
19
18
  config: async (context) => {
20
- const compiler = (0, common_1.getCompiler)(context, name);
19
+ const compiler = context.getCompiler();
21
20
  let options = defaultOptions(context);
22
21
  const custom = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)), context, options)[0];
23
22
  if (custom) {
@@ -31,11 +30,11 @@ const creator = new creator_1.BasicCaseCreator({
31
30
  compiler.setOptions(options);
32
31
  },
33
32
  compiler: async (context) => {
34
- const compiler = (0, common_1.getCompiler)(context, name);
33
+ const compiler = context.getCompiler();
35
34
  compiler.createCompiler();
36
35
  },
37
36
  build: async (context) => {
38
- const compiler = (0, common_1.getCompiler)(context, name);
37
+ const compiler = context.getCompiler();
39
38
  await compiler.build();
40
39
  },
41
40
  run: async (env, context) => {
@@ -89,7 +88,7 @@ function defaultOptions(context) {
89
88
  };
90
89
  }
91
90
  async function check(env, context, name, options) {
92
- const compiler = (0, common_1.getCompiler)(context, name);
91
+ const compiler = context.getCompiler();
93
92
  const stats = compiler.getStats();
94
93
  if (!stats) {
95
94
  throw new Error("Stats should exists");
@@ -1,5 +1,5 @@
1
- import type { StatsError } from "@rspack/core";
2
- import type { ECompilerType, ITestContext, TCompiler, TCompilerOptions } from "../type";
1
+ import type { Compiler, RspackOptions, StatsError } from "@rspack/core";
2
+ import type { ITestContext } from "../type";
3
3
  export declare function createErrorCase(name: string, src: string, dist: string, testConfig: string): void;
4
4
  declare class RspackStatsDiagnostics {
5
5
  errors: StatsError[];
@@ -9,9 +9,9 @@ declare class RspackStatsDiagnostics {
9
9
  export type TErrorCaseConfig = {
10
10
  description: string;
11
11
  skip?: boolean;
12
- options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
13
- compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
14
- build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
12
+ options?: (context: ITestContext) => RspackOptions;
13
+ compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
14
+ build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
15
15
  check?: (stats: RspackStatsDiagnostics) => Promise<void>;
16
16
  };
17
17
  export {};
@@ -7,7 +7,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
9
  const creator_1 = require("../test/creator");
10
- const common_1 = require("./common");
11
10
  let addedSerializer = false;
12
11
  const creator = new creator_1.BasicCaseCreator({
13
12
  clean: true,
@@ -17,16 +16,16 @@ const creator = new creator_1.BasicCaseCreator({
17
16
  return [
18
17
  {
19
18
  config: async (context) => {
20
- const compiler = (0, common_1.getCompiler)(context, name);
19
+ const compiler = context.getCompiler();
21
20
  compiler.setOptions(options(context, config.options));
22
21
  },
23
22
  compiler: async (context) => {
24
- const compilerManager = (0, common_1.getCompiler)(context, name);
23
+ const compilerManager = context.getCompiler();
25
24
  compilerManager.createCompiler();
26
25
  compiler(context, compilerManager.getCompiler(), config.compiler);
27
26
  },
28
27
  build: async (context) => {
29
- const compiler = (0, common_1.getCompiler)(context, name);
28
+ const compiler = context.getCompiler();
30
29
  if (typeof config.build === "function") {
31
30
  await config.build(context, compiler.getCompiler());
32
31
  }
@@ -130,12 +129,12 @@ class RspackStatsDiagnostics {
130
129
  }
131
130
  }
132
131
  async function check(env, context, name, check) {
133
- if (context.getError(name).length > 0) {
134
- await check?.(new RspackStatsDiagnostics(context.getError(name), []));
135
- context.clearError(name);
132
+ if (context.getError().length > 0) {
133
+ await check?.(new RspackStatsDiagnostics(context.getError(), []));
134
+ context.clearError();
136
135
  return;
137
136
  }
138
- const compiler = (0, common_1.getCompiler)(context, name);
137
+ const compiler = context.getCompiler();
139
138
  const stats = compiler.getStats();
140
139
  env.expect(typeof stats).toBe("object");
141
140
  const statsResult = stats.toJson({ errorDetails: false });
@@ -33,14 +33,14 @@ function createExampleProcessor(name) {
33
33
  // no need to run, just check the building
34
34
  },
35
35
  check: async (env, context) => {
36
- const compiler = (0, common_1.getCompiler)(context, name);
36
+ const compiler = context.getCompiler();
37
37
  const stats = compiler.getStats();
38
38
  if (stats?.hasErrors()) {
39
39
  console.log(stats.toString({
40
40
  all: false,
41
41
  errors: true,
42
42
  errorDetails: true,
43
- errorStacks: true
43
+ errorStack: true
44
44
  }));
45
45
  }
46
46
  expect(stats?.hasErrors()).toBe(false);
@@ -1,3 +1,3 @@
1
- import type { ECompilerType, TTestConfig } from "../type";
2
- export type THashCaseConfig = Pick<TTestConfig<ECompilerType.Rspack>, "validate">;
1
+ import type { TTestConfig } from "../type";
2
+ export type THashCaseConfig = Pick<TTestConfig, "validate">;
3
3
  export declare function createHashCase(name: string, src: string, dist: string): void;
package/dist/case/hash.js CHANGED
@@ -68,7 +68,7 @@ function overrideOptions(index, context, options) {
68
68
  }
69
69
  }
70
70
  async function check(env, context, name) {
71
- const compiler = (0, common_1.getCompiler)(context, name);
71
+ const compiler = context.getCompiler();
72
72
  const stats = compiler.getStats();
73
73
  const testConfig = context.getTestConfig();
74
74
  if (!stats) {
@@ -1,5 +1,6 @@
1
+ import { Compiler, type RspackOptions } from "@rspack/core";
1
2
  import { TestContext, type TTestContextOptions } from "../test/context";
2
- import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions } from "../type";
3
+ import type { ITestContext, ITestEnv } from "../type";
3
4
  export declare function createHookCase(name: string, src: string, dist: string, source: string): void;
4
5
  export declare class HookCasesContext extends TestContext {
5
6
  protected src: string;
@@ -29,8 +30,8 @@ export declare class HookCasesContext extends TestContext {
29
30
  }): Promise<void>;
30
31
  }
31
32
  export type THookCaseConfig = {
32
- options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
33
- compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
33
+ options?: (context: ITestContext) => RspackOptions;
34
+ compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
34
35
  check?: (context: ITestContext) => Promise<void>;
35
36
  snapshotFileFilter?: (file: string) => boolean;
36
37
  description: string;
package/dist/case/hook.js CHANGED
@@ -25,7 +25,7 @@ const creator = new creator_1.BasicCaseCreator({
25
25
  return [
26
26
  {
27
27
  config: async (context) => {
28
- const compiler = (0, common_1.getCompiler)(context, name);
28
+ const compiler = context.getCompiler();
29
29
  const options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"], defaultOptions(context, caseConfig.options));
30
30
  if (!global.printLogger) {
31
31
  options.infrastructureLogging = {
@@ -61,7 +61,8 @@ function createHookCase(name, src, dist, source) {
61
61
  description: () => caseConfig.description,
62
62
  createContext: (config) => new HookCasesContext(src, testName, {
63
63
  src: source,
64
- dist: dist
64
+ dist: dist,
65
+ name: name
65
66
  })
66
67
  });
67
68
  }
@@ -1,2 +1,2 @@
1
- import { ECompilerType, type TCompilerOptions } from "../type";
2
- export declare function createHotStepCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
1
+ import type { RspackOptions } from "@rspack/core";
2
+ export declare function createHotStepCase(name: string, src: string, dist: string, temp: string, target: RspackOptions["target"]): void;