@rspack-canary/test-tools 1.5.6-canary-e598f284-20250921173624 → 1.5.8-canary-e350b761-20250924173613
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 +2 -0
- package/dist/case/builtin.js +173 -13
- package/dist/case/cache.d.ts +1 -1
- package/dist/case/cache.js +210 -11
- package/dist/case/common.d.ts +10 -0
- package/dist/case/common.js +237 -0
- package/dist/case/compiler.d.ts +7 -4
- package/dist/case/compiler.js +144 -109
- package/dist/case/config.d.ts +5 -1
- package/dist/case/config.js +102 -16
- package/dist/case/defaults.d.ts +12 -4
- package/dist/case/defaults.js +67 -12
- package/dist/case/diagnostic.d.ts +6 -0
- package/dist/case/diagnostic.js +123 -14
- package/dist/case/diff.d.ts +17 -1
- package/dist/case/diff.js +170 -22
- package/dist/case/error.d.ts +14 -4
- package/dist/case/error.js +117 -10
- package/dist/case/hash.d.ts +1 -1
- package/dist/case/hash.js +70 -9
- package/dist/case/hook.d.ts +35 -4
- package/dist/case/hook.js +210 -21
- package/dist/case/hot-step.js +307 -9
- package/dist/case/hot.d.ts +8 -1
- package/dist/case/hot.js +235 -8
- package/dist/case/incremental.d.ts +1 -1
- package/dist/case/incremental.js +39 -41
- package/dist/case/index.d.ts +20 -20
- package/dist/case/index.js +44 -34
- package/dist/case/native-watcher.js +10 -23
- package/dist/case/normal.js +174 -12
- package/dist/case/runner.d.ts +18 -0
- package/dist/case/runner.js +108 -0
- package/dist/case/serial.d.ts +1 -1
- package/dist/case/serial.js +8 -12
- package/dist/case/stats-api.d.ts +0 -5
- package/dist/case/stats-api.js +71 -10
- package/dist/case/stats-output.js +197 -11
- package/dist/case/treeshaking.js +34 -7
- package/dist/case/watch.d.ts +27 -0
- package/dist/case/watch.js +321 -21
- package/dist/helper/plugins/hot-update.d.ts +2 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/runner/index.d.ts +2 -7
- package/dist/runner/index.js +2 -7
- package/dist/runner/{runner/node → node}/index.d.ts +1 -2
- package/dist/runner/{runner/node → node}/index.js +2 -2
- package/dist/runner/{runner/web → web}/fake.d.ts +1 -2
- package/dist/runner/{runner/web → web}/fake.js +7 -7
- package/dist/runner/{runner/web → web}/index.d.ts +2 -2
- package/dist/runner/{runner/web → web}/index.js +1 -1
- package/dist/runner/{runner/web → web}/jsdom.d.ts +1 -2
- package/dist/runner/{runner/web → web}/jsdom.js +4 -4
- package/dist/test/context.d.ts +3 -5
- package/dist/test/context.js +22 -12
- package/dist/test/creator.d.ts +13 -12
- package/dist/test/creator.js +52 -43
- package/dist/test/tester.js +4 -1
- package/dist/type.d.ts +42 -11
- package/dist/type.js +7 -1
- package/package.json +5 -5
- package/dist/processor/basic.d.ts +0 -24
- package/dist/processor/basic.js +0 -147
- package/dist/processor/builtin.d.ts +0 -9
- package/dist/processor/builtin.js +0 -171
- package/dist/processor/cache.d.ts +0 -20
- package/dist/processor/cache.js +0 -131
- package/dist/processor/config.d.ts +0 -11
- package/dist/processor/config.js +0 -88
- package/dist/processor/defaults.d.ts +0 -30
- package/dist/processor/defaults.js +0 -72
- package/dist/processor/diagnostic.d.ts +0 -15
- package/dist/processor/diagnostic.js +0 -104
- package/dist/processor/diff.d.ts +0 -30
- package/dist/processor/diff.js +0 -140
- package/dist/processor/error.d.ts +0 -23
- package/dist/processor/error.js +0 -95
- package/dist/processor/hash.d.ts +0 -10
- package/dist/processor/hash.js +0 -65
- package/dist/processor/hook.d.ts +0 -44
- package/dist/processor/hook.js +0 -206
- package/dist/processor/hot-incremental.d.ts +0 -14
- package/dist/processor/hot-incremental.js +0 -43
- package/dist/processor/hot-step.d.ts +0 -18
- package/dist/processor/hot-step.js +0 -307
- package/dist/processor/hot.d.ts +0 -17
- package/dist/processor/hot.js +0 -147
- package/dist/processor/index.d.ts +0 -20
- package/dist/processor/index.js +0 -36
- package/dist/processor/multi.d.ts +0 -17
- package/dist/processor/multi.js +0 -73
- package/dist/processor/normal.d.ts +0 -12
- package/dist/processor/normal.js +0 -170
- package/dist/processor/simple.d.ts +0 -24
- package/dist/processor/simple.js +0 -51
- package/dist/processor/snapshot.d.ts +0 -12
- package/dist/processor/snapshot.js +0 -66
- package/dist/processor/stats-api.d.ts +0 -18
- package/dist/processor/stats-api.js +0 -48
- package/dist/processor/stats.d.ts +0 -18
- package/dist/processor/stats.js +0 -206
- package/dist/processor/treeshaking.d.ts +0 -10
- package/dist/processor/treeshaking.js +0 -33
- package/dist/processor/watch.d.ts +0 -30
- package/dist/processor/watch.js +0 -252
- package/dist/runner/basic.d.ts +0 -10
- package/dist/runner/basic.js +0 -64
- package/dist/runner/cache.d.ts +0 -5
- package/dist/runner/cache.js +0 -92
- package/dist/runner/hot.d.ts +0 -5
- package/dist/runner/hot.js +0 -91
- package/dist/runner/multiple.d.ts +0 -11
- package/dist/runner/multiple.js +0 -52
- package/dist/runner/runner/index.d.ts +0 -2
- package/dist/runner/runner/index.js +0 -18
- package/dist/runner/type.d.ts +0 -42
- package/dist/runner/type.js +0 -9
- package/dist/runner/watch.d.ts +0 -7
- package/dist/runner/watch.js +0 -71
- package/dist/test/simple.d.ts +0 -5
- package/dist/test/simple.js +0 -43
package/dist/case/builtin.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
+
import type { ECompilerType, ITestContext, TCompilerOptions } from "../type";
|
|
1
2
|
export declare function createBuiltinCase(name: string, src: string, dist: string): void;
|
|
3
|
+
export declare function defaultOptions<T extends ECompilerType.Rspack>(context: ITestContext): TCompilerOptions<T>;
|
package/dist/case/builtin.js
CHANGED
|
@@ -4,16 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createBuiltinCase = createBuiltinCase;
|
|
7
|
+
exports.defaultOptions = defaultOptions;
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const core_1 = require("@rspack/core");
|
|
10
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
|
+
const webpack_merge_1 = require("webpack-merge");
|
|
8
12
|
const helper_1 = require("../helper");
|
|
9
|
-
const processor_1 = require("../processor");
|
|
10
13
|
const creator_1 = require("../test/creator");
|
|
11
|
-
const
|
|
12
|
-
const FILTERS = {
|
|
13
|
-
"plugin-css": (file) => file.endsWith(".css"),
|
|
14
|
-
"plugin-css-modules": (file) => file.endsWith(".css") || ((0, helper_1.isJavaScript)(file) && !file.includes("runtime")),
|
|
15
|
-
"plugin-html": (file) => file.endsWith(".html")
|
|
16
|
-
};
|
|
14
|
+
const common_1 = require("./common");
|
|
17
15
|
const creator = new creator_1.BasicCaseCreator({
|
|
18
16
|
clean: true,
|
|
19
17
|
describe: false,
|
|
@@ -24,12 +22,24 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
24
22
|
const cat = node_path_1.default.basename(node_path_1.default.dirname(src));
|
|
25
23
|
const filter = FILTERS[cat];
|
|
26
24
|
return [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
{
|
|
26
|
+
config: async (context) => {
|
|
27
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
28
|
+
compiler.setOptions(defaultOptions(context));
|
|
29
|
+
},
|
|
30
|
+
compiler: async (context) => {
|
|
31
|
+
await (0, common_1.compiler)(context, name);
|
|
32
|
+
},
|
|
33
|
+
build: async (context) => {
|
|
34
|
+
await (0, common_1.build)(context, name);
|
|
35
|
+
},
|
|
36
|
+
run: async (env, context) => {
|
|
37
|
+
// no need to run, just check snapshot
|
|
38
|
+
},
|
|
39
|
+
check: async (env, context) => {
|
|
40
|
+
await (0, common_1.checkSnapshot)(env, context, name, "output.snap.txt", filter);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
33
43
|
];
|
|
34
44
|
},
|
|
35
45
|
concurrent: true
|
|
@@ -37,3 +47,153 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
37
47
|
function createBuiltinCase(name, src, dist) {
|
|
38
48
|
creator.create(name, src, dist);
|
|
39
49
|
}
|
|
50
|
+
function defaultOptions(context) {
|
|
51
|
+
let defaultOptions = {
|
|
52
|
+
entry: {
|
|
53
|
+
main: {
|
|
54
|
+
import: "./index"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
output: {
|
|
58
|
+
publicPath: "/",
|
|
59
|
+
path: context.getDist(),
|
|
60
|
+
filename: "[name].js",
|
|
61
|
+
chunkFilename: "[name].js",
|
|
62
|
+
chunkFormat: "array-push",
|
|
63
|
+
cssFilename: "[name].css",
|
|
64
|
+
cssChunkFilename: "[name].css",
|
|
65
|
+
assetModuleFilename: "[hash][ext][query]",
|
|
66
|
+
sourceMapFilename: "[file].map",
|
|
67
|
+
chunkLoadingGlobal: "webpackChunkwebpack",
|
|
68
|
+
chunkLoading: "jsonp",
|
|
69
|
+
uniqueName: "__rspack_test__",
|
|
70
|
+
enabledLibraryTypes: ["system"],
|
|
71
|
+
strictModuleErrorHandling: false,
|
|
72
|
+
iife: true,
|
|
73
|
+
module: false,
|
|
74
|
+
asyncChunks: true,
|
|
75
|
+
scriptType: false,
|
|
76
|
+
globalObject: "self",
|
|
77
|
+
importFunctionName: "import",
|
|
78
|
+
wasmLoading: "fetch",
|
|
79
|
+
webassemblyModuleFilename: "[hash].module.wasm",
|
|
80
|
+
workerChunkLoading: "import-scripts",
|
|
81
|
+
workerWasmLoading: "fetch"
|
|
82
|
+
},
|
|
83
|
+
module: {
|
|
84
|
+
rules: [
|
|
85
|
+
{
|
|
86
|
+
test: /\.json$/,
|
|
87
|
+
type: "json"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
test: /\.mjs$/,
|
|
91
|
+
type: "javascript/esm"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
test: /\.cjs$/,
|
|
95
|
+
type: "javascript/dynamic"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
test: /\.js$/,
|
|
99
|
+
type: "javascript/auto"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
test: /\.css$/,
|
|
103
|
+
type: "css"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
test: /\.wasm$/,
|
|
107
|
+
type: "webassembly/async"
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
node: {
|
|
112
|
+
__dirname: "mock",
|
|
113
|
+
__filename: "mock",
|
|
114
|
+
global: "warn"
|
|
115
|
+
},
|
|
116
|
+
optimization: {
|
|
117
|
+
runtimeChunk: {
|
|
118
|
+
name: "runtime"
|
|
119
|
+
},
|
|
120
|
+
minimize: false,
|
|
121
|
+
removeAvailableModules: true,
|
|
122
|
+
removeEmptyChunks: true,
|
|
123
|
+
moduleIds: "named",
|
|
124
|
+
chunkIds: "named",
|
|
125
|
+
sideEffects: false,
|
|
126
|
+
mangleExports: false,
|
|
127
|
+
usedExports: false,
|
|
128
|
+
concatenateModules: false,
|
|
129
|
+
nodeEnv: false
|
|
130
|
+
},
|
|
131
|
+
resolve: {
|
|
132
|
+
extensions: [
|
|
133
|
+
".js",
|
|
134
|
+
".jsx",
|
|
135
|
+
".ts",
|
|
136
|
+
".tsx",
|
|
137
|
+
".json",
|
|
138
|
+
".d.ts",
|
|
139
|
+
".css",
|
|
140
|
+
".wasm"
|
|
141
|
+
]
|
|
142
|
+
},
|
|
143
|
+
resolveLoader: {
|
|
144
|
+
extensions: [".js"]
|
|
145
|
+
},
|
|
146
|
+
experiments: {
|
|
147
|
+
css: true,
|
|
148
|
+
futureDefaults: true,
|
|
149
|
+
rspackFuture: {
|
|
150
|
+
bundlerInfo: {
|
|
151
|
+
force: false
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
devtool: false,
|
|
156
|
+
context: context.getSource(),
|
|
157
|
+
plugins: []
|
|
158
|
+
};
|
|
159
|
+
const testConfigFile = context.getSource("rspack.config.js");
|
|
160
|
+
if (fs_extra_1.default.existsSync(testConfigFile)) {
|
|
161
|
+
const caseOptions = require(testConfigFile);
|
|
162
|
+
if (caseOptions.entry) {
|
|
163
|
+
delete defaultOptions.entry;
|
|
164
|
+
}
|
|
165
|
+
defaultOptions = (0, webpack_merge_1.merge)(defaultOptions, caseOptions);
|
|
166
|
+
}
|
|
167
|
+
// TODO: remove builtin compatible code
|
|
168
|
+
const defineOptions = defaultOptions.builtins?.define;
|
|
169
|
+
if (defineOptions) {
|
|
170
|
+
defaultOptions.plugins.push(new core_1.rspack.DefinePlugin(defineOptions));
|
|
171
|
+
}
|
|
172
|
+
const provideOptions = defaultOptions.builtins?.provide;
|
|
173
|
+
if (provideOptions) {
|
|
174
|
+
defaultOptions.plugins.push(new core_1.rspack.ProvidePlugin(provideOptions));
|
|
175
|
+
}
|
|
176
|
+
const htmlOptions = defaultOptions.builtins?.html;
|
|
177
|
+
if (htmlOptions) {
|
|
178
|
+
if (Array.isArray(htmlOptions)) {
|
|
179
|
+
for (const item of htmlOptions) {
|
|
180
|
+
defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(item));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(htmlOptions));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
delete defaultOptions.builtins;
|
|
188
|
+
if (!global.printLogger) {
|
|
189
|
+
defaultOptions.infrastructureLogging = {
|
|
190
|
+
level: "error"
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
return defaultOptions;
|
|
194
|
+
}
|
|
195
|
+
const FILTERS = {
|
|
196
|
+
"plugin-css": (file) => file.endsWith(".css"),
|
|
197
|
+
"plugin-css-modules": (file) => file.endsWith(".css") || ((0, helper_1.isJavaScript)(file) && !file.includes("runtime")),
|
|
198
|
+
"plugin-html": (file) => file.endsWith(".html")
|
|
199
|
+
};
|
package/dist/case/cache.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ECompilerType, type TCompilerOptions } from "../type";
|
|
1
|
+
import { type ECompilerType, type TCompilerOptions } from "../type";
|
|
2
2
|
export declare function createCacheCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], temp: string): void;
|
package/dist/case/cache.js
CHANGED
|
@@ -1,11 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.createCacheCase = createCacheCase;
|
|
4
|
-
const
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const core_1 = __importDefault(require("@rspack/core"));
|
|
9
|
+
const helper_1 = require("../helper");
|
|
10
|
+
const hot_update_1 = require("../helper/hot-update");
|
|
11
|
+
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
5
12
|
const runner_1 = require("../runner");
|
|
6
13
|
const creator_1 = require("../test/creator");
|
|
7
14
|
const type_1 = require("../type");
|
|
8
|
-
const
|
|
15
|
+
const common_1 = require("./common");
|
|
16
|
+
const runner_2 = require("./runner");
|
|
17
|
+
const MAX_COMPILER_INDEX = 100;
|
|
18
|
+
function createCacheProcessor(name, src, temp, target) {
|
|
19
|
+
const updatePlugin = new hot_update_1.HotUpdatePlugin(src, temp);
|
|
20
|
+
return {
|
|
21
|
+
before: async (context) => {
|
|
22
|
+
await updatePlugin.initialize();
|
|
23
|
+
context.setValue(name, "hotUpdateContext", updatePlugin);
|
|
24
|
+
},
|
|
25
|
+
config: async (context) => {
|
|
26
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
27
|
+
let options = defaultOptions(context, temp, target);
|
|
28
|
+
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
|
+
overrideOptions(options, temp, target, updatePlugin);
|
|
30
|
+
compiler.setOptions(options);
|
|
31
|
+
},
|
|
32
|
+
compiler: async (context) => {
|
|
33
|
+
await (0, common_1.compiler)(context, name);
|
|
34
|
+
},
|
|
35
|
+
build: async (context) => {
|
|
36
|
+
await (0, common_1.build)(context, name);
|
|
37
|
+
},
|
|
38
|
+
run: async (env, context) => {
|
|
39
|
+
await (0, common_1.run)(env, context, name, context => findBundle(name, target, context));
|
|
40
|
+
},
|
|
41
|
+
check: async (env, context) => {
|
|
42
|
+
await (0, common_1.check)(env, context, name);
|
|
43
|
+
},
|
|
44
|
+
afterAll: async (context) => {
|
|
45
|
+
const updateIndex = updatePlugin.getUpdateIndex();
|
|
46
|
+
const totalUpdates = updatePlugin.getTotalUpdates();
|
|
47
|
+
if (updateIndex + 1 !== totalUpdates) {
|
|
48
|
+
throw new Error(`Should run all hot steps (${updateIndex + 1} / ${totalUpdates}): ${name}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
9
53
|
function getCreator(target) {
|
|
10
54
|
if (!creators.has(target)) {
|
|
11
55
|
creators.set(target, new creator_1.BasicCaseCreator({
|
|
@@ -13,16 +57,12 @@ function getCreator(target) {
|
|
|
13
57
|
describe: true,
|
|
14
58
|
target,
|
|
15
59
|
steps: ({ name, src, target, temp }) => [
|
|
16
|
-
|
|
17
|
-
name,
|
|
18
|
-
sourceDir: src,
|
|
19
|
-
tempDir: temp,
|
|
20
|
-
target: target,
|
|
21
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
22
|
-
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
23
|
-
})
|
|
60
|
+
createCacheProcessor(name, src, temp, target)
|
|
24
61
|
],
|
|
25
|
-
runner:
|
|
62
|
+
runner: {
|
|
63
|
+
key: (context, name, file) => name,
|
|
64
|
+
runner: createRunner
|
|
65
|
+
},
|
|
26
66
|
concurrent: true
|
|
27
67
|
}));
|
|
28
68
|
}
|
|
@@ -32,3 +72,162 @@ function createCacheCase(name, src, dist, target, temp) {
|
|
|
32
72
|
const creator = getCreator(target);
|
|
33
73
|
creator.create(name, src, dist, temp);
|
|
34
74
|
}
|
|
75
|
+
const creators = new Map();
|
|
76
|
+
function defaultOptions(context, temp, target) {
|
|
77
|
+
const options = {
|
|
78
|
+
context: temp,
|
|
79
|
+
mode: "production",
|
|
80
|
+
cache: true,
|
|
81
|
+
devtool: false,
|
|
82
|
+
output: {
|
|
83
|
+
path: context.getDist(),
|
|
84
|
+
filename: "bundle.js",
|
|
85
|
+
chunkFilename: "[name].chunk.[fullhash].js",
|
|
86
|
+
publicPath: "https://test.cases/path/",
|
|
87
|
+
library: { type: "commonjs2" }
|
|
88
|
+
},
|
|
89
|
+
optimization: {
|
|
90
|
+
moduleIds: "named",
|
|
91
|
+
emitOnErrors: true
|
|
92
|
+
},
|
|
93
|
+
target,
|
|
94
|
+
experiments: {
|
|
95
|
+
css: true,
|
|
96
|
+
rspackFuture: {
|
|
97
|
+
bundlerInfo: {
|
|
98
|
+
force: false
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
inlineConst: true,
|
|
102
|
+
lazyBarrel: true
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
options.plugins ??= [];
|
|
106
|
+
options.plugins.push(new core_1.default.HotModuleReplacementPlugin());
|
|
107
|
+
return options;
|
|
108
|
+
}
|
|
109
|
+
function overrideOptions(options, temp, target, updatePlugin) {
|
|
110
|
+
if (!options.entry) {
|
|
111
|
+
options.entry = "./index.js";
|
|
112
|
+
}
|
|
113
|
+
// rewrite context to temp dir
|
|
114
|
+
options.context = temp;
|
|
115
|
+
options.module ??= {};
|
|
116
|
+
for (const cssModuleType of ["css/auto", "css/module", "css"]) {
|
|
117
|
+
options.module.generator ??= {};
|
|
118
|
+
options.module.generator[cssModuleType] ??= {};
|
|
119
|
+
options.module.generator[cssModuleType].exportsOnly ??=
|
|
120
|
+
target === "async-node";
|
|
121
|
+
}
|
|
122
|
+
options.plugins ??= [];
|
|
123
|
+
options.plugins.push(updatePlugin);
|
|
124
|
+
if (!global.printLogger) {
|
|
125
|
+
options.infrastructureLogging = {
|
|
126
|
+
level: "error"
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function findBundle(name, target, context) {
|
|
131
|
+
const files = [];
|
|
132
|
+
const prefiles = [];
|
|
133
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
134
|
+
if (!compiler)
|
|
135
|
+
throw new Error("Compiler should exists when find bundle");
|
|
136
|
+
const stats = compiler.getStats();
|
|
137
|
+
if (!stats)
|
|
138
|
+
throw new Error("Stats should exists when find bundle");
|
|
139
|
+
const info = stats.toJson({ all: false, entrypoints: true });
|
|
140
|
+
if (target === "web" || target === "webworker") {
|
|
141
|
+
for (const file of info.entrypoints.main.assets) {
|
|
142
|
+
if ((0, helper_1.isJavaScript)(file.name)) {
|
|
143
|
+
files.push(file.name);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
prefiles.push(file.name);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const assets = info.entrypoints.main.assets.filter(s => (0, helper_1.isJavaScript)(s.name));
|
|
152
|
+
files.push(assets[assets.length - 1].name);
|
|
153
|
+
}
|
|
154
|
+
return [...prefiles, ...files];
|
|
155
|
+
}
|
|
156
|
+
function createRunner(context, name, file, env) {
|
|
157
|
+
const compiler = context.getCompiler(name);
|
|
158
|
+
const options = compiler.getOptions();
|
|
159
|
+
let compilerIndex = 0;
|
|
160
|
+
const testConfig = context.getTestConfig();
|
|
161
|
+
const source = context.getSource();
|
|
162
|
+
const dist = context.getDist();
|
|
163
|
+
const updatePlugin = context.getValue(name, "hotUpdateContext");
|
|
164
|
+
const getWebRunner = () => {
|
|
165
|
+
return new runner_1.WebRunner({
|
|
166
|
+
dom: context.getValue(name, "documentType") || type_1.EDocumentType.JSDOM,
|
|
167
|
+
env,
|
|
168
|
+
stats: (0, runner_2.cachedStats)(context, name),
|
|
169
|
+
cachable: false,
|
|
170
|
+
name: name,
|
|
171
|
+
runInNewContext: false,
|
|
172
|
+
testConfig: {
|
|
173
|
+
...testConfig,
|
|
174
|
+
moduleScope(ms, stats, options) {
|
|
175
|
+
const moduleScope = typeof testConfig.moduleScope === "function"
|
|
176
|
+
? testConfig.moduleScope(ms, stats, options)
|
|
177
|
+
: ms;
|
|
178
|
+
moduleScope.COMPILER_INDEX = compilerIndex;
|
|
179
|
+
moduleScope.NEXT_HMR = nextHmr;
|
|
180
|
+
moduleScope.NEXT_START = nextStart;
|
|
181
|
+
return moduleScope;
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
source,
|
|
185
|
+
dist,
|
|
186
|
+
compilerOptions: options
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const nextHmr = async (m, options) => {
|
|
190
|
+
await updatePlugin.goNext();
|
|
191
|
+
const stats = await compiler.build();
|
|
192
|
+
if (!stats) {
|
|
193
|
+
throw new Error("Should generate stats during build");
|
|
194
|
+
}
|
|
195
|
+
const jsonStats = stats.toJson({
|
|
196
|
+
// errorDetails: true
|
|
197
|
+
});
|
|
198
|
+
const compilerOptions = compiler.getOptions();
|
|
199
|
+
const updateIndex = updatePlugin.getUpdateIndex();
|
|
200
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error", compilerOptions);
|
|
201
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning", compilerOptions);
|
|
202
|
+
const updatedModules = await m.hot.check(options || true);
|
|
203
|
+
if (!updatedModules) {
|
|
204
|
+
throw new Error("No update available");
|
|
205
|
+
}
|
|
206
|
+
return jsonStats;
|
|
207
|
+
};
|
|
208
|
+
const nextStart = async () => {
|
|
209
|
+
await compiler.close();
|
|
210
|
+
compiler.createCompiler();
|
|
211
|
+
await updatePlugin.goNext();
|
|
212
|
+
const stats = await compiler.build();
|
|
213
|
+
if (!stats) {
|
|
214
|
+
throw new Error("Should generate stats during build");
|
|
215
|
+
}
|
|
216
|
+
const jsonStats = stats.toJson({
|
|
217
|
+
// errorDetails: true
|
|
218
|
+
});
|
|
219
|
+
const compilerOptions = compiler.getOptions();
|
|
220
|
+
const updateIndex = updatePlugin.getUpdateIndex();
|
|
221
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error", compilerOptions);
|
|
222
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning", compilerOptions);
|
|
223
|
+
env.it(`NEXT_START run with compilerIndex==${compilerIndex + 1}`, async () => {
|
|
224
|
+
if (compilerIndex > MAX_COMPILER_INDEX) {
|
|
225
|
+
throw new Error("NEXT_START has been called more than the maximum times");
|
|
226
|
+
}
|
|
227
|
+
compilerIndex++;
|
|
228
|
+
return getWebRunner().run(file);
|
|
229
|
+
});
|
|
230
|
+
return jsonStats;
|
|
231
|
+
};
|
|
232
|
+
return getWebRunner();
|
|
233
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ECompilerType, type ITestCompilerManager, type ITestContext, type ITestEnv, type TCompiler, type TCompilerOptions } from "../type";
|
|
2
|
+
export declare function getCompiler<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string): ITestCompilerManager<T>;
|
|
3
|
+
export declare function config<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, configFiles: string[], defaultOptions?: TCompilerOptions<T>): Promise<TCompilerOptions<T>>;
|
|
4
|
+
export declare function compiler<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string): Promise<TCompiler<T>>;
|
|
5
|
+
export declare function build<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string): Promise<TCompiler<T>>;
|
|
6
|
+
export declare function run<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string, findBundle: (context: ITestContext, options: TCompilerOptions<T>) => string[] | string | void): Promise<void>;
|
|
7
|
+
export declare function check<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string): Promise<void>;
|
|
8
|
+
export declare function checkSnapshot<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string, snapshot: string, filter?: (file: string) => boolean): Promise<void>;
|
|
9
|
+
export declare function findMultiCompilerBundle<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, multiFindBundle: (index: number, context: ITestContext, options: TCompilerOptions<T>) => string[] | string | void): string[];
|
|
10
|
+
export declare function configMultiCompiler<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, configFiles: string[], defaultOptions: (index: number, context: ITestContext) => TCompilerOptions<T>, overrideOptions: (index: number, context: ITestContext, options: TCompilerOptions<T>) => void): void;
|