@rspack-canary/test-tools 1.5.4-canary-8cc7f155-20250915173802 → 1.5.5-canary-03ab52ad-20250916180415

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.
@@ -1,6 +1,15 @@
1
1
  import { type ISimpleProcessorOptions } from "../processor";
2
- import { ECompilerType } from "../type";
3
- export type TCompilerCaseConfig = Omit<ISimpleProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
2
+ import { ECompilerType, type ITestContext, type TCompilation, type TCompiler, type TCompilerStatsCompilation } from "../type";
3
+ export type TCompilerCaseConfig = Omit<ISimpleProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType" | "check"> & {
4
4
  description: string;
5
+ error?: boolean;
6
+ skip?: boolean;
7
+ check?: ({ context, stats, files, compiler, compilation }: {
8
+ context: ITestContext;
9
+ stats?: TCompilerStatsCompilation<ECompilerType.Rspack>;
10
+ files?: Record<string, string>;
11
+ compiler: TCompiler<ECompilerType.Rspack>;
12
+ compilation?: TCompilation<ECompilerType.Rspack>;
13
+ }) => Promise<void>;
5
14
  };
6
15
  export declare function createCompilerCase(name: string, src: string, dist: string, testConfig: string): void;
@@ -5,13 +5,116 @@ const processor_1 = require("../processor");
5
5
  const simple_1 = require("../test/simple");
6
6
  const type_1 = require("../type");
7
7
  function createCompilerCase(name, src, dist, testConfig) {
8
- const caseConfig = require(testConfig);
8
+ let caseConfigList = require(testConfig);
9
+ if (!Array.isArray(caseConfigList)) {
10
+ caseConfigList = [caseConfigList];
11
+ }
9
12
  const runner = (0, simple_1.getSimpleProcessorRunner)(src, dist);
10
- it(caseConfig.description, async () => {
11
- await runner(name, new processor_1.SimpleTaskProcessor({
12
- name: name,
13
- compilerType: type_1.ECompilerType.Rspack,
14
- ...caseConfig
15
- }));
16
- });
13
+ for (const caseConfig of caseConfigList) {
14
+ const testFn = caseConfig.skip ? it.skip : it;
15
+ testFn(caseConfig.description, async () => {
16
+ const logs = {
17
+ mkdir: [],
18
+ writeFile: []
19
+ };
20
+ const files = {};
21
+ await runner(name, new processor_1.SimpleTaskProcessor({
22
+ name: name,
23
+ compilerType: type_1.ECompilerType.Rspack,
24
+ compilerCallback: caseConfig.compilerCallback,
25
+ build: caseConfig.build,
26
+ options: context => {
27
+ const options = caseConfig.options?.(context) || {};
28
+ options.mode ??= "production";
29
+ options.context ??= context.getSource();
30
+ options.entry ??= "./a.js";
31
+ options.output ??= {};
32
+ options.output.path ??= "/";
33
+ options.output.pathinfo ??= true;
34
+ options.optimization ??= {};
35
+ options.optimization.minimize ??= false;
36
+ return options;
37
+ },
38
+ async compiler(context, compiler) {
39
+ compiler.outputFileSystem = {
40
+ // CHANGE: Added support for the `options` parameter to enable recursive directory creation,
41
+ // accommodating Rspack's requirement that differs from webpack's usage
42
+ mkdir(path, callback) {
43
+ const recursive = false;
44
+ // if (typeof options === "function") {
45
+ // callback = options;
46
+ // } else if (options) {
47
+ // if (options.recursive !== undefined) recursive = options.recursive;
48
+ // }
49
+ logs.mkdir.push(path);
50
+ if (recursive) {
51
+ callback();
52
+ }
53
+ else {
54
+ const err = new Error();
55
+ err.code = "EEXIST";
56
+ callback(err);
57
+ }
58
+ },
59
+ writeFile(name, content, callback) {
60
+ logs.writeFile.push(name, content);
61
+ files[name] = content.toString("utf-8");
62
+ callback();
63
+ },
64
+ stat(path, callback) {
65
+ callback(new Error("ENOENT"));
66
+ }
67
+ };
68
+ compiler.hooks.compilation.tap("CompilerTest", compilation => (compilation.bail = true));
69
+ await caseConfig.compiler?.(context, compiler);
70
+ },
71
+ async check(context, compiler, stats) {
72
+ if (caseConfig.error) {
73
+ const statsJson = stats?.toJson({
74
+ modules: true,
75
+ reasons: true
76
+ });
77
+ const compilation = stats?.compilation;
78
+ await caseConfig.check?.({
79
+ context,
80
+ compiler,
81
+ stats: statsJson,
82
+ compilation,
83
+ files
84
+ });
85
+ }
86
+ else if (stats) {
87
+ expect(typeof stats).toBe("object");
88
+ const compilation = stats.compilation;
89
+ const statsJson = stats.toJson({
90
+ modules: true,
91
+ reasons: true
92
+ });
93
+ expect(typeof statsJson).toBe("object");
94
+ expect(statsJson).toHaveProperty("errors");
95
+ expect(Array.isArray(statsJson.errors)).toBe(true);
96
+ if (statsJson.errors.length > 0) {
97
+ expect(statsJson.errors[0]).toBeInstanceOf(Object);
98
+ throw statsJson.errors[0];
99
+ }
100
+ statsJson.logs = logs;
101
+ await caseConfig.check?.({
102
+ context,
103
+ stats: statsJson,
104
+ files,
105
+ compiler,
106
+ compilation
107
+ });
108
+ }
109
+ else {
110
+ await caseConfig.check?.({
111
+ context,
112
+ files,
113
+ compiler
114
+ });
115
+ }
116
+ }
117
+ }));
118
+ });
119
+ }
17
120
  }
