@rspack-canary/test-tools 1.5.6-canary-9360f4d0-20250918174212 → 1.5.6-canary-7c0091e4-20250919173930

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.
@@ -11,6 +11,6 @@ export interface IFormatCodeOptions {
11
11
  }
12
12
  export interface IFormatCodeReplacement {
13
13
  from: string | RegExp;
14
- to: string;
14
+ to: string | ((substring: string, ...args: any[]) => string);
15
15
  }
16
16
  export declare function formatCode(name: string, raw: string, options: IFormatCodeOptions): string;
@@ -221,7 +221,12 @@ function formatCode(name, raw, options) {
221
221
  }
222
222
  if (options.replacements) {
223
223
  for (const { from, to } of options.replacements) {
224
- result = result.replaceAll(from, to);
224
+ if (typeof to === "string") {
225
+ result = result.replaceAll(from, to);
226
+ }
227
+ else {
228
+ result = result.replaceAll(from, to);
229
+ }
225
230
  }
226
231
  }
227
232
  // result of generate() is not stable with comments sometimes
@@ -1,2 +1,2 @@
1
- declare function _exports(testDirectory: any, object: any, kind: any, filename: any, upperCaseKind: any, done: any): Promise<true | undefined>;
1
+ declare function _exports(testDirectory: any, object: any, kind: any, filename: any, upperCaseKind: any, options: any, done: any): Promise<true | undefined>;
2
2
  export = _exports;
