@rspack/test-tools 1.6.0-beta.0 → 1.6.0

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 (118) 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 +13 -9
  5. package/dist/case/common.d.ts +11 -10
  6. package/dist/case/common.js +49 -43
  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/config.js +4 -1
  11. package/dist/case/defaults.d.ts +5 -4
  12. package/dist/case/defaults.js +10 -10
  13. package/dist/case/diagnostic.js +5 -6
  14. package/dist/case/error.d.ts +5 -5
  15. package/dist/case/error.js +7 -8
  16. package/dist/case/esm-output.js +30 -9
  17. package/dist/case/example.js +2 -2
  18. package/dist/case/hash.d.ts +2 -2
  19. package/dist/case/hash.js +1 -1
  20. package/dist/case/hook.d.ts +4 -3
  21. package/dist/case/hook.js +3 -2
  22. package/dist/case/hot-step.d.ts +2 -2
  23. package/dist/case/hot-step.js +4 -9
  24. package/dist/case/hot.d.ts +5 -4
  25. package/dist/case/hot.js +37 -49
  26. package/dist/case/incremental.d.ts +2 -2
  27. package/dist/case/incremental.js +1 -20
  28. package/dist/case/index.d.ts +0 -1
  29. package/dist/case/index.js +1 -3
  30. package/dist/case/multi-compiler.d.ts +9 -8
  31. package/dist/case/multi-compiler.js +3 -4
  32. package/dist/case/normal.js +5 -2
  33. package/dist/case/runner.d.ts +5 -4
  34. package/dist/case/runner.js +16 -11
  35. package/dist/case/serial.d.ts +2 -2
  36. package/dist/case/serial.js +1 -1
  37. package/dist/case/stats-api.d.ts +6 -5
  38. package/dist/case/stats-api.js +5 -7
  39. package/dist/case/stats-output.d.ts +3 -2
  40. package/dist/case/stats-output.js +1 -1
  41. package/dist/case/treeshaking.js +1 -1
  42. package/dist/case/watch.d.ts +8 -6
  43. package/dist/case/watch.js +21 -19
  44. package/dist/compiler.d.ts +16 -17
  45. package/dist/compiler.js +116 -16
  46. package/dist/helper/hot-update/loader.d.ts +2 -1
  47. package/dist/helper/hot-update/loader.js +5 -30
  48. package/dist/helper/hot-update/plugin.js +10 -14
  49. package/dist/helper/index.d.ts +1 -0
  50. package/dist/helper/index.js +1 -0
  51. package/dist/helper/legacy/asModule.js +0 -2
  52. package/dist/helper/legacy/checkArrayExpectation.js +1 -1
  53. package/dist/helper/legacy/createLazyTestEnv.d.ts +1 -0
  54. package/dist/helper/legacy/createLazyTestEnv.js +4 -3
  55. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  56. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  57. package/dist/helper/read-config-file.d.ts +3 -2
  58. package/dist/helper/read-config-file.js +12 -2
  59. package/dist/helper/setup-env.js +19 -2
  60. package/dist/helper/stringify-config.d.ts +2 -0
  61. package/dist/helper/stringify-config.js +43 -0
  62. package/dist/helper/util/expectWarningFactory.js +2 -4
  63. package/dist/index.d.ts +0 -1
  64. package/dist/index.js +0 -1
  65. package/dist/plugin/index.d.ts +0 -3
  66. package/dist/plugin/index.js +0 -3
  67. package/dist/runner/node/index.d.ts +13 -8
  68. package/dist/runner/node/index.js +88 -10
  69. package/dist/runner/web/index.d.ts +24 -10
  70. package/dist/runner/web/index.js +286 -18
  71. package/dist/test/context.d.ts +15 -16
  72. package/dist/test/context.js +44 -59
  73. package/dist/test/creator.d.ts +14 -14
  74. package/dist/test/creator.js +17 -12
  75. package/dist/test/debug.d.ts +15 -0
  76. package/dist/test/debug.js +205 -0
  77. package/dist/test/tester.d.ts +1 -0
  78. package/dist/test/tester.js +23 -4
  79. package/dist/type.d.ts +42 -55
  80. package/dist/type.js +1 -11
  81. package/jest.d.ts +2 -0
  82. package/package.json +10 -48
  83. package/dist/case/diff.d.ts +0 -19
  84. package/dist/case/diff.js +0 -274
  85. package/dist/compare/comparator.d.ts +0 -17
  86. package/dist/compare/comparator.js +0 -52
  87. package/dist/compare/compare.d.ts +0 -17
  88. package/dist/compare/compare.js +0 -178
  89. package/dist/compare/format-code.d.ts +0 -16
  90. package/dist/compare/format-code.js +0 -244
  91. package/dist/compare/index.d.ts +0 -5
  92. package/dist/compare/index.js +0 -21
  93. package/dist/compare/replace-module-argument.d.ts +0 -1
  94. package/dist/compare/replace-module-argument.js +0 -8
  95. package/dist/compare/replace-runtime-module-name.d.ts +0 -1
  96. package/dist/compare/replace-runtime-module-name.js +0 -71
  97. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  98. package/dist/helper/legacy/FakeDocument.js +0 -280
  99. package/dist/helper/legacy/update.d.ts +0 -2
  100. package/dist/helper/legacy/update.esm.d.ts +0 -1
  101. package/dist/helper/legacy/update.esm.js +0 -23
  102. package/dist/helper/legacy/update.js +0 -19
  103. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  104. package/dist/helper/legacy/walkCssTokens.js +0 -761
  105. package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
  106. package/dist/plugin/rspack-diff-config-plugin.js +0 -42
  107. package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
  108. package/dist/plugin/webpack-diff-config-plugin.js +0 -41
  109. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
  110. package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
  111. package/dist/runner/web/fake.d.ts +0 -15
  112. package/dist/runner/web/fake.js +0 -216
  113. package/dist/runner/web/jsdom.d.ts +0 -24
  114. package/dist/runner/web/jsdom.js +0 -224
  115. package/template/diff.bundle.css +0 -1
  116. package/template/diff.bundle.js +0 -144
  117. package/template/diff.html +0 -14
  118. 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, type 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;