@@ -1 +1,2 @@
1
1
  export declare function createNormalCase(name: string, src: string, dist: string): void;
2
+ export declare function createHotNormalCase(name: string, src: string, dist: string): void;
@@ -4,26 +4,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createNormalCase = createNormalCase;
7
+ exports.createHotNormalCase = createHotNormalCase;
7
8
  const node_path_1 = __importDefault(require("node:path"));
9
+ const core_1 = require("@rspack/core");
8
10
  const normal_1 = require("../processor/normal");
9
11
  const runner_1 = require("../runner");
10
12
  const creator_1 = require("../test/creator");
11
13
  const type_1 = require("../type");
12
- const creator = new creator_1.BasicCaseCreator({
13
- clean: true,
14
- describe: false,
15
- steps: ({ name }) => [
16
- new normal_1.NormalProcessor({
17
- name,
18
- root: node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/normalCases"),
19
- compilerOptions: {}, // do not used in rspack
20
- runable: true,
21
- compilerType: type_1.ECompilerType.Rspack
22
- })
23
- ],
24
- runner: runner_1.NormalRunnerFactory,
25
- concurrent: true
26
- });
14
+ const NORMAL_CASES_ROOT = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/normalCases");
15
+ const createCaseOptions = (hot) => {
16
+ return {
17
+ clean: true,
18
+ describe: false,
19
+ steps: ({ name }) => [
20
+ new normal_1.NormalProcessor({
21
+ name,
22
+ root: NORMAL_CASES_ROOT,
23
+ compilerOptions: {
24
+ plugins: hot ? [new core_1.HotModuleReplacementPlugin()] : []
25
+ },
26
+ runable: true,
27
+ compilerType: type_1.ECompilerType.Rspack
28
+ })
29
+ ],
30
+ runner: runner_1.NormalRunnerFactory,
31
+ concurrent: true
32
+ };
33
+ };
34
+ const creator = new creator_1.BasicCaseCreator(createCaseOptions(false));
27
35
  function createNormalCase(name, src, dist) {
28
36
  creator.create(name, src, dist);
29
37
  }
38
+ const hotCreator = new creator_1.BasicCaseCreator(createCaseOptions(true));
39
+ function createHotNormalCase(name, src, dist) {
40
+ hotCreator.create(name, src, dist);
41
+ }
@@ -6,20 +6,21 @@ export declare enum ECompilerEvent {
6
6
  Create = "create",
7
7
  Close = "close"
8
8
  }