@@ -59,16 +59,13 @@ ${tooMuch.map(item => `${explain(item)}`).join("\n\n")}`);
59
59
  }
60
60
  return diff.join("\n\n");
61
61
  };
62
- module.exports = async function checkArrayExpectation(testDirectory, object, kind, filename, upperCaseKind, done) {
63
- const usePromise = typeof done === "function";
62
+ module.exports = async function checkArrayExpectation(testDirectory, object, kind, filename, upperCaseKind, options, done) {
64
63
  done = typeof done === "function" ? done : error => {
65
64
  throw error;
66
65
  };
67
66
  let array = object[`${kind}s`];
68
- if (Array.isArray(array)) {
69
- if (kind === "warning") {
70
- array = array.filter(item => !/from Terser/.test(item));
71
- }
67
+ if (Array.isArray(array) && kind === "warning") {
68
+ array = array.filter(item => !/from Terser/.test(item));
72
69
  }
73
70
  if (fs.existsSync(path.join(testDirectory, `${filename}.js`))) {
74
71
  // CHANGE: added file for sorting messages in multi-thread environment
@@ -77,7 +74,10 @@ module.exports = async function checkArrayExpectation(testDirectory, object, kin
77
74
  array = sorter(array);
78
75
  }
79
76
  const expectedFilename = path.join(testDirectory, `${filename}.js`);
80
- const expected = require(expectedFilename);
77
+ let expected = require(expectedFilename);
78
+ if (typeof expected === "function") {
79
+ expected = expected(options);
80
+ }
81
81
  const diff = diffItems(array, expected, kind);
82
82
  if (expected.length < array.length) {
83
83
  done(new Error(`More ${kind}s (${array.length} instead of ${expected.length}) while compiling than expected:\n\n${diff}\n\nCheck expected ${kind}s: ${expectedFilename}`));
@@ -97,6 +97,7 @@ class BasicProcessor {
97
97
  const warnings = [];
98
98
  const compiler = this.getCompiler(context);
99
99
  const stats = compiler.getStats();
100
+ const options = compiler.getOptions();
100
101
  if (stats) {
101
102
  if (testConfig.writeStatsOuptut) {
102
103
  node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
@@ -125,8 +126,8 @@ class BasicProcessor {
125
126
  }
126
127
  }
127
128
  }
128
- await (0, checkArrayExpectation_1.default)(context.getSource(), { errors }, "error", "errors", "Error");
129
- await (0, checkArrayExpectation_1.default)(context.getSource(), { warnings }, "warning", "warnings", "Warning");
129
+ await (0, checkArrayExpectation_1.default)(context.getSource(), { errors }, "error", "errors", "Error", options);
130
+ await (0, checkArrayExpectation_1.default)(context.getSource(), { warnings }, "warning", "warnings", "Warning", options);
130
131
  // clear error if checked
131
132
  if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
132
133
  context.clearError(this._options.name);
@@ -93,7 +93,9 @@ class CacheProcessor extends basic_1.BasicProcessor {
93
93
  bundlerInfo: {
94
94
  force: false
95
95
  }
96
- }
96
+ },
97
+ inlineConst: true,
98
+ lazyBarrel: true
97
99
  }
98
100
  };
99
101
  if (this._cacheOptions.compilerType === type_1.ECompilerType.Rspack) {
@@ -58,7 +58,9 @@ class ConfigProcessor extends multi_1.MultiTaskProcessor {
58
58
  bundlerInfo: {
59
59
  force: false
60
60
  }
61
- }
61
+ },
62
+ inlineConst: true,
63
+ lazyBarrel: true
62
64
  }
63
65
  };
64
66
  }
@@ -87,7 +87,9 @@ class DiagnosticProcessor extends basic_1.BasicProcessor {
87
87
  bundlerInfo: {
88
88
  force: false
89
89
  }
90
- }
90
+ },
91
+ inlineConst: true,
92
+ lazyBarrel: true
91
93
  }
92
94
  };
93
95
  }
@@ -45,7 +45,9 @@ class HashProcessor extends multi_1.MultiTaskProcessor {
45
45
  bundlerInfo: {
46
46
  force: false
47
47
  }
48
- }
48
+ },
49
+ inlineConst: true,
50
+ lazyBarrel: true
49
51
  }
50
52
  };
51
53
  }
@@ -189,7 +189,9 @@ class HookTaskProcessor extends snapshot_1.SnapshotProcessor {
189
189
  bundlerInfo: {
190
190
  force: false
191
191
  }
192
- }
192
+ },
193
+ inlineConst: true,
194
+ lazyBarrel: true
193
195
  }
194
196
  };
195
197
  }
@@ -98,7 +98,9 @@ class HotProcessor extends basic_1.BasicProcessor {
98
98
  bundlerInfo: {
99
99
  force: false
100
100
  }
101
- }
101
+ },
102
+ inlineConst: true,
103
+ lazyBarrel: true
102
104
  }
103
105
  };
104
106
  if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
@@ -145,6 +145,8 @@ class NormalProcessor extends basic_1.BasicProcessor {
145
145
  },
146
146
  asyncWebAssembly: true,
147
147
  topLevelAwait: true,
148
+ inlineConst: true,
149
+ lazyBarrel: true,
148
150
  // CHANGE: rspack does not support `backCompat` yet.
149
151
  // backCompat: false,
150
152
  // CHANGE: Rspack enables `css` by default.
@@ -176,7 +176,9 @@ class StatsProcessor extends multi_1.MultiTaskProcessor {
176
176
  bundlerInfo: {
177
177
  force: false
178
178
  }
179
- }
179
+ },
180
+ inlineConst: true,
181
+ lazyBarrel: true
180
182
  }
181
183
  };
182
184
  }
@@ -66,6 +66,7 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
66
66
  const warnings = [];
67
67
  const compiler = this.getCompiler(context);
68
68
  const stats = compiler.getStats();
69
+ const options = compiler.getOptions();
69
70
  const checkStats = testConfig.checkStats || (() => true);
70
71
  if (stats) {
71
72
  if (testConfig.writeStatsOuptut) {
@@ -125,8 +126,8 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
125
126
  }
126
127
  }
127
128
  }
128
- await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { errors }, "error", "errors", "Error");
129
- await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { warnings }, "warning", "warnings", "Warning");
129
+ await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { errors }, "error", "errors", "Error", options);
130
+ await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { warnings }, "warning", "warnings", "Warning", options);
130
131
  // clear error if checked
131
132
  if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
132
133
  context.clearError(this._options.name);
@@ -52,9 +52,10 @@ class CacheRunnerFactory extends basic_1.BasicRunnerFactory {
52
52
  const jsonStats = stats.toJson({
53
53
  // errorDetails: true
54
54
  });
55
+ const compilerOptions = compiler.getOptions();
55
56
  const updateIndex = updatePlugin.getUpdateIndex();
56
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error");
57
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning");
57
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error", compilerOptions);
58
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning", compilerOptions);
58
59
  const updatedModules = await m.hot.check(options || true);
59
60
  if (!updatedModules) {
60
61
  throw new Error("No update available");
@@ -72,9 +73,10 @@ class CacheRunnerFactory extends basic_1.BasicRunnerFactory {
72
73
  const jsonStats = stats.toJson({
73
74
  // errorDetails: true
74
75
  });
76
+ const compilerOptions = compiler.getOptions();
75
77
  const updateIndex = updatePlugin.getUpdateIndex();
76
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error");
77
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning");
78
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error", compilerOptions);
79
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning", compilerOptions);
78
80
  env.it(`NEXT_START run with compilerIndex==${compilerIndex + 1}`, async () => {
79
81
  if (compilerIndex > MAX_COMPILER_INDEX) {
80
82
  throw new Error("NEXT_START has been called more than the maximum times");
@@ -26,14 +26,15 @@ class HotRunnerFactory extends basic_1.BasicRunnerFactory {
26
26
  const jsonStats = stats.toJson({
27
27
  // errorDetails: true
28
28
  });
29
+ const compilerOptions = compiler.getOptions();
29
30
  const checker = this.context.getValue(this.name, jsonStats.errors?.length
30
31
  ? "hotUpdateStepErrorChecker"
31
32
  : "hotUpdateStepChecker");
32
33
  if (checker) {
33
34
  checker(hotUpdateContext, stats, runner.getGlobal("__HMR_UPDATED_RUNTIME__"));
34
35
  }
35
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${hotUpdateContext.updateIndex}`, "Error");
36
- await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${hotUpdateContext.updateIndex}`, "Warning");
36
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${hotUpdateContext.updateIndex}`, "Error", compilerOptions);
37
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${hotUpdateContext.updateIndex}`, "Warning", compilerOptions);
37
38
  if (usePromise) {
38
39
  // old callback style hmr cases
39
40
  callback(null, jsonStats);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack-canary/test-tools",
3
- "version": "1.5.6-canary-9360f4d0-20250918174212",
3
+ "version": "1.5.6-canary-7c0091e4-20250919173930",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -65,7 +65,7 @@
65
65
  "@rspack/plugin-preact-refresh": "1.1.2",
66
66
  "@rspack/plugin-react-refresh": "^1.5.1",
67
67
  "@swc/helpers": "0.5.17",
68
- "@swc/plugin-remove-console": "^9.0.0",
68
+ "@swc/plugin-remove-console": "^9.1.0",
69
69
  "@types/babel__generator": "7.27.0",
70
70
  "@types/babel__traverse": "7.28.0",
71
71
  "@types/fs-extra": "11.0.4",
@@ -100,10 +100,10 @@
100
100
  "wast-loader": "^1.14.1",
101
101
  "worker-rspack-loader": "^3.1.2",
102
102
  "exports-loader": "^5.0.0",
103
- "@rspack/cli": "npm:@rspack-canary/cli@1.5.6-canary-9360f4d0-20250918174212",
104
- "@rspack/core": "npm:@rspack-canary/core@1.5.6-canary-9360f4d0-20250918174212",
105
- "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.6-canary-9360f4d0-20250918174212",
106
- "@rspack/binding-testing": "1.4.1"
103
+ "@rspack/core": "npm:@rspack-canary/core@1.5.6-canary-7c0091e4-20250919173930",
104
+ "@rspack/cli": "npm:@rspack-canary/cli@1.5.6-canary-7c0091e4-20250919173930",
105
+ "@rspack/binding-testing": "1.4.1",
106
+ "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.6-canary-7c0091e4-20250919173930"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "@rspack/core": ">=1.0.0"