@rspack-canary/test-tools 1.5.9-canary-bddc650e-20251012024608 → 1.5.9-canary-e259bc79-20251014173821

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 (92) hide show
  1. package/dist/case/builtin.js +0 -22
  2. package/dist/case/common.js +5 -1
  3. package/dist/case/error.js +1 -1
  4. package/dist/case/hook.js +2 -2
  5. package/dist/case/hot-step.d.ts +1 -1
  6. package/dist/case/hot-step.js +12 -10
  7. package/dist/case/hot.d.ts +5 -4
  8. package/dist/case/hot.js +32 -41
  9. package/dist/case/incremental.d.ts +1 -1
  10. package/dist/case/incremental.js +8 -6
  11. package/dist/case/normal.js +1 -5
  12. package/dist/case/watch.js +0 -7
  13. package/dist/compare/compare.js +6 -3
  14. package/dist/helper/expect/placeholder.js +7 -7
  15. package/dist/helper/expect/to-match-file-snapshot.d.ts +0 -1
  16. package/dist/helper/hot-update/plugin.d.ts +1 -1
  17. package/dist/helper/hot-update/plugin.js +4 -4
  18. package/dist/helper/legacy/update.d.ts +2 -0
  19. package/dist/helper/legacy/update.esm.d.ts +1 -0
  20. package/dist/helper/legacy/update.esm.js +23 -0
  21. package/dist/helper/legacy/update.js +19 -0
  22. package/dist/helper/util/checkStats.d.ts +0 -1
  23. package/dist/helper/util/checkStats.js +0 -18
  24. package/dist/index.d.ts +0 -1
  25. package/dist/index.js +0 -1
  26. package/dist/jest/ignore-snapshot-default-reporter.d.ts +2 -0
  27. package/dist/jest/ignore-snapshot-default-reporter.js +57 -0
  28. package/dist/jest/ignore-snapshot-summary-reporter.d.ts +2 -0
  29. package/dist/jest/ignore-snapshot-summary-reporter.js +24 -0
  30. package/dist/jest/patch-node-env.d.ts +5 -0
  31. package/dist/jest/patch-node-env.js +18 -0
  32. package/dist/jest/slash.d.ts +2 -0
  33. package/dist/jest/slash.js +16 -0
  34. package/dist/runner/node/index.js +4 -0
  35. package/dist/runner/web/fake.js +6 -3
  36. package/dist/runner/web/jsdom.js +0 -4
  37. package/dist/type.d.ts +8 -0
  38. package/package.json +8 -5
  39. package/dist/helper/legacy/createLogger.d.ts +0 -23
  40. package/dist/helper/legacy/createLogger.js +0 -20
  41. package/dist/helper/legacy/diffStats.d.ts +0 -2
  42. package/dist/helper/legacy/diffStats.js +0 -13
  43. package/dist/helper/legacy/supportsBlob.d.ts +0 -2
  44. package/dist/helper/legacy/supportsBlob.js +0 -10
  45. package/dist/helper/legacy/supportsClassFields.d.ts +0 -2
  46. package/dist/helper/legacy/supportsClassFields.js +0 -11
  47. package/dist/helper/legacy/supportsES6.d.ts +0 -2
  48. package/dist/helper/legacy/supportsES6.js +0 -11
  49. package/dist/helper/legacy/supportsForOf.d.ts +0 -2
  50. package/dist/helper/legacy/supportsForOf.js +0 -11
  51. package/dist/helper/legacy/supportsIteratorDestructuring.d.ts +0 -2
  52. package/dist/helper/legacy/supportsIteratorDestructuring.js +0 -11
  53. package/dist/helper/legacy/supportsLogicalAssignment.d.ts +0 -2
  54. package/dist/helper/legacy/supportsLogicalAssignment.js +0 -11
  55. package/dist/helper/legacy/supportsObjectDestructuring.d.ts +0 -2
  56. package/dist/helper/legacy/supportsObjectDestructuring.js +0 -11
  57. package/dist/helper/legacy/supportsOptionalCatchBinding.d.ts +0 -2
  58. package/dist/helper/legacy/supportsOptionalCatchBinding.js +0 -11
  59. package/dist/helper/legacy/supportsOptionalChaining.d.ts +0 -2
  60. package/dist/helper/legacy/supportsOptionalChaining.js +0 -11
  61. package/dist/helper/legacy/supportsRequireInModule.d.ts +0 -2
  62. package/dist/helper/legacy/supportsRequireInModule.js +0 -5
  63. package/dist/helper/legacy/supportsResponse.d.ts +0 -2
  64. package/dist/helper/legacy/supportsResponse.js +0 -10
  65. package/dist/helper/legacy/supportsSpread.d.ts +0 -2
  66. package/dist/helper/legacy/supportsSpread.js +0 -12
  67. package/dist/helper/legacy/supportsTemplateStrings.d.ts +0 -2
  68. package/dist/helper/legacy/supportsTemplateStrings.js +0 -11
  69. package/dist/helper/legacy/supportsWebAssembly.d.ts +0 -2
  70. package/dist/helper/legacy/supportsWebAssembly.js +0 -10
  71. package/dist/helper/legacy/supportsWorker.d.ts +0 -2
  72. package/dist/helper/legacy/supportsWorker.js +0 -17
  73. package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
  74. package/dist/helper/legacy/warmup-webpack.js +0 -26
  75. package/dist/helper/loaders/hot-update.d.ts +0 -1
  76. package/dist/helper/loaders/hot-update.js +0 -43
  77. package/dist/helper/plugins/hot-update.d.ts +0 -7
  78. package/dist/helper/plugins/hot-update.js +0 -40
  79. package/dist/helper/plugins/index.d.ts +0 -1
  80. package/dist/helper/plugins/index.js +0 -17
  81. package/dist/helper/util/currentWatchStep.d.ts +0 -1
  82. package/dist/helper/util/currentWatchStep.js +0 -2
  83. package/dist/helper/util/identifier.d.ts +0 -76
  84. package/dist/helper/util/identifier.js +0 -339
  85. package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
  86. package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
  87. package/dist/reporter/diff-html.d.ts +0 -15
  88. package/dist/reporter/diff-html.js +0 -69
  89. package/dist/reporter/diff-stats.d.ts +0 -24
  90. package/dist/reporter/diff-stats.js +0 -131
  91. package/dist/reporter/index.d.ts +0 -2
  92. package/dist/reporter/index.js +0 -18
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createBuiltinCase = createBuiltinCase;
7
7
  exports.defaultOptions = defaultOptions;
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
- const core_1 = require("@rspack/core");
10
9
  const fs_extra_1 = __importDefault(require("fs-extra"));