9
- export declare const COMPILER_FACTORIES: TCompilerFactories;
9
+ export declare const COMPILER_FACTORIES: TCompilerFactories<ECompilerType>;
10
10
  export declare class TestCompilerManager<T extends ECompilerType> implements ITestCompilerManager<T> {
11
11
  protected type: T;
12
- protected factories: TCompilerFactories;
12
+ protected factories: TCompilerFactories<T>;
13
13
  protected compilerOptions: TCompilerOptions<T>;
14
14
  protected compilerInstance: TCompiler<T> | null;
15
15
  protected compilerStats: TCompilerStats<T> | null;
16
16
  protected emitter: EventEmitter;
17
- constructor(type: T, factories?: TCompilerFactories);
17
+ constructor(type: T, factories?: TCompilerFactories<T>);
18
18
  getOptions(): TCompilerOptions<T>;
19
19
  setOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
20
20
  mergeOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
21
21
  getCompiler(): TCompiler<T> | null;
22
22
  createCompiler(): TCompiler<T>;
23
+ createCompilerWithCallback(callback: (error: Error | null, stats: TCompilerStats<T> | null) => void): TCompiler<T>;
23
24
  build(): Promise<TCompilerStats<T>>;
24
25
  watch(timeout?: number): void;
25
26
  getStats(): TCompilerStats<T> | null;
package/dist/compiler.js CHANGED
@@ -15,8 +15,8 @@ var ECompilerEvent;
15
15
  ECompilerEvent["Close"] = "close";
16
16
  })(ECompilerEvent || (exports.ECompilerEvent = ECompilerEvent = {}));
17
17
  exports.COMPILER_FACTORIES = {
18
- [type_1.ECompilerType.Rspack]: ((options) => require("@rspack/core")(options)),
19
- [type_1.ECompilerType.Webpack]: ((options) => require("webpack")(options))
18
+ [type_1.ECompilerType.Rspack]: ((options, callback) => require("@rspack/core")(options, callback)),
19
+ [type_1.ECompilerType.Webpack]: ((options, callback) => require("webpack")(options, callback))
20
20
  };
