@rspack-canary/test-tools 1.5.5-canary-f4d631e6-20250915072424 → 1.5.6-canary-95c56d3d-20250917183900
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.
- package/dist/case/compiler.d.ts +11 -2
- package/dist/case/compiler.js +111 -8
- package/dist/case/normal.d.ts +1 -0
- package/dist/case/normal.js +27 -15
- package/dist/compiler.d.ts +4 -3
- package/dist/compiler.js +7 -2
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
- package/dist/helper/legacy/deprecationTracking.js +41 -0
- package/dist/helper/legacy/supportDefaultAssignment.d.ts +2 -0
- package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
- package/dist/helper/legacy/supportsClassFields.d.ts +2 -0
- package/dist/helper/legacy/supportsClassFields.js +11 -0
- package/dist/helper/legacy/supportsES6.d.ts +2 -0
- package/dist/helper/legacy/supportsES6.js +11 -0
- package/dist/helper/legacy/supportsForOf.d.ts +2 -0
- package/dist/helper/legacy/supportsForOf.js +11 -0
- package/dist/helper/legacy/supportsIteratorDestructuring.d.ts +2 -0
- package/dist/helper/legacy/supportsIteratorDestructuring.js +11 -0
- package/dist/helper/legacy/supportsLogicalAssignment.d.ts +2 -0
- package/dist/helper/legacy/supportsLogicalAssignment.js +11 -0
- package/dist/helper/legacy/supportsObjectDestructuring.d.ts +2 -0
- package/dist/helper/legacy/supportsObjectDestructuring.js +11 -0
- package/dist/helper/legacy/supportsOptionalCatchBinding.d.ts +2 -0
- package/dist/helper/legacy/supportsOptionalCatchBinding.js +11 -0
- package/dist/helper/legacy/supportsRequireInModule.d.ts +2 -0
- package/dist/helper/legacy/supportsRequireInModule.js +5 -0
- package/dist/helper/legacy/supportsSpread.d.ts +2 -0
- package/dist/helper/legacy/supportsSpread.js +12 -0
- package/dist/helper/legacy/supportsTemplateStrings.d.ts +2 -0
- package/dist/helper/legacy/supportsTemplateStrings.js +11 -0
- package/dist/helper/legacy/supportsUsing.d.ts +2 -0
- package/dist/helper/legacy/supportsUsing.js +26 -0
- package/dist/processor/normal.js +21 -2
- package/dist/processor/simple.d.ts +1 -0
- package/dist/processor/simple.js +3 -1
- package/dist/runner/runner/cjs.js +5 -2
- package/dist/runner/runner/normal.js +4 -1
- package/dist/type.d.ts +7 -5
- package/package.json +17 -17
package/dist/case/compiler.d.ts
CHANGED
|
@@ -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;
|
package/dist/case/compiler.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
}
|
package/dist/case/normal.d.ts
CHANGED
package/dist/case/normal.js
CHANGED
|
@@ -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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
+
}
|
package/dist/compiler.d.ts
CHANGED
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
module.exports = function supportDefaultAssignment() {
|
|
4
|
+
try {
|
|
5
|
+
// eslint-disable-next-line no-unused-vars
|
|
6
|
+
var E = eval("class E { toString() { return 'default' } }");
|
|
7
|
+
var f1 = eval("(function f1({a, b = E}) {return new b().toString();})");
|
|
8
|
+
return f1({ a: "test" }) === "default";
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
"use strict";
|
|
3
|
+
module.exports = function supportsUsing() {
|
|
4
|
+
try {
|
|
5
|
+
const f = eval(`(function f() {
|
|
6
|
+
let disposed = false;
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
const getResource = () => {
|
|
10
|
+
return {
|
|
11
|
+
[Symbol.dispose]: () => {
|
|
12
|
+
disposed = true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
using resource = getResource();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return disposed;
|
|
20
|
+
})`);
|
|
21
|
+
return f() === true;
|
|
22
|
+
}
|
|
23
|
+
catch (_err) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
package/dist/processor/normal.js
CHANGED
|
@@ -11,6 +11,10 @@ class NormalProcessor extends basic_1.BasicProcessor {
|
|
|
11
11
|
constructor(_normalOptions) {
|
|
12
12
|
super({
|
|
13
13
|
findBundle: (context, options) => {
|
|
14
|
+
const testConfig = context.getTestConfig();
|
|
15
|
+
if (typeof testConfig.findBundle === "function") {
|
|
16
|
+
return testConfig.findBundle(0, options);
|
|
17
|
+
}
|
|
14
18
|
const filename = options.output?.filename;
|
|
15
19
|
return typeof filename === "string" ? filename : undefined;
|
|
16
20
|
},
|
|
@@ -31,6 +35,7 @@ class NormalProcessor extends basic_1.BasicProcessor {
|
|
|
31
35
|
});
|
|
32
36
|
const { root, compilerOptions } = this._normalOptions;
|
|
33
37
|
return {
|
|
38
|
+
amd: {},
|
|
34
39
|
context: root,
|
|
35
40
|
entry: `./${node_path_1.default.relative(root, context.getSource())}/`,
|
|
36
41
|
target: compilerOptions?.target || "async-node",
|
|
@@ -98,7 +103,21 @@ class NormalProcessor extends basic_1.BasicProcessor {
|
|
|
98
103
|
]
|
|
99
104
|
},
|
|
100
105
|
module: {
|
|
101
|
-
rules: [
|
|
106
|
+
rules: [
|
|
107
|
+
{
|
|
108
|
+
test: /\.coffee$/,
|
|
109
|
+
loader: "coffee-loader"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
test: /\.pug/,
|
|
113
|
+
loader: "@webdiscus/pug-loader"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
test: /\.wat$/i,
|
|
117
|
+
loader: "wast-loader",
|
|
118
|
+
type: "webassembly/async"
|
|
119
|
+
}
|
|
120
|
+
]
|
|
102
121
|
},
|
|
103
122
|
plugins: (compilerOptions?.plugins || [])
|
|
104
123
|
.concat(testConfig.plugins || [])
|
|
@@ -118,7 +137,7 @@ class NormalProcessor extends basic_1.BasicProcessor {
|
|
|
118
137
|
});
|
|
119
138
|
}),
|
|
120
139
|
experiments: {
|
|
121
|
-
css:
|
|
140
|
+
css: false,
|
|
122
141
|
rspackFuture: {
|
|
123
142
|
bundlerInfo: {
|
|
124
143
|
force: false
|
|
@@ -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>;
|
package/dist/processor/simple.js
CHANGED
|
@@ -13,7 +13,9 @@ class SimpleTaskProcessor {
|
|
|
13
13
|
}
|
|
14
14
|
async compiler(context) {
|
|
15
15
|
const compiler = this.getCompiler(context);
|
|
16
|
-
const instance =
|
|
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
|
}
|
|
@@ -81,9 +81,11 @@ class CommonJsRunner extends basic_1.BasicRunner {
|
|
|
81
81
|
return baseModuleScope;
|
|
82
82
|
}
|
|
83
83
|
createModuleScope(requireFn, m, file) {
|
|
84
|
+
const requirer = requireFn.bind(null, node_path_1.default.dirname(file.path));
|
|
85
|
+
requirer.webpackTestSuiteRequire = true;
|
|
84
86
|
return {
|
|
85
87
|
...this.baseModuleScope,
|
|
86
|
-
require:
|
|
88
|
+
require: requirer,
|
|
87
89
|
module: m,
|
|
88
90
|
exports: m.exports,
|
|
89
91
|
__dirname: node_path_1.default.dirname(file.path),
|
|
@@ -138,7 +140,8 @@ class CommonJsRunner extends basic_1.BasicRunner {
|
|
|
138
140
|
return this.requireCache[file.path].exports;
|
|
139
141
|
}
|
|
140
142
|
const m = {
|
|
141
|
-
exports: {}
|
|
143
|
+
exports: {},
|
|
144
|
+
webpackTestSuiteModule: true
|
|
142
145
|
};
|
|
143
146
|
this.requireCache[file.path] = m;
|
|
144
147
|
const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
|
|
@@ -7,7 +7,6 @@ class NormalRunner extends esm_1.EsmRunner {
|
|
|
7
7
|
createBaseModuleScope() {
|
|
8
8
|
const baseModuleScope = Object.assign(super.createBaseModuleScope(), {
|
|
9
9
|
process,
|
|
10
|
-
global,
|
|
11
10
|
URL: node_url_1.URL,
|
|
12
11
|
Buffer,
|
|
13
12
|
setImmediate
|
|
@@ -17,6 +16,10 @@ class NormalRunner extends esm_1.EsmRunner {
|
|
|
17
16
|
createModuleScope(requireFn, m, file) {
|
|
18
17
|
const moduleScope = super.createModuleScope(requireFn, m, file);
|
|
19
18
|
delete moduleScope.define;
|
|
19
|
+
moduleScope._globalAssign = {
|
|
20
|
+
...(moduleScope._globalAssign || {}),
|
|
21
|
+
expect: this._options.env.expect
|
|
22
|
+
};
|
|
20
23
|
return moduleScope;
|
|
21
24
|
}
|
|
22
25
|
}
|
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<
|
|
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.
|
|
3
|
+
"version": "1.5.6-canary-95c56d3d-20250917183900",
|
|
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.
|
|
39
|
-
"@babel/parser": "7.28.
|
|
40
|
-
"@babel/traverse": "7.28.
|
|
41
|
-
"@babel/types": "7.28.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
74
|
-
"@types/react-dom": "^19.1.
|
|
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.
|
|
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.
|
|
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.
|
|
92
|
-
"react-dom": "^19.1.
|
|
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.
|
|
103
|
+
"@rspack/cli": "npm:@rspack-canary/cli@1.5.6-canary-95c56d3d-20250917183900",
|
|
104
|
+
"@rspack/core": "npm:@rspack-canary/core@1.5.6-canary-95c56d3d-20250917183900",
|
|
104
105
|
"@rspack/binding-testing": "1.4.1",
|
|
105
|
-
"@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.
|
|
106
|
-
"@rspack/core": "npm:@rspack-canary/core@1.5.5-canary-f4d631e6-20250915072424"
|
|
106
|
+
"@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.6-canary-95c56d3d-20250917183900"
|
|
107
107
|
},
|
|
108
108
|
"peerDependencies": {
|
|
109
109
|
"@rspack/core": ">=1.0.0"
|