11
10
  const webpack_merge_1 = require("webpack-merge");
12
11
  const helper_1 = require("../helper");
@@ -164,27 +163,6 @@ function defaultOptions(context) {
164
163
  }
165
164
  defaultOptions = (0, webpack_merge_1.merge)(defaultOptions, caseOptions);
166
165
  }
167
- // TODO: remove builtin compatible code
168
- const defineOptions = defaultOptions.builtins?.define;
169
- if (defineOptions) {
170
- defaultOptions.plugins.push(new core_1.rspack.DefinePlugin(defineOptions));
171
- }
172
- const provideOptions = defaultOptions.builtins?.provide;
173
- if (provideOptions) {
174
- defaultOptions.plugins.push(new core_1.rspack.ProvidePlugin(provideOptions));
175
- }
176
- const htmlOptions = defaultOptions.builtins?.html;
177
- if (htmlOptions) {
178
- if (Array.isArray(htmlOptions)) {
179
- for (const item of htmlOptions) {
180
- defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(item));
181
- }
182
- }
183
- else {
184
- defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(htmlOptions));
185
- }
186
- }
187
- delete defaultOptions.builtins;
188
166
  if (!global.printLogger) {
189
167
  defaultOptions.infrastructureLogging = {
190
168
  level: "error"
@@ -81,7 +81,11 @@ async function run(env, context, name, findBundle) {
81
81
  const results = context.getValue(name, "modules") || [];
82
82
  await Promise.all(results);
83
83
  if (typeof testConfig.afterExecute === "function") {
84
- testConfig.afterExecute(compiler.getOptions());
84
+ let options = compiler.getOptions();
85
+ if (Array.isArray(options) && options.length === 1) {
86
+ options = options[0];
87
+ }
88
+ testConfig.afterExecute(options);
85
89
  }
86
90
  }
87
91
  async function check(env, context, name) {
@@ -71,7 +71,7 @@ function createErrorCase(name, src, dist, testConfig) {
71
71
  }
72
72
  function options(context, custom) {
73
73
  let options = {
74
- context: node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/fixtures/errors"),
74
+ context: node_path_1.default.resolve(__TEST_FIXTURES_PATH__, "errors"),
75
75
  mode: "none",
76
76
  devtool: false,
77
77
  optimization: {
package/dist/case/hook.js CHANGED
@@ -14,8 +14,8 @@ const webpack_merge_1 = __importDefault(require("webpack-merge"));
14
14
  const context_1 = require("../test/context");
15
15
  const creator_1 = require("../test/creator");
16
16
  const common_1 = require("./common");
17
- const srcDir = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/fixtures");
18
- const distDir = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/js/hook");
17
+ const srcDir = __TEST_FIXTURES_PATH__;
18
+ const distDir = node_path_1.default.resolve(__TEST_DIST_PATH__, "hook");
19
19
  const creator = new creator_1.BasicCaseCreator({
20
20
  clean: true,
21
21
  describe: true,
@@ -1,2 +1,2 @@
1
1
  import { ECompilerType, type TCompilerOptions } from "../type";
2
- export declare function createHotStepCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
2
+ export declare function createHotStepCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
@@ -39,8 +39,8 @@ const GET_MODULE_HANDLER = {
39
39
  node: NODE_HANDLER
40
40
  };
41
41
  const creators = new Map();
42
- function createHotStepProcessor(name, target) {
43
- const processor = (0, hot_1.createHotProcessor)(name, target);
42
+ function createHotStepProcessor(name, src, temp, target) {
43
+ const processor = (0, hot_1.createHotProcessor)(name, src, temp, target);
44
44
  const entries = {};
45
45
  const hashes = [];
46
46
  function matchStepSnapshot(env, context, step, options, stats, runtime) {
@@ -53,7 +53,9 @@ function createHotStepProcessor(name, target) {
53
53
  const hotUpdateManifest = [];
54
54
  const changedFiles = step === 0
55
55
  ? []
56
- : processor.hotUpdateContext.changedFiles.map((i) => (0, helper_1.escapeSep)(node_path_1.default.relative(context.getSource(), i)));
56
+ : processor.updatePlugin
57
+ .getModifiedFiles()
58
+ .map((i) => (0, helper_1.escapeSep)(node_path_1.default.relative(temp, i)));
57
59
  changedFiles.sort();
58
60
  const resultHashes = {
59
61
  [lastHash || "LAST_HASH"]: "LAST_HASH",
@@ -245,7 +247,7 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
245
247
  }
246
248
  const originRun = processor.run;
247
249
  processor.run = async function (env, context) {
248
- context.setValue(name, "hotUpdateStepChecker", (hotUpdateContext, stats, runtime) => {
250
+ context.setValue(name, "hotUpdateStepChecker", (updateIndex, stats, runtime) => {
249
251
  const statsJson = stats.toJson({
250
252
  assets: true,
251
253
  chunks: true
@@ -264,10 +266,10 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
264
266
  }
265
267
  const compiler = context.getCompiler(name, type_1.ECompilerType.Rspack);
266
268
  const compilerOptions = compiler.getOptions();
267
- matchStepSnapshot(env, context, hotUpdateContext.updateIndex, compilerOptions, statsJson, runtime);
269
+ matchStepSnapshot(env, context, updateIndex, compilerOptions, statsJson, runtime);
268
270
  hashes.push(stats.hash);
269
271
  });
270
- context.setValue(name, "hotUpdateStepErrorChecker", (_, stats, runtime) => {
272
+ context.setValue(name, "hotUpdateStepErrorChecker", (updateIndex, stats, runtime) => {
271
273
  hashes.push(stats.hash);
272
274
  });
273
275
  await originRun(env, context);
@@ -312,8 +314,8 @@ function getCreator(target) {
312
314
  clean: true,
313
315
  describe: false,
314
316
  target,
315
- steps: ({ name, target }) => [
316
- createHotStepProcessor(name, target)
317
+ steps: ({ name, target, src, temp, dist }) => [
318
+ createHotStepProcessor(name, src, temp || node_path_1.default.resolve(dist, "temp"), target)
317
319
  ],
318
320
  runner: {
319
321
  key: (context, name, file) => name,
@@ -324,7 +326,7 @@ function getCreator(target) {
324
326
  }
325
327
  return creators.get(target);
326
328
  }
327
- function createHotStepCase(name, src, dist, target) {
329
+ function createHotStepCase(name, src, dist, temp, target) {
328
330
  const creator = getCreator(target);
329
- creator.create(name, src, dist);
331
+ creator.create(name, src, dist, temp);
330
332
  }
@@ -1,9 +1,10 @@
1
- import { type ECompilerType, type ITestContext, type ITestEnv, type ITestProcessor, type ITestRunner, type TCompilerOptions, type THotUpdateContext } from "../type";
1
+ import { HotUpdatePlugin } from "../helper/hot-update/plugin";
2
+ import { type ECompilerType, type ITestContext, type ITestEnv, type ITestProcessor, type ITestRunner, type TCompilerOptions } from "../type";
2
3
  type TTarget = TCompilerOptions<ECompilerType.Rspack>["target"];
3
- export declare function createHotProcessor(name: string, target: TTarget, incremental?: boolean): THotProcessor;
4
- export declare function createHotCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
4
+ 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;
5
6
  type THotProcessor = ITestProcessor & {
6
- hotUpdateContext: THotUpdateContext;
7
+ updatePlugin: HotUpdatePlugin;
7
8
  };
8
9
  export declare function createHotRunner<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
9
10
  export {};
package/dist/case/hot.js CHANGED
@@ -9,27 +9,27 @@ exports.createHotRunner = createHotRunner;
9
9
  const node_path_1 = __importDefault(require("node:path"));
10
10
  const core_1 = __importDefault(require("@rspack/core"));
11
11
  const helper_1 = require("../helper");
12
+ const plugin_1 = require("../helper/hot-update/plugin");
12
13
  const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
13
- const plugins_1 = require("../helper/plugins");
14
- const plugin_1 = require("../plugin");
14
+ const plugin_2 = require("../plugin");
15
15
  const runner_1 = require("../runner");
16
16
  const creator_1 = require("../test/creator");
17
17
  const type_1 = require("../type");
18
18
  const common_1 = require("./common");
19
19
  const runner_2 = require("./runner");
20
20
  const creators = new Map();
21
- function createHotProcessor(name, target, incremental = false) {
22
- const hotUpdateContext = {
23
- updateIndex: 0,
24
- totalUpdates: 1,
25
- changedFiles: []
26
- };
21
+ function createHotProcessor(name, src, temp, target, incremental = false) {
22
+ const updatePlugin = new plugin_1.HotUpdatePlugin(src, temp);
27
23
  const processor = {
24
+ before: async (context) => {
25
+ await updatePlugin.initialize();
26
+ context.setValue(name, "hotUpdatePlugin", updatePlugin);
27
+ },
28
28
  config: async (context) => {
29
29
  const compiler = (0, common_1.getCompiler)(context, name);
30
- let options = defaultOptions(context, target, hotUpdateContext);
30
+ let options = defaultOptions(context, target);
31
31
  options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"], options);
32
- overrideOptions(context, options, target, hotUpdateContext);
32
+ overrideOptions(context, options, target, updatePlugin);
33
33
  if (incremental) {
34
34
  options.experiments ??= {};
35
35
  options.experiments.incremental ??= "advance-silent";
@@ -43,8 +43,7 @@ function createHotProcessor(name, target, incremental = false) {
43
43
  await (0, common_1.build)(context, name);
44
44
  },
45
45
  run: async (env, context) => {
46
- context.setValue(name, "hotUpdateContext", hotUpdateContext);
47
- await (0, common_1.run)(env, context, name, context => findBundle(context, name, target, hotUpdateContext));
46
+ await (0, common_1.run)(env, context, name, context => findBundle(context, name, target, updatePlugin));
48
47
  },
49
48
  check: async (env, context) => {
50
49
  await (0, common_1.check)(env, context, name);
@@ -53,12 +52,14 @@ function createHotProcessor(name, target, incremental = false) {
53
52
  if (context.getTestConfig().checkSteps === false) {
54
53
  return;
55
54
  }
56
- if (hotUpdateContext.updateIndex + 1 !== hotUpdateContext.totalUpdates) {
57
- throw new Error(`Should run all hot steps (${hotUpdateContext.updateIndex + 1} / ${hotUpdateContext.totalUpdates}): ${name}`);
55
+ const updateIndex = updatePlugin.getUpdateIndex();
56
+ const totalUpdates = updatePlugin.getTotalUpdates();
57
+ if (updateIndex + 1 !== totalUpdates) {
58
+ throw new Error(`Should run all hot steps (${updateIndex + 1} / ${totalUpdates}): ${name}`);
58
59
  }
59
60
  }
60
61
  };
61
- processor.hotUpdateContext = hotUpdateContext;
62
+ processor.updatePlugin = updatePlugin;
62
63
  return processor;
63
64
  }
64
65
  function getCreator(target) {
@@ -67,8 +68,8 @@ function getCreator(target) {
67
68
  clean: true,
68
69
  describe: true,
69
70
  target,
70
- steps: ({ name, target }) => [
71
- createHotProcessor(name, target)
71
+ steps: ({ name, target, src, dist, temp }) => [
72
+ createHotProcessor(name, src, temp || node_path_1.default.resolve(dist, "temp"), target)
72
73
  ],
73
74
  runner: {
74
75
  key: (context, name, file) => name,
@@ -79,11 +80,11 @@ function getCreator(target) {
79
80
  }
80
81
  return creators.get(target);
81
82
  }
82
- function createHotCase(name, src, dist, target) {
83
+ function createHotCase(name, src, dist, temp, target) {
83
84
  const creator = getCreator(target);
84
- creator.create(name, src, dist);
85
+ creator.create(name, src, dist, temp);
85
86
  }
86
- function defaultOptions(context, target, updateOptions) {
87
+ function defaultOptions(context, target) {
87
88
  const options = {
88
89
  context: context.getSource(),
89
90
  mode: "development",
@@ -112,10 +113,10 @@ function defaultOptions(context, target, updateOptions) {
112
113
  }
113
114
  };
114
115
  options.plugins ??= [];
115
- options.plugins.push(new core_1.default.HotModuleReplacementPlugin(), new plugins_1.TestHotUpdatePlugin(updateOptions));
116
+ options.plugins.push(new core_1.default.HotModuleReplacementPlugin());
116
117
  return options;
117
118
  }
118
- function overrideOptions(context, options, target, updateOptions) {
119
+ function overrideOptions(context, options, target, updatePlugin) {
119
120
  if (!options.entry) {
120
121
  options.entry = "./index.js";
121
122
  }
@@ -126,34 +127,24 @@ function overrideOptions(context, options, target, updateOptions) {
126
127
  options.module.generator[cssModuleType].exportsOnly ??=
127
128
  target === "async-node";
128
129
  }
129
- options.module.rules ??= [];
130
- options.module.rules.push({
131
- use: [
132
- {
133
- loader: node_path_1.default.resolve(__dirname, "../helper/loaders/hot-update.js"),
134
- options: updateOptions
135
- }
136
- ],
137
- enforce: "pre"
138
- });
139
130
  options.plugins ??= [];
140
- options.plugins.push(new core_1.default.LoaderOptionsPlugin(updateOptions));
131
+ options.plugins.push(updatePlugin);
141
132
  if (!global.printLogger) {
142
133
  options.infrastructureLogging = {
143
134
  level: "error"
144
135
  };
145
136
  }
146
137
  if (options.lazyCompilation) {
147
- options.plugins.push(new plugin_1.LazyCompilationTestPlugin());
138
+ options.plugins.push(new plugin_2.LazyCompilationTestPlugin());
148
139
  }
149
140
  }
150
- function findBundle(context, name, target, updateOptions) {
141
+ function findBundle(context, name, target, updatePlugin) {
151
142
  const compiler = context.getCompiler(name);
152
143
  if (!compiler)
153
144
  throw new Error("Compiler should exists when find bundle");
154
145
  const testConfig = context.getTestConfig();
155
146
  if (typeof testConfig.findBundle === "function") {
156
- return testConfig.findBundle(updateOptions.updateIndex, compiler.getOptions());
147
+ return testConfig.findBundle(updatePlugin.getUpdateIndex(), compiler.getOptions());
157
148
  }
158
149
  const files = [];
159
150
  const prefiles = [];
@@ -183,11 +174,11 @@ function createHotRunner(context, name, file, env) {
183
174
  const testConfig = context.getTestConfig();
184
175
  const source = context.getSource();
185
176
  const dist = context.getDist();
186
- const hotUpdateContext = context.getValue(name, "hotUpdateContext");
177
+ const updatePlugin = context.getValue(name, "hotUpdatePlugin");
187
178
  const next = async (callback) => {
188
179
  const usePromise = typeof callback === "function";
189
180
  try {
190
- hotUpdateContext.updateIndex++;
181
+ await updatePlugin.goNext();
191
182
  const stats = await compiler.build();
192
183
  if (!stats) {
193
184
  throw new Error("Should generate stats during build");
@@ -200,10 +191,10 @@ function createHotRunner(context, name, file, env) {
200
191
  ? "hotUpdateStepErrorChecker"
201
192
  : "hotUpdateStepChecker");
202
193
  if (checker) {
203
- checker(hotUpdateContext, stats, runner.getGlobal("__HMR_UPDATED_RUNTIME__"));
194
+ checker(updatePlugin.getUpdateIndex(), stats, runner.getGlobal("__HMR_UPDATED_RUNTIME__"));
204
195
  }
205
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${hotUpdateContext.updateIndex}`, "Error", compilerOptions);
206
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${hotUpdateContext.updateIndex}`, "Warning", compilerOptions);
196
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updatePlugin.getUpdateIndex()}`, "Error", compilerOptions);
197
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updatePlugin.getUpdateIndex()}`, "Warning", compilerOptions);
207
198
  if (usePromise) {
208
199
  // old callback style hmr cases
209
200
  callback(null, jsonStats);
@@ -1,5 +1,5 @@
1
1
  import { type ECompilerType, type TCompilerOptions } from "../type";
2
- export declare function createHotIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], webpackCases: boolean): void;
2
+ export declare function createHotIncrementalCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], webpackCases: boolean): void;
3
3
  export type WatchIncrementalOptions = {
4
4
  ignoreNotFriendlyForIncrementalWarnings?: boolean;
5
5
  };
@@ -12,9 +12,11 @@ const type_1 = require("../type");
12
12
  const hot_1 = require("./hot");
13
13
  const watch_1 = require("./watch");
14
14
  const hotCreators = new Map();
15
- function createHotIncrementalProcessor(name, target, webpackCases) {
16
- const processor = (0, hot_1.createHotProcessor)(name, target, true);
15
+ function createHotIncrementalProcessor(name, src, temp, target, webpackCases) {
16
+ const processor = (0, hot_1.createHotProcessor)(name, src, temp, target, true);
17
+ const originalBefore = processor.before;
17
18
  processor.before = async (context) => {
19
+ await originalBefore?.(context);
18
20
  context.setValue(name, "documentType", webpackCases ? type_1.EDocumentType.Fake : type_1.EDocumentType.JSDOM);
19
21
  };
20
22
  const originalAfterAll = processor.afterAll;
@@ -38,8 +40,8 @@ function getHotCreator(target, webpackCases) {
38
40
  clean: true,
39
41
  describe: true,
40
42
  target,
41
- steps: ({ name, target }) => [
42
- createHotIncrementalProcessor(name, target, webpackCases)
43
+ steps: ({ name, target, src, temp, dist }) => [
44
+ createHotIncrementalProcessor(name, src, temp || node_path_1.default.resolve(dist, "temp"), target, webpackCases)
43
45
  ],
44
46
  runner: {
45
47
  key: (context, name, file) => name,
@@ -50,9 +52,9 @@ function getHotCreator(target, webpackCases) {
50
52
  }
51
53
  return hotCreators.get(key);
52
54
  }
53
- function createHotIncrementalCase(name, src, dist, target, webpackCases) {
55
+ function createHotIncrementalCase(name, src, dist, temp, target, webpackCases) {
54
56
  const creator = getHotCreator(target, webpackCases);
55
- creator.create(name, src, dist);
57
+ creator.create(name, src, dist, temp);
56
58
  }
57
59
  const watchCreators = new Map();
58
60
  function getWatchCreator(options) {
@@ -13,7 +13,7 @@ const core_1 = require("@rspack/core");
13
13
  const creator_1 = require("../test/creator");
14
14
  const common_1 = require("./common");
15
15
  const runner_1 = require("./runner");
16
- const NORMAL_CASES_ROOT = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/normalCases");
16
+ const NORMAL_CASES_ROOT = node_path_1.default.resolve(__TEST_PATH__, "normalCases");
17
17
  const createCaseOptions = (hot, mode) => {
18
18
  return {
19
19
  clean: true,
@@ -199,10 +199,6 @@ function defaultOptions(context, compilerOptions, mode) {
199
199
  // Turning off here to fallback to webpack's default css processing logic.
200
200
  ...(compilerOptions?.module ? { outputModule: true } : {})
201
201
  }
202
- // infrastructureLogging: compilerOptions?.cache && {
203
- // debug: true,
204
- // console: createLogger(infraStructureLog)
205
- // }
206
202
  };
207
203
  }
208
204
  function overrideOptions(context, options) {
@@ -19,8 +19,6 @@ const runner_1 = require("../runner");
19
19
  const creator_1 = require("../test/creator");
20
20
  const type_1 = require("../type");
21
21
  const common_1 = require("./common");
22
- // This file is used to port step number to rspack.config.js/webpack.config.js
23
- const currentWatchStepModulePath = node_path_1.default.resolve(__dirname, "../helper/util/currentWatchStep");
24
22
  function createWatchInitialProcessor(name, tempDir, step, watchState, { incremental = false, nativeWatcher = false } = {}) {
25
23
  const watchContext = {
26
24
  currentTriggerFilename: null,
@@ -61,8 +59,6 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
61
59
  },
62
60
  build: async (context) => {
63
61
  const compiler = (0, common_1.getCompiler)(context, name);
64
- const currentWatchStepModule = require(currentWatchStepModulePath);
65
- currentWatchStepModule.step[name] = watchContext.step;
66
62
  node_fs_1.default.mkdirSync(watchContext.tempDir, { recursive: true });
67
63
  (0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), watchContext.tempDir, true);
68
64
  const task = new Promise((resolve, reject) => {
@@ -171,10 +167,7 @@ function createWatchStepProcessor(name, tempDir, step, watchState, { incremental
171
167
  // do nothing
172
168
  };
173
169
  processor.build = async (context) => {
174
- const watchContext = context.getValue(name, "watchContext");
175
170
  const compiler = (0, common_1.getCompiler)(context, name);
176
- const currentWatchStepModule = require(currentWatchStepModulePath);
177
- currentWatchStepModule.step[name] = watchContext.step;
178
171
  const task = new Promise((resolve, reject) => {
179
172
  compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
180
173
  if (e)
@@ -13,7 +13,6 @@ const helper_1 = require("../helper");
13
13
  const type_1 = require("../type");
14
14
  const format_code_1 = require("./format-code");
15
15
  const replace_runtime_module_name_1 = require("./replace-runtime-module-name");
16
- const WORKSPACE = node_path_1.default.resolve(__dirname, "../../../..");
17
16
  function compareFile(sourceFile, distFile, compareOptions) {
18
17
  const result = {
19
18
  type: type_1.ECompareResultType.Same,
@@ -49,7 +48,9 @@ function compareFile(sourceFile, distFile, compareOptions) {
49
48
  }
50
49
  return res;
51
50
  }
52
- const sourceContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default.readFileSync(sourceFile, "utf-8").replaceAll(WORKSPACE, "__WORKSPACE__"));
51
+ const sourceContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default
52
+ .readFileSync(sourceFile, "utf-8")
53
+ .replaceAll(__ROOT_PATH__, "__WORKSPACE__"));
53
54
  const sourceModules = (0, helper_1.parseModules)(sourceContent, {
54
55
  bootstrap: compareOptions.bootstrap,
55
56
  renameModule: compareOptions.renameModule
@@ -66,7 +67,9 @@ function compareFile(sourceFile, distFile, compareOptions) {
66
67
  distModules = JSON.parse(fs_extra_1.default.readFileSync(compareOptions.snapshot, "utf-8"));
67
68
  }
68
69
  else {
69
- const distContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default.readFileSync(distFile, "utf-8").replaceAll(WORKSPACE, "__WORKSPACE__"));
70
+ const distContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default
71
+ .readFileSync(distFile, "utf-8")
72
+ .replaceAll(__ROOT_PATH__, "__WORKSPACE__"));
70
73
  distModules = (0, helper_1.parseModules)(distContent, {
71
74
  bootstrap: compareOptions.bootstrap,
72
75
  renameModule: compareOptions.renameModule
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.normalizePlaceholder = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
4
  const path_serializer_1 = require("path-serializer");
9
5
  // 1. escapeEOL \r\n -> \n
10
6
  // 2. replace <RSPACK_ROOT> etc
@@ -13,14 +9,18 @@ const placeholderSerializer = (0, path_serializer_1.createSnapshotSerializer)({
13
9
  root: __dirname.includes("node_modules")
14
10
  ? // Use `process.cwd()` when using outside Rspack
15
11
  process.cwd()
16
- : node_path_1.default.resolve(__dirname, "../../../../../"),
12
+ : __ROOT_PATH__,
17
13
  replace: [
18
14
  {
19
- match: node_path_1.default.resolve(__dirname, "../../../../../tests/rspack-test"),
15
+ match: __RSPACK_TEST_TOOLS_PATH__,
20
16
  mark: "test_tools_root"
21
17
  },
22
18
  {
23
- match: node_path_1.default.resolve(__dirname, "../../../../rspack"),
19
+ match: __TEST_PATH__,
20
+ mark: "test_root"
21
+ },
22
+ {
23
+ match: __RSPACK_PATH__,
24
24
  mark: "rspack_root"
25
25
  },
26
26
  {
@@ -1,4 +1,3 @@
1
- import type { FileMatcherOptions } from "../../../jest";
2
1
  /**
3
2
  * Match given content against content of the specified file.
4
3
  *
@@ -6,10 +6,10 @@ export declare class HotUpdatePlugin {
6
6
  private updateIndex;
7
7
  private files;
8
8
  constructor(projectDir: string, tempDir: string);
9
- private getModifiedFiles;
10
9
  private getContent;
11
10
  private updateFiles;
12
11
  initialize(): Promise<void>;
12
+ getModifiedFiles(): string[];
13
13
  getUpdateIndex(): number;
14
14
  getTotalUpdates(): number;
15
15
  goNext(): Promise<void>;
@@ -29,9 +29,6 @@ class HotUpdatePlugin {
29
29
  this.updateIndex = 0;
30
30
  this.files = {};
31
31
  }
32
- getModifiedFiles() {
33
- return Object.keys(this.files);
34
- }
35
32
  getContent(filePath, index) {
36
33
  const contents = this.files[filePath] || [];
37
34
  let content = contents[index] === undefined ? contents.at(-1) || "" : contents[index];
@@ -86,13 +83,16 @@ class HotUpdatePlugin {
86
83
  });
87
84
  await this.updateFiles();
88
85
  }
86
+ getModifiedFiles() {
87
+ return Object.keys(this.files);
88
+ }
89
89
  getUpdateIndex() {
90
90
  return this.updateIndex;
91
91
  }
92
92
  getTotalUpdates() {
93
93
  return Object.values(this.files).reduce((max, item) => {
94
94
  return Math.max(max, item.length);
95
- }, 0);
95
+ }, 1);
96
96
  }
97
97
  async goNext() {
98
98
  this.updateIndex++;
@@ -0,0 +1,2 @@
1
+ declare function _exports(done: any, options: any, callback: any): (err: any, stats: any) => any;
2
+ export = _exports;
@@ -0,0 +1 @@
1
+ export default function update(done: any, options: any, callback: any): (err: any, stats: any) => any;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = update;
4
+ // @ts-nocheck
5
+ function update(done, options, callback) {
6
+ return function (err, stats) {
7
+ if (err)
8
+ return done(err);
9
+ import.meta.webpackHot
10
+ .check(options || true)
11
+ .then(updatedModules => {
12
+ if (!updatedModules) {
13
+ return done(new Error("No update available"));
14
+ }
15
+ if (callback)
16
+ callback(stats);
17
+ })
18
+ .catch(err => {
19
+ done(err);
20
+ });
21
+ };
22
+ }
23
+ ;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ module.exports = function (done, options, callback) {
4
+ return function (err, stats) {
5
+ if (err)
6
+ return done(err);
7
+ module.hot
8
+ .check(options || true)
9
+ .then(updatedModules => {
10
+ if (!updatedModules)
11
+ return done(new Error("No update available"));
12
+ if (callback)
13
+ callback(stats);
14
+ })
15
+ .catch(err => {
16
+ done(err);
17
+ });
18
+ };
19
+ };
@@ -1,2 +1 @@
1
1
  export function checkChunkModules(statsJson: any, chunkModulesMap: any, strict?: boolean): boolean;
2
- export function checkChunkRuntime(statsJson: any, chunkModulesMap: any, strict?: boolean): boolean;
@@ -16,24 +16,6 @@ exports.checkChunkModules = function checkChunkModules(statsJson, chunkModulesMa
16
16
  }
17
17
  return true;
18
18
  };
19
- exports.checkChunkRuntime = function checkChunkModules(statsJson, chunkModulesMap, strict = true) {
20
- for (const chunkId of Reflect.ownKeys(chunkModulesMap)) {
21
- const chunk = getChunk(statsJson, chunkId);
22
- const expectedRuntime = chunkModulesMap[chunkId];
23
- const chunkRuntime = chunk.runtime;
24
- if (strict) {
25
- expectedRuntime.length === chunkRuntime.length;
26
- }
27
- for (let i = 0; i < expectedRuntime.length; i++) {
28
- const expected = expectedRuntime[i];
29
- const rt = chunkRuntime[i];
30
- if (expected !== rt) {
31
- throw new Error(`chunk ${chunkId} runtime not equal, expected: ${expectedRuntime}, but got: ${chunkRuntime}`);
32
- }
33
- }
34
- }
35
- return true;
36
- };
37
19
  function getChunk(statsJson, id) {
38
20
  const chunk = statsJson.chunks.find(chunk => chunk.id.includes(id));
39
21
  if (!chunk) {
package/dist/index.d.ts CHANGED
@@ -2,7 +2,6 @@ export * from "./case";
2
2
  export * from "./compare";
3
3
  export * from "./helper";
4
4
  export * from "./plugin";
5
- export * from "./reporter";
6
5
  export * from "./runner";
7
6
  export * from "./test/context";
8
7
  export * from "./test/creator";
package/dist/index.js CHANGED
@@ -18,7 +18,6 @@ __exportStar(require("./case"), exports);
18
18
  __exportStar(require("./compare"), exports);
19
19
  __exportStar(require("./helper"), exports);
20
20
  __exportStar(require("./plugin"), exports);
21
- __exportStar(require("./reporter"), exports);
22
21
  __exportStar(require("./runner"), exports);
23
22
  __exportStar(require("./test/context"), exports);
24
23
  __exportStar(require("./test/creator"), exports);
@@ -0,0 +1,2 @@
1
+ export = DefaultReporter;
2
+ import { DefaultReporter } from "@jest/reporters";