@rspack/test-tools 1.6.0-beta.0 → 1.6.0
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/builtin.d.ts +3 -2
- package/dist/case/builtin.js +1 -1
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +13 -9
- package/dist/case/common.d.ts +11 -10
- package/dist/case/common.js +49 -43
- package/dist/case/compiler.d.ts +9 -8
- package/dist/case/compiler.js +5 -6
- package/dist/case/config.d.ts +6 -5
- package/dist/case/config.js +4 -1
- package/dist/case/defaults.d.ts +5 -4
- package/dist/case/defaults.js +10 -10
- package/dist/case/diagnostic.js +5 -6
- package/dist/case/error.d.ts +5 -5
- package/dist/case/error.js +7 -8
- package/dist/case/esm-output.js +30 -9
- package/dist/case/example.js +2 -2
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +1 -1
- package/dist/case/hook.d.ts +4 -3
- package/dist/case/hook.js +3 -2
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +4 -9
- package/dist/case/hot.d.ts +5 -4
- package/dist/case/hot.js +37 -49
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +1 -20
- package/dist/case/index.d.ts +0 -1
- package/dist/case/index.js +1 -3
- package/dist/case/multi-compiler.d.ts +9 -8
- package/dist/case/multi-compiler.js +3 -4
- package/dist/case/normal.js +5 -2
- package/dist/case/runner.d.ts +5 -4
- package/dist/case/runner.js +16 -11
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +1 -1
- package/dist/case/stats-api.d.ts +6 -5
- package/dist/case/stats-api.js +5 -7
- package/dist/case/stats-output.d.ts +3 -2
- package/dist/case/stats-output.js +1 -1
- package/dist/case/treeshaking.js +1 -1
- package/dist/case/watch.d.ts +8 -6
- package/dist/case/watch.js +21 -19
- package/dist/compiler.d.ts +16 -17
- package/dist/compiler.js +116 -16
- package/dist/helper/hot-update/loader.d.ts +2 -1
- package/dist/helper/hot-update/loader.js +5 -30
- package/dist/helper/hot-update/plugin.js +10 -14
- package/dist/helper/index.d.ts +1 -0
- package/dist/helper/index.js +1 -0
- package/dist/helper/legacy/asModule.js +0 -2
- package/dist/helper/legacy/checkArrayExpectation.js +1 -1
- package/dist/helper/legacy/createLazyTestEnv.d.ts +1 -0
- package/dist/helper/legacy/createLazyTestEnv.js +4 -3
- package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
- package/dist/helper/legacy/supportsTextDecoder.js +9 -0
- package/dist/helper/read-config-file.d.ts +3 -2
- package/dist/helper/read-config-file.js +12 -2
- package/dist/helper/setup-env.js +19 -2
- package/dist/helper/stringify-config.d.ts +2 -0
- package/dist/helper/stringify-config.js +43 -0
- package/dist/helper/util/expectWarningFactory.js +2 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/plugin/index.d.ts +0 -3
- package/dist/plugin/index.js +0 -3
- package/dist/runner/node/index.d.ts +13 -8
- package/dist/runner/node/index.js +88 -10
- package/dist/runner/web/index.d.ts +24 -10
- package/dist/runner/web/index.js +286 -18
- package/dist/test/context.d.ts +15 -16
- package/dist/test/context.js +44 -59
- package/dist/test/creator.d.ts +14 -14
- package/dist/test/creator.js +17 -12
- package/dist/test/debug.d.ts +15 -0
- package/dist/test/debug.js +205 -0
- package/dist/test/tester.d.ts +1 -0
- package/dist/test/tester.js +23 -4
- package/dist/type.d.ts +42 -55
- package/dist/type.js +1 -11
- package/jest.d.ts +2 -0
- package/package.json +10 -48
- package/dist/case/diff.d.ts +0 -19
- package/dist/case/diff.js +0 -274
- package/dist/compare/comparator.d.ts +0 -17
- package/dist/compare/comparator.js +0 -52
- package/dist/compare/compare.d.ts +0 -17
- package/dist/compare/compare.js +0 -178
- package/dist/compare/format-code.d.ts +0 -16
- package/dist/compare/format-code.js +0 -244
- package/dist/compare/index.d.ts +0 -5
- package/dist/compare/index.js +0 -21
- package/dist/compare/replace-module-argument.d.ts +0 -1
- package/dist/compare/replace-module-argument.js +0 -8
- package/dist/compare/replace-runtime-module-name.d.ts +0 -1
- package/dist/compare/replace-runtime-module-name.js +0 -71
- package/dist/helper/legacy/FakeDocument.d.ts +0 -54
- package/dist/helper/legacy/FakeDocument.js +0 -280
- package/dist/helper/legacy/update.d.ts +0 -2
- package/dist/helper/legacy/update.esm.d.ts +0 -1
- package/dist/helper/legacy/update.esm.js +0 -23
- package/dist/helper/legacy/update.js +0 -19
- package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
- package/dist/helper/legacy/walkCssTokens.js +0 -761
- package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/rspack-diff-config-plugin.js +0 -42
- package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/webpack-diff-config-plugin.js +0 -41
- package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
- package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
- package/dist/runner/web/fake.d.ts +0 -15
- package/dist/runner/web/fake.js +0 -216
- package/dist/runner/web/jsdom.d.ts +0 -24
- package/dist/runner/web/jsdom.js +0 -224
- package/template/diff.bundle.css +0 -1
- package/template/diff.bundle.js +0 -144
- package/template/diff.html +0 -14
- package/template/editor.worker.js +0 -1
package/dist/case/builtin.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RspackOptions } from "@rspack/core";
|
|
2
|
+
import type { ITestContext } from "../type";
|
|
2
3
|
export declare function createBuiltinCase(name: string, src: string, dist: string): void;
|
|
3
|
-
export declare function defaultOptions
|
|
4
|
+
export declare function defaultOptions(context: ITestContext): RspackOptions;
|
package/dist/case/builtin.js
CHANGED
|
@@ -23,7 +23,7 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
23
23
|
return [
|
|
24
24
|
{
|
|
25
25
|
config: async (context) => {
|
|
26
|
-
const compiler =
|
|
26
|
+
const compiler = context.getCompiler();
|
|
27
27
|
compiler.setOptions(defaultOptions(context));
|
|
28
28
|
},
|
|
29
29
|
compiler: async (context) => {
|
package/dist/case/cache.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function createCacheCase(name: string, src: string, dist: string, target:
|
|
1
|
+
import { type RspackOptions } from "@rspack/core";
|
|
2
|
+
export declare function createCacheCase(name: string, src: string, dist: string, target: RspackOptions["target"], temp: string): void;
|
package/dist/case/cache.js
CHANGED
|
@@ -11,7 +11,6 @@ const hot_update_1 = require("../helper/hot-update");
|
|
|
11
11
|
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
12
12
|
const runner_1 = require("../runner");
|
|
13
13
|
const creator_1 = require("../test/creator");
|
|
14
|
-
const type_1 = require("../type");
|
|
15
14
|
const common_1 = require("./common");
|
|
16
15
|
const runner_2 = require("./runner");
|
|
17
16
|
const MAX_COMPILER_INDEX = 100;
|
|
@@ -20,10 +19,10 @@ function createCacheProcessor(name, src, temp, target) {
|
|
|
20
19
|
return {
|
|
21
20
|
before: async (context) => {
|
|
22
21
|
await updatePlugin.initialize();
|
|
23
|
-
context.setValue(
|
|
22
|
+
context.setValue("hotUpdateContext", updatePlugin);
|
|
24
23
|
},
|
|
25
24
|
config: async (context) => {
|
|
26
|
-
const compiler =
|
|
25
|
+
const compiler = context.getCompiler();
|
|
27
26
|
let options = defaultOptions(context, temp, target);
|
|
28
27
|
options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"].map(i => node_path_1.default.resolve(temp, i)), options);
|
|
29
28
|
overrideOptions(options, temp, target, updatePlugin);
|
|
@@ -41,6 +40,9 @@ function createCacheProcessor(name, src, temp, target) {
|
|
|
41
40
|
check: async (env, context) => {
|
|
42
41
|
await (0, common_1.check)(env, context, name);
|
|
43
42
|
},
|
|
43
|
+
after: async (context) => {
|
|
44
|
+
await (0, common_1.afterExecute)(context, name);
|
|
45
|
+
},
|
|
44
46
|
afterAll: async (context) => {
|
|
45
47
|
const updateIndex = updatePlugin.getUpdateIndex();
|
|
46
48
|
const totalUpdates = updatePlugin.getTotalUpdates();
|
|
@@ -129,13 +131,16 @@ function overrideOptions(options, temp, target, updatePlugin) {
|
|
|
129
131
|
function findBundle(name, target, context) {
|
|
130
132
|
const files = [];
|
|
131
133
|
const prefiles = [];
|
|
132
|
-
const compiler =
|
|
134
|
+
const compiler = context.getCompiler();
|
|
133
135
|
if (!compiler)
|
|
134
136
|
throw new Error("Compiler should exists when find bundle");
|
|
135
137
|
const stats = compiler.getStats();
|
|
136
138
|
if (!stats)
|
|
137
139
|
throw new Error("Stats should exists when find bundle");
|
|
138
|
-
const info = stats.toJson({
|
|
140
|
+
const info = stats.toJson({
|
|
141
|
+
all: false,
|
|
142
|
+
entrypoints: true
|
|
143
|
+
});
|
|
139
144
|
if (target === "web" || target === "webworker") {
|
|
140
145
|
for (const file of info.entrypoints.main.assets) {
|
|
141
146
|
if ((0, helper_1.isJavaScript)(file.name)) {
|
|
@@ -153,16 +158,15 @@ function findBundle(name, target, context) {
|
|
|
153
158
|
return [...prefiles, ...files];
|
|
154
159
|
}
|
|
155
160
|
function createRunner(context, name, file, env) {
|
|
156
|
-
const compiler = context.getCompiler(
|
|
161
|
+
const compiler = context.getCompiler();
|
|
157
162
|
const options = compiler.getOptions();
|
|
158
163
|
let compilerIndex = 0;
|
|
159
164
|
const testConfig = context.getTestConfig();
|
|
160
165
|
const source = context.getSource();
|
|
161
166
|
const dist = context.getDist();
|
|
162
|
-
const updatePlugin = context.getValue(
|
|
167
|
+
const updatePlugin = context.getValue("hotUpdateContext");
|
|
163
168
|
const getWebRunner = () => {
|
|
164
|
-
return new runner_1.
|
|
165
|
-
dom: context.getValue(name, "documentType") || type_1.EDocumentType.JSDOM,
|
|
169
|
+
return new runner_1.NodeRunner({
|
|
166
170
|
env,
|
|
167
171
|
stats: (0, runner_2.cachedStats)(context, name),
|
|
168
172
|
cachable: false,
|
package/dist/case/common.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export declare function config
|
|
4
|
-
export declare function compiler
|
|
5
|
-
export declare function build
|
|
6
|
-
export declare function run
|
|
7
|
-
export declare function check
|
|
8
|
-
export declare function checkSnapshot
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
1
|
+
import type { Compiler, RspackOptions } from "@rspack/core";
|
|
2
|
+
import type { ITestContext, ITestEnv } from "../type";
|
|
3
|
+
export declare function config(context: ITestContext, name: string, configFiles: string[], defaultOptions?: RspackOptions): Promise<RspackOptions>;
|
|
4
|
+
export declare function compiler(context: ITestContext, name: string): Promise<Compiler>;
|
|
5
|
+
export declare function build(context: ITestContext, name: string): Promise<Compiler>;
|
|
6
|
+
export declare function run(env: ITestEnv, context: ITestContext, name: string, findBundle: (context: ITestContext, options: RspackOptions) => string[] | string | void): Promise<void>;
|
|
7
|
+
export declare function check(env: ITestEnv, context: ITestContext, name: string): Promise<void>;
|
|
8
|
+
export declare function checkSnapshot(env: ITestEnv, context: ITestContext, name: string, snapshot: string, filter?: (file: string) => boolean): Promise<void>;
|
|
9
|
+
export declare function afterExecute(context: ITestContext, name: string): Promise<void>;
|
|
10
|
+
export declare function findMultiCompilerBundle(context: ITestContext, name: string, multiFindBundle: (index: number, context: ITestContext, options: RspackOptions) => string[] | string | void): string[];
|
|
11
|
+
export declare function configMultiCompiler(context: ITestContext, name: string, configFiles: string[], defaultOptions: (index: number, context: ITestContext) => RspackOptions, overrideOptions: (index: number, context: ITestContext, options: RspackOptions) => void): void;
|
package/dist/case/common.js
CHANGED
|
@@ -3,13 +3,13 @@ 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.getCompiler = getCompiler;
|
|
7
6
|
exports.config = config;
|
|
8
7
|
exports.compiler = compiler;
|
|
9
8
|
exports.build = build;
|
|
10
9
|
exports.run = run;
|
|
11
10
|
exports.check = check;
|
|
12
11
|
exports.checkSnapshot = checkSnapshot;
|
|
12
|
+
exports.afterExecute = afterExecute;
|
|
13
13
|
exports.findMultiCompilerBundle = findMultiCompilerBundle;
|
|
14
14
|
exports.configMultiCompiler = configMultiCompiler;
|
|
15
15
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -18,26 +18,23 @@ const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
|
18
18
|
const helper_1 = require("../helper");
|
|
19
19
|
const placeholder_1 = require("../helper/expect/placeholder");
|
|
20
20
|
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
21
|
-
const
|
|
22
|
-
function getCompiler(context, name) {
|
|
23
|
-
return context.getCompiler(name, type_1.ECompilerType.Rspack);
|
|
24
|
-
}
|
|
21
|
+
const debug_1 = require("../test/debug");
|
|
25
22
|
async function config(context, name, configFiles, defaultOptions = {}) {
|
|
26
|
-
const compiler = getCompiler(
|
|
23
|
+
const compiler = context.getCompiler();
|
|
27
24
|
compiler.setOptions(defaultOptions);
|
|
28
25
|
if (Array.isArray(configFiles)) {
|
|
29
|
-
const fileOptions = (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)))[0];
|
|
26
|
+
const fileOptions = (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), context, defaultOptions)[0];
|
|
30
27
|
compiler.mergeOptions(fileOptions);
|
|
31
28
|
}
|
|
32
29
|
return compiler.getOptions();
|
|
33
30
|
}
|
|
34
31
|
async function compiler(context, name) {
|
|
35
|
-
const compiler = getCompiler(
|
|
32
|
+
const compiler = context.getCompiler();
|
|
36
33
|
compiler.createCompiler();
|
|
37
34
|
return compiler.getCompiler();
|
|
38
35
|
}
|
|
39
36
|
async function build(context, name) {
|
|
40
|
-
const compiler = getCompiler(
|
|
37
|
+
const compiler = context.getCompiler();
|
|
41
38
|
await compiler.build();
|
|
42
39
|
return compiler.getCompiler();
|
|
43
40
|
}
|
|
@@ -45,18 +42,12 @@ async function run(env, context, name, findBundle) {
|
|
|
45
42
|
const testConfig = context.getTestConfig();
|
|
46
43
|
if (testConfig.noTests)
|
|
47
44
|
return;
|
|
48
|
-
|
|
49
|
-
context.setValue(name, "documentType", testConfig.documentType);
|
|
50
|
-
}
|
|
51
|
-
const compiler = getCompiler(context, name);
|
|
45
|
+
const compiler = context.getCompiler();
|
|
52
46
|
if (typeof testConfig.beforeExecute === "function") {
|
|
53
47
|
testConfig.beforeExecute(compiler.getOptions());
|
|
54
48
|
}
|
|
55
49
|
let bundles;
|
|
56
|
-
if (
|
|
57
|
-
bundles = testConfig.bundlePath;
|
|
58
|
-
}
|
|
59
|
-
else if (typeof findBundle === "function") {
|
|
50
|
+
if (typeof findBundle === "function") {
|
|
60
51
|
bundles = findBundle(context, compiler.getOptions());
|
|
61
52
|
}
|
|
62
53
|
else {
|
|
@@ -65,35 +56,39 @@ async function run(env, context, name, findBundle) {
|
|
|
65
56
|
if (typeof bundles === "string") {
|
|
66
57
|
bundles = [bundles];
|
|
67
58
|
}
|
|
59
|
+
if (__DEBUG__) {
|
|
60
|
+
context.setValue(debug_1.DEBUG_SCOPES.RunFindBundle, bundles);
|
|
61
|
+
}
|
|
68
62
|
if (!bundles || !bundles.length) {
|
|
69
63
|
return;
|
|
70
64
|
}
|
|
65
|
+
if (__DEBUG__) {
|
|
66
|
+
context.setValue(debug_1.DEBUG_SCOPES.RunLogs, []);
|
|
67
|
+
context.setValue(debug_1.DEBUG_SCOPES.RunErrors, []);
|
|
68
|
+
}
|
|
71
69
|
for (const bundle of bundles) {
|
|
72
70
|
if (!bundle) {
|
|
73
71
|
continue;
|
|
74
72
|
}
|
|
75
|
-
const runner = context.getRunner(
|
|
73
|
+
const runner = context.getRunner(bundle, env);
|
|
74
|
+
if (__DEBUG__) {
|
|
75
|
+
const runLogs = context.getValue(debug_1.DEBUG_SCOPES.RunLogs);
|
|
76
|
+
runLogs?.push(`Start running entry: ${bundle} in ${runner.constructor.name}(${runner.__key__})`);
|
|
77
|
+
}
|
|
76
78
|
const mod = runner.run(bundle);
|
|
77
|
-
const result = context.getValue(
|
|
79
|
+
const result = context.getValue("modules") || [];
|
|
78
80
|
result.push(mod);
|
|
79
|
-
context.setValue(
|
|
81
|
+
context.setValue("modules", result);
|
|
80
82
|
}
|
|
81
|
-
const results = context.getValue(
|
|
83
|
+
const results = context.getValue("modules") || [];
|
|
82
84
|
await Promise.all(results);
|
|
83
|
-
if (typeof testConfig.afterExecute === "function") {
|
|
84
|
-
let options = compiler.getOptions();
|
|
85
|
-
if (Array.isArray(options) && options.length === 1) {
|
|
86
|
-
options = options[0];
|
|
87
|
-
}
|
|
88
|
-
testConfig.afterExecute(options);
|
|
89
|
-
}
|
|
90
85
|
}
|
|
91
86
|
async function check(env, context, name) {
|
|
92
87
|
const testConfig = context.getTestConfig();
|
|
93
88
|
if (testConfig.noTests)
|
|
94
89
|
return;
|
|
95
|
-
const compiler = getCompiler(
|
|
96
|
-
const errors = (context.getError(
|
|
90
|
+
const compiler = context.getCompiler();
|
|
91
|
+
const errors = (context.getError() || []).map(e => ({
|
|
97
92
|
message: e.message,
|
|
98
93
|
stack: e.stack
|
|
99
94
|
}));
|
|
@@ -132,14 +127,14 @@ async function check(env, context, name) {
|
|
|
132
127
|
await (0, checkArrayExpectation_1.default)(context.getSource(), { warnings }, "warning", "warnings", "Warning", options);
|
|
133
128
|
// clear error if checked
|
|
134
129
|
if (fs_extra_1.default.existsSync(context.getSource("errors.js"))) {
|
|
135
|
-
context.clearError(
|
|
130
|
+
context.clearError();
|
|
136
131
|
}
|
|
137
132
|
}
|
|
138
133
|
async function checkSnapshot(env, context, name, snapshot, filter) {
|
|
139
134
|
if (path_1.default.extname(snapshot) === ".snap") {
|
|
140
135
|
throw new Error("Snapshot with `.snap` will be managed by jest, please use `.snap.txt` instead");
|
|
141
136
|
}
|
|
142
|
-
const compilerManager = getCompiler(
|
|
137
|
+
const compilerManager = context.getCompiler();
|
|
143
138
|
const stats = compilerManager.getStats();
|
|
144
139
|
const compiler = compilerManager.getCompiler();
|
|
145
140
|
if (!stats || !compiler)
|
|
@@ -147,9 +142,7 @@ async function checkSnapshot(env, context, name, snapshot, filter) {
|
|
|
147
142
|
const compilers = "compilers" in compiler
|
|
148
143
|
? compiler.compilers
|
|
149
144
|
: [compiler];
|
|
150
|
-
const totalStats = "stats" in stats
|
|
151
|
-
? stats.stats
|
|
152
|
-
: [stats];
|
|
145
|
+
const totalStats = "stats" in stats ? stats.stats : [stats];
|
|
153
146
|
const total = compilers.length;
|
|
154
147
|
for (let i = 0; i < compilers.length; i++) {
|
|
155
148
|
const c = compilers[i];
|
|
@@ -175,23 +168,36 @@ async function checkSnapshot(env, context, name, snapshot, filter) {
|
|
|
175
168
|
if (testConfig.snapshotContent) {
|
|
176
169
|
content = testConfig.snapshotContent(content);
|
|
177
170
|
}
|
|
178
|
-
|
|
171
|
+
const filePath = file.replaceAll(path_1.default.sep, "/");
|
|
172
|
+
return `\`\`\`${tag} title=${filePath}\n${content}\n\`\`\``;
|
|
179
173
|
});
|
|
180
174
|
fileContents.sort();
|
|
181
175
|
const content = fileContents.join("\n\n");
|
|
182
176
|
const snapshotPath = path_1.default.isAbsolute(snapshot)
|
|
183
177
|
? snapshot
|
|
184
|
-
: path_1.default.resolve(context.getSource(),
|
|
178
|
+
: path_1.default.resolve(context.getSource(), path_1.default.join("__snapshots__", `${snapshot}${total > 1 ? `-${i}` : ""}`));
|
|
185
179
|
env.expect(content).toMatchFileSnapshot(snapshotPath);
|
|
186
180
|
}
|
|
187
181
|
}
|
|
182
|
+
async function afterExecute(context, name) {
|
|
183
|
+
const compiler = context.getCompiler();
|
|
184
|
+
const testConfig = context.getTestConfig();
|
|
185
|
+
if (typeof testConfig.afterExecute === "function") {
|
|
186
|
+
let options = compiler.getOptions();
|
|
187
|
+
if (Array.isArray(options) && options.length === 1) {
|
|
188
|
+
options = options[0];
|
|
189
|
+
}
|
|
190
|
+
testConfig.afterExecute(options);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
188
193
|
function findMultiCompilerBundle(context, name, multiFindBundle) {
|
|
189
194
|
if (typeof multiFindBundle !== "function") {
|
|
190
195
|
return [];
|
|
191
196
|
}
|
|
192
|
-
const multiCompilerOptions = (context.getValue(
|
|
197
|
+
const multiCompilerOptions = (context.getValue("multiCompilerOptions") ||
|
|
198
|
+
[]);
|
|
193
199
|
const result = [];
|
|
194
|
-
const multiFileIndexMap = context.getValue(
|
|
200
|
+
const multiFileIndexMap = context.getValue("multiFileIndexMap") || {};
|
|
195
201
|
for (const [index, compilerOptions] of multiCompilerOptions.entries()) {
|
|
196
202
|
const curBundles = multiFindBundle(index, context, compilerOptions);
|
|
197
203
|
const bundles = Array.isArray(curBundles)
|
|
@@ -209,13 +215,13 @@ function findMultiCompilerBundle(context, name, multiFindBundle) {
|
|
|
209
215
|
}
|
|
210
216
|
result.push(...bundles);
|
|
211
217
|
}
|
|
212
|
-
context.setValue(
|
|
218
|
+
context.setValue("multiFileIndexMap", multiFileIndexMap);
|
|
213
219
|
return result;
|
|
214
220
|
}
|
|
215
221
|
function configMultiCompiler(context, name, configFiles, defaultOptions, overrideOptions) {
|
|
216
222
|
const multiCompilerOptions = [];
|
|
217
223
|
const caseOptions = Array.isArray(configFiles)
|
|
218
|
-
? (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), configs => {
|
|
224
|
+
? (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), context, {}, configs => {
|
|
219
225
|
return configs.flatMap(c => {
|
|
220
226
|
if (typeof c === "function") {
|
|
221
227
|
const options = {
|
|
@@ -237,7 +243,7 @@ function configMultiCompiler(context, name, configFiles, defaultOptions, overrid
|
|
|
237
243
|
}
|
|
238
244
|
multiCompilerOptions.push(compilerOptions);
|
|
239
245
|
}
|
|
240
|
-
const compiler = getCompiler(
|
|
246
|
+
const compiler = context.getCompiler();
|
|
241
247
|
compiler.setOptions(multiCompilerOptions);
|
|
242
|
-
context.setValue(
|
|
248
|
+
context.setValue("multiCompilerOptions", multiCompilerOptions);
|
|
243
249
|
}
|
package/dist/case/compiler.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Compilation, Compiler, RspackOptions, Stats, StatsCompilation } from "@rspack/core";
|
|
2
|
+
import type { ITestContext } from "../type";
|
|
2
3
|
export declare function createCompilerCase(name: string, src: string, dist: string, testConfig: string): void;
|
|
3
4
|
export type TCompilerCaseConfig = {
|
|
4
5
|
description: string;
|
|
5
6
|
error?: boolean;
|
|
6
7
|
skip?: boolean;
|
|
7
|
-
options?: (context: ITestContext) =>
|
|
8
|
-
compiler?: (context: ITestContext, compiler:
|
|
9
|
-
build?: (context: ITestContext, compiler:
|
|
8
|
+
options?: (context: ITestContext) => RspackOptions;
|
|
9
|
+
compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
|
|
10
|
+
build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
|
|
10
11
|
check?: ({ context, stats, files, compiler, compilation }: {
|
|
11
12
|
context: ITestContext;
|
|
12
|
-
stats?:
|
|
13
|
+
stats?: StatsCompilation;
|
|
13
14
|
files?: Record<string, string>;
|
|
14
|
-
compiler:
|
|
15
|
-
compilation?:
|
|
15
|
+
compiler: Compiler;
|
|
16
|
+
compilation?: Compilation;
|
|
16
17
|
}) => Promise<void>;
|
|
17
|
-
compilerCallback?: (error: Error | null, stats:
|
|
18
|
+
compilerCallback?: (error: Error | null, stats: Stats | null) => void;
|
|
18
19
|
};
|
package/dist/case/compiler.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCompilerCase = createCompilerCase;
|
|
4
4
|
const creator_1 = require("../test/creator");
|
|
5
|
-
const common_1 = require("./common");
|
|
6
5
|
function createCompilerProcessor(name, caseConfig) {
|
|
7
6
|
const logs = {
|
|
8
7
|
mkdir: [],
|
|
@@ -11,7 +10,7 @@ function createCompilerProcessor(name, caseConfig) {
|
|
|
11
10
|
const files = {};
|
|
12
11
|
return {
|
|
13
12
|
config: async (context) => {
|
|
14
|
-
const compiler =
|
|
13
|
+
const compiler = context.getCompiler();
|
|
15
14
|
const options = caseConfig.options?.(context) || {};
|
|
16
15
|
options.mode ??= "production";
|
|
17
16
|
options.context ??= context.getSource();
|
|
@@ -24,7 +23,7 @@ function createCompilerProcessor(name, caseConfig) {
|
|
|
24
23
|
compiler.setOptions(options);
|
|
25
24
|
},
|
|
26
25
|
compiler: async (context) => {
|
|
27
|
-
const compiler =
|
|
26
|
+
const compiler = context.getCompiler();
|
|
28
27
|
if (caseConfig.compilerCallback) {
|
|
29
28
|
compiler.createCompilerWithCallback(caseConfig.compilerCallback);
|
|
30
29
|
}
|
|
@@ -65,7 +64,7 @@ function createCompilerProcessor(name, caseConfig) {
|
|
|
65
64
|
await caseConfig.compiler?.(context, c);
|
|
66
65
|
},
|
|
67
66
|
build: async (context) => {
|
|
68
|
-
const compiler =
|
|
67
|
+
const compiler = context.getCompiler();
|
|
69
68
|
if (typeof caseConfig.build === "function") {
|
|
70
69
|
await caseConfig.build?.(context, compiler.getCompiler());
|
|
71
70
|
}
|
|
@@ -75,7 +74,7 @@ function createCompilerProcessor(name, caseConfig) {
|
|
|
75
74
|
},
|
|
76
75
|
run: async (env, context) => { },
|
|
77
76
|
check: async (env, context) => {
|
|
78
|
-
const compiler =
|
|
77
|
+
const compiler = context.getCompiler();
|
|
79
78
|
const c = compiler.getCompiler();
|
|
80
79
|
const stats = compiler.getStats();
|
|
81
80
|
if (caseConfig.error) {
|
|
@@ -124,7 +123,7 @@ function createCompilerProcessor(name, caseConfig) {
|
|
|
124
123
|
}
|
|
125
124
|
},
|
|
126
125
|
after: async (context) => {
|
|
127
|
-
await context.closeCompiler(
|
|
126
|
+
await context.closeCompiler();
|
|
128
127
|
}
|
|
129
128
|
};
|
|
130
129
|
}
|
package/dist/case/config.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { RspackOptions } from "@rspack/core";
|
|
2
|
+
import type { ITestContext, ITestProcessor, TTestConfig } from "../type";
|
|
3
|
+
export type TConfigCaseConfig = Omit<TTestConfig, "validate">;
|
|
3
4
|
export declare function createConfigProcessor(name: string): ITestProcessor;
|
|
4
5
|
export declare function createConfigCase(name: string, src: string, dist: string): void;
|
|
5
|
-
export declare function defaultOptions(index: number, context: ITestContext):
|
|
6
|
-
export declare function overrideOptions(index: number, context: ITestContext, options:
|
|
7
|
-
export declare function findBundle(index: number, context: ITestContext, options:
|
|
6
|
+
export declare function defaultOptions(index: number, context: ITestContext): RspackOptions;
|
|
7
|
+
export declare function overrideOptions(index: number, context: ITestContext, options: RspackOptions): void;
|
|
8
|
+
export declare function findBundle(index: number, context: ITestContext, options: RspackOptions): string | string[];
|
package/dist/case/config.js
CHANGED
|
@@ -30,6 +30,9 @@ function createConfigProcessor(name) {
|
|
|
30
30
|
},
|
|
31
31
|
check: async (env, context) => {
|
|
32
32
|
await (0, common_1.check)(env, context, name);
|
|
33
|
+
},
|
|
34
|
+
after: async (context) => {
|
|
35
|
+
await (0, common_1.afterExecute)(context, name);
|
|
33
36
|
}
|
|
34
37
|
};
|
|
35
38
|
}
|
|
@@ -115,7 +118,7 @@ function findBundle(index, context, options) {
|
|
|
115
118
|
options.output?.cssFilename) ||
|
|
116
119
|
`bundle${index}.css`);
|
|
117
120
|
if (fs_extra_1.default.existsSync(cssOutputPath)) {
|
|
118
|
-
bundlePath.push(
|
|
121
|
+
bundlePath.push(path_1.default.relative(options.output.path, cssOutputPath));
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
bundlePath.push(`./bundle${index}${ext}`);
|
package/dist/case/defaults.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RspackOptions } from "@rspack/core";
|
|
2
|
+
import type { ITestContext } from "../type";
|
|
2
3
|
export declare function createDefaultsCase(name: string, src: string): void;
|
|
3
|
-
export declare function getRspackDefaultConfig(cwd: string, config:
|
|
4
|
+
export declare function getRspackDefaultConfig(cwd: string, config: RspackOptions): RspackOptions;
|
|
4
5
|
export type TDefaultsCaseConfig = {
|
|
5
|
-
options?: (context: ITestContext) =>
|
|
6
|
+
options?: (context: ITestContext) => RspackOptions;
|
|
6
7
|
cwd?: string;
|
|
7
|
-
diff: (diff: jest.JestMatchers<RspackTestDiff>, defaults: jest.JestMatchers<
|
|
8
|
+
diff: (diff: jest.JestMatchers<RspackTestDiff>, defaults: jest.JestMatchers<RspackOptions>) => Promise<void>;
|
|
8
9
|
description: string;
|
|
9
10
|
};
|
|
10
11
|
declare class RspackTestDiff {
|
package/dist/case/defaults.js
CHANGED
|
@@ -9,18 +9,17 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
9
9
|
const node_util_1 = require("node:util");
|
|
10
10
|
const jest_diff_1 = require("jest-diff");
|
|
11
11
|
const context_1 = require("../test/context");
|
|
12
|
-
const common_1 = require("./common");
|
|
13
12
|
const CURRENT_CWD = process.cwd();
|
|
14
13
|
function createDefaultsCase(name, src) {
|
|
15
14
|
const caseConfig = require(src);
|
|
16
15
|
it(`should generate the correct defaults from ${caseConfig.description}`, async () => {
|
|
17
16
|
await run(name, {
|
|
18
17
|
config: async (context) => {
|
|
19
|
-
const compiler =
|
|
18
|
+
const compiler = context.getCompiler();
|
|
20
19
|
compiler.setOptions(options(context, caseConfig.options));
|
|
21
20
|
},
|
|
22
21
|
compiler: async (context) => {
|
|
23
|
-
const compiler =
|
|
22
|
+
const compiler = context.getCompiler();
|
|
24
23
|
compiler.createCompiler();
|
|
25
24
|
},
|
|
26
25
|
build: async (context) => {
|
|
@@ -48,10 +47,6 @@ function getRspackDefaultConfig(cwd, config) {
|
|
|
48
47
|
}
|
|
49
48
|
const srcDir = node_path_1.default.resolve(__dirname, "../../tests/fixtures");
|
|
50
49
|
const distDir = node_path_1.default.resolve(__dirname, "../../tests/js/defaults");
|
|
51
|
-
const context = new context_1.TestContext({
|
|
52
|
-
src: srcDir,
|
|
53
|
-
dist: distDir
|
|
54
|
-
});
|
|
55
50
|
function options(context, custom) {
|
|
56
51
|
let res;
|
|
57
52
|
if (typeof custom === "function") {
|
|
@@ -71,7 +66,7 @@ class RspackTestDiff {
|
|
|
71
66
|
}
|
|
72
67
|
}
|
|
73
68
|
async function check(env, context, name, options) {
|
|
74
|
-
const compiler =
|
|
69
|
+
const compiler = context.getCompiler();
|
|
75
70
|
const config = getRspackDefaultConfig(options.cwd || CURRENT_CWD, compiler.getOptions());
|
|
76
71
|
const defaultConfig = getRspackDefaultConfig(options.cwd || CURRENT_CWD, {
|
|
77
72
|
mode: "none"
|
|
@@ -80,15 +75,20 @@ async function check(env, context, name, options) {
|
|
|
80
75
|
await options.diff(env.expect(new RspackTestDiff(diff)), env.expect(defaultConfig));
|
|
81
76
|
}
|
|
82
77
|
async function run(name, processor) {
|
|
78
|
+
const context = new context_1.TestContext({
|
|
79
|
+
name: name,
|
|
80
|
+
src: srcDir,
|
|
81
|
+
dist: distDir
|
|
82
|
+
});
|
|
83
83
|
try {
|
|
84
84
|
await processor.before?.(context);
|
|
85
85
|
await processor.config?.(context);
|
|
86
86
|
}
|
|
87
87
|
catch (e) {
|
|
88
|
-
context.emitError(
|
|
88
|
+
context.emitError(e);
|
|
89
89
|
}
|
|
90
90
|
finally {
|
|
91
|
-
await processor.check?.({ expect, it, beforeEach, afterEach, jest }, context);
|
|
91
|
+
await processor.check?.({ expect, it, beforeEach, afterEach, jest: global.jest || global.rstest }, context);
|
|
92
92
|
await processor.after?.(context);
|
|
93
93
|
}
|
|
94
94
|
}
|
package/dist/case/diagnostic.js
CHANGED
|
@@ -10,16 +10,15 @@ const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
|
10
10
|
const helper_1 = require("../helper");
|
|
11
11
|
const placeholder_1 = require("../helper/expect/placeholder");
|
|
12
12
|
const creator_1 = require("../test/creator");
|
|
13
|
-
const common_1 = require("./common");
|
|
14
13
|
const creator = new creator_1.BasicCaseCreator({
|
|
15
14
|
clean: true,
|
|
16
15
|
describe: false,
|
|
17
16
|
steps: ({ name }) => [
|
|
18
17
|
{
|
|
19
18
|
config: async (context) => {
|
|
20
|
-
const compiler =
|
|
19
|
+
const compiler = context.getCompiler();
|
|
21
20
|
let options = defaultOptions(context);
|
|
22
|
-
const custom = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)))[0];
|
|
21
|
+
const custom = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)), context, options)[0];
|
|
23
22
|
if (custom) {
|
|
24
23
|
options = (0, webpack_merge_1.default)(options, custom);
|
|
25
24
|
}
|
|
@@ -31,11 +30,11 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
31
30
|
compiler.setOptions(options);
|
|
32
31
|
},
|
|
33
32
|
compiler: async (context) => {
|
|
34
|
-
const compiler =
|
|
33
|
+
const compiler = context.getCompiler();
|
|
35
34
|
compiler.createCompiler();
|
|
36
35
|
},
|
|
37
36
|
build: async (context) => {
|
|
38
|
-
const compiler =
|
|
37
|
+
const compiler = context.getCompiler();
|
|
39
38
|
await compiler.build();
|
|
40
39
|
},
|
|
41
40
|
run: async (env, context) => {
|
|
@@ -89,7 +88,7 @@ function defaultOptions(context) {
|
|
|
89
88
|
};
|
|
90
89
|
}
|
|
91
90
|
async function check(env, context, name, options) {
|
|
92
|
-
const compiler =
|
|
91
|
+
const compiler = context.getCompiler();
|
|
93
92
|
const stats = compiler.getStats();
|
|
94
93
|
if (!stats) {
|
|
95
94
|
throw new Error("Stats should exists");
|
package/dist/case/error.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { StatsError } from "@rspack/core";
|
|
2
|
-
import type {
|
|
1
|
+
import type { Compiler, RspackOptions, StatsError } from "@rspack/core";
|
|
2
|
+
import type { ITestContext } from "../type";
|
|
3
3
|
export declare function createErrorCase(name: string, src: string, dist: string, testConfig: string): void;
|
|
4
4
|
declare class RspackStatsDiagnostics {
|
|
5
5
|
errors: StatsError[];
|
|
@@ -9,9 +9,9 @@ declare class RspackStatsDiagnostics {
|
|
|
9
9
|
export type TErrorCaseConfig = {
|
|
10
10
|
description: string;
|
|
11
11
|
skip?: boolean;
|
|
12
|
-
options?: (context: ITestContext) =>
|
|
13
|
-
compiler?: (context: ITestContext, compiler:
|
|
14
|
-
build?: (context: ITestContext, compiler:
|
|
12
|
+
options?: (context: ITestContext) => RspackOptions;
|
|
13
|
+
compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
|
|
14
|
+
build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
|
|
15
15
|
check?: (stats: RspackStatsDiagnostics) => Promise<void>;
|
|
16
16
|
};
|
|
17
17
|
export {};
|
package/dist/case/error.js
CHANGED
|
@@ -7,7 +7,6 @@ exports.createErrorCase = createErrorCase;
|
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
9
9
|
const creator_1 = require("../test/creator");
|
|
10
|
-
const common_1 = require("./common");
|
|
11
10
|
let addedSerializer = false;
|
|
12
11
|
const creator = new creator_1.BasicCaseCreator({
|
|
13
12
|
clean: true,
|
|
@@ -17,16 +16,16 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
17
16
|
return [
|
|
18
17
|
{
|
|
19
18
|
config: async (context) => {
|
|
20
|
-
const compiler =
|
|
19
|
+
const compiler = context.getCompiler();
|
|
21
20
|
compiler.setOptions(options(context, config.options));
|
|
22
21
|
},
|
|
23
22
|
compiler: async (context) => {
|
|
24
|
-
const compilerManager =
|
|
23
|
+
const compilerManager = context.getCompiler();
|
|
25
24
|
compilerManager.createCompiler();
|
|
26
25
|
compiler(context, compilerManager.getCompiler(), config.compiler);
|
|
27
26
|
},
|
|
28
27
|
build: async (context) => {
|
|
29
|
-
const compiler =
|
|
28
|
+
const compiler = context.getCompiler();
|
|
30
29
|
if (typeof config.build === "function") {
|
|
31
30
|
await config.build(context, compiler.getCompiler());
|
|
32
31
|
}
|
|
@@ -130,12 +129,12 @@ class RspackStatsDiagnostics {
|
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
131
|
async function check(env, context, name, check) {
|
|
133
|
-
if (context.getError(
|
|
134
|
-
await check?.(new RspackStatsDiagnostics(context.getError(
|
|
135
|
-
context.clearError(
|
|
132
|
+
if (context.getError().length > 0) {
|
|
133
|
+
await check?.(new RspackStatsDiagnostics(context.getError(), []));
|
|
134
|
+
context.clearError();
|
|
136
135
|
return;
|
|
137
136
|
}
|
|
138
|
-
const compiler =
|
|
137
|
+
const compiler = context.getCompiler();
|
|
139
138
|
const stats = compiler.getStats();
|
|
140
139
|
env.expect(typeof stats).toBe("object");
|
|
141
140
|
const statsResult = stats.toJson({ errorDetails: false });
|