@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/serial.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSerialCase = createSerialCase;
|
|
4
|
-
const config_1 = require("../processor/config");
|
|
5
|
-
const runner_1 = require("../runner");
|
|
6
4
|
const creator_1 = require("../test/creator");
|
|
7
|
-
const
|
|
5
|
+
const config_1 = require("./config");
|
|
6
|
+
const runner_1 = require("./runner");
|
|
8
7
|
const creator = new creator_1.BasicCaseCreator({
|
|
9
8
|
clean: true,
|
|
10
9
|
describe: false,
|
|
@@ -19,15 +18,12 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
19
18
|
return res;
|
|
20
19
|
};
|
|
21
20
|
},
|
|
22
|
-
steps: ({ name }) => [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
],
|
|
30
|
-
runner: runner_1.MultipleRunnerFactory
|
|
21
|
+
steps: ({ name }) => [(0, config_1.createConfigProcessor)(name)],
|
|
22
|
+
runner: {
|
|
23
|
+
key: runner_1.getMultiCompilerRunnerKey,
|
|
24
|
+
runner: runner_1.createMultiCompilerRunner
|
|
25
|
+
},
|
|
26
|
+
concurrent: false
|
|
31
27
|
});
|
|
32
28
|
function createSerialCase(name, src, dist) {
|
|
33
29
|
creator.create(name, src, dist);
|
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,21 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStatsAPICase = createStatsAPICase;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const memfs_1 = require("memfs");
|
|
5
|
+
const creator_1 = require("../test/creator");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
7
|
let addedSerializer = false;
|
|
8
|
+
const creator = new creator_1.BasicCaseCreator({
|
|
9
|
+
clean: true,
|
|
10
|
+
describe: true,
|
|
11
|
+
steps: ({ name, caseConfig }) => {
|
|
12
|
+
const config = caseConfig;
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
config: async (context) => {
|
|
16
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
17
|
+
compiler.setOptions(options(context, config.options));
|
|
18
|
+
},
|
|
19
|
+
compiler: async (context) => {
|
|
20
|
+
const compilerManager = (0, common_1.getCompiler)(context, name);
|
|
21
|
+
compilerManager.createCompiler();
|
|
22
|
+
compiler(context, compilerManager.getCompiler(), config.compiler);
|
|
23
|
+
},
|
|
24
|
+
build: async (context) => {
|
|
25
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
26
|
+
if (typeof config.build === "function") {
|
|
27
|
+
await config.build(context, compiler.getCompiler());
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
await compiler.build();
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
run: async (env, context) => {
|
|
34
|
+
// no need to run, just check the snapshot of diagnostics
|
|
35
|
+
},
|
|
36
|
+
check: async (env, context) => {
|
|
37
|
+
await check(env, context, name, config.check);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
},
|
|
42
|
+
concurrent: true
|
|
43
|
+
});
|
|
8
44
|
function createStatsAPICase(name, src, dist, testConfig) {
|
|
9
45
|
if (!addedSerializer) {
|
|
10
46
|
addedSerializer = true;
|
|
11
47
|
}
|
|
12
48
|
const caseConfig = require(testConfig);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
name: name,
|
|
17
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
18
|
-
...caseConfig
|
|
19
|
-
}));
|
|
49
|
+
creator.create(name, src, dist, undefined, {
|
|
50
|
+
caseConfig,
|
|
51
|
+
description: () => caseConfig.description
|
|
20
52
|
});
|
|
21
53
|
}
|
|
54
|
+
function options(context, custom) {
|
|
55
|
+
const res = (custom?.(context) ||
|
|
56
|
+
{});
|
|
57
|
+
res.experiments ??= {};
|
|
58
|
+
res.experiments.css ??= true;
|
|
59
|
+
res.experiments.rspackFuture ??= {};
|
|
60
|
+
res.experiments.rspackFuture.bundlerInfo ??= {};
|
|
61
|
+
res.experiments.rspackFuture.bundlerInfo.force ??= false;
|
|
62
|
+
if (!global.printLogger) {
|
|
63
|
+
res.infrastructureLogging = {
|
|
64
|
+
level: "error"
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return res;
|
|
68
|
+
}
|
|
69
|
+
async function compiler(context, compiler, custom) {
|
|
70
|
+
if (custom) {
|
|
71
|
+
await custom(context, compiler);
|
|
72
|
+
}
|
|
73
|
+
if (compiler) {
|
|
74
|
+
compiler.outputFileSystem = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function check(env, context, name, custom) {
|
|
78
|
+
const manager = (0, common_1.getCompiler)(context, name);
|
|
79
|
+
const stats = manager.getStats();
|
|
80
|
+
env.expect(typeof stats).toBe("object");
|
|
81
|
+
await custom?.(stats, manager.getCompiler());
|
|
82
|
+
}
|
|
@@ -1,23 +1,209 @@
|
|
|
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"));
|
|
5
11
|
const creator_1 = require("../test/creator");
|
|
6
|
-
const
|
|
12
|
+
const common_1 = require("./common");
|
|
13
|
+
const REG_ERROR_CASE = /error$/;
|
|
14
|
+
function createStatsProcessor(name) {
|
|
15
|
+
const writeStatsOuptut = false;
|
|
16
|
+
const snapshotName = "stats.txt";
|
|
17
|
+
let stderr = null;
|
|
18
|
+
return {
|
|
19
|
+
before: async (context) => {
|
|
20
|
+
stderr = (0, captureStdio_1.default)(process.stderr, true);
|
|
21
|
+
},
|
|
22
|
+
config: async (context) => {
|
|
23
|
+
(0, common_1.configMultiCompiler)(context, name, ["rspack.config.js", "webpack.config.js"], defaultOptions, overrideOptions);
|
|
24
|
+
},
|
|
25
|
+
compiler: async (context) => {
|
|
26
|
+
const c = await (0, common_1.compiler)(context, name);
|
|
27
|
+
await statsCompiler(context, c);
|
|
28
|
+
},
|
|
29
|
+
build: async (context) => {
|
|
30
|
+
await (0, common_1.build)(context, name);
|
|
31
|
+
},
|
|
32
|
+
run: async (env, context) => {
|
|
33
|
+
// no need to run, just check snapshot
|
|
34
|
+
},
|
|
35
|
+
check: async (env, context) => {
|
|
36
|
+
await check(env, context, name, writeStatsOuptut, snapshotName, stderr);
|
|
37
|
+
},
|
|
38
|
+
after: async (context) => {
|
|
39
|
+
stderr.restore();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
7
43
|
const creator = new creator_1.BasicCaseCreator({
|
|
8
44
|
clean: true,
|
|
9
45
|
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
|
-
],
|
|
46
|
+
steps: ({ name }) => [createStatsProcessor(name)],
|
|
19
47
|
description: () => "should print correct stats for"
|
|
20
48
|
});
|
|
21
49
|
function createStatsOutputCase(name, src, dist) {
|
|
22
50
|
creator.create(name, src, dist);
|
|
23
51
|
}
|
|
52
|
+
function defaultOptions(index, context) {
|
|
53
|
+
if (fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), "rspack.config.js"))) {
|
|
54
|
+
return {
|
|
55
|
+
experiments: {
|
|
56
|
+
css: true,
|
|
57
|
+
rspackFuture: {
|
|
58
|
+
bundlerInfo: {
|
|
59
|
+
force: false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
context: context.getSource(),
|
|
67
|
+
mode: "development",
|
|
68
|
+
entry: "./index.js",
|
|
69
|
+
output: {
|
|
70
|
+
filename: "bundle.js",
|
|
71
|
+
path: context.getDist()
|
|
72
|
+
},
|
|
73
|
+
optimization: {
|
|
74
|
+
minimize: false
|
|
75
|
+
},
|
|
76
|
+
experiments: {
|
|
77
|
+
css: true,
|
|
78
|
+
rspackFuture: {
|
|
79
|
+
bundlerInfo: {
|
|
80
|
+
force: false
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
inlineConst: true,
|
|
84
|
+
lazyBarrel: true
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function overrideOptions(index, context, options) {
|
|
89
|
+
if (!options.context)
|
|
90
|
+
options.context = context.getSource();
|
|
91
|
+
if (!options.output)
|
|
92
|
+
options.output = options.output || {};
|
|
93
|
+
if (!options.output.path)
|
|
94
|
+
options.output.path = context.getDist();
|
|
95
|
+
if (!options.plugins)
|
|
96
|
+
options.plugins = [];
|
|
97
|
+
if (!options.optimization)
|
|
98
|
+
options.optimization = {};
|
|
99
|
+
if (options.optimization.minimize === undefined) {
|
|
100
|
+
options.optimization.minimize = false;
|
|
101
|
+
}
|
|
102
|
+
if (!global.printLogger) {
|
|
103
|
+
options.infrastructureLogging = {
|
|
104
|
+
level: "error"
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
class RspackStats {
|
|
109
|
+
constructor(value) {
|
|
110
|
+
this.value = value;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function check(env, context, name, writeStatsOuptut, snapshot, stderr) {
|
|
114
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
115
|
+
const options = compiler.getOptions();
|
|
116
|
+
const stats = compiler.getStats();
|
|
117
|
+
if (!stats || !compiler)
|
|
118
|
+
return;
|
|
119
|
+
for (const compilation of []
|
|
120
|
+
.concat(stats.stats || stats)
|
|
121
|
+
.map((s) => s.compilation)) {
|
|
122
|
+
compilation.logging.delete("webpack.Compilation.ModuleProfile");
|
|
123
|
+
}
|
|
124
|
+
if (REG_ERROR_CASE.test(name)) {
|
|
125
|
+
env.expect(stats.hasErrors()).toBe(true);
|
|
126
|
+
}
|
|
127
|
+
else if (stats.hasErrors()) {
|
|
128
|
+
throw new Error(stats.toString({
|
|
129
|
+
all: false,
|
|
130
|
+
errors: true
|
|
131
|
+
// errorStack: true,
|
|
132
|
+
// errorDetails: true
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
else if (writeStatsOuptut) {
|
|
136
|
+
fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
|
|
137
|
+
preset: "verbose",
|
|
138
|
+
// context: context.getSource(),
|
|
139
|
+
colors: false
|
|
140
|
+
}), "utf-8");
|
|
141
|
+
}
|
|
142
|
+
let toStringOptions = {
|
|
143
|
+
context: context.getSource(),
|
|
144
|
+
colors: false
|
|
145
|
+
};
|
|
146
|
+
let hasColorSetting = false;
|
|
147
|
+
if (typeof options.stats !== "undefined") {
|
|
148
|
+
toStringOptions = options.stats;
|
|
149
|
+
if (toStringOptions === null || typeof toStringOptions !== "object")
|
|
150
|
+
toStringOptions = { preset: toStringOptions };
|
|
151
|
+
if (!toStringOptions.context)
|
|
152
|
+
toStringOptions.context = context.getSource();
|
|
153
|
+
hasColorSetting = typeof toStringOptions.colors !== "undefined";
|
|
154
|
+
}
|
|
155
|
+
if (Array.isArray(options) && !toStringOptions.children) {
|
|
156
|
+
toStringOptions.children = options.map(o => o.stats);
|
|
157
|
+
}
|
|
158
|
+
// mock timestamps
|
|
159
|
+
for (const { compilation: s } of [].concat(stats.stats || stats)) {
|
|
160
|
+
env.expect(s.startTime).toBeGreaterThan(0);
|
|
161
|
+
env.expect(s.endTime).toBeGreaterThan(0);
|
|
162
|
+
s.endTime = new Date("04/20/1970, 12:42:42 PM").getTime();
|
|
163
|
+
s.startTime = s.endTime - 1234;
|
|
164
|
+
}
|
|
165
|
+
let actual = stats.toString(toStringOptions);
|
|
166
|
+
env.expect(typeof actual).toBe("string");
|
|
167
|
+
actual = stderr.toString() + actual;
|
|
168
|
+
if (!hasColorSetting) {
|
|
169
|
+
actual = actual
|
|
170
|
+
.replace(/\u001b\[[0-9;]*m/g, "")
|
|
171
|
+
// CHANGE: The time unit display in Rspack is second
|
|
172
|
+
.replace(/[.0-9]+(\s?s)/g, "X$1")
|
|
173
|
+
// CHANGE: Replace bundle size, since bundle sizes may differ between platforms
|
|
174
|
+
.replace(/[0-9]+\.?[0-9]+ KiB/g, "xx KiB");
|
|
175
|
+
}
|
|
176
|
+
const snapshotPath = node_path_1.default.isAbsolute(snapshot)
|
|
177
|
+
? snapshot
|
|
178
|
+
: node_path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshot}`);
|
|
179
|
+
env.expect(new RspackStats(actual)).toMatchFileSnapshot(snapshotPath);
|
|
180
|
+
const testConfig = context.getTestConfig();
|
|
181
|
+
if (typeof testConfig?.validate === "function") {
|
|
182
|
+
testConfig.validate(stats, stderr.toString());
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function statsCompiler(context, compiler) {
|
|
186
|
+
const compilers = compiler.compilers
|
|
187
|
+
? compiler.compilers
|
|
188
|
+
: [compiler];
|
|
189
|
+
for (const compiler of compilers) {
|
|
190
|
+
if (!compiler.inputFileSystem) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const ifs = compiler.inputFileSystem;
|
|
194
|
+
const inputFileSystem = Object.create(ifs);
|
|
195
|
+
compiler.inputFileSystem = inputFileSystem;
|
|
196
|
+
inputFileSystem.readFile = (...args) => {
|
|
197
|
+
const callback = args.pop();
|
|
198
|
+
ifs.readFile.apply(ifs, args.concat([
|
|
199
|
+
(err, result) => {
|
|
200
|
+
if (err)
|
|
201
|
+
return callback(err);
|
|
202
|
+
if (!/\.(js|json|txt)$/.test(args[0]))
|
|
203
|
+
return callback(null, result);
|
|
204
|
+
callback(null, (0, placeholder_1.normalizePlaceholder)(result.toString("utf-8")));
|
|
205
|
+
}
|
|
206
|
+
]));
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
package/dist/case/treeshaking.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTreeShakingCase = createTreeShakingCase;
|
|
4
|
-
const treeshaking_1 = require("../processor/treeshaking");
|
|
5
4
|
const creator_1 = require("../test/creator");
|
|
6
|
-
const
|
|
5
|
+
const builtin_1 = require("./builtin");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
7
|
const creator = new creator_1.BasicCaseCreator({
|
|
8
8
|
clean: true,
|
|
9
9
|
describe: false,
|
|
@@ -11,13 +11,40 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
11
11
|
return `${name} with newTreeshaking should match snapshot`;
|
|
12
12
|
},
|
|
13
13
|
steps: ({ name }) => [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
{
|
|
15
|
+
config: async (context) => {
|
|
16
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
17
|
+
const options = (0, builtin_1.defaultOptions)(context);
|
|
18
|
+
overrideOptions(context, options);
|
|
19
|
+
compiler.setOptions(options);
|
|
20
|
+
},
|
|
21
|
+
compiler: async (context) => {
|
|
22
|
+
await (0, common_1.compiler)(context, name);
|
|
23
|
+
},
|
|
24
|
+
build: async (context) => {
|
|
25
|
+
await (0, common_1.build)(context, name);
|
|
26
|
+
},
|
|
27
|
+
run: async (env, context) => {
|
|
28
|
+
// no need to run, just check snapshot
|
|
29
|
+
},
|
|
30
|
+
check: async (env, context) => {
|
|
31
|
+
await (0, common_1.checkSnapshot)(env, context, name, "treeshaking.snap.txt");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
19
34
|
]
|
|
20
35
|
});
|
|
21
36
|
function createTreeShakingCase(name, src, dist) {
|
|
22
37
|
creator.create(name, src, dist);
|
|
23
38
|
}
|
|
39
|
+
function overrideOptions(context, options) {
|
|
40
|
+
options.target = options.target || ["web", "es2022"];
|
|
41
|
+
options.optimization ??= {};
|
|
42
|
+
options.optimization.providedExports = true;
|
|
43
|
+
options.optimization.innerGraph = true;
|
|
44
|
+
options.optimization.usedExports = true;
|
|
45
|
+
if (!global.printLogger) {
|
|
46
|
+
options.infrastructureLogging = {
|
|
47
|
+
level: "error"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
package/dist/case/watch.d.ts
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
+
import { type ECompilerType, type ITestContext, type ITestEnv, type ITestRunner } from "../type";
|
|
2
|
+
export declare function createWatchInitialProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher, ignoreNotFriendlyForIncrementalWarnings }?: {
|
|
3
|
+
incremental?: boolean | undefined;
|
|
4
|
+
nativeWatcher?: boolean | undefined;
|
|
5
|
+
ignoreNotFriendlyForIncrementalWarnings?: boolean | undefined;
|
|
6
|
+
}): {
|
|
7
|
+
before: (context: ITestContext) => Promise<void>;
|
|
8
|
+
config: <T extends ECompilerType.Rspack>(context: ITestContext) => Promise<void>;
|
|
9
|
+
compiler: (context: ITestContext) => Promise<void>;
|
|
10
|
+
build: (context: ITestContext) => Promise<void>;
|
|
11
|
+
run: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
12
|
+
check: <T extends ECompilerType.Rspack>(env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
export declare function createWatchStepProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher, ignoreNotFriendlyForIncrementalWarnings }?: {
|
|
15
|
+
incremental?: boolean | undefined;
|
|
16
|
+
nativeWatcher?: boolean | undefined;
|
|
17
|
+
ignoreNotFriendlyForIncrementalWarnings?: boolean | undefined;
|
|
18
|
+
}): {
|
|
19
|
+
before: (context: ITestContext) => Promise<void>;
|
|
20
|
+
config: <T extends ECompilerType.Rspack>(context: ITestContext) => Promise<void>;
|
|
21
|
+
compiler: (context: ITestContext) => Promise<void>;
|
|
22
|
+
build: (context: ITestContext) => Promise<void>;
|
|
23
|
+
run: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
24
|
+
check: <T extends ECompilerType.Rspack>(env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
25
|
+
};
|
|
1
26
|
export declare function createWatchCase(name: string, src: string, dist: string, temp: string): void;
|
|
27
|
+
export declare function getWatchRunnerKey(context: ITestContext, name: string, file: string): string;
|
|
28
|
+
export declare function createWatchRunner<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
|