@rspack-canary/test-tools 1.5.6-canary-e598f284-20250921173624 → 1.5.7-canary-a3406c0a-20250922173625
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 +153 -2
- package/dist/case/cache.js +115 -9
- package/dist/case/compiler.js +1 -1
- package/dist/case/config.d.ts +4 -1
- package/dist/case/config.js +80 -2
- package/dist/case/defaults.d.ts +11 -3
- package/dist/case/defaults.js +47 -2
- package/dist/case/diagnostic.d.ts +6 -0
- package/dist/case/diagnostic.js +109 -9
- package/dist/case/error.d.ts +2 -2
- package/dist/case/error.js +79 -2
- package/dist/case/hash.js +61 -7
- package/dist/case/hook.d.ts +35 -3
- package/dist/case/hook.js +185 -4
- package/dist/case/hot-step.d.ts +1 -1
- package/dist/case/hot-step.js +302 -8
- package/dist/case/hot.d.ts +8 -1
- package/dist/case/hot.js +147 -7
- package/dist/case/incremental.js +21 -8
- package/dist/case/index.d.ts +20 -20
- package/dist/case/index.js +44 -34
- package/dist/case/normal.js +152 -5
- package/dist/case/serial.js +7 -3
- package/dist/case/stats-api.d.ts +0 -5
- package/dist/case/stats-api.js +33 -2
- package/dist/case/stats-output.js +200 -10
- package/dist/case/treeshaking.js +19 -3
- package/dist/helper/plugins/hot-update.d.ts +2 -2
- package/dist/processor/basic.d.ts +4 -1
- package/dist/processor/basic.js +20 -10
- package/dist/processor/index.d.ts +0 -14
- package/dist/processor/index.js +0 -14
- package/dist/processor/multi.d.ts +3 -1
- package/dist/processor/multi.js +2 -0
- package/dist/processor/simple.d.ts +1 -1
- package/dist/processor/simple.js +4 -4
- package/dist/processor/snapshot.js +4 -3
- package/dist/type.d.ts +1 -1
- package/package.json +4 -4
- 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/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/normal.d.ts +0 -12
- package/dist/processor/normal.js +0 -170
- 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/case/index.js
CHANGED
|
@@ -1,36 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
3
|
+
exports.createWatchCase = exports.createTreeShakingCase = exports.createStatsOutputCase = exports.createStatsAPICase = exports.createSerialCase = exports.createNormalCase = exports.createHotNormalCase = exports.createNativeWatcher = exports.createWatchIncrementalCase = exports.createHotIncrementalCase = exports.createHotStepCase = exports.createHotCase = exports.createHookCase = exports.createHashCase = exports.createErrorCase = exports.createDiffCase = exports.createDiagnosticCase = exports.getRspackDefaultConfig = exports.createDefaultsCase = exports.createConfigCase = exports.createCompilerCase = exports.createCacheCase = exports.createBuiltinCase = void 0;
|
|
4
|
+
var builtin_1 = require("./builtin");
|
|
5
|
+
Object.defineProperty(exports, "createBuiltinCase", { enumerable: true, get: function () { return builtin_1.createBuiltinCase; } });
|
|
6
|
+
var cache_1 = require("./cache");
|
|
7
|
+
Object.defineProperty(exports, "createCacheCase", { enumerable: true, get: function () { return cache_1.createCacheCase; } });
|
|
8
|
+
var compiler_1 = require("./compiler");
|
|
9
|
+
Object.defineProperty(exports, "createCompilerCase", { enumerable: true, get: function () { return compiler_1.createCompilerCase; } });
|
|
10
|
+
var config_1 = require("./config");
|
|
11
|
+
Object.defineProperty(exports, "createConfigCase", { enumerable: true, get: function () { return config_1.createConfigCase; } });
|
|
12
|
+
var defaults_1 = require("./defaults");
|
|
13
|
+
Object.defineProperty(exports, "createDefaultsCase", { enumerable: true, get: function () { return defaults_1.createDefaultsCase; } });
|
|
14
|
+
Object.defineProperty(exports, "getRspackDefaultConfig", { enumerable: true, get: function () { return defaults_1.getRspackDefaultConfig; } });
|
|
15
|
+
var diagnostic_1 = require("./diagnostic");
|
|
16
|
+
Object.defineProperty(exports, "createDiagnosticCase", { enumerable: true, get: function () { return diagnostic_1.createDiagnosticCase; } });
|
|
17
|
+
var diff_1 = require("./diff");
|
|
18
|
+
Object.defineProperty(exports, "createDiffCase", { enumerable: true, get: function () { return diff_1.createDiffCase; } });
|
|
19
|
+
var error_1 = require("./error");
|
|
20
|
+
Object.defineProperty(exports, "createErrorCase", { enumerable: true, get: function () { return error_1.createErrorCase; } });
|
|
21
|
+
var hash_1 = require("./hash");
|
|
22
|
+
Object.defineProperty(exports, "createHashCase", { enumerable: true, get: function () { return hash_1.createHashCase; } });
|
|
23
|
+
var hook_1 = require("./hook");
|
|
24
|
+
Object.defineProperty(exports, "createHookCase", { enumerable: true, get: function () { return hook_1.createHookCase; } });
|
|
25
|
+
var hot_1 = require("./hot");
|
|
26
|
+
Object.defineProperty(exports, "createHotCase", { enumerable: true, get: function () { return hot_1.createHotCase; } });
|
|
27
|
+
var hot_step_1 = require("./hot-step");
|
|
28
|
+
Object.defineProperty(exports, "createHotStepCase", { enumerable: true, get: function () { return hot_step_1.createHotStepCase; } });
|
|
29
|
+
var incremental_1 = require("./incremental");
|
|
30
|
+
Object.defineProperty(exports, "createHotIncrementalCase", { enumerable: true, get: function () { return incremental_1.createHotIncrementalCase; } });
|
|
31
|
+
Object.defineProperty(exports, "createWatchIncrementalCase", { enumerable: true, get: function () { return incremental_1.createWatchIncrementalCase; } });
|
|
32
|
+
var native_watcher_1 = require("./native-watcher");
|
|
33
|
+
Object.defineProperty(exports, "createNativeWatcher", { enumerable: true, get: function () { return native_watcher_1.createNativeWatcher; } });
|
|
34
|
+
var normal_1 = require("./normal");
|
|
35
|
+
Object.defineProperty(exports, "createHotNormalCase", { enumerable: true, get: function () { return normal_1.createHotNormalCase; } });
|
|
36
|
+
Object.defineProperty(exports, "createNormalCase", { enumerable: true, get: function () { return normal_1.createNormalCase; } });
|
|
37
|
+
var serial_1 = require("./serial");
|
|
38
|
+
Object.defineProperty(exports, "createSerialCase", { enumerable: true, get: function () { return serial_1.createSerialCase; } });
|
|
39
|
+
var stats_api_1 = require("./stats-api");
|
|
40
|
+
Object.defineProperty(exports, "createStatsAPICase", { enumerable: true, get: function () { return stats_api_1.createStatsAPICase; } });
|
|
41
|
+
var stats_output_1 = require("./stats-output");
|
|
42
|
+
Object.defineProperty(exports, "createStatsOutputCase", { enumerable: true, get: function () { return stats_output_1.createStatsOutputCase; } });
|
|
43
|
+
var treeshaking_1 = require("./treeshaking");
|
|
44
|
+
Object.defineProperty(exports, "createTreeShakingCase", { enumerable: true, get: function () { return treeshaking_1.createTreeShakingCase; } });
|
|
45
|
+
var watch_1 = require("./watch");
|
|
46
|
+
Object.defineProperty(exports, "createWatchCase", { enumerable: true, get: function () { return watch_1.createWatchCase; } });
|
package/dist/case/normal.js
CHANGED
|
@@ -5,24 +5,171 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createNormalCase = createNormalCase;
|
|
7
7
|
exports.createHotNormalCase = createHotNormalCase;
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
10
|
const core_1 = require("@rspack/core");
|
|
10
|
-
const
|
|
11
|
+
const processor_1 = require("../processor");
|
|
11
12
|
const runner_1 = require("../runner");
|
|
12
13
|
const creator_1 = require("../test/creator");
|
|
13
14
|
const type_1 = require("../type");
|
|
14
15
|
const NORMAL_CASES_ROOT = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/normalCases");
|
|
16
|
+
function findBundle(context, options) {
|
|
17
|
+
const testConfig = context.getTestConfig();
|
|
18
|
+
if (typeof testConfig.findBundle === "function") {
|
|
19
|
+
return testConfig.findBundle(0, options);
|
|
20
|
+
}
|
|
21
|
+
const filename = options.output?.filename;
|
|
22
|
+
return typeof filename === "string" ? filename : undefined;
|
|
23
|
+
}
|
|
24
|
+
function defaultOptions(context, compilerOptions) {
|
|
25
|
+
let testConfig = {};
|
|
26
|
+
const testConfigPath = node_path_1.default.join(context.getSource(), "test.config.js");
|
|
27
|
+
if (node_fs_1.default.existsSync(testConfigPath)) {
|
|
28
|
+
testConfig = require(testConfigPath);
|
|
29
|
+
}
|
|
30
|
+
const TerserPlugin = require("terser-webpack-plugin");
|
|
31
|
+
const terserForTesting = new TerserPlugin({
|
|
32
|
+
parallel: false
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
amd: {},
|
|
36
|
+
context: NORMAL_CASES_ROOT,
|
|
37
|
+
entry: `./${node_path_1.default.relative(NORMAL_CASES_ROOT, context.getSource())}/`,
|
|
38
|
+
target: compilerOptions?.target || "async-node",
|
|
39
|
+
devtool: compilerOptions?.devtool,
|
|
40
|
+
mode: compilerOptions?.mode || "none",
|
|
41
|
+
optimization: compilerOptions?.mode
|
|
42
|
+
? {
|
|
43
|
+
// emitOnErrors: true,
|
|
44
|
+
minimizer: [terserForTesting],
|
|
45
|
+
...testConfig.optimization
|
|
46
|
+
}
|
|
47
|
+
: {
|
|
48
|
+
removeAvailableModules: true,
|
|
49
|
+
removeEmptyChunks: true,
|
|
50
|
+
mergeDuplicateChunks: true,
|
|
51
|
+
// CHANGE: rspack does not support `flagIncludedChunks` yet.
|
|
52
|
+
// flagIncludedChunks: true,
|
|
53
|
+
sideEffects: true,
|
|
54
|
+
providedExports: true,
|
|
55
|
+
usedExports: true,
|
|
56
|
+
mangleExports: true,
|
|
57
|
+
// CHANGE: rspack does not support `emitOnErrors` yet.
|
|
58
|
+
// emitOnErrors: true,
|
|
59
|
+
concatenateModules: !!testConfig?.optimization?.concatenateModules,
|
|
60
|
+
innerGraph: true,
|
|
61
|
+
// CHANGE: size is not supported yet
|
|
62
|
+
// moduleIds: "size",
|
|
63
|
+
// chunkIds: "size",
|
|
64
|
+
moduleIds: "named",
|
|
65
|
+
chunkIds: "named",
|
|
66
|
+
minimizer: [terserForTesting],
|
|
67
|
+
...compilerOptions?.optimization
|
|
68
|
+
},
|
|
69
|
+
// CHANGE: rspack does not support `performance` yet.
|
|
70
|
+
// performance: {
|
|
71
|
+
// hints: false
|
|
72
|
+
// },
|
|
73
|
+
node: {
|
|
74
|
+
__dirname: "mock",
|
|
75
|
+
__filename: "mock"
|
|
76
|
+
},
|
|
77
|
+
cache: compilerOptions?.cache && {
|
|
78
|
+
// cacheDirectory,
|
|
79
|
+
...compilerOptions.cache
|
|
80
|
+
},
|
|
81
|
+
output: {
|
|
82
|
+
pathinfo: "verbose",
|
|
83
|
+
path: context.getDist(),
|
|
84
|
+
filename: compilerOptions?.module ? "bundle.mjs" : "bundle.js"
|
|
85
|
+
},
|
|
86
|
+
resolve: {
|
|
87
|
+
modules: ["web_modules", "node_modules"],
|
|
88
|
+
mainFields: ["webpack", "browser", "web", "browserify", "main"],
|
|
89
|
+
aliasFields: ["browser"],
|
|
90
|
+
extensions: [".webpack.js", ".web.js", ".js", ".json"]
|
|
91
|
+
},
|
|
92
|
+
resolveLoader: {
|
|
93
|
+
modules: ["web_loaders", "web_modules", "node_loaders", "node_modules"],
|
|
94
|
+
mainFields: ["webpackLoader", "webLoader", "loader", "main"],
|
|
95
|
+
extensions: [".webpack-loader.js", ".web-loader.js", ".loader.js", ".js"]
|
|
96
|
+
},
|
|
97
|
+
module: {
|
|
98
|
+
rules: [
|
|
99
|
+
{
|
|
100
|
+
test: /\.coffee$/,
|
|
101
|
+
loader: "coffee-loader"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
test: /\.pug/,
|
|
105
|
+
loader: "@webdiscus/pug-loader"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
test: /\.wat$/i,
|
|
109
|
+
loader: "wast-loader",
|
|
110
|
+
type: "webassembly/async"
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
plugins: (compilerOptions?.plugins || [])
|
|
115
|
+
.concat(testConfig.plugins || [])
|
|
116
|
+
.concat(function () {
|
|
117
|
+
this.hooks.compilation.tap("TestCasesTest", compilation => {
|
|
118
|
+
const hooks = [
|
|
119
|
+
// CHANGE: the following hooks are not supported yet, so comment it out
|
|
120
|
+
// "optimize",
|
|
121
|
+
// "optimizeModules",
|
|
122
|
+
// "optimizeChunks",
|
|
123
|
+
// "afterOptimizeTree",
|
|
124
|
+
// "afterOptimizeAssets"
|
|
125
|
+
];
|
|
126
|
+
for (const hook of hooks) {
|
|
127
|
+
compilation.hooks[hook].tap("TestCasesTest", () => compilation.checkConstraints());
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}),
|
|
131
|
+
experiments: {
|
|
132
|
+
css: false,
|
|
133
|
+
rspackFuture: {
|
|
134
|
+
bundlerInfo: {
|
|
135
|
+
force: false
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
asyncWebAssembly: true,
|
|
139
|
+
topLevelAwait: true,
|
|
140
|
+
inlineConst: true,
|
|
141
|
+
lazyBarrel: true,
|
|
142
|
+
// CHANGE: rspack does not support `backCompat` yet.
|
|
143
|
+
// backCompat: false,
|
|
144
|
+
// CHANGE: Rspack enables `css` by default.
|
|
145
|
+
// Turning off here to fallback to webpack's default css processing logic.
|
|
146
|
+
...(compilerOptions?.module ? { outputModule: true } : {})
|
|
147
|
+
}
|
|
148
|
+
// infrastructureLogging: compilerOptions?.cache && {
|
|
149
|
+
// debug: true,
|
|
150
|
+
// console: createLogger(infraStructureLog)
|
|
151
|
+
// }
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function overrideOptions(context, options) {
|
|
155
|
+
if (!global.printLogger) {
|
|
156
|
+
options.infrastructureLogging = {
|
|
157
|
+
level: "error"
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
15
161
|
const createCaseOptions = (hot) => {
|
|
16
162
|
return {
|
|
17
163
|
clean: true,
|
|
18
164
|
describe: false,
|
|
19
165
|
steps: ({ name }) => [
|
|
20
|
-
new
|
|
166
|
+
new processor_1.BasicProcessor({
|
|
21
167
|
name,
|
|
22
|
-
|
|
23
|
-
|
|
168
|
+
findBundle,
|
|
169
|
+
defaultOptions: context => defaultOptions(context, {
|
|
24
170
|
plugins: hot ? [new core_1.HotModuleReplacementPlugin()] : []
|
|
25
|
-
},
|
|
171
|
+
}),
|
|
172
|
+
overrideOptions,
|
|
26
173
|
runable: true,
|
|
27
174
|
compilerType: type_1.ECompilerType.Rspack
|
|
28
175
|
})
|
package/dist/case/serial.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSerialCase = createSerialCase;
|
|
4
|
-
const
|
|
4
|
+
const processor_1 = require("../processor");
|
|
5
5
|
const runner_1 = require("../runner");
|
|
6
6
|
const creator_1 = require("../test/creator");
|
|
7
7
|
const type_1 = require("../type");
|
|
8
|
+
const config_1 = require("./config");
|
|
8
9
|
const creator = new creator_1.BasicCaseCreator({
|
|
9
10
|
clean: true,
|
|
10
11
|
describe: false,
|
|
@@ -20,11 +21,14 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
20
21
|
};
|
|
21
22
|
},
|
|
22
23
|
steps: ({ name }) => [
|
|
23
|
-
new
|
|
24
|
+
new processor_1.MultiTaskProcessor({
|
|
24
25
|
name,
|
|
25
26
|
runable: true,
|
|
26
27
|
compilerType: type_1.ECompilerType.Rspack,
|
|
27
|
-
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
28
|
+
configFiles: ["rspack.config.js", "webpack.config.js"],
|
|
29
|
+
defaultOptions: config_1.defaultOptions,
|
|
30
|
+
overrideOptions: config_1.overrideOptions,
|
|
31
|
+
findBundle: config_1.findBundle
|
|
28
32
|
})
|
|
29
33
|
],
|
|
30
34
|
runner: runner_1.MultipleRunnerFactory
|
package/dist/case/stats-api.d.ts
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import { type IStatsAPIProcessorOptions } from "../processor";
|
|
2
|
-
import { ECompilerType } from "../type";
|
|
3
|
-
export type TStatsAPICaseConfig = Omit<IStatsAPIProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
|
|
4
|
-
description: string;
|
|
5
|
-
};
|
|
6
1
|
export declare function createStatsAPICase(name: string, src: string, dist: string, testConfig: string): void;
|
package/dist/case/stats-api.js
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStatsAPICase = createStatsAPICase;
|
|
4
|
+
const memfs_1 = require("memfs");
|
|
4
5
|
const processor_1 = require("../processor");
|
|
5
6
|
const simple_1 = require("../test/simple");
|
|
6
7
|
const type_1 = require("../type");
|
|
7
8
|
let addedSerializer = false;
|
|
9
|
+
function options(context, custom) {
|
|
10
|
+
const res = (custom?.(context) ||
|
|
11
|
+
{});
|
|
12
|
+
res.experiments ??= {};
|
|
13
|
+
res.experiments.css ??= true;
|
|
14
|
+
res.experiments.rspackFuture ??= {};
|
|
15
|
+
res.experiments.rspackFuture.bundlerInfo ??= {};
|
|
16
|
+
res.experiments.rspackFuture.bundlerInfo.force ??= false;
|
|
17
|
+
if (!global.printLogger) {
|
|
18
|
+
res.infrastructureLogging = {
|
|
19
|
+
level: "error"
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return res;
|
|
23
|
+
}
|
|
24
|
+
async function compiler(context, compiler, custom) {
|
|
25
|
+
if (custom) {
|
|
26
|
+
await custom(context, compiler);
|
|
27
|
+
}
|
|
28
|
+
if (compiler) {
|
|
29
|
+
compiler.outputFileSystem = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function check(env, context, compiler, stats, custom) {
|
|
33
|
+
env.expect(typeof stats).toBe("object");
|
|
34
|
+
await custom?.(stats, compiler);
|
|
35
|
+
}
|
|
8
36
|
function createStatsAPICase(name, src, dist, testConfig) {
|
|
9
37
|
if (!addedSerializer) {
|
|
10
38
|
addedSerializer = true;
|
|
@@ -12,10 +40,13 @@ function createStatsAPICase(name, src, dist, testConfig) {
|
|
|
12
40
|
const caseConfig = require(testConfig);
|
|
13
41
|
const runner = (0, simple_1.getSimpleProcessorRunner)(src, dist);
|
|
14
42
|
it(caseConfig.description, async () => {
|
|
15
|
-
await runner(name, new processor_1.
|
|
43
|
+
await runner(name, new processor_1.SimpleTaskProcessor({
|
|
16
44
|
name: name,
|
|
17
45
|
compilerType: type_1.ECompilerType.Rspack,
|
|
18
|
-
|
|
46
|
+
options: context => options(context, caseConfig.options),
|
|
47
|
+
compiler: (context, c) => compiler(context, c, caseConfig.compiler),
|
|
48
|
+
build: caseConfig.build,
|
|
49
|
+
check: (env, context, compiler, stats) => check(env, context, compiler, stats, caseConfig.check)
|
|
19
50
|
}));
|
|
20
51
|
});
|
|
21
52
|
}
|
|
@@ -1,21 +1,211 @@
|
|
|
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.createStatsOutputCase = createStatsOutputCase;
|
|
4
|
-
const
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const placeholder_1 = require("../helper/expect/placeholder");
|
|
10
|
+
const captureStdio_1 = __importDefault(require("../helper/legacy/captureStdio"));
|
|
11
|
+
const processor_1 = require("../processor");
|
|
5
12
|
const creator_1 = require("../test/creator");
|
|
6
13
|
const type_1 = require("../type");
|
|
14
|
+
const REG_ERROR_CASE = /error$/;
|
|
15
|
+
function defaultOptions(index, context) {
|
|
16
|
+
if (fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), "rspack.config.js"))) {
|
|
17
|
+
return {
|
|
18
|
+
experiments: {
|
|
19
|
+
css: true,
|
|
20
|
+
rspackFuture: {
|
|
21
|
+
bundlerInfo: {
|
|
22
|
+
force: false
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
context: context.getSource(),
|
|
30
|
+
mode: "development",
|
|
31
|
+
entry: "./index.js",
|
|
32
|
+
output: {
|
|
33
|
+
filename: "bundle.js",
|
|
34
|
+
path: context.getDist()
|
|
35
|
+
},
|
|
36
|
+
optimization: {
|
|
37
|
+
minimize: false
|
|
38
|
+
},
|
|
39
|
+
experiments: {
|
|
40
|
+
css: true,
|
|
41
|
+
rspackFuture: {
|
|
42
|
+
bundlerInfo: {
|
|
43
|
+
force: false
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
inlineConst: true,
|
|
47
|
+
lazyBarrel: true
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function overrideOptions(index, context, options) {
|
|
52
|
+
if (!options.context)
|
|
53
|
+
options.context = context.getSource();
|
|
54
|
+
if (!options.output)
|
|
55
|
+
options.output = options.output || {};
|
|
56
|
+
if (!options.output.path)
|
|
57
|
+
options.output.path = context.getDist();
|
|
58
|
+
if (!options.plugins)
|
|
59
|
+
options.plugins = [];
|
|
60
|
+
if (!options.optimization)
|
|
61
|
+
options.optimization = {};
|
|
62
|
+
if (options.optimization.minimize === undefined) {
|
|
63
|
+
options.optimization.minimize = false;
|
|
64
|
+
}
|
|
65
|
+
if (!global.printLogger) {
|
|
66
|
+
options.infrastructureLogging = {
|
|
67
|
+
level: "error"
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
class RspackStats {
|
|
72
|
+
constructor(value) {
|
|
73
|
+
this.value = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function createStatsProcessor(name) {
|
|
77
|
+
const writeStatsOuptut = false;
|
|
78
|
+
const snapshotName = "stats.txt";
|
|
79
|
+
const processor = new processor_1.MultiTaskProcessor({
|
|
80
|
+
name,
|
|
81
|
+
compilerType: type_1.ECompilerType.Rspack,
|
|
82
|
+
configFiles: ["rspack.config.js", "webpack.config.js"],
|
|
83
|
+
runable: false,
|
|
84
|
+
defaultOptions: (index, context) => defaultOptions(index, context),
|
|
85
|
+
overrideOptions: (index, context, options) => overrideOptions(index, context, options),
|
|
86
|
+
async check(env, context, compiler, stats) {
|
|
87
|
+
if (!stats || !compiler)
|
|
88
|
+
return;
|
|
89
|
+
for (const compilation of []
|
|
90
|
+
.concat(stats.stats || stats)
|
|
91
|
+
.map((s) => s.compilation)) {
|
|
92
|
+
compilation.logging.delete("webpack.Compilation.ModuleProfile");
|
|
93
|
+
}
|
|
94
|
+
if (REG_ERROR_CASE.test(name)) {
|
|
95
|
+
env.expect(stats.hasErrors()).toBe(true);
|
|
96
|
+
}
|
|
97
|
+
else if (stats.hasErrors()) {
|
|
98
|
+
throw new Error(stats.toString({
|
|
99
|
+
all: false,
|
|
100
|
+
errors: true
|
|
101
|
+
// errorStack: true,
|
|
102
|
+
// errorDetails: true
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
else if (writeStatsOuptut) {
|
|
106
|
+
fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
|
|
107
|
+
preset: "verbose",
|
|
108
|
+
// context: context.getSource(),
|
|
109
|
+
colors: false
|
|
110
|
+
}), "utf-8");
|
|
111
|
+
}
|
|
112
|
+
let toStringOptions = {
|
|
113
|
+
context: context.getSource(),
|
|
114
|
+
colors: false
|
|
115
|
+
};
|
|
116
|
+
let hasColorSetting = false;
|
|
117
|
+
if (typeof compiler.options.stats !== "undefined") {
|
|
118
|
+
toStringOptions = compiler.options.stats;
|
|
119
|
+
if (toStringOptions === null || typeof toStringOptions !== "object")
|
|
120
|
+
toStringOptions = { preset: toStringOptions };
|
|
121
|
+
if (!toStringOptions.context)
|
|
122
|
+
toStringOptions.context = context.getSource();
|
|
123
|
+
hasColorSetting = typeof toStringOptions.colors !== "undefined";
|
|
124
|
+
}
|
|
125
|
+
if (Array.isArray(compiler.options) && !toStringOptions.children) {
|
|
126
|
+
toStringOptions.children = compiler.options.map(o => o.stats);
|
|
127
|
+
}
|
|
128
|
+
// mock timestamps
|
|
129
|
+
for (const { compilation: s } of [].concat(stats.stats || stats)) {
|
|
130
|
+
env.expect(s.startTime).toBeGreaterThan(0);
|
|
131
|
+
env.expect(s.endTime).toBeGreaterThan(0);
|
|
132
|
+
s.endTime = new Date("04/20/1970, 12:42:42 PM").getTime();
|
|
133
|
+
s.startTime = s.endTime - 1234;
|
|
134
|
+
}
|
|
135
|
+
let actual = stats.toString(toStringOptions);
|
|
136
|
+
env.expect(typeof actual).toBe("string");
|
|
137
|
+
actual = stderr.toString() + actual;
|
|
138
|
+
if (!hasColorSetting) {
|
|
139
|
+
actual = actual
|
|
140
|
+
.replace(/\u001b\[[0-9;]*m/g, "")
|
|
141
|
+
// CHANGE: The time unit display in Rspack is second
|
|
142
|
+
.replace(/[.0-9]+(\s?s)/g, "X$1")
|
|
143
|
+
// CHANGE: Replace bundle size, since bundle sizes may differ between platforms
|
|
144
|
+
.replace(/[0-9]+\.?[0-9]+ KiB/g, "xx KiB");
|
|
145
|
+
}
|
|
146
|
+
const snapshotPath = node_path_1.default.isAbsolute(snapshotName)
|
|
147
|
+
? snapshotName
|
|
148
|
+
: node_path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshotName}`);
|
|
149
|
+
env.expect(new RspackStats(actual)).toMatchFileSnapshot(snapshotPath);
|
|
150
|
+
const testConfig = context.getTestConfig();
|
|
151
|
+
if (typeof testConfig?.validate === "function") {
|
|
152
|
+
testConfig.validate(stats, stderr.toString());
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
async compiler(context, compiler) {
|
|
156
|
+
const compilers = compiler.compilers
|
|
157
|
+
? compiler.compilers
|
|
158
|
+
: [compiler];
|
|
159
|
+
for (const compiler of compilers) {
|
|
160
|
+
if (!compiler.inputFileSystem) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const ifs = compiler.inputFileSystem;
|
|
164
|
+
const inputFileSystem = Object.create(ifs);
|
|
165
|
+
compiler.inputFileSystem = inputFileSystem;
|
|
166
|
+
inputFileSystem.readFile = (...args) => {
|
|
167
|
+
const callback = args.pop();
|
|
168
|
+
ifs.readFile.apply(ifs, args.concat([
|
|
169
|
+
(err, result) => {
|
|
170
|
+
if (err)
|
|
171
|
+
return callback(err);
|
|
172
|
+
if (!/\.(js|json|txt)$/.test(args[0]))
|
|
173
|
+
return callback(null, result);
|
|
174
|
+
callback(null, (0, placeholder_1.normalizePlaceholder)(result.toString("utf-8")));
|
|
175
|
+
}
|
|
176
|
+
]));
|
|
177
|
+
};
|
|
178
|
+
// CHANGE: The checkConstraints() function is currently not implemented in rspack
|
|
179
|
+
// compiler.hooks.compilation.tap("StatsTestCasesTest", compilation => {
|
|
180
|
+
// [
|
|
181
|
+
// "optimize",
|
|
182
|
+
// "optimizeModules",
|
|
183
|
+
// "optimizeChunks",
|
|
184
|
+
// "afterOptimizeTree",
|
|
185
|
+
// "afterOptimizeAssets",
|
|
186
|
+
// "beforeHash"
|
|
187
|
+
// ].forEach(hook => {
|
|
188
|
+
// compilation.hooks[hook].tap("TestCasesTest", () =>
|
|
189
|
+
// compilation.checkConstraints()
|
|
190
|
+
// );
|
|
191
|
+
// });
|
|
192
|
+
// });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
let stderr;
|
|
197
|
+
processor.before = async (context) => {
|
|
198
|
+
stderr = (0, captureStdio_1.default)(process.stderr, true);
|
|
199
|
+
};
|
|
200
|
+
processor.after = async (context) => {
|
|
201
|
+
stderr.restore();
|
|
202
|
+
};
|
|
203
|
+
return processor;
|
|
204
|
+
}
|
|
7
205
|
const creator = new creator_1.BasicCaseCreator({
|
|
8
206
|
clean: true,
|
|
9
207
|
describe: false,
|
|
10
|
-
steps: ({ name }) => [
|
|
11
|
-
new stats_1.StatsProcessor({
|
|
12
|
-
name,
|
|
13
|
-
snapshotName: "stats.txt",
|
|
14
|
-
writeStatsOuptut: false,
|
|
15
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
16
|
-
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
17
|
-
})
|
|
18
|
-
],
|
|
208
|
+
steps: ({ name }) => [createStatsProcessor(name)],
|
|
19
209
|
description: () => "should print correct stats for"
|
|
20
210
|
});
|
|
21
211
|
function createStatsOutputCase(name, src, dist) {
|
package/dist/case/treeshaking.js
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTreeShakingCase = createTreeShakingCase;
|
|
4
|
-
const
|
|
4
|
+
const processor_1 = require("../processor");
|
|
5
5
|
const creator_1 = require("../test/creator");
|
|
6
6
|
const type_1 = require("../type");
|
|
7
|
+
const builtin_1 = require("./builtin");
|
|
8
|
+
function overrideOptions(context, options) {
|
|
9
|
+
options.target = options.target || ["web", "es2022"];
|
|
10
|
+
options.optimization ??= {};
|
|
11
|
+
options.optimization.providedExports = true;
|
|
12
|
+
options.optimization.innerGraph = true;
|
|
13
|
+
options.optimization.usedExports = true;
|
|
14
|
+
if (!global.printLogger) {
|
|
15
|
+
options.infrastructureLogging = {
|
|
16
|
+
level: "error"
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
7
20
|
const creator = new creator_1.BasicCaseCreator({
|
|
8
21
|
clean: true,
|
|
9
22
|
describe: false,
|
|
@@ -11,10 +24,13 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
11
24
|
return `${name} with newTreeshaking should match snapshot`;
|
|
12
25
|
},
|
|
13
26
|
steps: ({ name }) => [
|
|
14
|
-
new
|
|
27
|
+
new processor_1.SnapshotProcessor({
|
|
15
28
|
name,
|
|
16
29
|
snapshot: "treeshaking.snap.txt",
|
|
17
|
-
compilerType: type_1.ECompilerType.Rspack
|
|
30
|
+
compilerType: type_1.ECompilerType.Rspack,
|
|
31
|
+
runable: false,
|
|
32
|
+
defaultOptions: builtin_1.defaultOptions,
|
|
33
|
+
overrideOptions
|
|
18
34
|
})
|
|
19
35
|
]
|
|
20
36
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Compiler } from "@rspack/core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { THotUpdateContext } from "../../type";
|
|
3
3
|
export declare class TestHotUpdatePlugin {
|
|
4
4
|
private updateOptions;
|
|
5
|
-
constructor(updateOptions:
|
|
5
|
+
constructor(updateOptions: THotUpdateContext);
|
|
6
6
|
apply(compiler: Compiler): void;
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, TCompilerOptions } from "../type";
|
|
1
|
+
import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, TCompiler, TCompilerMultiStats, TCompilerOptions, TCompilerStats } from "../type";
|
|
2
2
|
export interface IBasicProcessorOptions<T extends ECompilerType> {
|
|
3
3
|
defaultOptions?: (context: ITestContext) => TCompilerOptions<T>;
|
|
4
4
|
configFiles?: string[];
|
|
@@ -7,6 +7,9 @@ export interface IBasicProcessorOptions<T extends ECompilerType> {
|
|
|
7
7
|
compilerType: T;
|
|
8
8
|
runable: boolean;
|
|
9
9
|
name: string;
|
|
10
|
+
compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
11
|
+
build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
12
|
+
check?: (env: ITestEnv, context: ITestContext, compiler: TCompiler<T>, stats: TCompilerStats<T> | TCompilerMultiStats<T> | null) => Promise<void>;
|
|
10
13
|
}
|
|
11
14
|
export declare class BasicProcessor<T extends ECompilerType> implements ITestProcessor {
|
|
12
15
|
protected _options: IBasicProcessorOptions<T>;
|