@rspack-canary/test-tools 1.5.8-canary-15732646-20250927173602 → 1.5.8-canary-e88f22dc-20250928174002

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.
@@ -135,49 +135,51 @@ async function checkSnapshot(env, context, name, snapshot, filter) {
135
135
  if (path_1.default.extname(snapshot) === ".snap") {
136
136
  throw new Error("Snapshot with `.snap` will be managed by jest, please use `.snap.txt` instead");
137
137
  }
138
- const compiler = getCompiler(context, name);
139
- const stats = compiler.getStats();
140
- const c = compiler.getCompiler();
141
- if (!stats || !c)
138
+ const compilerManager = getCompiler(context, name);
139
+ const stats = compilerManager.getStats();
140
+ const compiler = compilerManager.getCompiler();
141
+ if (!stats || !compiler)
142
142
  return;
143
- if (stats.hasErrors()) {
144
- const errors = [];
145
- if (stats.stats) {
146
- for (const s of stats.stats) {
147
- if (s.hasErrors()) {
148
- errors.push(...s.compilation.errors);
149
- }
150
- }
143
+ const compilers = "compilers" in compiler
144
+ ? compiler.compilers
145
+ : [compiler];
146
+ const totalStats = "stats" in stats
147
+ ? stats.stats
148
+ : [stats];
149
+ const total = compilers.length;
150
+ for (let i = 0; i < compilers.length; i++) {
151
+ const c = compilers[i];
152
+ const stats = totalStats[i];
153
+ if (stats.hasErrors()) {
154
+ const errors = [];
155
+ errors.push(...stats.compilation.errors);
156
+ throw new Error(`Failed to compile in fixture ${name}, Errors: ${errors
157
+ ?.map(i => `${i.message}\n${i.stack}`)
158
+ .join("\n\n")}`);
151
159
  }
152
- else {
153
- const s = stats;
154
- errors.push(...s.compilation.errors);
155
- }
156
- throw new Error(`Failed to compile in fixture ${name}, Errors: ${errors
157
- ?.map(i => `${i.message}\n${i.stack}`)
158
- .join("\n\n")}`);
159
- }
160
- const compilation = c._lastCompilation ||
161
- c._lastCompilation;
162
- const snapshotFileFilter = filter ||
163
- ((file) => file.endsWith(".js") && !file.includes("runtime.js"));
164
- const fileContents = Object.entries(compilation.assets)
165
- .filter(([file]) => snapshotFileFilter(file))
166
- .map(([file, source]) => {
167
- const tag = path_1.default.extname(file).slice(1) || "txt";
168
- let content = (0, placeholder_1.normalizePlaceholder)(source.source().toString());
169
- const testConfig = context.getTestConfig();
170
- if (testConfig.snapshotContent) {
171
- content = testConfig.snapshotContent(content);
172
- }
173
- return `\`\`\`${tag} title=${file}\n${content}\n\`\`\``;
174
- });
175
- fileContents.sort();
176
- const content = fileContents.join("\n\n");
177
- const snapshotPath = path_1.default.isAbsolute(snapshot)
178
- ? snapshot
179
- : path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshot}`);
180
- env.expect(content).toMatchFileSnapshot(snapshotPath);
160
+ const compilation = c._lastCompilation ||
161
+ c._lastCompilation;
162
+ const snapshotFileFilter = filter ||
163
+ ((file) => (file.endsWith(".js") || file.endsWith(".mjs")) &&
164
+ !file.includes("runtime.js"));
165
+ const fileContents = Object.entries(compilation.assets)
166
+ .filter(([file]) => snapshotFileFilter(file))
167
+ .map(([file, source]) => {
168
+ const tag = path_1.default.extname(file).slice(1) || "txt";
169
+ let content = (0, placeholder_1.normalizePlaceholder)(source.source().toString());
170
+ const testConfig = context.getTestConfig();
171
+ if (testConfig.snapshotContent) {
172
+ content = testConfig.snapshotContent(content);
173
+ }
174
+ return `\`\`\`${tag} title=${file}\n${content}\n\`\`\``;
175
+ });
176
+ fileContents.sort();
177
+ const content = fileContents.join("\n\n");
178
+ const snapshotPath = path_1.default.isAbsolute(snapshot)
179
+ ? snapshot
180
+ : path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshot}${total > 1 ? `-${i}` : ""}`);
181
+ env.expect(content).toMatchFileSnapshot(snapshotPath);
182
+ }
181
183
  }
182
184
  function findMultiCompilerBundle(context, name, multiFindBundle) {
183
185
  if (typeof multiFindBundle !== "function") {
@@ -0,0 +1 @@
1
+ export declare function createEsmOutputCase(name: string, src: string, dist: string): void;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createEsmOutputCase = createEsmOutputCase;
7
+ const core_1 = __importDefault(require("@rspack/core"));
8
+ const creator_1 = require("../test/creator");
9
+ const common_1 = require("./common");
10
+ const runner_1 = require("./runner");
11
+ const creator = new creator_1.BasicCaseCreator({
12
+ clean: true,
13
+ describe: false,
14
+ testConfig: testConfig => {
15
+ const oldModuleScope = testConfig.moduleScope;
16
+ testConfig.moduleScope = (ms, stats) => {
17
+ let res = ms;
18
+ // TODO: modify runner module scope based on stats here
19
+ if (typeof oldModuleScope === "function") {
20
+ res = oldModuleScope(ms, stats);
21
+ }
22
+ return res;
23
+ };
24
+ },
25
+ steps: ({ name }) => [
26
+ {
27
+ config: async (context) => {
28
+ (0, common_1.configMultiCompiler)(context, name, ["rspack.config.cjs", "rspack.config.js", "webpack.config.js"], defaultOptions, () => { });
29
+ },
30
+ compiler: async (context) => {
31
+ await (0, common_1.compiler)(context, name);
32
+ },
33
+ build: async (context) => {
34
+ await (0, common_1.build)(context, name);
35
+ },
36
+ run: async (env, context) => {
37
+ await (0, common_1.run)(env, context, name, (context) => (0, common_1.findMultiCompilerBundle)(context, name, (_index, _context, options) => {
38
+ if (options.output?.filename === "[name].mjs") {
39
+ return ["main.mjs"];
40
+ }
41
+ else {
42
+ return [options.output.filename];
43
+ }
44
+ }));
45
+ },
46
+ check: async (env, context) => {
47
+ await (0, common_1.check)(env, context, name);
48
+ await (0, common_1.checkSnapshot)(env, context, name, "esm.snap.txt");
49
+ }
50
+ }
51
+ ],
52
+ runner: {
53
+ key: runner_1.getMultiCompilerRunnerKey,
54
+ runner: runner_1.createMultiCompilerRunner
55
+ },
56
+ concurrent: false
57
+ });
58
+ const defaultOptions = (_index, context) => ({
59
+ context: context.getSource(),
60
+ mode: "production",
61
+ target: "async-node",
62
+ devtool: false,
63
+ entry: "./index.js",
64
+ cache: false,
65
+ output: {
66
+ path: context.getDist(),
67
+ filename: "[name].mjs",
68
+ chunkLoading: "import",
69
+ chunkFormat: false,
70
+ pathinfo: true,
71
+ module: true
72
+ },
73
+ bail: true,
74
+ optimization: {
75
+ minimize: false,
76
+ moduleIds: "named",
77
+ chunkIds: "named",
78
+ runtimeChunk: "single",
79
+ removeEmptyChunks: false,
80
+ concatenateModules: false,
81
+ splitChunks: false
82
+ },
83
+ plugins: [new core_1.default.experiments.EsmLibraryPlugin()],
84
+ experiments: {
85
+ css: true,
86
+ rspackFuture: {
87
+ bundlerInfo: {
88
+ force: false
89
+ }
90
+ },
91
+ outputModule: true
92
+ }
93
+ });
94
+ function createEsmOutputCase(name, src, dist) {
95
+ creator.create(name, src, dist);
96
+ }
@@ -6,6 +6,7 @@ export { createDefaultsCase, getRspackDefaultConfig } from "./defaults";
6
6
  export { createDiagnosticCase } from "./diagnostic";
7
7
  export { createDiffCase } from "./diff";
8
8
  export { createErrorCase } from "./error";
9
+ export { createEsmOutputCase } from "./esm-output";
9
10
  export { createHashCase } from "./hash";
10
11
  export { createHookCase } from "./hook";
11
12
  export { createHotCase } from "./hot";
@@ -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.createNormalCase = exports.createHotNormalCase = exports.createNativeWatcher = exports.createWatchIncrementalCase = exports.createHotIncrementalCase = exports.createHotStepCase = exports.createHotCase = exports.createHookCase = exports.createHashCase = 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.createNormalCase = exports.createHotNormalCase = exports.createNativeWatcher = exports.createWatchIncrementalCase = exports.createHotIncrementalCase = exports.createHotStepCase = exports.createHotCase = exports.createHookCase = exports.createHashCase = exports.createEsmOutputCase = exports.createErrorCase = exports.createDiffCase = 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");
@@ -18,6 +18,8 @@ var diff_1 = require("./diff");
18
18
  Object.defineProperty(exports, "createDiffCase", { enumerable: true, get: function () { return diff_1.createDiffCase; } });
19
19
  var error_1 = require("./error");
20
20
  Object.defineProperty(exports, "createErrorCase", { enumerable: true, get: function () { return error_1.createErrorCase; } });
21
+ var esm_output_1 = require("./esm-output");
22
+ Object.defineProperty(exports, "createEsmOutputCase", { enumerable: true, get: function () { return esm_output_1.createEsmOutputCase; } });
21
23
  var hash_1 = require("./hash");
22
24
  Object.defineProperty(exports, "createHashCase", { enumerable: true, get: function () { return hash_1.createHashCase; } });
23
25
  var hook_1 = require("./hook");
@@ -1 +1,11 @@
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): {
3
+ before: (context: ITestContext) => Promise<void>;
4
+ config: (context: ITestContext) => Promise<void>;
5
+ compiler: (context: ITestContext) => Promise<void>;
6
+ build: (context: ITestContext) => Promise<void>;
7
+ run: (env: ITestEnv, context: ITestContext) => Promise<void>;
8
+ check: (env: ITestEnv, context: ITestContext) => Promise<void>;
9
+ after: (context: ITestContext) => Promise<void>;
10
+ };
1
11
  export declare function createStatsOutputCase(name: string, src: string, dist: string): void;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createStatsProcessor = createStatsProcessor;
6
7
  exports.createStatsOutputCase = createStatsOutputCase;
7
8
  const node_path_1 = __importDefault(require("node:path"));
8
9
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -11,7 +12,7 @@ const captureStdio_1 = __importDefault(require("../helper/legacy/captureStdio"))
11
12
  const creator_1 = require("../test/creator");
12
13
  const common_1 = require("./common");
13
14
  const REG_ERROR_CASE = /error$/;
14
- function createStatsProcessor(name) {
15
+ function createStatsProcessor(name, defaultOptions, overrideOptions) {
15
16
  const writeStatsOuptut = false;
16
17
  const snapshotName = "stats.txt";
17
18
  let stderr = null;
@@ -43,7 +44,9 @@ function createStatsProcessor(name) {
43
44
  const creator = new creator_1.BasicCaseCreator({
44
45
  clean: true,
45
46
  describe: false,
46
- steps: ({ name }) => [createStatsProcessor(name)],
47
+ steps: ({ name }) => [
48
+ createStatsProcessor(name, defaultOptions, overrideOptions)
49
+ ],
47
50
  description: () => "should print correct stats for"
48
51
  });
49
52
  function createStatsOutputCase(name, src, dist) {
@@ -376,13 +376,15 @@ class NodeRunner {
376
376
  if (context.esmMode === type_1.EEsmMode.Unlinked)
377
377
  return esm;
378
378
  return (async () => {
379
- await esm.link(async (specifier, referencingModule) => {
380
- return await (0, asModule_1.default)(await _require(node_path_1.default.dirname(referencingModule.identifier
381
- ? referencingModule.identifier.slice(esmIdentifier.length + 1)
382
- : (0, node_url_1.fileURLToPath)(referencingModule.url)), specifier, {
383
- esmMode: type_1.EEsmMode.Unlinked
384
- }), referencingModule.context, true);
385
- });
379
+ if (esm.status === "unlinked") {
380
+ await esm.link(async (specifier, referencingModule) => {
381
+ return await (0, asModule_1.default)(await _require(node_path_1.default.dirname(referencingModule.identifier
382
+ ? referencingModule.identifier.slice(esmIdentifier.length + 1)
383
+ : (0, node_url_1.fileURLToPath)(referencingModule.url)), specifier, {
384
+ esmMode: type_1.EEsmMode.Unlinked
385
+ }), referencingModule.context, true);
386
+ });
387
+ }
386
388
  if (esm.instantiate)
387
389
  esm.instantiate();
388
390
  await esm.evaluate();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack-canary/test-tools",
3
- "version": "1.5.8-canary-15732646-20250927173602",
3
+ "version": "1.5.8-canary-e88f22dc-20250928174002",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -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.8-canary-15732646-20250927173602",
104
- "@rspack/binding-testing": "1.4.1",
105
- "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.8-canary-15732646-20250927173602",
106
- "@rspack/core": "npm:@rspack-canary/core@1.5.8-canary-15732646-20250927173602"
103
+ "@rspack/cli": "npm:@rspack-canary/cli@1.5.8-canary-e88f22dc-20250928174002",
104
+ "@rspack/core": "npm:@rspack-canary/core@1.5.8-canary-e88f22dc-20250928174002",
105
+ "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.8-canary-e88f22dc-20250928174002",
106
+ "@rspack/binding-testing": "1.4.1"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "@rspack/core": ">=1.0.0"