@rspack-canary/test-tools 1.5.7-canary-a3406c0a-20250922173625 → 1.5.8-canary-6c1a40e3-20250925175235
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 -2
- package/dist/case/builtin.js +37 -28
- package/dist/case/cache.d.ts +1 -1
- package/dist/case/cache.js +135 -42
- 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 +3 -2
- package/dist/case/config.js +47 -39
- package/dist/case/defaults.d.ts +2 -2
- package/dist/case/defaults.js +28 -18
- package/dist/case/diagnostic.d.ts +1 -1
- package/dist/case/diagnostic.js +52 -43
- 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 +51 -21
- package/dist/case/hash.d.ts +1 -1
- package/dist/case/hash.js +41 -34
- package/dist/case/hook.d.ts +4 -5
- package/dist/case/hook.js +78 -70
- package/dist/case/hot-step.d.ts +1 -1
- package/dist/case/hot-step.js +9 -5
- package/dist/case/hot.d.ts +5 -5
- package/dist/case/hot.js +142 -55
- package/dist/case/incremental.d.ts +1 -1
- package/dist/case/incremental.js +19 -34
- package/dist/case/native-watcher.js +10 -23
- package/dist/case/normal.js +46 -31
- 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 +7 -15
- package/dist/case/stats-api.js +52 -22
- package/dist/case/stats-output.js +133 -137
- package/dist/case/treeshaking.js +33 -22
- package/dist/case/watch.d.ts +27 -0
- package/dist/case/watch.js +321 -21
- 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 +41 -10
- package/dist/type.js +7 -1
- package/package.json +6 -6
- package/dist/processor/basic.d.ts +0 -27
- package/dist/processor/basic.js +0 -157
- package/dist/processor/diff.d.ts +0 -30
- package/dist/processor/diff.js +0 -140
- package/dist/processor/index.d.ts +0 -6
- package/dist/processor/index.js +0 -22
- package/dist/processor/multi.d.ts +0 -19
- package/dist/processor/multi.js +0 -75
- 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 -67
- 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/processor/watch.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WatchStepProcessor = exports.WatchProcessor = void 0;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const webpack_merge_1 = require("webpack-merge");
|
|
10
|
-
const compiler_1 = require("../compiler");
|
|
11
|
-
const helper_1 = require("../helper");
|
|
12
|
-
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
13
|
-
const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
|
|
14
|
-
const multi_1 = require("./multi");
|
|
15
|
-
// This file is used to port step number to rspack.config.js/webpack.config.js
|
|
16
|
-
const currentWatchStepModulePath = node_path_1.default.resolve(__dirname, "../helper/util/currentWatchStep");
|
|
17
|
-
class WatchProcessor extends multi_1.MultiTaskProcessor {
|
|
18
|
-
constructor(_watchOptions, _watchState) {
|
|
19
|
-
super({
|
|
20
|
-
overrideOptions: WatchProcessor.overrideOptions(_watchOptions),
|
|
21
|
-
findBundle: (WatchProcessor.findBundle),
|
|
22
|
-
..._watchOptions
|
|
23
|
-
});
|
|
24
|
-
this._watchOptions = _watchOptions;
|
|
25
|
-
this._watchState = _watchState;
|
|
26
|
-
this.currentTriggerFilename = null;
|
|
27
|
-
this.lastHash = null;
|
|
28
|
-
}
|
|
29
|
-
async compiler(context) {
|
|
30
|
-
await super.compiler(context);
|
|
31
|
-
const compiler = this.getCompiler(context).getCompiler();
|
|
32
|
-
compiler.hooks.invalid.tap("WatchTestCasesTest", (filename, mtime) => {
|
|
33
|
-
this.currentTriggerFilename = filename;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
async build(context) {
|
|
37
|
-
const compiler = this.getCompiler(context);
|
|
38
|
-
const currentWatchStepModule = require(currentWatchStepModulePath);
|
|
39
|
-
currentWatchStepModule.step[this._options.name] =
|
|
40
|
-
this._watchOptions.stepName;
|
|
41
|
-
node_fs_1.default.mkdirSync(this._watchOptions.tempDir, { recursive: true });
|
|
42
|
-
(0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), this._watchOptions.tempDir, true);
|
|
43
|
-
const task = new Promise((resolve, reject) => {
|
|
44
|
-
compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
|
|
45
|
-
if (e)
|
|
46
|
-
return reject(e);
|
|
47
|
-
resolve(stats);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
compiler.watch();
|
|
51
|
-
await task;
|
|
52
|
-
}
|
|
53
|
-
async run(env, context) {
|
|
54
|
-
context.setValue(this._options.name, "watchStepName", this._watchOptions.stepName);
|
|
55
|
-
context.setValue(this._options.name, "watchState", this._watchState);
|
|
56
|
-
await super.run(env, context);
|
|
57
|
-
}
|
|
58
|
-
async check(env, context) {
|
|
59
|
-
const testConfig = context.getTestConfig();
|
|
60
|
-
if (testConfig.noTests)
|
|
61
|
-
return;
|
|
62
|
-
const errors = (context.getError(this._options.name) || []).map(e => ({
|
|
63
|
-
message: e.message,
|
|
64
|
-
stack: e.stack
|
|
65
|
-
}));
|
|
66
|
-
const warnings = [];
|
|
67
|
-
const compiler = this.getCompiler(context);
|
|
68
|
-
const stats = compiler.getStats();
|
|
69
|
-
const options = compiler.getOptions();
|
|
70
|
-
const checkStats = testConfig.checkStats || (() => true);
|
|
71
|
-
if (stats) {
|
|
72
|
-
if (testConfig.writeStatsOuptut) {
|
|
73
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
|
|
74
|
-
preset: "verbose",
|
|
75
|
-
colors: false
|
|
76
|
-
}), "utf-8");
|
|
77
|
-
}
|
|
78
|
-
const getJsonStats = (() => {
|
|
79
|
-
let cached = null;
|
|
80
|
-
return () => {
|
|
81
|
-
if (!cached) {
|
|
82
|
-
cached = stats.toJson({
|
|
83
|
-
errorDetails: true
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return cached;
|
|
87
|
-
};
|
|
88
|
-
})();
|
|
89
|
-
const getStringStats = (() => {
|
|
90
|
-
let cached = null;
|
|
91
|
-
return () => {
|
|
92
|
-
if (!cached) {
|
|
93
|
-
cached = stats.toString({
|
|
94
|
-
logging: "verbose"
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return cached;
|
|
98
|
-
};
|
|
99
|
-
})();
|
|
100
|
-
if (checkStats.length > 1) {
|
|
101
|
-
if (!checkStats(this._watchOptions.stepName, getJsonStats(), getStringStats())) {
|
|
102
|
-
throw new Error("stats check failed");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
// @ts-expect-error only one param
|
|
107
|
-
if (!checkStats(this._watchOptions.stepName)) {
|
|
108
|
-
throw new Error("stats check failed");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (testConfig.writeStatsJson) {
|
|
112
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.json"), JSON.stringify(getJsonStats(), null, 2), "utf-8");
|
|
113
|
-
}
|
|
114
|
-
if (node_fs_1.default.existsSync(context.getSource(`${this._watchOptions.stepName}/errors.js`)) ||
|
|
115
|
-
node_fs_1.default.existsSync(context.getSource(`${this._watchOptions.stepName}/warnings.js`)) ||
|
|
116
|
-
stats.hasErrors() ||
|
|
117
|
-
stats.hasWarnings()) {
|
|
118
|
-
const statsJson = stats.toJson({
|
|
119
|
-
errorDetails: true
|
|
120
|
-
});
|
|
121
|
-
if (statsJson.errors) {
|
|
122
|
-
errors.push(...statsJson.errors);
|
|
123
|
-
}
|
|
124
|
-
if (statsJson.warnings) {
|
|
125
|
-
warnings.push(...statsJson.warnings);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { errors }, "error", "errors", "Error", options);
|
|
130
|
-
await (0, checkArrayExpectation_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), { warnings }, "warning", "warnings", "Warning", options);
|
|
131
|
-
// clear error if checked
|
|
132
|
-
if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
|
|
133
|
-
context.clearError(this._options.name);
|
|
134
|
-
}
|
|
135
|
-
// check hash
|
|
136
|
-
if (testConfig.writeStatsOuptut) {
|
|
137
|
-
node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.txt"), node_path_1.default.join(context.getDist(), `stats.${this._watchOptions.stepName}.txt`));
|
|
138
|
-
}
|
|
139
|
-
if (testConfig.writeStatsJson) {
|
|
140
|
-
node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.json"), node_path_1.default.join(context.getDist(), `stats.${this._watchOptions.stepName}.json`));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
async config(context) {
|
|
144
|
-
this.multiCompilerOptions = [];
|
|
145
|
-
const caseOptions = Array.isArray(this._multiOptions.configFiles)
|
|
146
|
-
? (0, helper_1.readConfigFile)(this._multiOptions.configFiles.map(i => context.getSource(i)))
|
|
147
|
-
: [{}];
|
|
148
|
-
for (const [index, options] of caseOptions.entries()) {
|
|
149
|
-
const compilerOptions = (0, webpack_merge_1.merge)(typeof this._multiOptions.defaultOptions === "function"
|
|
150
|
-
? this._multiOptions.defaultOptions(index, context)
|
|
151
|
-
: {}, options);
|
|
152
|
-
if (typeof this._multiOptions.overrideOptions === "function") {
|
|
153
|
-
this._multiOptions.overrideOptions(index, context, compilerOptions);
|
|
154
|
-
}
|
|
155
|
-
this.multiCompilerOptions.push(compilerOptions);
|
|
156
|
-
}
|
|
157
|
-
const compilerOptions = this.multiCompilerOptions.length === 1
|
|
158
|
-
? this.multiCompilerOptions[0]
|
|
159
|
-
: this.multiCompilerOptions;
|
|
160
|
-
const compiler = this.getCompiler(context);
|
|
161
|
-
compiler.setOptions(compilerOptions);
|
|
162
|
-
}
|
|
163
|
-
static overrideOptions({ tempDir, nativeWatcher }) {
|
|
164
|
-
return (index, context, options) => {
|
|
165
|
-
if (!options.mode)
|
|
166
|
-
options.mode = "development";
|
|
167
|
-
if (!options.context)
|
|
168
|
-
options.context = tempDir;
|
|
169
|
-
if (!options.entry)
|
|
170
|
-
options.entry = "./index.js";
|
|
171
|
-
if (!options.target)
|
|
172
|
-
options.target = "async-node";
|
|
173
|
-
if (!options.devtool)
|
|
174
|
-
options.devtool = false;
|
|
175
|
-
if (!options.output)
|
|
176
|
-
options.output = {};
|
|
177
|
-
if (!options.output.path)
|
|
178
|
-
options.output.path = context.getDist();
|
|
179
|
-
if (typeof options.output.pathinfo === "undefined")
|
|
180
|
-
options.output.pathinfo = false;
|
|
181
|
-
if (!options.output.filename)
|
|
182
|
-
options.output.filename = "bundle.js";
|
|
183
|
-
if (options.cache && options.cache.type === "filesystem") {
|
|
184
|
-
const cacheDirectory = node_path_1.default.join(tempDir, ".cache");
|
|
185
|
-
options.cache.cacheDirectory = cacheDirectory;
|
|
186
|
-
options.cache.name = `config-${index}`;
|
|
187
|
-
}
|
|
188
|
-
options.optimization ??= {};
|
|
189
|
-
options.experiments ??= {};
|
|
190
|
-
options.experiments.css ??= true;
|
|
191
|
-
if (nativeWatcher) {
|
|
192
|
-
options.experiments.nativeWatcher ??= true;
|
|
193
|
-
}
|
|
194
|
-
options.experiments.rspackFuture ??= {};
|
|
195
|
-
options.experiments.rspackFuture.bundlerInfo ??= {};
|
|
196
|
-
options.experiments.rspackFuture.bundlerInfo.force ??= false;
|
|
197
|
-
// test incremental: "safe" here, we test default incremental in Incremental-*.test.js
|
|
198
|
-
options.experiments.incremental ??= "safe";
|
|
199
|
-
if (!global.printLogger) {
|
|
200
|
-
options.infrastructureLogging = {
|
|
201
|
-
level: "error"
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
static findBundle(index, context, options) {
|
|
207
|
-
const testConfig = context.getTestConfig();
|
|
208
|
-
if (typeof testConfig.findBundle === "function") {
|
|
209
|
-
return testConfig.findBundle(index, options, this.stepName);
|
|
210
|
-
}
|
|
211
|
-
return "./bundle.js";
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
exports.WatchProcessor = WatchProcessor;
|
|
215
|
-
class WatchStepProcessor extends WatchProcessor {
|
|
216
|
-
constructor(_watchOptions, _watchState) {
|
|
217
|
-
super(_watchOptions, _watchState);
|
|
218
|
-
this._watchOptions = _watchOptions;
|
|
219
|
-
this._watchState = _watchState;
|
|
220
|
-
}
|
|
221
|
-
async compiler(context) {
|
|
222
|
-
// do nothing
|
|
223
|
-
}
|
|
224
|
-
async build(context) {
|
|
225
|
-
const compiler = this.getCompiler(context);
|
|
226
|
-
const currentWatchStepModule = require(currentWatchStepModulePath);
|
|
227
|
-
currentWatchStepModule.step[this._options.name] =
|
|
228
|
-
this._watchOptions.stepName;
|
|
229
|
-
const task = new Promise((resolve, reject) => {
|
|
230
|
-
compiler.getEmitter().once(compiler_1.ECompilerEvent.Build, (e, stats) => {
|
|
231
|
-
if (e)
|
|
232
|
-
return reject(e);
|
|
233
|
-
resolve(stats);
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
// wait compiler to ready watch the files and diretories
|
|
237
|
-
// Native Watcher using [notify](https://github.com/notify-rs/notify) to watch files.
|
|
238
|
-
// After tests, notify will cost many milliseconds to watch in windows OS when jest run concurrently.
|
|
239
|
-
// So we need to wait a while to ensure the watcher is ready.
|
|
240
|
-
// If we don't wait, copyDiff will happen before the watcher is ready,
|
|
241
|
-
// which will cause the compiler not rebuild when the files change.
|
|
242
|
-
// The timeout is set to 400ms for windows OS and 100ms for other OS.
|
|
243
|
-
// TODO: This is a workaround, we can remove it when notify support windows better.
|
|
244
|
-
const timeout = this._watchOptions.nativeWatcher && process.platform === "win32"
|
|
245
|
-
? 400
|
|
246
|
-
: 100;
|
|
247
|
-
await new Promise(resolve => setTimeout(resolve, timeout));
|
|
248
|
-
(0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), this._watchOptions.tempDir, false);
|
|
249
|
-
await task;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
exports.WatchStepProcessor = WatchStepProcessor;
|
package/dist/runner/basic.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type ECompilerType, type ITestContext, type ITestEnv, type ITestRunner, type TCompilerOptions, type TCompilerStatsCompilation, type TRunnerFactory } from "../type";
|
|
2
|
-
export declare class BasicRunnerFactory<T extends ECompilerType> implements TRunnerFactory<T> {
|
|
3
|
-
protected name: string;
|
|
4
|
-
protected context: ITestContext;
|
|
5
|
-
constructor(name: string, context: ITestContext);
|
|
6
|
-
protected createStatsGetter(): () => TCompilerStatsCompilation<T>;
|
|
7
|
-
create(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
|
|
8
|
-
protected getRunnerKey(file: string): string;
|
|
9
|
-
protected createRunner(file: string, stats: () => TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
|
|
10
|
-
}
|
package/dist/runner/basic.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BasicRunnerFactory = void 0;
|
|
4
|
-
const type_1 = require("../type");
|
|
5
|
-
const node_1 = require("./runner/node");
|
|
6
|
-
const web_1 = require("./runner/web");
|
|
7
|
-
class BasicRunnerFactory {
|
|
8
|
-
constructor(name, context) {
|
|
9
|
-
this.name = name;
|
|
10
|
-
this.context = context;
|
|
11
|
-
}
|
|
12
|
-
createStatsGetter() {
|
|
13
|
-
const compiler = this.context.getCompiler(this.name);
|
|
14
|
-
const statsGetter = (() => {
|
|
15
|
-
let cached = null;
|
|
16
|
-
return () => {
|
|
17
|
-
if (cached) {
|
|
18
|
-
return cached;
|
|
19
|
-
}
|
|
20
|
-
cached = compiler.getStats().toJson({
|
|
21
|
-
errorDetails: true
|
|
22
|
-
});
|
|
23
|
-
return cached;
|
|
24
|
-
};
|
|
25
|
-
})();
|
|
26
|
-
return statsGetter;
|
|
27
|
-
}
|
|
28
|
-
create(file, compilerOptions, env) {
|
|
29
|
-
const key = this.getRunnerKey(file);
|
|
30
|
-
const exists = this.context.getRunner(key);
|
|
31
|
-
if (exists) {
|
|
32
|
-
return exists;
|
|
33
|
-
}
|
|
34
|
-
const runner = this.createRunner(file, this.createStatsGetter(), compilerOptions, env);
|
|
35
|
-
this.context.setRunner(key, runner);
|
|
36
|
-
return runner;
|
|
37
|
-
}
|
|
38
|
-
getRunnerKey(file) {
|
|
39
|
-
return this.name;
|
|
40
|
-
}
|
|
41
|
-
createRunner(file, stats, compilerOptions, env) {
|
|
42
|
-
const runnerOptions = {
|
|
43
|
-
runInNewContext: false,
|
|
44
|
-
cachable: true,
|
|
45
|
-
env,
|
|
46
|
-
stats,
|
|
47
|
-
name: this.name,
|
|
48
|
-
testConfig: this.context.getTestConfig(),
|
|
49
|
-
source: this.context.getSource(),
|
|
50
|
-
dist: this.context.getDist(),
|
|
51
|
-
compilerOptions
|
|
52
|
-
};
|
|
53
|
-
if (compilerOptions.target === "web" ||
|
|
54
|
-
compilerOptions.target === "webworker") {
|
|
55
|
-
return new web_1.WebRunner({
|
|
56
|
-
...runnerOptions,
|
|
57
|
-
runInNewContext: true,
|
|
58
|
-
dom: this.context.getValue(this.name, "documentType") || type_1.EDocumentType.Fake
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
return new node_1.NodeRunner(runnerOptions);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.BasicRunnerFactory = BasicRunnerFactory;
|
package/dist/runner/cache.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { type ECompilerType, type ITestEnv, type ITestRunner, type TCompilerOptions, type TCompilerStatsCompilation } from "../type";
|
|
2
|
-
import { BasicRunnerFactory } from "./basic";
|
|
3
|
-
export declare class CacheRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
|
|
4
|
-
protected createRunner(file: string, stats: TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
|
|
5
|
-
}
|
package/dist/runner/cache.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CacheRunnerFactory = void 0;
|
|
7
|
-
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
8
|
-
const type_1 = require("../type");
|
|
9
|
-
const basic_1 = require("./basic");
|
|
10
|
-
const web_1 = require("./runner/web");
|
|
11
|
-
const MAX_COMPILER_INDEX = 100;
|
|
12
|
-
class CacheRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
13
|
-
createRunner(file, stats, compilerOptions, env) {
|
|
14
|
-
const compiler = this.context.getCompiler(this.name);
|
|
15
|
-
let compilerIndex = 0;
|
|
16
|
-
const testConfig = this.context.getTestConfig();
|
|
17
|
-
const source = this.context.getSource();
|
|
18
|
-
const dist = this.context.getDist();
|
|
19
|
-
const updatePlugin = this.context.getValue(this.name, "hotUpdateContext");
|
|
20
|
-
const getWebRunner = () => {
|
|
21
|
-
return new web_1.WebRunner({
|
|
22
|
-
dom: this.context.getValue(this.name, "documentType") ||
|
|
23
|
-
type_1.EDocumentType.JSDOM,
|
|
24
|
-
env,
|
|
25
|
-
stats: this.createStatsGetter(),
|
|
26
|
-
cachable: false,
|
|
27
|
-
name: this.name,
|
|
28
|
-
runInNewContext: false,
|
|
29
|
-
testConfig: {
|
|
30
|
-
...testConfig,
|
|
31
|
-
moduleScope(ms, stats) {
|
|
32
|
-
const moduleScope = typeof testConfig.moduleScope === "function"
|
|
33
|
-
? testConfig.moduleScope(ms, stats, compilerOptions)
|
|
34
|
-
: ms;
|
|
35
|
-
moduleScope.COMPILER_INDEX = compilerIndex;
|
|
36
|
-
moduleScope.NEXT_HMR = nextHmr;
|
|
37
|
-
moduleScope.NEXT_START = nextStart;
|
|
38
|
-
return moduleScope;
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
source,
|
|
42
|
-
dist,
|
|
43
|
-
compilerOptions
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
const nextHmr = async (m, options) => {
|
|
47
|
-
await updatePlugin.goNext();
|
|
48
|
-
const stats = await compiler.build();
|
|
49
|
-
if (!stats) {
|
|
50
|
-
throw new Error("Should generate stats during build");
|
|
51
|
-
}
|
|
52
|
-
const jsonStats = stats.toJson({
|
|
53
|
-
// errorDetails: true
|
|
54
|
-
});
|
|
55
|
-
const compilerOptions = compiler.getOptions();
|
|
56
|
-
const updateIndex = updatePlugin.getUpdateIndex();
|
|
57
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error", compilerOptions);
|
|
58
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning", compilerOptions);
|
|
59
|
-
const updatedModules = await m.hot.check(options || true);
|
|
60
|
-
if (!updatedModules) {
|
|
61
|
-
throw new Error("No update available");
|
|
62
|
-
}
|
|
63
|
-
return jsonStats;
|
|
64
|
-
};
|
|
65
|
-
const nextStart = async () => {
|
|
66
|
-
await compiler.close();
|
|
67
|
-
compiler.createCompiler();
|
|
68
|
-
await updatePlugin.goNext();
|
|
69
|
-
const stats = await compiler.build();
|
|
70
|
-
if (!stats) {
|
|
71
|
-
throw new Error("Should generate stats during build");
|
|
72
|
-
}
|
|
73
|
-
const jsonStats = stats.toJson({
|
|
74
|
-
// errorDetails: true
|
|
75
|
-
});
|
|
76
|
-
const compilerOptions = compiler.getOptions();
|
|
77
|
-
const updateIndex = updatePlugin.getUpdateIndex();
|
|
78
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error", compilerOptions);
|
|
79
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning", compilerOptions);
|
|
80
|
-
env.it(`NEXT_START run with compilerIndex==${compilerIndex + 1}`, async () => {
|
|
81
|
-
if (compilerIndex > MAX_COMPILER_INDEX) {
|
|
82
|
-
throw new Error("NEXT_START has been called more than the maximum times");
|
|
83
|
-
}
|
|
84
|
-
compilerIndex++;
|
|
85
|
-
return getWebRunner().run(file);
|
|
86
|
-
});
|
|
87
|
-
return jsonStats;
|
|
88
|
-
};
|
|
89
|
-
return getWebRunner();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.CacheRunnerFactory = CacheRunnerFactory;
|
package/dist/runner/hot.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { type ECompilerType, type ITestEnv, type ITestRunner, type TCompilerOptions, type TCompilerStatsCompilation } from "../type";
|
|
2
|
-
import { BasicRunnerFactory } from "./basic";
|
|
3
|
-
export declare class HotRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
|
|
4
|
-
protected createRunner(file: string, stats: TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
|
|
5
|
-
}
|
package/dist/runner/hot.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.HotRunnerFactory = void 0;
|
|
7
|
-
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
8
|
-
const type_1 = require("../type");
|
|
9
|
-
const basic_1 = require("./basic");
|
|
10
|
-
const web_1 = require("./runner/web");
|
|
11
|
-
class HotRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
12
|
-
createRunner(file, stats, compilerOptions, env) {
|
|
13
|
-
const compiler = this.context.getCompiler(this.name);
|
|
14
|
-
const testConfig = this.context.getTestConfig();
|
|
15
|
-
const source = this.context.getSource();
|
|
16
|
-
const dist = this.context.getDist();
|
|
17
|
-
const hotUpdateContext = this.context.getValue(this.name, "hotUpdateContext");
|
|
18
|
-
const next = async (callback) => {
|
|
19
|
-
const usePromise = typeof callback === "function";
|
|
20
|
-
try {
|
|
21
|
-
hotUpdateContext.updateIndex++;
|
|
22
|
-
const stats = await compiler.build();
|
|
23
|
-
if (!stats) {
|
|
24
|
-
throw new Error("Should generate stats during build");
|
|
25
|
-
}
|
|
26
|
-
const jsonStats = stats.toJson({
|
|
27
|
-
// errorDetails: true
|
|
28
|
-
});
|
|
29
|
-
const compilerOptions = compiler.getOptions();
|
|
30
|
-
const checker = this.context.getValue(this.name, jsonStats.errors?.length
|
|
31
|
-
? "hotUpdateStepErrorChecker"
|
|
32
|
-
: "hotUpdateStepChecker");
|
|
33
|
-
if (checker) {
|
|
34
|
-
checker(hotUpdateContext, stats, runner.getGlobal("__HMR_UPDATED_RUNTIME__"));
|
|
35
|
-
}
|
|
36
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${hotUpdateContext.updateIndex}`, "Error", compilerOptions);
|
|
37
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${hotUpdateContext.updateIndex}`, "Warning", compilerOptions);
|
|
38
|
-
if (usePromise) {
|
|
39
|
-
// old callback style hmr cases
|
|
40
|
-
callback(null, jsonStats);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
// new promise style hmr cases
|
|
44
|
-
return jsonStats;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
if (usePromise) {
|
|
49
|
-
callback(e);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
throw e;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const nextHMR = async (m, options) => {
|
|
57
|
-
const jsonStats = await next();
|
|
58
|
-
const updatedModules = await m.hot.check(options || true);
|
|
59
|
-
if (!updatedModules) {
|
|
60
|
-
throw new Error("No update available");
|
|
61
|
-
}
|
|
62
|
-
return jsonStats;
|
|
63
|
-
};
|
|
64
|
-
const runner = new web_1.WebRunner({
|
|
65
|
-
dom: this.context.getValue(this.name, "documentType") || type_1.EDocumentType.JSDOM,
|
|
66
|
-
env,
|
|
67
|
-
stats: this.createStatsGetter(),
|
|
68
|
-
name: this.name,
|
|
69
|
-
runInNewContext: false,
|
|
70
|
-
testConfig: {
|
|
71
|
-
documentType: testConfig.documentType || type_1.EDocumentType.Fake,
|
|
72
|
-
...testConfig,
|
|
73
|
-
moduleScope(ms, stats) {
|
|
74
|
-
const moduleScope = ms;
|
|
75
|
-
if (typeof testConfig.moduleScope === "function") {
|
|
76
|
-
testConfig.moduleScope(moduleScope, stats, compilerOptions);
|
|
77
|
-
}
|
|
78
|
-
moduleScope.NEXT = next;
|
|
79
|
-
moduleScope.NEXT_HMR = nextHMR;
|
|
80
|
-
return moduleScope;
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
cachable: true,
|
|
84
|
-
source,
|
|
85
|
-
dist,
|
|
86
|
-
compilerOptions
|
|
87
|
-
});
|
|
88
|
-
return runner;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.HotRunnerFactory = HotRunnerFactory;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ECompilerType, ITestEnv, ITestRunner, TCompilerOptions, TCompilerStatsCompilation } from "../type";
|
|
2
|
-
import { BasicRunnerFactory } from "./basic";
|
|
3
|
-
export declare class MultipleRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
|
|
4
|
-
protected runned: Set<string>;
|
|
5
|
-
protected getRunnerKey(file: string): string;
|
|
6
|
-
protected createRunner(file: string, stats: () => TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
|
|
7
|
-
protected getFileIndexHandler(file: string): {
|
|
8
|
-
getIndex: () => number[];
|
|
9
|
-
flagIndex: () => Set<string>;
|
|
10
|
-
};
|
|
11
|
-
}
|
package/dist/runner/multiple.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MultipleRunnerFactory = void 0;
|
|
4
|
-
const basic_1 = require("./basic");
|
|
5
|
-
class MultipleRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.runned = new Set();
|
|
9
|
-
}
|
|
10
|
-
getRunnerKey(file) {
|
|
11
|
-
const { getIndex } = this.getFileIndexHandler(file);
|
|
12
|
-
const [index, seq] = getIndex();
|
|
13
|
-
return `${this.name}-${index}[${seq}]`;
|
|
14
|
-
}
|
|
15
|
-
createRunner(file, stats, compilerOptions, env) {
|
|
16
|
-
const { getIndex, flagIndex } = this.getFileIndexHandler(file);
|
|
17
|
-
const key = this.getRunnerKey(file);
|
|
18
|
-
const exists = this.context.getRunner(key);
|
|
19
|
-
if (exists) {
|
|
20
|
-
flagIndex();
|
|
21
|
-
return exists;
|
|
22
|
-
}
|
|
23
|
-
const multiCompilerOptions = this.context.getValue(this.name, "multiCompilerOptions") || [];
|
|
24
|
-
const [index] = getIndex();
|
|
25
|
-
const runner = super.createRunner(file, () => {
|
|
26
|
-
const s = stats();
|
|
27
|
-
if (s.children?.length && s.children.length > 1) {
|
|
28
|
-
s.__index__ = index;
|
|
29
|
-
return s;
|
|
30
|
-
}
|
|
31
|
-
return s.children[index];
|
|
32
|
-
}, multiCompilerOptions[index], env);
|
|
33
|
-
flagIndex();
|
|
34
|
-
this.context.setRunner(key, runner);
|
|
35
|
-
return runner;
|
|
36
|
-
}
|
|
37
|
-
getFileIndexHandler(file) {
|
|
38
|
-
const multiFileIndexMap = this.context.getValue(this.name, "multiFileIndexMap") || {};
|
|
39
|
-
if (typeof multiFileIndexMap[file] === "undefined") {
|
|
40
|
-
throw new Error("Unexpect file in multiple runner");
|
|
41
|
-
}
|
|
42
|
-
const indexList = multiFileIndexMap[file];
|
|
43
|
-
const seq = indexList.findIndex((index, n) => !this.runned.has(`${this.name}:${file}[${n}]`));
|
|
44
|
-
if (seq === -1) {
|
|
45
|
-
throw new Error(`File ${file} should run only ${indexList.length} times`);
|
|
46
|
-
}
|
|
47
|
-
const getIndex = () => [indexList[seq], seq];
|
|
48
|
-
const flagIndex = () => this.runned.add(`${this.name}:${file}[${seq}]`);
|
|
49
|
-
return { getIndex, flagIndex };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.MultipleRunnerFactory = MultipleRunnerFactory;
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./node"), exports);
|
|
18
|
-
__exportStar(require("./web"), exports);
|
package/dist/runner/type.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { ITestEnv } from "../type";
|
|
2
|
-
export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] | string, context?: {
|
|
3
|
-
file?: TRunnerFile;
|
|
4
|
-
esmMode?: EEsmMode;
|
|
5
|
-
}) => Object | Promise<Object>;
|
|
6
|
-
export type TRunnerFile = {
|
|
7
|
-
path: string;
|
|
8
|
-
content: string;
|
|
9
|
-
subPath: string;
|
|
10
|
-
};
|
|
11
|
-
export declare enum EEsmMode {
|
|
12
|
-
Unknown = 0,
|
|
13
|
-
Evaluated = 1,
|
|
14
|
-
Unlinked = 2
|
|
15
|
-
}
|
|
16
|
-
export interface IModuleScope extends ITestEnv {
|
|
17
|
-
console: Record<string, (...args: any[]) => void>;
|
|
18
|
-
expect: jest.Expect;
|
|
19
|
-
[key: string]: any;
|
|
20
|
-
}
|
|
21
|
-
export interface IGlobalContext {
|
|
22
|
-
console: Record<string, (...args: any[]) => void>;
|
|
23
|
-
setTimeout: typeof setTimeout;
|
|
24
|
-
clearTimeout: typeof clearTimeout;
|
|
25
|
-
[key: string]: any;
|
|
26
|
-
}
|
|
27
|
-
export type TModuleObject = {
|
|
28
|
-
exports: unknown;
|
|
29
|
-
};
|
|
30
|
-
export type THotStepRuntimeLangData = {
|
|
31
|
-
outdatedModules: string[];
|
|
32
|
-
outdatedDependencies: Record<string, string[]>;
|
|
33
|
-
updatedModules: string[];
|
|
34
|
-
updatedRuntime: string[];
|
|
35
|
-
acceptedModules: string[];
|
|
36
|
-
disposedModules: string[];
|
|
37
|
-
};
|
|
38
|
-
export type THotStepRuntimeData = {
|
|
39
|
-
javascript: THotStepRuntimeLangData;
|
|
40
|
-
css: THotStepRuntimeLangData;
|
|
41
|
-
statusPath: string[];
|
|
42
|
-
};
|
package/dist/runner/type.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EEsmMode = void 0;
|
|
4
|
-
var EEsmMode;
|
|
5
|
-
(function (EEsmMode) {
|
|
6
|
-
EEsmMode[EEsmMode["Unknown"] = 0] = "Unknown";
|
|
7
|
-
EEsmMode[EEsmMode["Evaluated"] = 1] = "Evaluated";
|
|
8
|
-
EEsmMode[EEsmMode["Unlinked"] = 2] = "Unlinked";
|
|
9
|
-
})(EEsmMode || (exports.EEsmMode = EEsmMode = {}));
|