@rspack-debug/test-tools 1.4.9 → 1.6.2
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/README.md +1 -1
- package/dist/case/builtin.d.ts +3 -0
- package/dist/case/builtin.js +152 -14
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +214 -12
- package/dist/case/common.d.ts +11 -0
- package/dist/case/common.js +249 -0
- package/dist/case/compiler.d.ts +17 -4
- package/dist/case/compiler.js +149 -12
- package/dist/case/config.d.ts +7 -2
- package/dist/case/config.js +106 -18
- package/dist/case/defaults.d.ts +13 -4
- package/dist/case/defaults.js +73 -18
- package/dist/case/diagnostic.d.ts +6 -0
- package/dist/case/diagnostic.js +121 -14
- package/dist/case/error.d.ts +15 -4
- package/dist/case/error.js +137 -12
- package/dist/case/esm-output.d.ts +1 -0
- package/dist/case/esm-output.js +117 -0
- package/dist/case/example.d.ts +1 -0
- package/dist/case/example.js +57 -0
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +72 -9
- package/dist/case/hook.d.ts +36 -4
- package/dist/case/hook.js +209 -20
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +309 -13
- package/dist/case/hot.d.ts +11 -2
- package/dist/case/hot.js +217 -12
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +24 -45
- package/dist/case/index.d.ts +31 -20
- package/dist/case/index.js +50 -34
- package/dist/case/multi-compiler.d.ts +19 -0
- package/dist/case/multi-compiler.js +97 -0
- package/dist/case/{nativeWatcher.js → native-watcher.js} +12 -25
- package/dist/case/normal.d.ts +3 -0
- package/dist/case/normal.js +202 -18
- package/dist/case/runner.d.ts +19 -0
- package/dist/case/runner.js +113 -0
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +10 -14
- package/dist/case/stats-api.d.ts +8 -3
- package/dist/case/stats-api.js +69 -10
- package/dist/case/stats-output.d.ts +11 -0
- package/dist/case/stats-output.js +199 -8
- package/dist/case/treeshaking.js +34 -7
- package/dist/case/watch.d.ts +27 -0
- package/dist/case/watch.js +318 -22
- package/dist/compiler.d.ts +16 -16
- package/dist/compiler.js +120 -15
- package/dist/helper/directory.d.ts +1 -1
- package/dist/helper/directory.js +2 -2
- package/dist/helper/expect/error.js +1 -1
- package/dist/helper/expect/placeholder.js +7 -7
- package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
- package/dist/helper/expect/to-match-file-snapshot.js +3 -3
- 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.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +15 -14
- package/dist/helper/index.d.ts +2 -1
- package/dist/helper/index.js +2 -1
- package/dist/helper/is.d.ts +2 -0
- package/dist/helper/is.js +15 -0
- package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
- package/dist/helper/legacy/LogTestPlugin.js +35 -0
- package/dist/helper/legacy/asModule.js +0 -2
- package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
- package/dist/helper/legacy/checkArrayExpectation.js +8 -8
- package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
- package/dist/helper/legacy/createFakeWorker.js +44 -20
- package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
- package/dist/helper/legacy/createLazyTestEnv.js +3 -3
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
- package/dist/helper/legacy/deprecationTracking.js +41 -0
- package/dist/helper/legacy/expectSource.d.ts +10 -0
- package/dist/helper/legacy/expectSource.js +23 -0
- package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
- package/dist/helper/legacy/findOutputFiles.js +14 -0
- package/dist/helper/legacy/regexEscape.d.ts +2 -0
- package/dist/helper/legacy/regexEscape.js +5 -0
- package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
- package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
- package/dist/helper/legacy/supportsTextDecoder.js +9 -0
- package/dist/helper/legacy/supportsUsing.d.ts +2 -0
- package/dist/helper/legacy/supportsUsing.js +26 -0
- package/dist/helper/legacy/urlToRelativePath.js +5 -2
- 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 +15 -2
- package/dist/helper/setup-expect.js +2 -2
- package/dist/helper/setup-wasm.js +2 -2
- package/dist/helper/stringify-config.d.ts +2 -0
- package/dist/helper/stringify-config.js +43 -0
- package/dist/helper/util/checkStats.d.ts +0 -1
- package/dist/helper/util/checkStats.js +0 -18
- package/dist/helper/util/expectWarningFactory.js +2 -4
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -4
- package/dist/plugin/index.d.ts +0 -3
- package/dist/plugin/index.js +0 -3
- package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
- package/dist/runner/index.d.ts +2 -9
- package/dist/runner/index.js +2 -9
- package/dist/runner/node/index.d.ts +41 -0
- package/dist/runner/node/index.js +450 -0
- package/dist/runner/web/index.d.ts +30 -0
- package/dist/runner/web/index.js +343 -0
- package/dist/test/context.d.ts +15 -18
- package/dist/test/context.js +52 -57
- package/dist/test/creator.d.ts +20 -19
- package/dist/test/creator.js +69 -57
- 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 +44 -6
- package/dist/type.d.ts +94 -64
- package/dist/type.js +8 -12
- package/package.json +23 -62
- package/rstest.d.ts +24 -0
- package/dist/case/diff.d.ts +0 -3
- package/dist/case/diff.js +0 -126
- 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 -175
- package/dist/compare/format-code.d.ts +0 -16
- package/dist/compare/format-code.js +0 -239
- 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 -278
- package/dist/helper/legacy/createLogger.d.ts +0 -23
- package/dist/helper/legacy/createLogger.js +0 -20
- package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
- package/dist/helper/legacy/supportsImportFn.js +0 -15
- package/dist/helper/legacy/supportsWorker.js +0 -17
- package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
- package/dist/helper/legacy/walkCssTokens.js +0 -761
- package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
- package/dist/helper/legacy/warmup-webpack.js +0 -26
- package/dist/helper/loaders/hot-update.d.ts +0 -1
- package/dist/helper/loaders/hot-update.js +0 -40
- package/dist/helper/plugins/hot-update.d.ts +0 -7
- package/dist/helper/plugins/hot-update.js +0 -40
- package/dist/helper/plugins/index.d.ts +0 -1
- package/dist/helper/plugins/index.js +0 -17
- package/dist/helper/util/currentWatchStep.d.ts +0 -1
- package/dist/helper/util/currentWatchStep.js +0 -2
- package/dist/helper/util/identifier.d.ts +0 -76
- package/dist/helper/util/identifier.js +0 -339
- package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
- package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
- 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/processor/basic.d.ts +0 -24
- package/dist/processor/basic.js +0 -146
- 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 -127
- package/dist/processor/config.d.ts +0 -11
- package/dist/processor/config.js +0 -81
- 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 -102
- 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 -63
- package/dist/processor/hook.d.ts +0 -44
- package/dist/processor/hook.js +0 -204
- 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 -304
- package/dist/processor/hot.d.ts +0 -17
- package/dist/processor/hot.js +0 -140
- 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 -150
- package/dist/processor/simple.d.ts +0 -23
- package/dist/processor/simple.js +0 -49
- 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 -245
- package/dist/reporter/diff-html.d.ts +0 -15
- package/dist/reporter/diff-html.js +0 -69
- package/dist/reporter/diff-stats.d.ts +0 -24
- package/dist/reporter/diff-stats.js +0 -131
- package/dist/reporter/index.d.ts +0 -2
- package/dist/reporter/index.js +0 -18
- package/dist/runner/basic.d.ts +0 -10
- package/dist/runner/basic.js +0 -63
- package/dist/runner/cache.d.ts +0 -5
- package/dist/runner/cache.js +0 -90
- package/dist/runner/hot-step.d.ts +0 -5
- package/dist/runner/hot-step.js +0 -87
- package/dist/runner/hot.d.ts +0 -5
- package/dist/runner/hot.js +0 -83
- package/dist/runner/multiple.d.ts +0 -11
- package/dist/runner/multiple.js +0 -38
- package/dist/runner/normal.d.ts +0 -5
- package/dist/runner/normal.js +0 -20
- package/dist/runner/runner/basic.d.ts +0 -30
- package/dist/runner/runner/basic.js +0 -107
- package/dist/runner/runner/cjs.d.ts +0 -14
- package/dist/runner/runner/cjs.js +0 -151
- package/dist/runner/runner/esm.d.ts +0 -7
- package/dist/runner/runner/esm.js +0 -125
- package/dist/runner/runner/index.d.ts +0 -8
- package/dist/runner/runner/index.js +0 -24
- package/dist/runner/runner/normal.d.ts +0 -9
- package/dist/runner/runner/normal.js +0 -23
- package/dist/runner/runner/watch.d.ts +0 -16
- package/dist/runner/runner/watch.js +0 -27
- package/dist/runner/runner/web/fake.d.ts +0 -18
- package/dist/runner/runner/web/fake.js +0 -143
- package/dist/runner/runner/web/jsdom.d.ts +0 -26
- package/dist/runner/runner/web/jsdom.js +0 -219
- package/dist/runner/runner/web.d.ts +0 -15
- package/dist/runner/runner/web.js +0 -32
- 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 -60
- package/dist/test/simple.d.ts +0 -5
- package/dist/test/simple.js +0 -43
- package/jest.d.ts +0 -25
- 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/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
- /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
|
@@ -1,22 +1,213 @@
|
|
|
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 });
|
|
6
|
+
exports.createStatsProcessor = createStatsProcessor;
|
|
3
7
|
exports.createStatsOutputCase = createStatsOutputCase;
|
|
4
|
-
const
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const placeholder_1 = require("../helper/expect/placeholder");
|
|
11
|
+
const captureStdio_1 = __importDefault(require("../helper/legacy/captureStdio"));
|
|
5
12
|
const creator_1 = require("../test/creator");
|
|
6
|
-
const
|
|
13
|
+
const common_1 = require("./common");
|
|
14
|
+
const REG_ERROR_CASE = /error$/;
|
|
15
|
+
function createStatsProcessor(name, defaultOptions, overrideOptions) {
|
|
16
|
+
const writeStatsOuptut = false;
|
|
17
|
+
const snapshotName = "stats.txt";
|
|
18
|
+
let stderr = null;
|
|
19
|
+
return {
|
|
20
|
+
before: async (context) => {
|
|
21
|
+
stderr = (0, captureStdio_1.default)(process.stderr, true);
|
|
22
|
+
},
|
|
23
|
+
config: async (context) => {
|
|
24
|
+
(0, common_1.configMultiCompiler)(context, name, ["rspack.config.js", "webpack.config.js"], defaultOptions, overrideOptions);
|
|
25
|
+
},
|
|
26
|
+
compiler: async (context) => {
|
|
27
|
+
const c = await (0, common_1.compiler)(context, name);
|
|
28
|
+
await statsCompiler(context, c);
|
|
29
|
+
},
|
|
30
|
+
build: async (context) => {
|
|
31
|
+
await (0, common_1.build)(context, name);
|
|
32
|
+
},
|
|
33
|
+
run: async (env, context) => {
|
|
34
|
+
// no need to run, just check snapshot
|
|
35
|
+
},
|
|
36
|
+
check: async (env, context) => {
|
|
37
|
+
await check(env, context, name, writeStatsOuptut, snapshotName, stderr);
|
|
38
|
+
},
|
|
39
|
+
after: async (context) => {
|
|
40
|
+
stderr.restore();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
7
44
|
const creator = new creator_1.BasicCaseCreator({
|
|
8
45
|
clean: true,
|
|
9
46
|
describe: false,
|
|
10
47
|
steps: ({ name }) => [
|
|
11
|
-
|
|
12
|
-
name,
|
|
13
|
-
writeStatsOuptut: false,
|
|
14
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
15
|
-
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
16
|
-
})
|
|
48
|
+
createStatsProcessor(name, defaultOptions, overrideOptions)
|
|
17
49
|
],
|
|
18
50
|
description: () => "should print correct stats for"
|
|
19
51
|
});
|
|
20
52
|
function createStatsOutputCase(name, src, dist) {
|
|
21
53
|
creator.create(name, src, dist);
|
|
22
54
|
}
|
|
55
|
+
function defaultOptions(index, context) {
|
|
56
|
+
if (fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), "rspack.config.js")) ||
|
|
57
|
+
fs_extra_1.default.existsSync(node_path_1.default.join(context.getSource(), "webpack.config.js"))) {
|
|
58
|
+
return {
|
|
59
|
+
experiments: {
|
|
60
|
+
css: true,
|
|
61
|
+
rspackFuture: {
|
|
62
|
+
bundlerInfo: {
|
|
63
|
+
force: false
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
context: context.getSource(),
|
|
71
|
+
mode: "development",
|
|
72
|
+
entry: "./index.js",
|
|
73
|
+
output: {
|
|
74
|
+
filename: "bundle.js",
|
|
75
|
+
path: context.getDist()
|
|
76
|
+
},
|
|
77
|
+
optimization: {
|
|
78
|
+
minimize: false
|
|
79
|
+
},
|
|
80
|
+
experiments: {
|
|
81
|
+
css: true,
|
|
82
|
+
rspackFuture: {
|
|
83
|
+
bundlerInfo: {
|
|
84
|
+
force: false
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
inlineConst: true
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function overrideOptions(index, context, options) {
|
|
92
|
+
if (!options.context)
|
|
93
|
+
options.context = context.getSource();
|
|
94
|
+
if (!options.output)
|
|
95
|
+
options.output = options.output || {};
|
|
96
|
+
if (!options.output.path)
|
|
97
|
+
options.output.path = context.getDist();
|
|
98
|
+
if (!options.plugins)
|
|
99
|
+
options.plugins = [];
|
|
100
|
+
if (!options.optimization)
|
|
101
|
+
options.optimization = {};
|
|
102
|
+
if (options.optimization.minimize === undefined) {
|
|
103
|
+
options.optimization.minimize = false;
|
|
104
|
+
}
|
|
105
|
+
if (!global.printLogger) {
|
|
106
|
+
options.infrastructureLogging = {
|
|
107
|
+
level: "error"
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
class RspackStats {
|
|
112
|
+
constructor(value) {
|
|
113
|
+
this.value = value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function check(env, context, name, writeStatsOuptut, snapshot, stderr) {
|
|
117
|
+
const compiler = context.getCompiler();
|
|
118
|
+
const options = compiler.getOptions();
|
|
119
|
+
const stats = compiler.getStats();
|
|
120
|
+
if (!stats || !compiler)
|
|
121
|
+
return;
|
|
122
|
+
for (const compilation of []
|
|
123
|
+
.concat(stats.stats || stats)
|
|
124
|
+
.map((s) => s.compilation)) {
|
|
125
|
+
compilation.logging.delete("webpack.Compilation.ModuleProfile");
|
|
126
|
+
}
|
|
127
|
+
if (REG_ERROR_CASE.test(name)) {
|
|
128
|
+
env.expect(stats.hasErrors()).toBe(true);
|
|
129
|
+
}
|
|
130
|
+
else if (stats.hasErrors()) {
|
|
131
|
+
throw new Error(stats.toString({
|
|
132
|
+
all: false,
|
|
133
|
+
errors: true
|
|
134
|
+
// errorStack: true,
|
|
135
|
+
// errorDetails: true
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
else if (writeStatsOuptut) {
|
|
139
|
+
fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
|
|
140
|
+
preset: "verbose",
|
|
141
|
+
// context: context.getSource(),
|
|
142
|
+
colors: false
|
|
143
|
+
}), "utf-8");
|
|
144
|
+
}
|
|
145
|
+
let toStringOptions = {
|
|
146
|
+
context: context.getSource(),
|
|
147
|
+
colors: false
|
|
148
|
+
};
|
|
149
|
+
let hasColorSetting = false;
|
|
150
|
+
if (typeof options.stats !== "undefined") {
|
|
151
|
+
toStringOptions = options.stats;
|
|
152
|
+
if (toStringOptions === null || typeof toStringOptions !== "object")
|
|
153
|
+
toStringOptions = { preset: toStringOptions };
|
|
154
|
+
if (!toStringOptions.context)
|
|
155
|
+
toStringOptions.context = context.getSource();
|
|
156
|
+
hasColorSetting = typeof toStringOptions.colors !== "undefined";
|
|
157
|
+
}
|
|
158
|
+
if (Array.isArray(options) && !toStringOptions.children) {
|
|
159
|
+
toStringOptions.children = options.map(o => o.stats);
|
|
160
|
+
}
|
|
161
|
+
// mock timestamps
|
|
162
|
+
for (const { compilation: s } of [].concat(stats.stats || stats)) {
|
|
163
|
+
env.expect(s.startTime).toBeGreaterThan(0);
|
|
164
|
+
env.expect(s.endTime).toBeGreaterThan(0);
|
|
165
|
+
s.endTime = new Date("04/20/1970, 12:42:42 PM").getTime();
|
|
166
|
+
s.startTime = s.endTime - 1234;
|
|
167
|
+
}
|
|
168
|
+
let actual = stats.toString(toStringOptions);
|
|
169
|
+
env.expect(typeof actual).toBe("string");
|
|
170
|
+
actual = stderr.toString() + actual;
|
|
171
|
+
if (!hasColorSetting) {
|
|
172
|
+
actual = actual
|
|
173
|
+
.replace(/\u001b\[[0-9;]*m/g, "")
|
|
174
|
+
// CHANGE: The time unit display in Rspack is second
|
|
175
|
+
.replace(/[.0-9]+(\s?s)/g, "X$1")
|
|
176
|
+
// CHANGE: Replace bundle size, since bundle sizes may differ between platforms
|
|
177
|
+
.replace(/[0-9]+\.?[0-9]+ KiB/g, "xx KiB")
|
|
178
|
+
.replace(/[0-9]+ ms/g, "xx ms");
|
|
179
|
+
}
|
|
180
|
+
const snapshotPath = node_path_1.default.isAbsolute(snapshot)
|
|
181
|
+
? snapshot
|
|
182
|
+
: node_path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshot}`);
|
|
183
|
+
env.expect(new RspackStats(actual)).toMatchFileSnapshotSync(snapshotPath);
|
|
184
|
+
const testConfig = context.getTestConfig();
|
|
185
|
+
if (typeof testConfig?.validate === "function") {
|
|
186
|
+
testConfig.validate(stats, stderr.toString());
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async function statsCompiler(context, compiler) {
|
|
190
|
+
const compilers = compiler.compilers
|
|
191
|
+
? compiler.compilers
|
|
192
|
+
: [compiler];
|
|
193
|
+
for (const compiler of compilers) {
|
|
194
|
+
if (!compiler.inputFileSystem) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const ifs = compiler.inputFileSystem;
|
|
198
|
+
const inputFileSystem = Object.create(ifs);
|
|
199
|
+
compiler.inputFileSystem = inputFileSystem;
|
|
200
|
+
inputFileSystem.readFile = (...args) => {
|
|
201
|
+
const callback = args.pop();
|
|
202
|
+
ifs.readFile.apply(ifs, args.concat([
|
|
203
|
+
(err, result) => {
|
|
204
|
+
if (err)
|
|
205
|
+
return callback(err);
|
|
206
|
+
if (!/\.(js|json|txt)$/.test(args[0]))
|
|
207
|
+
return callback(null, result);
|
|
208
|
+
callback(null, (0, placeholder_1.normalizePlaceholder)(result.toString("utf-8")));
|
|
209
|
+
}
|
|
210
|
+
]));
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
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 = context.getCompiler();
|
|
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 { ITestContext, ITestEnv, ITestRunner } from "../type";
|
|
2
|
+
export declare function createWatchInitialProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher }?: {
|
|
3
|
+
incremental?: boolean | undefined;
|
|
4
|
+
nativeWatcher?: boolean | undefined;
|
|
5
|
+
}): {
|
|
6
|
+
before: (context: ITestContext) => Promise<void>;
|
|
7
|
+
config: (context: ITestContext) => Promise<void>;
|
|
8
|
+
compiler: (context: ITestContext) => Promise<void>;
|
|
9
|
+
build: (context: ITestContext) => Promise<void>;
|
|
10
|
+
run: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
11
|
+
check: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
12
|
+
after: (context: ITestContext) => Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
export declare function createWatchStepProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher }?: {
|
|
15
|
+
incremental?: boolean | undefined;
|
|
16
|
+
nativeWatcher?: boolean | undefined;
|
|
17
|
+
}): {
|
|
18
|
+
before: (context: ITestContext) => Promise<void>;
|
|
19
|
+
config: (context: ITestContext) => Promise<void>;
|
|
20
|
+
compiler: (context: ITestContext) => Promise<void>;
|
|
21
|
+
build: (context: ITestContext) => Promise<void>;
|
|
22
|
+
run: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
23
|
+
check: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
24
|
+
after: (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(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
|
package/dist/case/watch.js
CHANGED
|
@@ -3,16 +3,201 @@ 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.createWatchInitialProcessor = createWatchInitialProcessor;
|
|
7
|
+
exports.createWatchStepProcessor = createWatchStepProcessor;
|
|
6
8
|
exports.createWatchCase = createWatchCase;
|
|
9
|
+
exports.getWatchRunnerKey = getWatchRunnerKey;
|
|
10
|
+
exports.createWatchRunner = createWatchRunner;
|
|
7
11
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const
|
|
13
|
+
const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
14
|
+
const compiler_1 = require("../compiler");
|
|
15
|
+
const helper_1 = require("../helper");
|
|
16
|
+
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
17
|
+
const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
|
|
10
18
|
const runner_1 = require("../runner");
|
|
11
19
|
const creator_1 = require("../test/creator");
|
|
12
|
-
const
|
|
20
|
+
const common_1 = require("./common");
|
|
21
|
+
function createWatchInitialProcessor(name, tempDir, step, watchState, { incremental = false, nativeWatcher = false } = {}) {
|
|
22
|
+
const watchContext = {
|
|
23
|
+
currentTriggerFilename: null,
|
|
24
|
+
lastHash: null,
|
|
25
|
+
step,
|
|
26
|
+
tempDir,
|
|
27
|
+
nativeWatcher,
|
|
28
|
+
watchState
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
before: async (context) => {
|
|
32
|
+
context.setValue("watchContext", watchContext);
|
|
33
|
+
},
|
|
34
|
+
config: async (context) => {
|
|
35
|
+
const testConfig = context.getTestConfig();
|
|
36
|
+
const multiCompilerOptions = [];
|
|
37
|
+
const caseOptions = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)), context, {});
|
|
38
|
+
for (const [index, options] of caseOptions.entries()) {
|
|
39
|
+
const compilerOptions = (0, webpack_merge_1.default)(defaultOptions({
|
|
40
|
+
incremental,
|
|
41
|
+
ignoreNotFriendlyForIncrementalWarnings: testConfig.ignoreNotFriendlyForIncrementalWarnings
|
|
42
|
+
}), options);
|
|
43
|
+
overrideOptions(index, context, compilerOptions, tempDir, nativeWatcher);
|
|
44
|
+
multiCompilerOptions.push(compilerOptions);
|
|
45
|
+
}
|
|
46
|
+
const compilerOptions = multiCompilerOptions.length === 1
|
|
47
|
+
? multiCompilerOptions[0]
|
|
48
|
+
: multiCompilerOptions;
|
|
49
|
+
const compiler = context.getCompiler();
|
|
50
|
+
compiler.setOptions(compilerOptions);
|
|
51
|
+
context.setValue("multiCompilerOptions", multiCompilerOptions);
|
|
52
|
+
},
|
|
53
|
+
compiler: async (context) => {
|
|
54
|
+
const c = await (0, common_1.compiler)(context, name);
|
|
55
|
+
c.hooks.invalid.tap("WatchTestCasesTest", (filename, mtime) => {
|
|
56
|
+
watchContext.currentTriggerFilename = filename;
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
build: async (context) => {
|
|
60
|
+
const compiler = context.getCompiler();
|
|
61
|
+
node_fs_1.default.mkdirSync(watchContext.tempDir, { recursive: true });
|
|
62
|
+
(0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), watchContext.tempDir, true);
|
|
63
|
+
const task = new Promise((resolve, reject) => {
|
|
64
|
+
compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
|
|
65
|
+
if (e)
|
|
66
|
+
return reject(e);
|
|
67
|
+
resolve(stats);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
compiler.watch();
|
|
71
|
+
await task;
|
|
72
|
+
},
|
|
73
|
+
run: async (env, context) => {
|
|
74
|
+
await (0, common_1.run)(env, context, name, (context) => (0, common_1.findMultiCompilerBundle)(context, name, (index, context, options) => findBundle(index, context, options, step)));
|
|
75
|
+
},
|
|
76
|
+
check: async (env, context) => {
|
|
77
|
+
const testConfig = context.getTestConfig();
|
|
78
|
+
if (testConfig.noTests)
|
|
79
|
+
return;
|
|
80
|
+
const errors = (context.getError() || []).map(e => ({
|
|
81
|
+
message: e.message,
|
|
82
|
+
stack: e.stack
|
|
83
|
+
}));
|
|
84
|
+
const warnings = [];
|
|
85
|
+
const compiler = context.getCompiler();
|
|
86
|
+
const stats = compiler.getStats();
|
|
87
|
+
const options = compiler.getOptions();
|
|
88
|
+
const checkStats = testConfig.checkStats || (() => true);
|
|
89
|
+
if (stats) {
|
|
90
|
+
if (testConfig.writeStatsOuptut) {
|
|
91
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
|
|
92
|
+
preset: "verbose",
|
|
93
|
+
colors: false
|
|
94
|
+
}), "utf-8");
|
|
95
|
+
}
|
|
96
|
+
const getJsonStats = (() => {
|
|
97
|
+
let cached = null;
|
|
98
|
+
return () => {
|
|
99
|
+
if (!cached) {
|
|
100
|
+
cached = stats.toJson({
|
|
101
|
+
errorDetails: true
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return cached;
|
|
105
|
+
};
|
|
106
|
+
})();
|
|
107
|
+
const getStringStats = (() => {
|
|
108
|
+
let cached = null;
|
|
109
|
+
return () => {
|
|
110
|
+
if (!cached) {
|
|
111
|
+
cached = stats.toString({
|
|
112
|
+
logging: "verbose"
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return cached;
|
|
116
|
+
};
|
|
117
|
+
})();
|
|
118
|
+
if (checkStats.length > 1) {
|
|
119
|
+
if (!checkStats(watchContext.step, getJsonStats(), getStringStats())) {
|
|
120
|
+
throw new Error("stats check failed");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// @ts-expect-error only one param
|
|
125
|
+
if (!checkStats(watchContext.step)) {
|
|
126
|
+
throw new Error("stats check failed");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (testConfig.writeStatsJson) {
|
|
130
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.json"), JSON.stringify(getJsonStats(), null, 2), "utf-8");
|
|
131
|
+
}
|
|
132
|
+
if (node_fs_1.default.existsSync(context.getSource(`${watchContext.step}/errors.js`)) ||
|
|
133
|
+
node_fs_1.default.existsSync(context.getSource(`${watchContext.step}/warnings.js`)) ||
|
|
134
|
+
stats.hasErrors() ||
|
|
135
|
+
stats.hasWarnings()) {
|
|
136
|
+
const statsJson = stats.toJson({
|
|
137
|
+
errorDetails: true
|
|
138
|
+
});
|
|
139
|
+
if (statsJson.errors) {
|
|
140
|
+
errors.push(...statsJson.errors);
|
|
141
|
+
}
|
|
142
|
+
if (statsJson.warnings) {
|
|
143
|
+
warnings.push(...statsJson.warnings);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), { errors }, "error", "errors", "Error", options);
|
|
148
|
+
await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), watchContext.step), { warnings }, "warning", "warnings", "Warning", options);
|
|
149
|
+
// clear error if checked
|
|
150
|
+
if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
|
|
151
|
+
context.clearError();
|
|
152
|
+
}
|
|
153
|
+
// check hash
|
|
154
|
+
if (testConfig.writeStatsOuptut) {
|
|
155
|
+
node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.txt"), node_path_1.default.join(context.getDist(), `stats.${watchContext.step}.txt`));
|
|
156
|
+
}
|
|
157
|
+
if (testConfig.writeStatsJson) {
|
|
158
|
+
node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.json"), node_path_1.default.join(context.getDist(), `stats.${watchContext.step}.json`));
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
after: async (context) => {
|
|
162
|
+
await (0, common_1.afterExecute)(context, name);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function createWatchStepProcessor(name, tempDir, step, watchState, { incremental = false, nativeWatcher = false } = {}) {
|
|
167
|
+
const processor = createWatchInitialProcessor(name, tempDir, step, watchState, { incremental });
|
|
168
|
+
processor.compiler = async (context) => {
|
|
169
|
+
// do nothing
|
|
170
|
+
};
|
|
171
|
+
processor.build = async (context) => {
|
|
172
|
+
const compiler = context.getCompiler();
|
|
173
|
+
const task = new Promise((resolve, reject) => {
|
|
174
|
+
compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
|
|
175
|
+
if (e)
|
|
176
|
+
return reject(e);
|
|
177
|
+
resolve(stats);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
// wait compiler to ready watch the files and diretories
|
|
181
|
+
// Native Watcher using [notify](https://github.com/notify-rs/notify) to watch files.
|
|
182
|
+
// After tests, notify will cost many milliseconds to watch in windows OS when jest run concurrently.
|
|
183
|
+
// So we need to wait a while to ensure the watcher is ready.
|
|
184
|
+
// If we don't wait, copyDiff will happen before the watcher is ready,
|
|
185
|
+
// which will cause the compiler not rebuild when the files change.
|
|
186
|
+
// The timeout is set to 400ms for windows OS and 100ms for other OS.
|
|
187
|
+
// TODO: This is a workaround, we can remove it when notify support windows better.
|
|
188
|
+
const timeout = nativeWatcher && process.platform === "win32" ? 400 : 100;
|
|
189
|
+
await new Promise(resolve => setTimeout(resolve, timeout));
|
|
190
|
+
(0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), step), tempDir, false);
|
|
191
|
+
await task;
|
|
192
|
+
};
|
|
193
|
+
return processor;
|
|
194
|
+
}
|
|
13
195
|
const creator = new creator_1.BasicCaseCreator({
|
|
14
196
|
clean: true,
|
|
15
|
-
runner:
|
|
197
|
+
runner: {
|
|
198
|
+
key: getWatchRunnerKey,
|
|
199
|
+
runner: createWatchRunner
|
|
200
|
+
},
|
|
16
201
|
description: (name, index) => {
|
|
17
202
|
return index === 0
|
|
18
203
|
? `${name} should compile`
|
|
@@ -24,30 +209,141 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
24
209
|
const runs = node_fs_1.default
|
|
25
210
|
.readdirSync(src)
|
|
26
211
|
.sort()
|
|
27
|
-
.filter(name =>
|
|
28
|
-
return node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory();
|
|
29
|
-
})
|
|
212
|
+
.filter(name => node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory())
|
|
30
213
|
.map(name => ({ name }));
|
|
31
214
|
return runs.map((run, index) => index === 0
|
|
32
|
-
?
|
|
33
|
-
|
|
34
|
-
stepName: run.name,
|
|
35
|
-
tempDir: temp,
|
|
36
|
-
runable: true,
|
|
37
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
38
|
-
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
39
|
-
}, watchState)
|
|
40
|
-
: new watch_1.WatchStepProcessor({
|
|
41
|
-
name,
|
|
42
|
-
stepName: run.name,
|
|
43
|
-
tempDir: temp,
|
|
44
|
-
runable: true,
|
|
45
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
46
|
-
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
47
|
-
}, watchState));
|
|
215
|
+
? createWatchInitialProcessor(name, temp, run.name, watchState)
|
|
216
|
+
: createWatchStepProcessor(name, temp, run.name, watchState));
|
|
48
217
|
},
|
|
49
218
|
concurrent: true
|
|
50
219
|
});
|
|
51
220
|
function createWatchCase(name, src, dist, temp) {
|
|
52
221
|
creator.create(name, src, dist, temp);
|
|
53
222
|
}
|
|
223
|
+
function overrideOptions(index, context, options, tempDir, nativeWatcher) {
|
|
224
|
+
if (!options.mode)
|
|
225
|
+
options.mode = "development";
|
|
226
|
+
if (!options.context)
|
|
227
|
+
options.context = tempDir;
|
|
228
|
+
if (!options.entry)
|
|
229
|
+
options.entry = "./index.js";
|
|
230
|
+
if (!options.target)
|
|
231
|
+
options.target = "async-node";
|
|
232
|
+
if (!options.devtool)
|
|
233
|
+
options.devtool = false;
|
|
234
|
+
if (!options.output)
|
|
235
|
+
options.output = {};
|
|
236
|
+
if (!options.output.path)
|
|
237
|
+
options.output.path = context.getDist();
|
|
238
|
+
if (typeof options.output.pathinfo === "undefined")
|
|
239
|
+
options.output.pathinfo = false;
|
|
240
|
+
if (!options.output.filename)
|
|
241
|
+
options.output.filename = "bundle.js";
|
|
242
|
+
if (options.cache && options.cache.type === "filesystem") {
|
|
243
|
+
const cacheDirectory = node_path_1.default.join(tempDir, ".cache");
|
|
244
|
+
options.cache.cacheDirectory = cacheDirectory;
|
|
245
|
+
options.cache.name = `config-${index}`;
|
|
246
|
+
}
|
|
247
|
+
options.optimization ??= {};
|
|
248
|
+
options.experiments ??= {};
|
|
249
|
+
options.experiments.css ??= true;
|
|
250
|
+
if (nativeWatcher) {
|
|
251
|
+
options.experiments.nativeWatcher ??= true;
|
|
252
|
+
}
|
|
253
|
+
options.experiments.rspackFuture ??= {};
|
|
254
|
+
options.experiments.rspackFuture.bundlerInfo ??= {};
|
|
255
|
+
options.experiments.rspackFuture.bundlerInfo.force ??=
|
|
256
|
+
false;
|
|
257
|
+
// test incremental: "safe" here, we test default incremental in Incremental-*.test.js
|
|
258
|
+
options.experiments.incremental ??= "safe";
|
|
259
|
+
if (!global.printLogger) {
|
|
260
|
+
options.infrastructureLogging = {
|
|
261
|
+
level: "error"
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function findBundle(index, context, options, stepName) {
|
|
266
|
+
const testConfig = context.getTestConfig();
|
|
267
|
+
if (typeof testConfig.findBundle === "function") {
|
|
268
|
+
return testConfig.findBundle(index, options, stepName);
|
|
269
|
+
}
|
|
270
|
+
return "./bundle.js";
|
|
271
|
+
}
|
|
272
|
+
function defaultOptions({ incremental = false, ignoreNotFriendlyForIncrementalWarnings = false } = {}) {
|
|
273
|
+
if (incremental) {
|
|
274
|
+
return {
|
|
275
|
+
experiments: {
|
|
276
|
+
incremental: "advance"
|
|
277
|
+
},
|
|
278
|
+
ignoreWarnings: ignoreNotFriendlyForIncrementalWarnings
|
|
279
|
+
? [/is not friendly for incremental/]
|
|
280
|
+
: undefined
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return {};
|
|
284
|
+
}
|
|
285
|
+
function getWatchRunnerKey(context, name, file) {
|
|
286
|
+
const watchContext = context.getValue("watchContext");
|
|
287
|
+
const stepName = watchContext?.step;
|
|
288
|
+
return `${name}-${stepName}`;
|
|
289
|
+
}
|
|
290
|
+
function cachedWatchStats(context, name) {
|
|
291
|
+
const compiler = context.getCompiler();
|
|
292
|
+
const watchContext = context.getValue("watchContext");
|
|
293
|
+
const stepName = watchContext?.step;
|
|
294
|
+
const statsGetter = (() => {
|
|
295
|
+
const cached = {};
|
|
296
|
+
return () => {
|
|
297
|
+
if (cached[stepName]) {
|
|
298
|
+
return cached[stepName];
|
|
299
|
+
}
|
|
300
|
+
cached[stepName] = compiler.getStats().toJson({
|
|
301
|
+
errorDetails: true
|
|
302
|
+
});
|
|
303
|
+
return cached[stepName];
|
|
304
|
+
};
|
|
305
|
+
})();
|
|
306
|
+
return statsGetter;
|
|
307
|
+
}
|
|
308
|
+
function createWatchRunner(context, name, file, env) {
|
|
309
|
+
const compiler = context.getCompiler();
|
|
310
|
+
const compilerOptions = compiler.getOptions();
|
|
311
|
+
const watchContext = context.getValue("watchContext");
|
|
312
|
+
const stepName = watchContext?.step;
|
|
313
|
+
if (!stepName) {
|
|
314
|
+
throw new Error("Can not get watch step name from context");
|
|
315
|
+
}
|
|
316
|
+
const state = watchContext?.watchState;
|
|
317
|
+
if (!state) {
|
|
318
|
+
throw new Error("Can not get watch state from context");
|
|
319
|
+
}
|
|
320
|
+
const isWeb = Array.isArray(compilerOptions)
|
|
321
|
+
? compilerOptions.some(option => {
|
|
322
|
+
return option.target === "web" || option.target === "webworker";
|
|
323
|
+
})
|
|
324
|
+
: compilerOptions.target === "web" ||
|
|
325
|
+
compilerOptions.target === "webworker";
|
|
326
|
+
const testConfig = context.getTestConfig();
|
|
327
|
+
return new runner_1.WebRunner({
|
|
328
|
+
env,
|
|
329
|
+
stats: cachedWatchStats(context, name),
|
|
330
|
+
name: name,
|
|
331
|
+
runInNewContext: isWeb,
|
|
332
|
+
cachable: false,
|
|
333
|
+
testConfig: {
|
|
334
|
+
...(testConfig || {}),
|
|
335
|
+
moduleScope: (ms, stats, options) => {
|
|
336
|
+
ms.STATE = state;
|
|
337
|
+
ms.WATCH_STEP = stepName;
|
|
338
|
+
if (typeof testConfig.moduleScope === "function") {
|
|
339
|
+
return testConfig.moduleScope(ms, stats, options);
|
|
340
|
+
}
|
|
341
|
+
return ms;
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
source: context.getSource(),
|
|
345
|
+
dist: context.getDist(),
|
|
346
|
+
compilerOptions,
|
|
347
|
+
location: testConfig.location || "https://test.cases/path/index.html"
|
|
348
|
+
});
|
|
349
|
+
}
|