@@ -11,7 +11,6 @@ const hot_update_1 = require("../helper/hot-update");
11
11
  const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
12
12
  const runner_1 = require("../runner");
13
13
  const creator_1 = require("../test/creator");
14
- const type_1 = require("../type");
15
14
  const common_1 = require("./common");
16
15
  const runner_2 = require("./runner");
17
16
  const MAX_COMPILER_INDEX = 100;
@@ -20,10 +19,10 @@ function createCacheProcessor(name, src, temp, target) {
20
19
  return {
21
20
  before: async (context) => {
22
21
  await updatePlugin.initialize();
23
- context.setValue(name, "hotUpdateContext", updatePlugin);
22
+ context.setValue("hotUpdateContext", updatePlugin);
24
23
  },
25
24
  config: async (context) => {
26
- const compiler = (0, common_1.getCompiler)(context, name);
25
+ const compiler = context.getCompiler();
27
26
  let options = defaultOptions(context, temp, target);
28
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);
29
28
  overrideOptions(options, temp, target, updatePlugin);
@@ -41,6 +40,9 @@ function createCacheProcessor(name, src, temp, target) {
41
40
  check: async (env, context) => {
42
41
  await (0, common_1.check)(env, context, name);
43
42
  },
43
+ after: async (context) => {
44
+ await (0, common_1.afterExecute)(context, name);
45
+ },
44
46
  afterAll: async (context) => {
45
47
  const updateIndex = updatePlugin.getUpdateIndex();
46
48
  const totalUpdates = updatePlugin.getTotalUpdates();
@@ -129,13 +131,16 @@ function overrideOptions(options, temp, target, updatePlugin) {
129
131
  function findBundle(name, target, context) {
130
132
  const files = [];
131
133
  const prefiles = [];
132
- const compiler = (0, common_1.getCompiler)(context, name);
134
+ const compiler = context.getCompiler();
133
135
  if (!compiler)
134
136
  throw new Error("Compiler should exists when find bundle");
135
137
  const stats = compiler.getStats();
136
138
  if (!stats)
137
139
  throw new Error("Stats should exists when find bundle");
138
- const info = stats.toJson({ all: false, entrypoints: true });
140
+ const info = stats.toJson({
141
+ all: false,
142
+ entrypoints: true
143
+ });
139
144
  if (target === "web" || target === "webworker") {
140
145
  for (const file of info.entrypoints.main.assets) {
141
146
  if ((0, helper_1.isJavaScript)(file.name)) {
@@ -153,16 +158,15 @@ function findBundle(name, target, context) {
153
158
  return [...prefiles, ...files];
154
159
  }
155
160
  function createRunner(context, name, file, env) {
156
- const compiler = context.getCompiler(name);
161
+ const compiler = context.getCompiler();
157
162
  const options = compiler.getOptions();
158
163
  let compilerIndex = 0;
159
164
  const testConfig = context.getTestConfig();
160
165
  const source = context.getSource();
161
166
  const dist = context.getDist();
162
- const updatePlugin = context.getValue(name, "hotUpdateContext");
167
+ const updatePlugin = context.getValue("hotUpdateContext");
163
168
  const getWebRunner = () => {
164
- return new runner_1.WebRunner({
165
- dom: context.getValue(name, "documentType") || type_1.EDocumentType.JSDOM,
169
+ return new runner_1.NodeRunner({
166
170
  env,
167
171
  stats: (0, runner_2.cachedStats)(context, name),
168
172
  cachable: false,
@@ -1,10 +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>;
9
- 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[];
10
- 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;
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
+ export declare function afterExecute(context: ITestContext, name: string): Promise<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,13 +3,13 @@ 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;
10
9
  exports.run = run;
11
10
  exports.check = check;
12
11
  exports.checkSnapshot = checkSnapshot;
12
+ exports.afterExecute = afterExecute;
13
13
  exports.findMultiCompilerBundle = findMultiCompilerBundle;
14
14
  exports.configMultiCompiler = configMultiCompiler;
15
15
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -18,26 +18,23 @@ const webpack_merge_1 = __importDefault(require("webpack-merge"));
18
18
  const helper_1 = require("../helper");
19
19
  const placeholder_1 = require("../helper/expect/placeholder");
20
20
  const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
21
- const type_1 = require("../type");
22
- function getCompiler(context, name) {
23
- return context.getCompiler(name, type_1.ECompilerType.Rspack);
24
- }
21
+ const debug_1 = require("../test/debug");
25
22
  async function config(context, name, configFiles, defaultOptions = {}) {
26
- const compiler = getCompiler(context, name);
23
+ const compiler = context.getCompiler();
27
24
  compiler.setOptions(defaultOptions);
28
25
  if (Array.isArray(configFiles)) {
29
- const fileOptions = (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)))[0];
26
+ const fileOptions = (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), context, defaultOptions)[0];
30
27
  compiler.mergeOptions(fileOptions);
31
28
  }
32
29
  return compiler.getOptions();
33
30
  }
34
31
  async function compiler(context, name) {
35
- const compiler = getCompiler(context, name);
32
+ const compiler = context.getCompiler();
36
33
  compiler.createCompiler();
37
34
  return compiler.getCompiler();
38
35
  }
39
36
  async function build(context, name) {
40
- const compiler = getCompiler(context, name);
37
+ const compiler = context.getCompiler();
41
38
  await compiler.build();
42
39
  return compiler.getCompiler();
43
40
  }
@@ -45,18 +42,12 @@ async function run(env, context, name, findBundle) {
45
42
  const testConfig = context.getTestConfig();
46
43
  if (testConfig.noTests)
47
44
  return;
48
- if (testConfig.documentType) {
49
- context.setValue(name, "documentType", testConfig.documentType);
50
- }
51
- const compiler = getCompiler(context, name);
45
+ const compiler = context.getCompiler();
52
46
  if (typeof testConfig.beforeExecute === "function") {
53
47
  testConfig.beforeExecute(compiler.getOptions());
54
48
  }
55
49
  let bundles;
56
- if (testConfig.bundlePath) {
57
- bundles = testConfig.bundlePath;
58
- }
59
- else if (typeof findBundle === "function") {
50
+ if (typeof findBundle === "function") {
60
51
  bundles = findBundle(context, compiler.getOptions());
61
52
  }
62
53
  else {
@@ -65,35 +56,39 @@ async function run(env, context, name, findBundle) {
65
56
  if (typeof bundles === "string") {
66
57
  bundles = [bundles];
67
58
  }
59
+ if (__DEBUG__) {
60
+ context.setValue(debug_1.DEBUG_SCOPES.RunFindBundle, bundles);
61
+ }
68
62
  if (!bundles || !bundles.length) {
69
63
  return;
70
64
  }
65
+ if (__DEBUG__) {
66
+ context.setValue(debug_1.DEBUG_SCOPES.RunLogs, []);
67
+ context.setValue(debug_1.DEBUG_SCOPES.RunErrors, []);
68
+ }
71
69
  for (const bundle of bundles) {
72
70
  if (!bundle) {
73
71
  continue;
74
72
  }
75
- 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
+ }
76
78
  const mod = runner.run(bundle);
77
- const result = context.getValue(name, "modules") || [];
79
+ const result = context.getValue("modules") || [];
78
80
  result.push(mod);
79
- context.setValue(name, "modules", result);
81
+ context.setValue("modules", result);
80
82
  }
81
- const results = context.getValue(name, "modules") || [];
83
+ const results = context.getValue("modules") || [];
82
84
  await Promise.all(results);
83
- if (typeof testConfig.afterExecute === "function") {
84
- let options = compiler.getOptions();
85
- if (Array.isArray(options) && options.length === 1) {
86
- options = options[0];
87
- }
88
- testConfig.afterExecute(options);
89
- }
90
85
  }
91
86
  async function check(env, context, name) {
92
87
  const testConfig = context.getTestConfig();
93
88
  if (testConfig.noTests)
94
89
  return;
95
- const compiler = getCompiler(context, name);
96
- const errors = (context.getError(name) || []).map(e => ({
90
+ const compiler = context.getCompiler();
91
+ const errors = (context.getError() || []).map(e => ({
97
92
  message: e.message,
98
93
  stack: e.stack
99
94
  }));
@@ -132,14 +127,14 @@ async function check(env, context, name) {
132
127
  await (0, checkArrayExpectation_1.default)(context.getSource(), { warnings }, "warning", "warnings", "Warning", options);
133
128
  // clear error if checked
134
129
  if (fs_extra_1.default.existsSync(context.getSource("errors.js"))) {
135
- context.clearError(name);
130
+ context.clearError();
136
131
  }
137
132
  }
138
133
  async function checkSnapshot(env, context, name, snapshot, filter) {
139
134
  if (path_1.default.extname(snapshot) === ".snap") {
140
135
  throw new Error("Snapshot with `.snap` will be managed by jest, please use `.snap.txt` instead");
141
136
  }
142
- const compilerManager = getCompiler(context, name);
137
+ const compilerManager = context.getCompiler();
143
138
  const stats = compilerManager.getStats();
144
139
  const compiler = compilerManager.getCompiler();
145
140
  if (!stats || !compiler)
@@ -147,9 +142,7 @@ async function checkSnapshot(env, context, name, snapshot, filter) {
147
142
  const compilers = "compilers" in compiler
148
143
  ? compiler.compilers
149
144
  : [compiler];
150
- const totalStats = "stats" in stats
151
- ? stats.stats
152
- : [stats];
145
+ const totalStats = "stats" in stats ? stats.stats : [stats];
153
146
  const total = compilers.length;
154
147
  for (let i = 0; i < compilers.length; i++) {
155
148
  const c = compilers[i];
@@ -175,23 +168,36 @@ async function checkSnapshot(env, context, name, snapshot, filter) {
175
168
  if (testConfig.snapshotContent) {
176
169
  content = testConfig.snapshotContent(content);
177
170
  }
178
- return `\`\`\`${tag} title=${file}\n${content}\n\`\`\``;
171
+ const filePath = file.replaceAll(path_1.default.sep, "/");
172
+ return `\`\`\`${tag} title=${filePath}\n${content}\n\`\`\``;
179
173
  });
180
174
  fileContents.sort();
181
175
  const content = fileContents.join("\n\n");
182
176
  const snapshotPath = path_1.default.isAbsolute(snapshot)
183
177
  ? snapshot
184
- : path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshot}${total > 1 ? `-${i}` : ""}`);
178
+ : path_1.default.resolve(context.getSource(), path_1.default.join("__snapshots__", `${snapshot}${total > 1 ? `-${i}` : ""}`));
185
179
  env.expect(content).toMatchFileSnapshot(snapshotPath);
186
180
  }
187
181
  }
182
+ async function afterExecute(context, name) {
183
+ const compiler = context.getCompiler();
184
+ const testConfig = context.getTestConfig();
185
+ if (typeof testConfig.afterExecute === "function") {
186
+ let options = compiler.getOptions();
187
+ if (Array.isArray(options) && options.length === 1) {
188
+ options = options[0];
189
+ }
190
+ testConfig.afterExecute(options);
191
+ }
192
+ }
188
193
  function findMultiCompilerBundle(context, name, multiFindBundle) {
189
194
  if (typeof multiFindBundle !== "function") {
190
195
  return [];
191
196
  }
192
- const multiCompilerOptions = (context.getValue(name, "multiCompilerOptions") || []);
197
+ const multiCompilerOptions = (context.getValue("multiCompilerOptions") ||
198
+ []);
193
199
  const result = [];
194
- const multiFileIndexMap = context.getValue(name, "multiFileIndexMap") || {};
200
+ const multiFileIndexMap = context.getValue("multiFileIndexMap") || {};
195
201
  for (const [index, compilerOptions] of multiCompilerOptions.entries()) {
196
202
  const curBundles = multiFindBundle(index, context, compilerOptions);
197
203
  const bundles = Array.isArray(curBundles)
@@ -209,13 +215,13 @@ function findMultiCompilerBundle(context, name, multiFindBundle) {
209
215
  }
210
216
  result.push(...bundles);
211
217
  }
212
- context.setValue(name, "multiFileIndexMap", multiFileIndexMap);
218
+ context.setValue("multiFileIndexMap", multiFileIndexMap);
213
219
  return result;
214
220
  }
215
221
  function configMultiCompiler(context, name, configFiles, defaultOptions, overrideOptions) {
216
222
  const multiCompilerOptions = [];
217
223
  const caseOptions = Array.isArray(configFiles)
218
- ? (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), configs => {
224
+ ? (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), context, {}, configs => {
219
225
  return configs.flatMap(c => {
220
226
  if (typeof c === "function") {
221
227
  const options = {
@@ -237,7 +243,7 @@ function configMultiCompiler(context, name, configFiles, defaultOptions, overrid
237
243
  }
238
244
  multiCompilerOptions.push(compilerOptions);
239
245
  }
240
- const compiler = getCompiler(context, name);
246
+ const compiler = context.getCompiler();
241
247
  compiler.setOptions(multiCompilerOptions);
242
- context.setValue(name, "multiCompilerOptions", multiCompilerOptions);
248
+ context.setValue("multiCompilerOptions", multiCompilerOptions);
243
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[];
@@ -30,6 +30,9 @@ function createConfigProcessor(name) {
30
30
  },
31
31
  check: async (env, context) => {
32
32
  await (0, common_1.check)(env, context, name);
33
+ },
34
+ after: async (context) => {
35
+ await (0, common_1.afterExecute)(context, name);
33
36
  }
34
37
  };
35
38
  }
@@ -115,7 +118,7 @@ function findBundle(index, context, options) {
115
118
  options.output?.cssFilename) ||
116
119
  `bundle${index}.css`);
117
120
  if (fs_extra_1.default.existsSync(cssOutputPath)) {
118
- bundlePath.push(`./bundle${index}.css`);
121
+ bundlePath.push(path_1.default.relative(options.output.path, cssOutputPath));
119
122
  }
120
123
  }
121
124
  bundlePath.push(`./bundle${index}${ext}`);
@@ -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,16 +10,15 @@ 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
- const custom = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)))[0];
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) {
24
23
  options = (0, webpack_merge_1.default)(options, custom);
25
24
  }
@@ -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 });