@rspack-canary/test-tools 1.6.7-canary-545fe05f-20251203071712 → 1.6.7-canary-39f82ff6-20251203173928

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.
@@ -13,7 +13,6 @@ const runner_1 = require("../runner");
13
13
  const creator_1 = require("../test/creator");
14
14
  const common_1 = require("./common");
15
15
  const runner_2 = require("./runner");
16
- const MAX_COMPILER_INDEX = 100;
17
16
  function createCacheProcessor(name, src, temp, target) {
18
17
  const updatePlugin = new hot_update_1.HotUpdatePlugin(src, temp);
19
18
  return {
@@ -23,9 +22,7 @@ function createCacheProcessor(name, src, temp, target) {
23
22
  },
24
23
  config: async (context) => {
25
24
  const compiler = context.getCompiler();
26
- let options = defaultOptions(context, temp, target);
27
- options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"].map(i => node_path_1.default.resolve(temp, i)), options);
28
- overrideOptions(options, temp, target, updatePlugin);
25
+ const options = await generateOptions(context, temp, target, updatePlugin);
29
26
  compiler.setOptions(options);
30
27
  },
31
28
  compiler: async (context) => {
@@ -75,8 +72,8 @@ function createCacheCase(name, src, dist, target, temp) {
75
72
  creator.create(name, src, dist, temp);
76
73
  }
77
74
  const creators = new Map();
78
- function defaultOptions(context, temp, target) {
79
- const options = {
75
+ async function generateOptions(context, temp, target, updatePlugin) {
76
+ let options = {
80
77
  context: temp,
81
78
  mode: "production",
82
79
  cache: true,
@@ -105,9 +102,8 @@ function defaultOptions(context, temp, target) {
105
102
  };
106
103
  options.plugins ??= [];
107
104
  options.plugins.push(new core_1.default.HotModuleReplacementPlugin());
108
- return options;
109
- }
110
- function overrideOptions(options, temp, target, updatePlugin) {
105
+ options = await (0, common_1.config)(context, "cacheCase", ["rspack.config.js", "webpack.config.js"].map(i => node_path_1.default.resolve(temp, i)), options);
106
+ // overwrite
111
107
  if (!options.entry) {
112
108
  options.entry = "./index.js";
113
109
  }
@@ -127,6 +123,7 @@ function overrideOptions(options, temp, target, updatePlugin) {
127
123
  level: "error"
128
124
  };
129
125
  }
126
+ return options;
130
127
  }
131
128
  function findBundle(name, target, context) {
132
129
  const files = [];
@@ -181,6 +178,7 @@ function createRunner(context, name, file, env) {
181
178
  moduleScope.COMPILER_INDEX = compilerIndex;
182
179
  moduleScope.NEXT_HMR = nextHmr;
183
180
  moduleScope.NEXT_START = nextStart;
181
+ moduleScope.NEXT_MOVE_DIR_START = nextMoveDirStart;
184
182
  return moduleScope;
185
183
  }
186
184
  },
@@ -189,19 +187,19 @@ function createRunner(context, name, file, env) {
189
187
  compilerOptions: options
190
188
  });
191
189
  };
190
+ const checkStats = async (stats) => {
191
+ const compilerOptions = compiler.getOptions();
192
+ const updateIndex = updatePlugin.getUpdateIndex();
193
+ await (0, checkArrayExpectation_1.default)(source, stats, "error", `errors${updateIndex}`, "Error", compilerOptions);
194
+ await (0, checkArrayExpectation_1.default)(source, stats, "warning", `warnings${updateIndex}`, "Warning", compilerOptions);
195
+ };
192
196
  const nextHmr = async (m, options) => {
193
197
  await updatePlugin.goNext();
194
198
  const stats = await compiler.build();
195
- if (!stats) {
196
- throw new Error("Should generate stats during build");
197
- }
198
199
  const jsonStats = stats.toJson({
199
200
  // errorDetails: true
200
201
  });
201
- const compilerOptions = compiler.getOptions();
202
- const updateIndex = updatePlugin.getUpdateIndex();
203
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error", compilerOptions);
204
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning", compilerOptions);
202
+ await checkStats(jsonStats);
205
203
  const updatedModules = await m.hot.check(options || true);
206
204
  if (!updatedModules) {
207
205
  throw new Error("No update available");
@@ -210,24 +208,33 @@ function createRunner(context, name, file, env) {
210
208
  };
211
209
  const nextStart = async () => {
212
210
  await compiler.close();
211
+ await updatePlugin.goNext();
212
+ compilerIndex++;
213
213
  compiler.createCompiler();
214
+ const stats = await compiler.build();
215
+ const jsonStats = stats.toJson({
216
+ // errorDetails: true
217
+ });
218
+ await checkStats(jsonStats);
219
+ env.it(`NEXT_START run with compilerIndex==${compilerIndex}`, async () => {
220
+ return getWebRunner().run(file);
221
+ });
222
+ return jsonStats;
223
+ };
224
+ const nextMoveDirStart = async () => {
225
+ await compiler.close();
226
+ const tempDir = await updatePlugin.moveTempDir();
227
+ const options = await generateOptions(context, tempDir, compiler.getOptions().target, updatePlugin);
228
+ compiler.setOptions(options);
214
229
  await updatePlugin.goNext();
230
+ compilerIndex++;
231
+ compiler.createCompiler();
215
232
  const stats = await compiler.build();
216
- if (!stats) {
217
- throw new Error("Should generate stats during build");
218
- }
219
233
  const jsonStats = stats.toJson({
220
234
  // errorDetails: true
221
235
  });
222
- const compilerOptions = compiler.getOptions();
223
- const updateIndex = updatePlugin.getUpdateIndex();
224
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error", compilerOptions);
225
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning", compilerOptions);
226
- env.it(`NEXT_START run with compilerIndex==${compilerIndex + 1}`, async () => {
227
- if (compilerIndex > MAX_COMPILER_INDEX) {
228
- throw new Error("NEXT_START has been called more than the maximum times");
229
- }
230
- compilerIndex++;
236
+ await checkStats(jsonStats);
237
+ env.it(`NEXT_MOVE_DIR_START run with compilerIndex==${compilerIndex}`, async () => {
231
238
  return getWebRunner().run(file);
232
239
  });
233
240
  return jsonStats;
@@ -13,5 +13,6 @@ export declare class HotUpdatePlugin {
13
13
  getUpdateIndex(): number;
14
14
  getTotalUpdates(): number;
15
15
  goNext(): Promise<void>;
16
+ moveTempDir(): Promise<string>;
16
17
  apply(compiler: Compiler): void;
17
18
  }
@@ -22,6 +22,7 @@ async function loopFile(dir, callback) {
22
22
  }));
23
23
  }
24
24
  const PLUGIN_NAME = "HotUpdatePlugin";
25
+ const MAX_UPDATE_INDEX = 100;
25
26
  class HotUpdatePlugin {
26
27
  constructor(projectDir, tempDir) {
27
28
  this.projectDir = projectDir;
@@ -91,9 +92,29 @@ class HotUpdatePlugin {
91
92
  }, 1);
92
93
  }
93
94
  async goNext() {
95
+ if (this.updateIndex > MAX_UPDATE_INDEX) {
96
+ throw new Error("NEXT_* has been called more than the maximum times");
97
+ }
94
98
  this.updateIndex++;
95
99
  await this.updateFiles();
96
100
  }
101
+ async moveTempDir() {
102
+ // generate next temp dir path.
103
+ const nextTempDir = this.tempDir.replace(/(___[0-9]+)?[/\\]*$/, "") +
104
+ "___" +
105
+ this.updateIndex;
106
+ // update this.files.
107
+ for (const key of Object.keys(this.files)) {
108
+ const nextKey = key.replace(this.tempDir, nextTempDir);
109
+ this.files[nextKey] = this.files[key];
110
+ delete this.files[key];
111
+ }
112
+ // move files.
113
+ (0, rimraf_1.rimrafSync)(nextTempDir);
114
+ fs_extra_1.default.renameSync(this.tempDir, nextTempDir);
115
+ this.tempDir = nextTempDir;
116
+ return this.tempDir;
117
+ }
97
118
  apply(compiler) {
98
119
  const options = compiler.options;
99
120
  options.context = this.tempDir;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack-canary/test-tools",
3
- "version": "1.6.7-canary-545fe05f-20251203071712",
3
+ "version": "1.6.7-canary-39f82ff6-20251203173928",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -65,7 +65,7 @@
65
65
  "@types/jsdom": "^21.1.7",
66
66
  "typescript": "^5.9.3",
67
67
  "wast-loader": "^1.14.1",
68
- "@rspack/core": "npm:@rspack-canary/core@1.6.7-canary-545fe05f-20251203071712"
68
+ "@rspack/core": "npm:@rspack-canary/core@1.6.7-canary-39f82ff6-20251203173928"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "@rspack/core": ">=1.0.0"