@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
@@ -9,8 +9,6 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const helper_1 = require("../helper");
10
10
  const placeholder_1 = require("../helper/expect/placeholder");
11
11
  const creator_1 = require("../test/creator");
12
- const type_1 = require("../type");
13
- const common_1 = require("./common");
14
12
  const hot_1 = require("./hot");
15
13
  const NOOP_SET = new Set();
16
14
  const escapeLocalName = (str) => str.split(/[-<>:"/|?*.]/).join("_");
@@ -244,7 +242,7 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
244
242
  }
245
243
  const originRun = processor.run;
246
244
  processor.run = async function (env, context) {
247
- context.setValue(name, "hotUpdateStepChecker", (updateIndex, stats, runtime) => {
245
+ context.setValue("hotUpdateStepChecker", (updateIndex, stats, runtime) => {
248
246
  const statsJson = stats.toJson({
249
247
  assets: true,
250
248
  chunks: true
@@ -261,18 +259,18 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
261
259
  : Array.from(entry.runtime);
262
260
  }
263
261
  }
264
- const compiler = context.getCompiler(name, type_1.ECompilerType.Rspack);
262
+ const compiler = context.getCompiler();
265
263
  const compilerOptions = compiler.getOptions();
266
264
  matchStepSnapshot(env, context, updateIndex, compilerOptions, statsJson, runtime);
267
265
  hashes.push(stats.hash);
268
266
  });
269
- context.setValue(name, "hotUpdateStepErrorChecker", (updateIndex, stats, runtime) => {
267
+ context.setValue("hotUpdateStepErrorChecker", (updateIndex, stats, runtime) => {
270
268
  hashes.push(stats.hash);
271
269
  });
272
270
  await originRun(env, context);
273
271
  };
274
272
  processor.check = async function (env, context) {
275
- const compiler = (0, common_1.getCompiler)(context, name);
273
+ const compiler = context.getCompiler();
276
274
  const stats = compiler.getStats();
277
275
  if (!stats || !stats.hash) {
278
276
  env.expect(false);
@@ -1,10 +1,11 @@
1
+ import { type RspackOptions } from "@rspack/core";
1
2
  import { HotUpdatePlugin } from "../helper/hot-update/plugin";
2
- import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, ITestRunner, TCompilerOptions } from "../type";
3
- type TTarget = TCompilerOptions<ECompilerType.Rspack>["target"];
3
+ import type { ITestContext, ITestEnv, ITestProcessor, ITestRunner } from "../type";
4
+ type TTarget = RspackOptions["target"];
4
5
  export declare function createHotProcessor(name: string, src: string, temp: string, target: TTarget, incremental?: boolean): THotProcessor;
5
- export declare function createHotCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
6
+ export declare function createHotCase(name: string, src: string, dist: string, temp: string, target: RspackOptions["target"]): void;
6
7
  type THotProcessor = ITestProcessor & {
7
8
  updatePlugin: HotUpdatePlugin;
8
9
  };
9
- export declare function createHotRunner<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
10
+ export declare function createHotRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
10
11
  export {};
package/dist/case/hot.js CHANGED
@@ -22,10 +22,10 @@ function createHotProcessor(name, src, temp, target, incremental = false) {
22
22
  const processor = {
23
23
  before: async (context) => {
24
24
  await updatePlugin.initialize();
25
- context.setValue(name, "hotUpdatePlugin", updatePlugin);
25
+ context.setValue("hotUpdatePlugin", updatePlugin);
26
26
  },
27
27
  config: async (context) => {
28
- const compiler = (0, common_1.getCompiler)(context, name);
28
+ const compiler = context.getCompiler();
29
29
  let options = defaultOptions(context, target);
30
30
  options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"], options);
31
31
  overrideOptions(context, options, target, updatePlugin);
@@ -141,7 +141,7 @@ function overrideOptions(context, options, target, updatePlugin) {
141
141
  }
142
142
  }
143
143
  function findBundle(context, name, target, updatePlugin) {
144
- const compiler = context.getCompiler(name);
144
+ const compiler = context.getCompiler();
145
145
  if (!compiler)
146
146
  throw new Error("Compiler should exists when find bundle");
147
147
  const testConfig = context.getTestConfig();
@@ -171,12 +171,12 @@ function findBundle(context, name, target, updatePlugin) {
171
171
  return [...prefiles, ...files];
172
172
  }
173
173
  function createHotRunner(context, name, file, env) {
174
- const compiler = context.getCompiler(name);
174
+ const compiler = context.getCompiler();
175
175
  const compilerOptions = compiler.getOptions();
176
176
  const testConfig = context.getTestConfig();
177
177
  const source = context.getSource();
178
178
  const dist = context.getDist();
179
- const updatePlugin = context.getValue(name, "hotUpdatePlugin");
179
+ const updatePlugin = context.getValue("hotUpdatePlugin");
180
180
  const nextHMR = async (m, options) => {
181
181
  await updatePlugin.goNext();
182
182
  const stats = await compiler.build();
@@ -187,7 +187,7 @@ function createHotRunner(context, name, file, env) {
187
187
  // errorDetails: true
188
188
  });
189
189
  const compilerOptions = compiler.getOptions();
190
- const checker = context.getValue(name, jsonStats.errors?.length
190
+ const checker = context.getValue(jsonStats.errors?.length
191
191
  ? "hotUpdateStepErrorChecker"
192
192
  : "hotUpdateStepChecker");
193
193
  if (checker) {
@@ -1,5 +1,5 @@
1
- import type { ECompilerType, TCompilerOptions } from "../type";
2
- export declare function createHotIncrementalCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], webpackCases: boolean): void;
1
+ import type { RspackOptions } from "@rspack/core";
2
+ export declare function createHotIncrementalCase(name: string, src: string, dist: string, temp: string, target: RspackOptions["target"], webpackCases: boolean): void;
3
3
  export type WatchIncrementalOptions = {
4
4
  ignoreNotFriendlyForIncrementalWarnings?: boolean;
5
5
  };
@@ -8,7 +8,6 @@ export type { TDefaultsCaseConfig } from "./defaults";
8
8
  export { createDefaultsCase, getRspackDefaultConfig } from "./defaults";
9
9
  export type { TDiagnosticOptions } from "./diagnostic";
10
10
  export { createDiagnosticCase } from "./diagnostic";
11
- export { createDiffCase } from "./diff";
12
11
  export type { TErrorCaseConfig } from "./error";
13
12
  export { createErrorCase } from "./error";
14
13
  export { createEsmOutputCase } from "./esm-output";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createWatchCase = exports.createTreeShakingCase = exports.createStatsOutputCase = exports.createStatsAPICase = exports.createSerialCase = exports.createProdNormalCase = exports.createNormalCase = exports.createHotNormalCase = exports.createDevNormalCase = exports.createNativeWatcher = exports.createMultiCompilerCase = exports.createWatchIncrementalCase = exports.createHotIncrementalCase = exports.createHotStepCase = exports.createHotCase = exports.createHookCase = exports.createHashCase = exports.createExampleCase = exports.createEsmOutputCase = exports.createErrorCase = exports.createDiffCase = exports.createDiagnosticCase = exports.getRspackDefaultConfig = exports.createDefaultsCase = exports.createConfigCase = exports.createCompilerCase = exports.createCacheCase = exports.createBuiltinCase = void 0;
3
+ exports.createWatchCase = exports.createTreeShakingCase = exports.createStatsOutputCase = exports.createStatsAPICase = exports.createSerialCase = exports.createProdNormalCase = exports.createNormalCase = exports.createHotNormalCase = exports.createDevNormalCase = exports.createNativeWatcher = exports.createMultiCompilerCase = exports.createWatchIncrementalCase = exports.createHotIncrementalCase = exports.createHotStepCase = exports.createHotCase = exports.createHookCase = exports.createHashCase = exports.createExampleCase = exports.createEsmOutputCase = exports.createErrorCase = exports.createDiagnosticCase = exports.getRspackDefaultConfig = exports.createDefaultsCase = exports.createConfigCase = exports.createCompilerCase = exports.createCacheCase = exports.createBuiltinCase = void 0;
4
4
  var builtin_1 = require("./builtin");
5
5
  Object.defineProperty(exports, "createBuiltinCase", { enumerable: true, get: function () { return builtin_1.createBuiltinCase; } });
6
6
  var cache_1 = require("./cache");
@@ -14,8 +14,6 @@ Object.defineProperty(exports, "createDefaultsCase", { enumerable: true, get: fu
14
14
  Object.defineProperty(exports, "getRspackDefaultConfig", { enumerable: true, get: function () { return defaults_1.getRspackDefaultConfig; } });
15
15
  var diagnostic_1 = require("./diagnostic");
16
16
  Object.defineProperty(exports, "createDiagnosticCase", { enumerable: true, get: function () { return diagnostic_1.createDiagnosticCase; } });
17
- var diff_1 = require("./diff");
18
- Object.defineProperty(exports, "createDiffCase", { enumerable: true, get: function () { return diff_1.createDiffCase; } });
19
17
  var error_1 = require("./error");
20
18
  Object.defineProperty(exports, "createErrorCase", { enumerable: true, get: function () { return error_1.createErrorCase; } });
21
19
  var esm_output_1 = require("./esm-output");
@@ -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 createMultiCompilerCase(name: string, src: string, dist: string, testConfig: string): void;
3
4
  export type TMultiCompilerCaseConfig = {
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
  };
@@ -7,11 +7,10 @@ exports.createMultiCompilerCase = createMultiCompilerCase;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const memfs_1 = require("memfs");
9
9
  const creator_1 = require("../test/creator");
10
- const common_1 = require("./common");
11
10
  function createMultiCompilerProcessor(name, caseConfig) {
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 = Object.assign([
16
15
  {
17
16
  name: "a",
@@ -27,7 +26,7 @@ function createMultiCompilerProcessor(name, caseConfig) {
27
26
  compiler.setOptions(options);
28
27
  },
29
28
  compiler: async (context) => {
30
- const compiler = (0, common_1.getCompiler)(context, name);
29
+ const compiler = context.getCompiler();
31
30
  if (caseConfig.compilerCallback) {
32
31
  compiler.createCompilerWithCallback(caseConfig.compilerCallback);
33
32
  }
@@ -57,7 +56,7 @@ function createMultiCompilerProcessor(name, caseConfig) {
57
56
  await caseConfig.compiler?.(context, c);
58
57
  },
59
58
  build: async (context) => {
60
- const compiler = (0, common_1.getCompiler)(context, name);
59
+ const compiler = context.getCompiler();
61
60
  if (typeof caseConfig.build === "function") {
62
61
  await caseConfig.build?.(context, compiler.getCompiler());
63
62
  }
@@ -21,7 +21,7 @@ const createCaseOptions = (hot, mode) => {
21
21
  steps: ({ name }) => [
22
22
  {
23
23
  config: async (context) => {
24
- const compiler = (0, common_1.getCompiler)(context, name);
24
+ const compiler = context.getCompiler();
25
25
  let options = defaultOptions(context, {
26
26
  plugins: hot ? [new core_1.HotModuleReplacementPlugin()] : []
27
27
  }, mode);
@@ -1,4 +1,5 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, ITestRunner, TCompilerStatsCompilation } from "../type";
1
+ import type { StatsCompilation } from "@rspack/core";
2
+ import type { ITestContext, ITestEnv, ITestRunner } from "../type";
2
3
  export type THotStepRuntimeLangData = {
3
4
  outdatedModules: string[];
4
5
  outdatedDependencies: Record<string, string[]>;
@@ -12,7 +13,7 @@ export type THotStepRuntimeData = {
12
13
  css: THotStepRuntimeLangData;
13
14
  statusPath: string[];
14
15
  };
15
- export declare function cachedStats<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string): () => TCompilerStatsCompilation<T>;
16
- export declare function createRunner<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
16
+ export declare function cachedStats(context: ITestContext, name: string): () => StatsCompilation;
17
+ export declare function createRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
17
18
  export declare function getMultiCompilerRunnerKey(context: ITestContext, name: string, file: string): string;
18
- export declare function createMultiCompilerRunner<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
19
+ export declare function createMultiCompilerRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
@@ -5,9 +5,9 @@ exports.createRunner = createRunner;
5
5
  exports.getMultiCompilerRunnerKey = getMultiCompilerRunnerKey;
6
6
  exports.createMultiCompilerRunner = createMultiCompilerRunner;
7
7
  const runner_1 = require("../runner");
8
- const common_1 = require("./common");
8
+ const debug_1 = require("../test/debug");
9
9
  function cachedStats(context, name) {
10
- const compiler = context.getCompiler(name);
10
+ const compiler = context.getCompiler();
11
11
  const statsGetter = (() => {
12
12
  let cached = null;
13
13
  return () => {
@@ -23,7 +23,7 @@ function cachedStats(context, name) {
23
23
  return statsGetter;
24
24
  }
25
25
  function createRunner(context, name, file, env) {
26
- const compiler = (0, common_1.getCompiler)(context, name);
26
+ const compiler = context.getCompiler();
27
27
  const testConfig = context.getTestConfig();
28
28
  const compilerOptions = compiler.getOptions();
29
29
  const runnerOptions = {
@@ -48,8 +48,8 @@ function createRunner(context, name, file, env) {
48
48
  return new runner_1.NodeRunner(runnerOptions);
49
49
  }
50
50
  function getFileIndexHandler(context, name, file) {
51
- const multiFileIndexMap = context.getValue(name, "multiFileIndexMap") || {};
52
- const runned = context.getValue(name, "runned") || new Set();
51
+ const multiFileIndexMap = context.getValue("multiFileIndexMap") || {};
52
+ const runned = context.getValue("runned") || new Set();
53
53
  if (typeof multiFileIndexMap[file] === "undefined") {
54
54
  throw new Error("Unexpect file in multiple runner");
55
55
  }
@@ -60,7 +60,7 @@ function getFileIndexHandler(context, name, file) {
60
60
  }
61
61
  const getIndex = () => [indexList[seq], seq];
62
62
  const flagIndex = () => runned.add(`${name}:${file}[${seq}]`);
63
- context.setValue(name, "runned", runned);
63
+ context.setValue("runned", runned);
64
64
  return { getIndex, flagIndex };
65
65
  }
66
66
  function getMultiCompilerRunnerKey(context, name, file) {
@@ -71,9 +71,11 @@ function getMultiCompilerRunnerKey(context, name, file) {
71
71
  function createMultiCompilerRunner(context, name, file, env) {
72
72
  const testConfig = context.getTestConfig();
73
73
  const { getIndex, flagIndex } = getFileIndexHandler(context, name, file);
74
- const multiCompilerOptions = context.getValue(name, "multiCompilerOptions") || [];
74
+ const multiCompilerOptions = context.getValue("multiCompilerOptions") || [];
75
75
  const [index] = getIndex();
76
76
  const compilerOptions = multiCompilerOptions[index];
77
+ const logs = context.getValue(debug_1.DEBUG_SCOPES.RunLogs);
78
+ const errors = context.getValue(debug_1.DEBUG_SCOPES.RunErrors);
77
79
  let runner;
78
80
  const runnerOptions = {
79
81
  runInNewContext: false,
@@ -91,7 +93,9 @@ function createMultiCompilerRunner(context, name, file, env) {
91
93
  testConfig: context.getTestConfig(),
92
94
  source: context.getSource(),
93
95
  dist: context.getDist(),
94
- compilerOptions
96
+ compilerOptions,
97
+ logs,
98
+ errors
95
99
  };
96
100
  if (compilerOptions.target === "web" ||
97
101
  compilerOptions.target === "webworker") {
@@ -1,3 +1,3 @@
1
- import type { ECompilerType, TTestConfig } from "../type";
2
- export type TSerialCaseConfig = Omit<TTestConfig<ECompilerType.Rspack>, "validate">;
1
+ import type { TTestConfig } from "../type";
2
+ export type TSerialCaseConfig = Omit<TTestConfig, "validate">;
3
3
  export declare function createSerialCase(name: string, src: string, dist: string): void;
@@ -1,10 +1,11 @@
1
- import type { ECompilerType, ITestContext, TCompiler, TCompilerOptions, TCompilerStats } from "../type";
1
+ import type { Compiler, RspackOptions, Stats } from "@rspack/core";
2
+ import type { ITestContext } from "../type";
2
3
  export type TStatsAPICaseConfig = {
3
4
  description: string;
4
- options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
5
+ options?: (context: ITestContext) => RspackOptions;
5
6
  snapshotName?: string;
6
- compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
7
- build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
8
- check?: (stats: TCompilerStats<ECompilerType.Rspack>, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
7
+ compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
8
+ build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
9
+ check?: (stats: Stats, compiler: Compiler) => Promise<void>;
9
10
  };
10
11
  export declare function createStatsAPICase(name: string, src: string, dist: string, testConfig: string): void;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createStatsAPICase = createStatsAPICase;
4
4
  const memfs_1 = require("memfs");
5
5
  const creator_1 = require("../test/creator");
6
- const common_1 = require("./common");
7
6
  let addedSerializer = false;
8
7
  const creator = new creator_1.BasicCaseCreator({
9
8
  clean: true,
@@ -13,16 +12,16 @@ const creator = new creator_1.BasicCaseCreator({
13
12
  return [
14
13
  {
15
14
  config: async (context) => {
16
- const compiler = (0, common_1.getCompiler)(context, name);
15
+ const compiler = context.getCompiler();
17
16
  compiler.setOptions(options(context, config.options));
18
17
  },
19
18
  compiler: async (context) => {
20
- const compilerManager = (0, common_1.getCompiler)(context, name);
19
+ const compilerManager = context.getCompiler();
21
20
  compilerManager.createCompiler();
22
21
  compiler(context, compilerManager.getCompiler(), config.compiler);
23
22
  },
24
23
  build: async (context) => {
25
- const compiler = (0, common_1.getCompiler)(context, name);
24
+ const compiler = context.getCompiler();
26
25
  if (typeof config.build === "function") {
27
26
  await config.build(context, compiler.getCompiler());
28
27
  }
@@ -52,8 +51,7 @@ function createStatsAPICase(name, src, dist, testConfig) {
52
51
  });
53
52
  }
54
53
  function options(context, custom) {
55
- const res = (custom?.(context) ||
56
- {});
54
+ const res = (custom?.(context) || {});
57
55
  res.experiments ??= {};
58
56
  res.experiments.css ??= true;
59
57
  res.experiments.rspackFuture ??= {};
@@ -75,7 +73,7 @@ async function compiler(context, compiler, custom) {
75
73
  }
76
74
  }
77
75
  async function check(env, context, name, custom) {
78
- const manager = (0, common_1.getCompiler)(context, name);
76
+ const manager = context.getCompiler();
79
77
  const stats = manager.getStats();
80
78
  env.expect(typeof stats).toBe("object");
81
79
  await custom?.(stats, manager.getCompiler());
@@ -1,5 +1,6 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
2
- export declare function createStatsProcessor(name: string, defaultOptions: (index: number, context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>, overrideOptions: (index: number, context: ITestContext, options: TCompilerOptions<ECompilerType.Rspack>) => void): {
1
+ import type { RspackOptions } from "@rspack/core";
2
+ import type { ITestContext, ITestEnv } from "../type";
3
+ export declare function createStatsProcessor(name: string, defaultOptions: (index: number, context: ITestContext) => RspackOptions, overrideOptions: (index: number, context: ITestContext, options: RspackOptions) => void): {
3
4
  before: (context: ITestContext) => Promise<void>;
4
5
  config: (context: ITestContext) => Promise<void>;
5
6
  compiler: (context: ITestContext) => Promise<void>;
@@ -114,7 +114,7 @@ class RspackStats {
114
114
  }
115
115
  }
116
116
  async function check(env, context, name, writeStatsOuptut, snapshot, stderr) {
117
- const compiler = (0, common_1.getCompiler)(context, name);
117
+ const compiler = context.getCompiler();
118
118
  const options = compiler.getOptions();
119
119
  const stats = compiler.getStats();
120
120
  if (!stats || !compiler)
@@ -13,7 +13,7 @@ const creator = new creator_1.BasicCaseCreator({
13
13
  steps: ({ name }) => [
14
14
  {
15
15
  config: async (context) => {
16
- const compiler = (0, common_1.getCompiler)(context, name);
16
+ const compiler = context.getCompiler();
17
17
  const options = (0, builtin_1.defaultOptions)(context);
18
18
  overrideOptions(context, options);
19
19
  compiler.setOptions(options);
@@ -1,14 +1,14 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, ITestRunner } from "../type";
1
+ import type { ITestContext, ITestEnv, ITestRunner } from "../type";
2
2
  export declare function createWatchInitialProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher }?: {
3
3
  incremental?: boolean | undefined;
4
4
  nativeWatcher?: boolean | undefined;
5
5
  }): {
6
6
  before: (context: ITestContext) => Promise<void>;
7
- config: <T extends ECompilerType.Rspack>(context: ITestContext) => Promise<void>;
7
+ config: (context: ITestContext) => Promise<void>;
8
8
  compiler: (context: ITestContext) => Promise<void>;
9
9
  build: (context: ITestContext) => Promise<void>;
10
10
  run: (env: ITestEnv, context: ITestContext) => Promise<void>;
11
- check: <T extends ECompilerType.Rspack>(env: ITestEnv, context: ITestContext) => Promise<void>;
11
+ check: (env: ITestEnv, context: ITestContext) => Promise<void>;
12
12
  after: (context: ITestContext) => Promise<void>;
13
13
  };
14
14
  export declare function createWatchStepProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher }?: {
@@ -16,13 +16,13 @@ export declare function createWatchStepProcessor(name: string, tempDir: string,
16
16
  nativeWatcher?: boolean | undefined;
17
17
  }): {
18
18
  before: (context: ITestContext) => Promise<void>;
19
- config: <T extends ECompilerType.Rspack>(context: ITestContext) => Promise<void>;
19
+ config: (context: ITestContext) => Promise<void>;
20
20
  compiler: (context: ITestContext) => Promise<void>;
21
21
  build: (context: ITestContext) => Promise<void>;
22
22
  run: (env: ITestEnv, context: ITestContext) => Promise<void>;
23
- check: <T extends ECompilerType.Rspack>(env: ITestEnv, context: ITestContext) => Promise<void>;
23
+ check: (env: ITestEnv, context: ITestContext) => Promise<void>;
24
24
  after: (context: ITestContext) => Promise<void>;
25
25
  };
26
26
  export declare function createWatchCase(name: string, src: string, dist: string, temp: string): void;
27
27
  export declare function getWatchRunnerKey(context: ITestContext, name: string, file: string): string;
28
- export declare function createWatchRunner<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
28
+ export declare function createWatchRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
@@ -29,7 +29,7 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
29
29
  };
30
30
  return {
31
31
  before: async (context) => {
32
- context.setValue(name, "watchContext", watchContext);
32
+ context.setValue("watchContext", watchContext);
33
33
  },
34
34
  config: async (context) => {
35
35
  const testConfig = context.getTestConfig();
@@ -46,9 +46,9 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
46
46
  const compilerOptions = multiCompilerOptions.length === 1
47
47
  ? multiCompilerOptions[0]
48
48
  : multiCompilerOptions;
49
- const compiler = (0, common_1.getCompiler)(context, name);
49
+ const compiler = context.getCompiler();
50
50
  compiler.setOptions(compilerOptions);
51
- context.setValue(name, "multiCompilerOptions", multiCompilerOptions);
51
+ context.setValue("multiCompilerOptions", multiCompilerOptions);
52
52
  },
53
53
  compiler: async (context) => {
54
54
  const c = await (0, common_1.compiler)(context, name);
@@ -57,7 +57,7 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
57
57
  });
58
58
  },
59
59
  build: async (context) => {
60
- const compiler = (0, common_1.getCompiler)(context, name);
60
+ const compiler = context.getCompiler();
61
61
  node_fs_1.default.mkdirSync(watchContext.tempDir, { recursive: true });
62
62
  (0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), watchContext.tempDir, true);
63
63
  const task = new Promise((resolve, reject) => {
@@ -77,12 +77,12 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
77
77
  const testConfig = context.getTestConfig();
78
78
  if (testConfig.noTests)
79
79
  return;
80
- const errors = (context.getError(name) || []).map(e => ({
80
+ const errors = (context.getError() || []).map(e => ({
81
81
  message: e.message,
82
82
  stack: e.stack
83
83
  }));
84
84
  const warnings = [];
85
- const compiler = (0, common_1.getCompiler)(context, name);
85
+ const compiler = context.getCompiler();
86
86
  const stats = compiler.getStats();
87
87
  const options = compiler.getOptions();
88
88
  const checkStats = testConfig.checkStats || (() => true);
@@ -148,7 +148,7 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
148
148
  await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), { warnings }, "warning", "warnings", "Warning", options);
149
149
  // clear error if checked
150
150
  if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
151
- context.clearError(name);
151
+ context.clearError();
152
152
  }
153
153
  // check hash
154
154
  if (testConfig.writeStatsOuptut) {
@@ -169,7 +169,7 @@ function createWatchStepProcessor(name, tempDir, step, watchState, { incremental
169
169
  // do nothing
170
170
  };
171
171
  processor.build = async (context) => {
172
- const compiler = (0, common_1.getCompiler)(context, name);
172
+ const compiler = context.getCompiler();
173
173
  const task = new Promise((resolve, reject) => {
174
174
  compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
175
175
  if (e)
@@ -252,7 +252,8 @@ function overrideOptions(index, context, options, tempDir, nativeWatcher) {
252
252
  }
253
253
  options.experiments.rspackFuture ??= {};
254
254
  options.experiments.rspackFuture.bundlerInfo ??= {};
255
- options.experiments.rspackFuture.bundlerInfo.force ??= false;
255
+ options.experiments.rspackFuture.bundlerInfo.force ??=
256
+ false;
256
257
  // test incremental: "safe" here, we test default incremental in Incremental-*.test.js
257
258
  options.experiments.incremental ??= "safe";
258
259
  if (!global.printLogger) {
@@ -282,13 +283,13 @@ function defaultOptions({ incremental = false, ignoreNotFriendlyForIncrementalWa
282
283
  return {};
283
284
  }
284
285
  function getWatchRunnerKey(context, name, file) {
285
- const watchContext = context.getValue(name, "watchContext");
286
+ const watchContext = context.getValue("watchContext");
286
287
  const stepName = watchContext?.step;
287
288
  return `${name}-${stepName}`;
288
289
  }
289
290
  function cachedWatchStats(context, name) {
290
- const compiler = context.getCompiler(name);
291
- const watchContext = context.getValue(name, "watchContext");
291
+ const compiler = context.getCompiler();
292
+ const watchContext = context.getValue("watchContext");
292
293
  const stepName = watchContext?.step;
293
294
  const statsGetter = (() => {
294
295
  const cached = {};
@@ -305,9 +306,9 @@ function cachedWatchStats(context, name) {
305
306
  return statsGetter;
306
307
  }
307
308
  function createWatchRunner(context, name, file, env) {
308
- const compiler = context.getCompiler(name);
309
+ const compiler = context.getCompiler();
309
310
  const compilerOptions = compiler.getOptions();
310
- const watchContext = context.getValue(name, "watchContext");
311
+ const watchContext = context.getValue("watchContext");
311
312
  const stepName = watchContext?.step;
312
313
  if (!stepName) {
313
314
  throw new Error("Can not get watch step name from context");
@@ -1,29 +1,28 @@
1
1
  import EventEmitter from "node:events";
2
- import { ECompilerType, type ITestCompilerManager, type TCompiler, type TCompilerFactories, type TCompilerOptions, type TCompilerStats } from "./type";
2
+ import { Compiler, type RspackOptions, type Stats } from "@rspack/core";
3
+ import type { ITestCompilerManager, ITestContext } from "./type";
3
4
  export declare enum ECompilerEvent {
4
5
  Build = "build",
5
6
  Option = "option",
6
7
  Create = "create",
7
8
  Close = "close"
8
9
  }
9
- export declare const COMPILER_FACTORIES: TCompilerFactories<ECompilerType>;
10
- export declare class TestCompilerManager<T extends ECompilerType> implements ITestCompilerManager<T> {
11
- protected type: T;
12
- protected factories: TCompilerFactories<T>;
13
- protected compilerOptions: TCompilerOptions<T>;
14
- protected compilerInstance: TCompiler<T> | null;
15
- protected compilerStats: TCompilerStats<T> | null;
10
+ export declare class TestCompilerManager implements ITestCompilerManager {
11
+ protected context: ITestContext;
12
+ protected compilerOptions: RspackOptions;
13
+ protected compilerInstance: Compiler | null;
14
+ protected compilerStats: Stats | null;
16
15
  protected emitter: EventEmitter;
17
- constructor(type: T, factories?: TCompilerFactories<T>);
18
- getOptions(): TCompilerOptions<T>;
19
- setOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
20
- mergeOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
21
- getCompiler(): TCompiler<T> | null;
22
- createCompiler(): TCompiler<T>;
23
- createCompilerWithCallback(callback: (error: Error | null, stats: TCompilerStats<T> | null) => void): TCompiler<T>;
24
- build(): Promise<TCompilerStats<T>>;
16
+ constructor(context: ITestContext);
17
+ getOptions(): RspackOptions;
18
+ setOptions(newOptions: RspackOptions): RspackOptions;
19
+ mergeOptions(newOptions: RspackOptions): RspackOptions;
20
+ getCompiler(): Compiler | null;
21
+ createCompiler(): Compiler;
22
+ createCompilerWithCallback(callback: (error: Error | null, stats: Stats | null) => void): Compiler;
23
+ build(): Promise<Stats>;
25
24
  watch(timeout?: number): void;
26
- getStats(): TCompilerStats<T> | null;
25
+ getStats(): Stats | null;
27
26
  getEmitter(): EventEmitter<[never]>;
28
27
  close(): Promise<void>;
29
28
  }