@rspack-canary/test-tools 1.5.8-canary-f37fe028-20250928065933 → 1.5.9-canary-740cd963-20250929173807

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.
@@ -12,6 +12,7 @@ export { createHookCase } from "./hook";
12
12
  export { createHotCase } from "./hot";
13
13
  export { createHotStepCase } from "./hot-step";
14
14
  export { createHotIncrementalCase, createWatchIncrementalCase } from "./incremental";
15
+ export { createMultiCompilerCase } from "./multi-compiler";
15
16
  export { createNativeWatcher } from "./native-watcher";
16
17
  export { createHotNormalCase, createNormalCase } from "./normal";
17
18
  export { createSerialCase } from "./serial";
@@ -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.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.createNormalCase = exports.createHotNormalCase = exports.createNativeWatcher = exports.createMultiCompilerCase = 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");
@@ -31,6 +31,8 @@ Object.defineProperty(exports, "createHotStepCase", { enumerable: true, get: fun
31
31
  var incremental_1 = require("./incremental");
32
32
  Object.defineProperty(exports, "createHotIncrementalCase", { enumerable: true, get: function () { return incremental_1.createHotIncrementalCase; } });
33
33
  Object.defineProperty(exports, "createWatchIncrementalCase", { enumerable: true, get: function () { return incremental_1.createWatchIncrementalCase; } });
34
+ var multi_compiler_1 = require("./multi-compiler");
35
+ Object.defineProperty(exports, "createMultiCompilerCase", { enumerable: true, get: function () { return multi_compiler_1.createMultiCompilerCase; } });
34
36
  var native_watcher_1 = require("./native-watcher");
35
37
  Object.defineProperty(exports, "createNativeWatcher", { enumerable: true, get: function () { return native_watcher_1.createNativeWatcher; } });
36
38
  var normal_1 = require("./normal");
@@ -0,0 +1,18 @@
1
+ import type { ECompilerType, ITestContext, TCompilation, TCompiler, TCompilerOptions, TCompilerStats, TCompilerStatsCompilation } from "../type";
2
+ export declare function createMultiCompilerCase(name: string, src: string, dist: string, testConfig: string): void;
3
+ export type TMultiCompilerCaseConfig = {
4
+ description: string;
5
+ error?: boolean;
6
+ 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>;
10
+ check?: ({ context, stats, files, compiler, compilation }: {
11
+ context: ITestContext;
12
+ stats?: TCompilerStatsCompilation<ECompilerType.Rspack>;
13
+ files?: Record<string, string>;
14
+ compiler: TCompiler<ECompilerType.Rspack>;
15
+ compilation?: TCompilation<ECompilerType.Rspack>;
16
+ }) => Promise<void>;
17
+ compilerCallback?: (error: Error | null, stats: TCompilerStats<ECompilerType.Rspack> | null) => void;
18
+ };
@@ -0,0 +1,98 @@
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.createMultiCompilerCase = createMultiCompilerCase;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const memfs_1 = require("memfs");
9
+ const creator_1 = require("../test/creator");
10
+ const common_1 = require("./common");
11
+ function createMultiCompilerProcessor(name, caseConfig) {
12
+ return {
13
+ config: async (context) => {
14
+ const compiler = (0, common_1.getCompiler)(context, name);
15
+ const options = Object.assign([
16
+ {
17
+ name: "a",
18
+ context: node_path_1.default.join(__dirname, "fixtures"),
19
+ entry: "./a.js"
20
+ },
21
+ {
22
+ name: "b",
23
+ context: node_path_1.default.join(__dirname, "fixtures"),
24
+ entry: "./b.js"
25
+ }
26
+ ], caseConfig.options?.(context) || {});
27
+ compiler.setOptions(options);
28
+ },
29
+ compiler: async (context) => {
30
+ const compiler = (0, common_1.getCompiler)(context, name);
31
+ if (caseConfig.compilerCallback) {
32
+ compiler.createCompilerWithCallback(caseConfig.compilerCallback);
33
+ }
34
+ else {
35
+ compiler.createCompiler();
36
+ }
37
+ const c = compiler.getCompiler();
38
+ c.outputFileSystem = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
39
+ c.watchFileSystem = {
40
+ watch() {
41
+ // watch should return a watcher instance
42
+ // watcher instance should have close, pause and getInfo methods
43
+ return {
44
+ close: () => { },
45
+ pause: () => { },
46
+ getInfo: () => {
47
+ return {
48
+ changes: new Set(),
49
+ removals: new Set(),
50
+ fileTimeInfoEntries: new Map(),
51
+ directoryTimeInfoEntries: new Map()
52
+ };
53
+ }
54
+ };
55
+ }
56
+ };
57
+ await caseConfig.compiler?.(context, c);
58
+ },
59
+ build: async (context) => {
60
+ const compiler = (0, common_1.getCompiler)(context, name);
61
+ if (typeof caseConfig.build === "function") {
62
+ await caseConfig.build?.(context, compiler.getCompiler());
63
+ }
64
+ else {
65
+ await compiler.build();
66
+ }
67
+ },
68
+ run: async (env, context) => { },
69
+ check: async (env, context) => { }
70
+ };
71
+ }
72
+ const creator = new creator_1.BasicCaseCreator({
73
+ clean: true,
74
+ describe: false,
75
+ steps: ({ name, caseConfig }) => {
76
+ return [
77
+ createMultiCompilerProcessor(name, caseConfig)
78
+ ];
79
+ },
80
+ concurrent: false
81
+ });
82
+ function createMultiCompilerCase(name, src, dist, testConfig) {
83
+ let caseConfigList = require(testConfig);
84
+ if (!Array.isArray(caseConfigList)) {
85
+ caseConfigList = [caseConfigList];
86
+ }
87
+ for (let i = 0; i < caseConfigList.length; i++) {
88
+ const caseConfig = caseConfigList[i];
89
+ if (caseConfig.skip) {
90
+ it.skip(`${name}[${i}]`, () => { });
91
+ continue;
92
+ }
93
+ creator.create(`${name}[${i}]`, src, dist, undefined, {
94
+ caseConfig,
95
+ description: () => caseConfig.description
96
+ });
97
+ }
98
+ }
@@ -53,7 +53,8 @@ function createStatsOutputCase(name, src, dist) {
53
53
  creator.create(name, src, dist);
54
54
  }
55
55
  function defaultOptions(index, context) {
56
- if (fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), "rspack.config.js"))) {
56
+ if (fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), "rspack.config.js")) ||
57
+ fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), "webpack.config.js"))) {
57
58
  return {
58
59
  experiments: {
59
60
  css: true,
@@ -174,7 +175,8 @@ async function check(env, context, name, writeStatsOuptut, snapshot, stderr) {
174
175
  // CHANGE: The time unit display in Rspack is second
175
176
  .replace(/[.0-9]+(\s?s)/g, "X$1")
176
177
  // CHANGE: Replace bundle size, since bundle sizes may differ between platforms
177
- .replace(/[0-9]+\.?[0-9]+ KiB/g, "xx KiB");
178
+ .replace(/[0-9]+\.?[0-9]+ KiB/g, "xx KiB")
179
+ .replace(/[0-9]+ ms/g, "xx ms");
178
180
  }
179
181
  const snapshotPath = node_path_1.default.isAbsolute(snapshot)
180
182
  ? snapshot
@@ -0,0 +1,6 @@
1
+ export = LogTestPlugin;
2
+ declare class LogTestPlugin {
3
+ constructor(noTraced: any);
4
+ noTraced: any;
5
+ apply(compiler: any): void;
6
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ module.exports = class LogTestPlugin {
4
+ constructor(noTraced) {
5
+ this.noTraced = noTraced;
6
+ }
7
+ apply(compiler) {
8
+ const logSome = logger => {
9
+ logger.group("Group");
10
+ if (!this.noTraced) {
11
+ logger.error("Error");
12
+ logger.warn("Warning");
13
+ }
14
+ logger.info("Info");
15
+ logger.log("Log");
16
+ logger.debug("Debug");
17
+ logger.groupCollapsed("Collapsed group");
18
+ logger.log("Log inside collapsed group");
19
+ logger.group("Inner group");
20
+ logger.log("Inner inner message");
21
+ logger.groupEnd();
22
+ logger.groupEnd();
23
+ logger.log("Log");
24
+ logger.groupEnd();
25
+ logger.log("End");
26
+ };
27
+ logSome(compiler.getInfrastructureLogger("LogTestPlugin"));
28
+ compiler.hooks.compilation.tap("LogTestPlugin", compilation => {
29
+ const logger = compilation.getLogger("LogTestPlugin");
30
+ logSome(logger);
31
+ const otherLogger = compilation.getLogger("LogOtherTestPlugin");
32
+ otherLogger.debug("debug message only");
33
+ });
34
+ }
35
+ };
@@ -0,0 +1,2 @@
1
+ declare function _exports(rawStats: any, name: any): string;
2
+ export = _exports;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ const diff = require("jest-diff").diff;
4
+ const { stripVTControlCharacters: stripAnsi } = require("node:util");
5
+ const processStats = str => {
6
+ return str.trim().split('\n').map(i => i.trim()).join('\n').replace(/\d+(\.\d+)?/g, 'XX').replace(/"/g, "");
7
+ };
8
+ const webpackStats = require('../__snapshots__/StatsTestCases.basictest.js.snap.webpack');
9
+ module.exports = (rawStats, name) => {
10
+ const key = `StatsTestCases should print correct stats for ${name} 1`;
11
+ const res = stripAnsi(diff(processStats(rawStats), processStats(webpackStats[key] || ''), { expand: false, contextLines: 0 }));
12
+ return res;
13
+ };
@@ -90,11 +90,17 @@ class Tester {
90
90
  }
91
91
  }
92
92
  async runCheckStepMethods(step, env, methods) {
93
- for (const i of methods) {
94
- if (typeof step[i] === "function") {
95
- await step[i](env, this.context);
93
+ try {
94
+ for (const i of methods) {
95
+ if (typeof step[i] === "function") {
96
+ await step[i](env, this.context);
97
+ }
96
98
  }
97
99
  }
100
+ catch (e) {
101
+ console.error(e);
102
+ throw e;
103
+ }
98
104
  }
99
105
  }
100
106
  exports.Tester = Tester;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack-canary/test-tools",
3
- "version": "1.5.8-canary-f37fe028-20250928065933",
3
+ "version": "1.5.9-canary-740cd963-20250929173807",
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/core": "npm:@rspack-canary/core@1.5.8-canary-f37fe028-20250928065933",
104
- "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.8-canary-f37fe028-20250928065933",
105
- "@rspack/cli": "npm:@rspack-canary/cli@1.5.8-canary-f37fe028-20250928065933",
106
- "@rspack/binding-testing": "1.4.1"
103
+ "@rspack/cli": "npm:@rspack-canary/cli@1.5.9-canary-740cd963-20250929173807",
104
+ "@rspack/binding-testing": "1.4.1",
105
+ "@rspack/core": "npm:@rspack-canary/core@1.5.9-canary-740cd963-20250929173807",
106
+ "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.9-canary-740cd963-20250929173807"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "@rspack/core": ">=1.0.0"