21
21
  class TestCompilerManager {
22
22
  constructor(type, factories = exports.COMPILER_FACTORIES) {
@@ -48,6 +48,11 @@ class TestCompilerManager {
48
48
  this.emitter.emit(ECompilerEvent.Create, this.compilerInstance);
49
49
  return this.compilerInstance;
50
50
  }
51
+ createCompilerWithCallback(callback) {
52
+ this.compilerInstance = this.factories[this.type](this.compilerOptions, callback);
53
+ this.emitter.emit(ECompilerEvent.Create, this.compilerInstance);
54
+ return this.compilerInstance;
55
+ }
51
56
  build() {
52
57
  if (!this.compilerInstance)
53
58
  throw new Error("Compiler should be created before build");
@@ -0,0 +1 @@
1
+ export function start(handler: any): () => any[];
@@ -0,0 +1,41 @@
1
+ // @ts-nocheck
2
+ /*
3
+ MIT License http://www.opensource.org/licenses/mit-license.php
4
+ Author Tobias Koppers @sokra
5
+ */
6
+ "use strict";
7
+ const util = require("util");
8
+ let interception = undefined;
9
+ const originalDeprecate = util.deprecate;
10
+ util.deprecate = (fn, message, code) => {
11
+ const original = originalDeprecate(fn, message, code);
12
+ return function (...args) {
13
+ if (interception) {
14
+ interception.set(`${code}: ${message}`, {
15
+ code,
16
+ message,
17
+ stack: new Error(message).stack
18
+ });
19
+ return fn.apply(this, args);
20
+ }
21
+ else {
22
+ return original.apply(this, args);
23
+ }
24
+ };
25
+ };
26
+ exports.start = handler => {
27
+ interception = new Map();
28
+ return () => {
29
+ const map = interception;
30
+ interception = undefined;
31
+ return Array.from(map || [])
32
+ .sort(([a], [b]) => {
33
+ if (a < b)
34
+ return -1;
35
+ if (a > b)
36
+ return 1;
37
+ return 0;
38
+ })
39
+ .map(([key, data]) => data);
40
+ };
41
+ };
@@ -1,6 +1,7 @@
1
1
  import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, TCompiler, TCompilerOptions, TCompilerStats } from "../type";
2
2
  export interface ISimpleProcessorOptions<T extends ECompilerType> {
3
3
  options?: (context: ITestContext) => TCompilerOptions<T>;
4
+ compilerCallback?: (error: Error | null, stats: TCompilerStats<T> | null) => void;
4
5
  compilerType: T;
5
6
  name: string;
6
7
  build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
@@ -13,7 +13,9 @@ class SimpleTaskProcessor {
13
13
  }
14
14
  async compiler(context) {
15
15
  const compiler = this.getCompiler(context);
16
- const instance = compiler.createCompiler();
16
+ const instance = this._options.compilerCallback
17
+ ? compiler.createCompilerWithCallback(this._options.compilerCallback)
18
+ : compiler.createCompiler();
17
19
  if (typeof this._options.compiler === "function") {
18
20
  await this._options.compiler(context, instance);
19
21
  }
package/dist/type.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type EventEmitter from "node:events";
2
- import type { Compiler as RspackCompiler, MultiStats as RspackMultiStats, RspackOptions, Stats as RspackStats, StatsCompilation as RspackStatsCompilation } from "@rspack/core";
3
- import type { Compiler as WebpackCompiler, MultiStats as WebpackMultiStats, Configuration as WebpackOptions, Stats as WebpackStats, StatsCompilation as WebpackStatsCompilation } from "webpack";
2
+ import type { Compilation as RspackCompilation, Compiler as RspackCompiler, MultiStats as RspackMultiStats, RspackOptions, Stats as RspackStats, StatsCompilation as RspackStatsCompilation } from "@rspack/core";
3
+ import type { Compilation as WebpackCompilation, Compiler as WebpackCompiler, MultiStats as WebpackMultiStats, Configuration as WebpackOptions, Stats as WebpackStats, StatsCompilation as WebpackStatsCompilation } from "webpack";
4
4
  import type { IBasicModuleScope, TRunnerRequirer } from "./runner/type";
5
5
  export interface ITestContext {
6
6
  getSource(sub?: string): string;
@@ -25,6 +25,7 @@ export declare enum ECompilerType {
25
25
  }
26
26
  export type TCompilerOptions<T> = T extends ECompilerType.Rspack ? RspackOptions : WebpackOptions;
27
27
  export type TCompiler<T> = T extends ECompilerType.Rspack ? RspackCompiler : WebpackCompiler;
28
+ export type TCompilation<T> = T extends ECompilerType.Rspack ? RspackCompilation : WebpackCompilation;
28
29
  export type TCompilerStats<T> = T extends ECompilerType.Rspack ? RspackStats : WebpackStats;
29
30
  export type TCompilerMultiStats<T> = T extends ECompilerType.Rspack ? RspackMultiStats : WebpackMultiStats;
30
31
  export type TCompilerStatsCompilation<T> = T extends ECompilerType.Rspack ? RspackStatsCompilation : WebpackStatsCompilation;
@@ -34,6 +35,7 @@ export interface ITestCompilerManager<T extends ECompilerType> {
34
35
  mergeOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
35
36
  getCompiler(): TCompiler<T> | null;
36
37
  createCompiler(): TCompiler<T>;
38
+ createCompilerWithCallback(callback: (error: Error | null, stats: TCompilerStats<T> | null) => void): TCompiler<T>;
37
39
  build(): Promise<TCompilerStats<T>>;
38
40
  watch(timeout?: number): void;
39
41
  getStats(): TCompilerStats<T> | TCompilerMultiStats<T> | null;
@@ -51,7 +53,7 @@ export interface ITesterConfig {
51
53
  temp?: string;
52
54
  steps?: ITestProcessor[];
53
55
  testConfig?: TTestConfig<ECompilerType>;
54
- compilerFactories?: TCompilerFactories;
56
+ compilerFactories?: TCompilerFactories<ECompilerType>;
55
57
  contextValue?: Record<string, unknown>;
56
58
  runnerFactory?: new (name: string, context: ITestContext) => TRunnerFactory<ECompilerType>;
57
59
  }
@@ -157,7 +159,7 @@ export interface ITestRunner {
157
159
  getRequire(): TRunnerRequirer;
158
160
  getGlobal(name: string): unknown;
159
161
  }
160
- export type TCompilerFactory<T extends ECompilerType> = (options: TCompilerOptions<T> | TCompilerOptions<T>[]) => TCompiler<T>;
162
+ export type TCompilerFactory<T extends ECompilerType> = (options: TCompilerOptions<T> | TCompilerOptions<T>[], callback?: (error: Error | null, stats: TCompilerStats<T> | null) => void) => TCompiler<T>;
161
163
  export interface TRunnerFactory<T extends ECompilerType> {
162
164
  create(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
163
165
  }
@@ -166,4 +168,4 @@ export type TUpdateOptions = {
166
168
  totalUpdates: number;
167
169
  changedFiles: string[];
168
170
  };
169
- export type TCompilerFactories = Record<ECompilerType, TCompilerFactory<ECompilerType>>;
171
+ export type TCompilerFactories<T extends ECompilerType> = Record<T, TCompilerFactory<T>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack-canary/test-tools",
3
- "version": "1.5.4-canary-8cc7f155-20250915173802",
3
+ "version": "1.5.5-canary-03ab52ad-20250916180415",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -35,15 +35,15 @@
35
35
  "directory": "packages/rspack-test-tools"
36
36
  },
37
37
  "dependencies": {
38
- "@babel/generator": "7.28.0",
39
- "@babel/parser": "7.28.0",
40
- "@babel/traverse": "7.28.0",
41
- "@babel/types": "7.28.2",
38
+ "@babel/generator": "7.28.3",
39
+ "@babel/parser": "7.28.4",
40
+ "@babel/traverse": "7.28.4",
41
+ "@babel/types": "7.28.4",
42
42
  "cross-env": "^7.0.3",
43
43
  "csv-to-markdown-table": "^1.5.0",
44
44
  "deepmerge": "^4.3.1",
45
45
  "filenamify": "4.3.0",
46
- "fs-extra": "^11.3.0",
46
+ "fs-extra": "^11.3.2",
47
47
  "glob": "^11.0.3",
48
48
  "graceful-fs": "^4.2.11",
49
49
  "iconv-lite": "^0.6.3",
@@ -52,7 +52,7 @@
52
52
  "jsdom": "^26.1.0",
53
53
  "memfs": "4.38.2",
54
54
  "loader-utils": "^2.0.4",
55
- "path-serializer": "0.5.0",
55
+ "path-serializer": "0.5.1",
56
56
  "pretty-format": "29.7.0",
57
57
  "rimraf": "^5.0.10",
58
58
  "source-map": "^0.7.6",
@@ -63,33 +63,33 @@
63
63
  },
64
64
  "devDependencies": {
65
65
  "@rspack/plugin-preact-refresh": "1.1.2",
66
- "@rspack/plugin-react-refresh": "^1.5.0",
66
+ "@rspack/plugin-react-refresh": "^1.5.1",
67
67
  "@swc/helpers": "0.5.17",
68
68
  "@swc/plugin-remove-console": "^9.0.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",
72
72
  "@types/jsdom": "^21.1.7",
73
- "@types/react": "^19.1.8",
74
- "@types/react-dom": "^19.1.6",
73
+ "@types/react": "^19.1.13",
74
+ "@types/react-dom": "^19.1.9",
75
75
  "@webdiscus/pug-loader": "^2.11.1",
76
76
  "acorn": "^8.15.0",
77
77
  "babel-loader": "^10.0.0",
78
78
  "babel-plugin-import": "^1.13.8",
79
79
  "chalk": "^4.1.2",
80
- "core-js": "3.45.0",
80
+ "core-js": "3.45.1",
81
81
  "css-loader": "^7.1.2",
82
82
  "file-loader": "^6.2.0",
83
83
  "graceful-fs": "^4.2.11",
84
84
  "html-loader": "^5.1.0",
85
- "html-webpack-plugin": "^5.6.3",
85
+ "html-webpack-plugin": "^5.6.4",
86
86
  "less-loader": "^12.3.0",
87
87
  "lodash": "^4.17.21",
88
88
  "postcss-loader": "^8.2.0",
89
89
  "postcss-pxtorem": "^6.1.0",
90
90
  "raw-loader": "^4.0.2",
91
- "react": "^19.1.0",
92
- "react-dom": "^19.1.0",
91
+ "react": "^19.1.1",
92
+ "react-dom": "^19.1.1",
93
93
  "react-refresh": "^0.17.0",
94
94
  "sass-loader": "^16.0.5",
95
95
  "source-map": "^0.7.6",
@@ -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.4-canary-8cc7f155-20250915173802",
103
+ "@rspack/cli": "npm:@rspack-canary/cli@1.5.5-canary-03ab52ad-20250916180415",
104
104
  "@rspack/binding-testing": "1.4.1",
105
- "@rspack/core": "npm:@rspack-canary/core@1.5.4-canary-8cc7f155-20250915173802",
106
- "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.4-canary-8cc7f155-20250915173802"
105
+ "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.5-canary-03ab52ad-20250916180415",
106
+ "@rspack/core": "npm:@rspack-canary/core@1.5.5-canary-03ab52ad-20250916180415"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "@rspack/core": ">=1.0.0"