vitest 0.24.5 → 0.25.1
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/LICENSE.md +286 -57
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +18 -11
- package/dist/{chunk-api-setup.629f8133.js → chunk-api-setup.f40616e2.js} +38 -19
- package/dist/{chunk-env-node.700b7e95.js → chunk-env-node.67948209.js} +8 -11
- package/dist/{chunk-install-pkg.22707ee4.js → chunk-install-pkg.579a5a27.js} +3 -4
- package/dist/{chunk-integrations-coverage.cca09977.js → chunk-integrations-coverage.befed097.js} +57 -1
- package/dist/chunk-integrations-globals.796fe181.js +25 -0
- package/dist/{chunk-node-git.82174cfe.js → chunk-node-git.5a1b1656.js} +5 -6
- package/dist/{chunk-runtime-chain.37ec5d73.js → chunk-runtime-chain.e387e274.js} +36 -25
- package/dist/{chunk-runtime-error.17751c39.js → chunk-runtime-error.6287172c.js} +9 -2
- package/dist/{chunk-runtime-mocker.41b92ec9.js → chunk-runtime-mocker.503a4f67.js} +4 -4
- package/dist/{chunk-runtime-rpc.b418c0ab.js → chunk-runtime-rpc.1e7530d3.js} +2 -2
- package/dist/chunk-runtime-setup.5c4e0f49.js +1363 -0
- package/dist/{chunk-runtime-hooks.d748b085.js → chunk-runtime-test-state.4ed42543.js} +119 -6
- package/dist/{chunk-mock-date.030959d3.js → chunk-typecheck-constants.4891f22f.js} +23 -4
- package/dist/{chunk-utils-env.b1281522.js → chunk-utils-env.03f840f2.js} +2 -0
- package/dist/chunk-utils-source-map.c6dfbbc1.js +90 -0
- package/dist/{chunk-utils-timers.8fca243e.js → chunk-utils-timers.06f993db.js} +86 -79
- package/dist/{chunk-vite-node-client.3868b3ba.js → chunk-vite-node-client.b2ab6dcf.js} +25 -5
- package/dist/{chunk-vite-node-externalize.d9033432.js → chunk-vite-node-externalize.477f36a4.js} +821 -92
- package/dist/chunk-vite-node-utils.8f0b4a12.js +1400 -0
- package/dist/cli-wrapper.js +5 -6
- package/dist/cli.js +27 -13
- package/dist/config.cjs +6 -1
- package/dist/config.d.ts +6 -1
- package/dist/config.js +6 -1
- package/dist/entry.js +15 -13
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +1 -1
- package/dist/index-2f5b6168.d.ts +256 -0
- package/dist/index.d.ts +13 -4
- package/dist/index.js +13 -7
- package/dist/loader.js +4 -3
- package/dist/node.d.ts +2 -2
- package/dist/node.js +18 -11
- package/dist/suite.js +6 -6
- package/dist/{global-58e8e951.d.ts → types-f302dae9.d.ts} +210 -19
- package/dist/{vendor-index.cc8d244b.js → vendor-index.737c3cff.js} +1 -2
- package/dist/{vendor-index.12d51d29.js → vendor-index.e1d4cf84.js} +279 -7
- package/dist/worker.js +9 -8
- package/globals.d.ts +2 -0
- package/package.json +13 -9
- package/dist/chunk-integrations-globals.32ef80c3.js +0 -25
- package/dist/chunk-runtime-setup.ab6b6274.js +0 -676
- package/dist/chunk-utils-source-map.663e2952.js +0 -3429
- package/dist/chunk-vite-node-utils.2144000e.js +0 -6946
- package/dist/index-220c1d70.d.ts +0 -117
- package/dist/vendor-index.1a291e86.js +0 -275
|
@@ -1,676 +0,0 @@
|
|
|
1
|
-
import { performance } from 'perf_hooks';
|
|
2
|
-
import { t as takeCoverageInsideWorker, p as pLimit } from './chunk-integrations-coverage.cca09977.js';
|
|
3
|
-
import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.d748b085.js';
|
|
4
|
-
import { g as getWorkerState, R as RealDate, t as toArray, k as relativePath, h as isRunningInBenchmark, p as partitionSuiteChildren, l as shuffle, o as hasTests, q as hasFailed, u as createDefer, d as assertTypes, e as getFullName } from './chunk-mock-date.030959d3.js';
|
|
5
|
-
import { f as clearCollectorContext, h as defaultSuite, j as setHooks, k as getHooks, l as collectorContext, m as getFn, n as setState, G as GLOBAL_EXPECT, o as getState } from './chunk-runtime-chain.37ec5d73.js';
|
|
6
|
-
import { r as rpc } from './chunk-runtime-rpc.b418c0ab.js';
|
|
7
|
-
import { p as processError } from './chunk-runtime-error.17751c39.js';
|
|
8
|
-
import { e as environments } from './chunk-env-node.700b7e95.js';
|
|
9
|
-
import { i as isNode, a as isBrowser } from './chunk-utils-env.b1281522.js';
|
|
10
|
-
import { b as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.8fca243e.js';
|
|
11
|
-
|
|
12
|
-
let globalSetup = false;
|
|
13
|
-
async function setupGlobalEnv(config) {
|
|
14
|
-
resetRunOnceCounter();
|
|
15
|
-
Object.defineProperty(globalThis, "__vitest_index__", {
|
|
16
|
-
value: index,
|
|
17
|
-
enumerable: false
|
|
18
|
-
});
|
|
19
|
-
Error.stackTraceLimit = 100;
|
|
20
|
-
setupDefines(config.defines);
|
|
21
|
-
if (globalSetup)
|
|
22
|
-
return;
|
|
23
|
-
globalSetup = true;
|
|
24
|
-
if (isNode)
|
|
25
|
-
await setupConsoleLogSpy();
|
|
26
|
-
if (config.globals)
|
|
27
|
-
(await import('./chunk-integrations-globals.32ef80c3.js')).registerApiGlobally();
|
|
28
|
-
}
|
|
29
|
-
function setupDefines(defines) {
|
|
30
|
-
for (const key in defines)
|
|
31
|
-
globalThis[key] = defines[key];
|
|
32
|
-
}
|
|
33
|
-
async function setupConsoleLogSpy() {
|
|
34
|
-
const stdoutBuffer = /* @__PURE__ */ new Map();
|
|
35
|
-
const stderrBuffer = /* @__PURE__ */ new Map();
|
|
36
|
-
const timers = /* @__PURE__ */ new Map();
|
|
37
|
-
const unknownTestId = "__vitest__unknown_test__";
|
|
38
|
-
const { Writable } = await import('stream');
|
|
39
|
-
const { Console } = await import('console');
|
|
40
|
-
function schedule(taskId) {
|
|
41
|
-
const timer = timers.get(taskId);
|
|
42
|
-
const { stdoutTime, stderrTime } = timer;
|
|
43
|
-
safeClearTimeout(timer.timer);
|
|
44
|
-
timer.timer = safeSetTimeout(() => {
|
|
45
|
-
if (stderrTime < stdoutTime) {
|
|
46
|
-
sendStderr(taskId);
|
|
47
|
-
sendStdout(taskId);
|
|
48
|
-
} else {
|
|
49
|
-
sendStdout(taskId);
|
|
50
|
-
sendStderr(taskId);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function sendStdout(taskId) {
|
|
55
|
-
const buffer = stdoutBuffer.get(taskId);
|
|
56
|
-
if (!buffer)
|
|
57
|
-
return;
|
|
58
|
-
const content = buffer.map((i) => String(i)).join("");
|
|
59
|
-
if (!content.trim())
|
|
60
|
-
return;
|
|
61
|
-
const timer = timers.get(taskId);
|
|
62
|
-
rpc().onUserConsoleLog({
|
|
63
|
-
type: "stdout",
|
|
64
|
-
content,
|
|
65
|
-
taskId,
|
|
66
|
-
time: timer.stdoutTime || RealDate.now(),
|
|
67
|
-
size: buffer.length
|
|
68
|
-
});
|
|
69
|
-
stdoutBuffer.set(taskId, []);
|
|
70
|
-
timer.stdoutTime = 0;
|
|
71
|
-
}
|
|
72
|
-
function sendStderr(taskId) {
|
|
73
|
-
const buffer = stderrBuffer.get(taskId);
|
|
74
|
-
if (!buffer)
|
|
75
|
-
return;
|
|
76
|
-
const content = buffer.map((i) => String(i)).join("");
|
|
77
|
-
if (!content.trim())
|
|
78
|
-
return;
|
|
79
|
-
const timer = timers.get(taskId);
|
|
80
|
-
rpc().onUserConsoleLog({
|
|
81
|
-
type: "stderr",
|
|
82
|
-
content,
|
|
83
|
-
taskId,
|
|
84
|
-
time: timer.stderrTime || RealDate.now(),
|
|
85
|
-
size: buffer.length
|
|
86
|
-
});
|
|
87
|
-
stderrBuffer.set(taskId, []);
|
|
88
|
-
timer.stderrTime = 0;
|
|
89
|
-
}
|
|
90
|
-
const stdout = new Writable({
|
|
91
|
-
write(data, encoding, callback) {
|
|
92
|
-
var _a, _b;
|
|
93
|
-
const id = ((_b = (_a = getWorkerState()) == null ? void 0 : _a.current) == null ? void 0 : _b.id) ?? unknownTestId;
|
|
94
|
-
let timer = timers.get(id);
|
|
95
|
-
if (timer) {
|
|
96
|
-
timer.stdoutTime = timer.stdoutTime || RealDate.now();
|
|
97
|
-
} else {
|
|
98
|
-
timer = { stdoutTime: RealDate.now(), stderrTime: RealDate.now(), timer: 0 };
|
|
99
|
-
timers.set(id, timer);
|
|
100
|
-
}
|
|
101
|
-
let buffer = stdoutBuffer.get(id);
|
|
102
|
-
if (!buffer) {
|
|
103
|
-
buffer = [];
|
|
104
|
-
stdoutBuffer.set(id, buffer);
|
|
105
|
-
}
|
|
106
|
-
buffer.push(data);
|
|
107
|
-
schedule(id);
|
|
108
|
-
callback();
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
const stderr = new Writable({
|
|
112
|
-
write(data, encoding, callback) {
|
|
113
|
-
var _a, _b;
|
|
114
|
-
const id = ((_b = (_a = getWorkerState()) == null ? void 0 : _a.current) == null ? void 0 : _b.id) ?? unknownTestId;
|
|
115
|
-
let timer = timers.get(id);
|
|
116
|
-
if (timer) {
|
|
117
|
-
timer.stderrTime = timer.stderrTime || RealDate.now();
|
|
118
|
-
} else {
|
|
119
|
-
timer = { stderrTime: RealDate.now(), stdoutTime: RealDate.now(), timer: 0 };
|
|
120
|
-
timers.set(id, timer);
|
|
121
|
-
}
|
|
122
|
-
let buffer = stderrBuffer.get(id);
|
|
123
|
-
if (!buffer) {
|
|
124
|
-
buffer = [];
|
|
125
|
-
stderrBuffer.set(id, buffer);
|
|
126
|
-
}
|
|
127
|
-
buffer.push(data);
|
|
128
|
-
schedule(id);
|
|
129
|
-
callback();
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
globalThis.console = new Console({
|
|
133
|
-
stdout,
|
|
134
|
-
stderr,
|
|
135
|
-
colorMode: true,
|
|
136
|
-
groupIndentation: 2
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
async function loadEnvironment(name) {
|
|
140
|
-
const pkg = await import(`vitest-environment-${name}`);
|
|
141
|
-
if (!pkg || !pkg.default || typeof pkg.default !== "object" || typeof pkg.default.setup !== "function") {
|
|
142
|
-
throw new Error(
|
|
143
|
-
`Environment "${name}" is not a valid environment. Package "vitest-environment-${name}" should have default export with "setup" method.`
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
return pkg.default;
|
|
147
|
-
}
|
|
148
|
-
async function withEnv(name, options, fn) {
|
|
149
|
-
const config = environments[name] || await loadEnvironment(name);
|
|
150
|
-
const env = await config.setup(globalThis, options);
|
|
151
|
-
try {
|
|
152
|
-
await fn();
|
|
153
|
-
} finally {
|
|
154
|
-
await env.teardown(globalThis);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
async function runSetupFiles(config) {
|
|
158
|
-
const files = toArray(config.setupFiles);
|
|
159
|
-
await Promise.all(
|
|
160
|
-
files.map(async (fsPath) => {
|
|
161
|
-
getWorkerState().moduleCache.delete(fsPath);
|
|
162
|
-
await import(fsPath);
|
|
163
|
-
})
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const now$1 = Date.now;
|
|
168
|
-
function hash(str) {
|
|
169
|
-
let hash2 = 0;
|
|
170
|
-
if (str.length === 0)
|
|
171
|
-
return `${hash2}`;
|
|
172
|
-
for (let i = 0; i < str.length; i++) {
|
|
173
|
-
const char = str.charCodeAt(i);
|
|
174
|
-
hash2 = (hash2 << 5) - hash2 + char;
|
|
175
|
-
hash2 = hash2 & hash2;
|
|
176
|
-
}
|
|
177
|
-
return `${hash2}`;
|
|
178
|
-
}
|
|
179
|
-
async function collectTests(paths, config) {
|
|
180
|
-
const files = [];
|
|
181
|
-
const browserHashMap = getWorkerState().browserHashMap;
|
|
182
|
-
async function importFromBrowser(filepath) {
|
|
183
|
-
const match = filepath.match(/^(\w:\/)/);
|
|
184
|
-
const hash2 = browserHashMap.get(filepath);
|
|
185
|
-
if (match)
|
|
186
|
-
return await import(`/@fs/${filepath.slice(match[1].length)}?v=${hash2}`);
|
|
187
|
-
else
|
|
188
|
-
return await import(`${filepath}?v=${hash2}`);
|
|
189
|
-
}
|
|
190
|
-
for (const filepath of paths) {
|
|
191
|
-
const path = relativePath(config.root, filepath);
|
|
192
|
-
const file = {
|
|
193
|
-
id: hash(path),
|
|
194
|
-
name: path,
|
|
195
|
-
type: "suite",
|
|
196
|
-
mode: "run",
|
|
197
|
-
filepath,
|
|
198
|
-
tasks: []
|
|
199
|
-
};
|
|
200
|
-
clearCollectorContext();
|
|
201
|
-
try {
|
|
202
|
-
const setupStart = now$1();
|
|
203
|
-
await runSetupFiles(config);
|
|
204
|
-
const collectStart = now$1();
|
|
205
|
-
file.setupDuration = collectStart - setupStart;
|
|
206
|
-
if (config.browser && isBrowser)
|
|
207
|
-
await importFromBrowser(filepath);
|
|
208
|
-
else
|
|
209
|
-
await import(filepath);
|
|
210
|
-
const defaultTasks = await defaultSuite.collect(file);
|
|
211
|
-
setHooks(file, getHooks(defaultTasks));
|
|
212
|
-
for (const c of [...defaultTasks.tasks, ...collectorContext.tasks]) {
|
|
213
|
-
if (c.type === "test") {
|
|
214
|
-
file.tasks.push(c);
|
|
215
|
-
} else if (c.type === "benchmark") {
|
|
216
|
-
file.tasks.push(c);
|
|
217
|
-
} else if (c.type === "suite") {
|
|
218
|
-
file.tasks.push(c);
|
|
219
|
-
} else if (c.type === "collector") {
|
|
220
|
-
const suite = await c.collect(file);
|
|
221
|
-
if (suite.name || suite.tasks.length)
|
|
222
|
-
file.tasks.push(suite);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
file.collectDuration = now$1() - collectStart;
|
|
226
|
-
} catch (e) {
|
|
227
|
-
file.result = {
|
|
228
|
-
state: "fail",
|
|
229
|
-
error: processError(e)
|
|
230
|
-
};
|
|
231
|
-
if (config.browser)
|
|
232
|
-
console.error(e);
|
|
233
|
-
}
|
|
234
|
-
calculateHash(file);
|
|
235
|
-
const hasOnlyTasks = someTasksAreOnly(file);
|
|
236
|
-
interpretTaskModes(file, config.testNamePattern, hasOnlyTasks, false, config.allowOnly);
|
|
237
|
-
files.push(file);
|
|
238
|
-
}
|
|
239
|
-
return files;
|
|
240
|
-
}
|
|
241
|
-
function interpretTaskModes(suite, namePattern, onlyMode, parentIsOnly, allowOnly) {
|
|
242
|
-
const suiteIsOnly = parentIsOnly || suite.mode === "only";
|
|
243
|
-
suite.tasks.forEach((t) => {
|
|
244
|
-
const includeTask = suiteIsOnly || t.mode === "only";
|
|
245
|
-
if (onlyMode) {
|
|
246
|
-
if (t.type === "suite" && (includeTask || someTasksAreOnly(t))) {
|
|
247
|
-
if (t.mode === "only") {
|
|
248
|
-
checkAllowOnly(t, allowOnly);
|
|
249
|
-
t.mode = "run";
|
|
250
|
-
}
|
|
251
|
-
} else if (t.mode === "run" && !includeTask) {
|
|
252
|
-
t.mode = "skip";
|
|
253
|
-
} else if (t.mode === "only") {
|
|
254
|
-
checkAllowOnly(t, allowOnly);
|
|
255
|
-
t.mode = "run";
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (t.type === "test") {
|
|
259
|
-
if (namePattern && !getTaskFullName(t).match(namePattern))
|
|
260
|
-
t.mode = "skip";
|
|
261
|
-
} else if (t.type === "suite") {
|
|
262
|
-
if (t.mode === "skip")
|
|
263
|
-
skipAllTasks(t);
|
|
264
|
-
else
|
|
265
|
-
interpretTaskModes(t, namePattern, onlyMode, includeTask, allowOnly);
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
if (suite.mode === "run") {
|
|
269
|
-
if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run"))
|
|
270
|
-
suite.mode = "skip";
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
function getTaskFullName(task) {
|
|
274
|
-
return `${task.suite ? `${getTaskFullName(task.suite)} ` : ""}${task.name}`;
|
|
275
|
-
}
|
|
276
|
-
function someTasksAreOnly(suite) {
|
|
277
|
-
return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
|
|
278
|
-
}
|
|
279
|
-
function skipAllTasks(suite) {
|
|
280
|
-
suite.tasks.forEach((t) => {
|
|
281
|
-
if (t.mode === "run") {
|
|
282
|
-
t.mode = "skip";
|
|
283
|
-
if (t.type === "suite")
|
|
284
|
-
skipAllTasks(t);
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
function checkAllowOnly(task, allowOnly) {
|
|
289
|
-
if (allowOnly)
|
|
290
|
-
return;
|
|
291
|
-
task.result = {
|
|
292
|
-
state: "fail",
|
|
293
|
-
error: processError(new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error"))
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
function calculateHash(parent) {
|
|
297
|
-
parent.tasks.forEach((t, idx) => {
|
|
298
|
-
t.id = `${parent.id}_${idx}`;
|
|
299
|
-
if (t.type === "suite")
|
|
300
|
-
calculateHash(t);
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
async function importTinybench() {
|
|
305
|
-
if (!globalThis.EventTarget)
|
|
306
|
-
await import('./vendor-index.534e612c.js').then(function (n) { return n.i; });
|
|
307
|
-
return await import('tinybench');
|
|
308
|
-
}
|
|
309
|
-
const now = Date.now;
|
|
310
|
-
function updateSuiteHookState(suite, name, state) {
|
|
311
|
-
var _a;
|
|
312
|
-
if (!suite.result)
|
|
313
|
-
suite.result = { state: "run" };
|
|
314
|
-
if (!((_a = suite.result) == null ? void 0 : _a.hooks))
|
|
315
|
-
suite.result.hooks = {};
|
|
316
|
-
const suiteHooks = suite.result.hooks;
|
|
317
|
-
if (suiteHooks) {
|
|
318
|
-
suiteHooks[name] = state;
|
|
319
|
-
updateTask(suite);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
async function callSuiteHook(suite, currentTask, name, args) {
|
|
323
|
-
const callbacks = [];
|
|
324
|
-
if (name === "beforeEach" && suite.suite) {
|
|
325
|
-
callbacks.push(
|
|
326
|
-
...await callSuiteHook(suite.suite, currentTask, name, args)
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
updateSuiteHookState(currentTask, name, "run");
|
|
330
|
-
callbacks.push(
|
|
331
|
-
...await Promise.all(getHooks(suite)[name].map((fn) => fn(...args)))
|
|
332
|
-
);
|
|
333
|
-
updateSuiteHookState(currentTask, name, "pass");
|
|
334
|
-
if (name === "afterEach" && suite.suite) {
|
|
335
|
-
callbacks.push(
|
|
336
|
-
...await callSuiteHook(suite.suite, currentTask, name, args)
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
return callbacks;
|
|
340
|
-
}
|
|
341
|
-
const packs = /* @__PURE__ */ new Map();
|
|
342
|
-
let updateTimer;
|
|
343
|
-
let previousUpdate;
|
|
344
|
-
function updateTask(task) {
|
|
345
|
-
packs.set(task.id, task.result);
|
|
346
|
-
safeClearTimeout(updateTimer);
|
|
347
|
-
updateTimer = safeSetTimeout(() => {
|
|
348
|
-
previousUpdate = sendTasksUpdate();
|
|
349
|
-
}, 10);
|
|
350
|
-
}
|
|
351
|
-
async function sendTasksUpdate() {
|
|
352
|
-
safeClearTimeout(updateTimer);
|
|
353
|
-
await previousUpdate;
|
|
354
|
-
if (packs.size) {
|
|
355
|
-
const p = rpc().onTaskUpdate(Array.from(packs));
|
|
356
|
-
packs.clear();
|
|
357
|
-
return p;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
const callCleanupHooks = async (cleanups) => {
|
|
361
|
-
await Promise.all(cleanups.map(async (fn) => {
|
|
362
|
-
if (!fn)
|
|
363
|
-
return;
|
|
364
|
-
assertTypes(fn, "hook teardown", ["function"]);
|
|
365
|
-
await fn();
|
|
366
|
-
}));
|
|
367
|
-
};
|
|
368
|
-
async function runTest(test) {
|
|
369
|
-
var _a, _b;
|
|
370
|
-
if (test.mode !== "run") {
|
|
371
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.37ec5d73.js').then(function (n) { return n.q; });
|
|
372
|
-
getSnapshotClient().skipTestSnapshots(test);
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
if (((_a = test.result) == null ? void 0 : _a.state) === "fail") {
|
|
376
|
-
updateTask(test);
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
const start = now();
|
|
380
|
-
test.result = {
|
|
381
|
-
state: "run",
|
|
382
|
-
startTime: start
|
|
383
|
-
};
|
|
384
|
-
updateTask(test);
|
|
385
|
-
clearModuleMocks();
|
|
386
|
-
if (isNode) {
|
|
387
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.37ec5d73.js').then(function (n) { return n.q; });
|
|
388
|
-
await getSnapshotClient().setTest(test);
|
|
389
|
-
}
|
|
390
|
-
const workerState = getWorkerState();
|
|
391
|
-
workerState.current = test;
|
|
392
|
-
const retry = test.retry || 1;
|
|
393
|
-
for (let retryCount = 0; retryCount < retry; retryCount++) {
|
|
394
|
-
let beforeEachCleanups = [];
|
|
395
|
-
try {
|
|
396
|
-
beforeEachCleanups = await callSuiteHook(test.suite, test, "beforeEach", [test.context, test.suite]);
|
|
397
|
-
setState({
|
|
398
|
-
assertionCalls: 0,
|
|
399
|
-
isExpectingAssertions: false,
|
|
400
|
-
isExpectingAssertionsError: null,
|
|
401
|
-
expectedAssertionsNumber: null,
|
|
402
|
-
expectedAssertionsNumberErrorGen: null,
|
|
403
|
-
testPath: (_b = test.suite.file) == null ? void 0 : _b.filepath,
|
|
404
|
-
currentTestName: getFullName(test)
|
|
405
|
-
}, globalThis[GLOBAL_EXPECT]);
|
|
406
|
-
test.result.retryCount = retryCount;
|
|
407
|
-
await getFn(test)();
|
|
408
|
-
const {
|
|
409
|
-
assertionCalls,
|
|
410
|
-
expectedAssertionsNumber,
|
|
411
|
-
expectedAssertionsNumberErrorGen,
|
|
412
|
-
isExpectingAssertions,
|
|
413
|
-
isExpectingAssertionsError
|
|
414
|
-
} = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
|
415
|
-
if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber)
|
|
416
|
-
throw expectedAssertionsNumberErrorGen();
|
|
417
|
-
if (isExpectingAssertions === true && assertionCalls === 0)
|
|
418
|
-
throw isExpectingAssertionsError;
|
|
419
|
-
test.result.state = "pass";
|
|
420
|
-
} catch (e) {
|
|
421
|
-
test.result.state = "fail";
|
|
422
|
-
test.result.error = processError(e);
|
|
423
|
-
}
|
|
424
|
-
try {
|
|
425
|
-
await callSuiteHook(test.suite, test, "afterEach", [test.context, test.suite]);
|
|
426
|
-
await callCleanupHooks(beforeEachCleanups);
|
|
427
|
-
} catch (e) {
|
|
428
|
-
test.result.state = "fail";
|
|
429
|
-
test.result.error = processError(e);
|
|
430
|
-
}
|
|
431
|
-
if (test.result.state === "pass")
|
|
432
|
-
break;
|
|
433
|
-
updateTask(test);
|
|
434
|
-
}
|
|
435
|
-
if (test.fails) {
|
|
436
|
-
if (test.result.state === "pass") {
|
|
437
|
-
test.result.state = "fail";
|
|
438
|
-
test.result.error = processError(new Error("Expect test to fail"));
|
|
439
|
-
} else {
|
|
440
|
-
test.result.state = "pass";
|
|
441
|
-
test.result.error = void 0;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
if (isBrowser && test.result.error)
|
|
445
|
-
console.error(test.result.error.message, test.result.error.stackStr);
|
|
446
|
-
if (isNode) {
|
|
447
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.37ec5d73.js').then(function (n) { return n.q; });
|
|
448
|
-
getSnapshotClient().clearTest();
|
|
449
|
-
}
|
|
450
|
-
test.result.duration = now() - start;
|
|
451
|
-
if (workerState.config.logHeapUsage && isNode)
|
|
452
|
-
test.result.heap = process.memoryUsage().heapUsed;
|
|
453
|
-
workerState.current = void 0;
|
|
454
|
-
updateTask(test);
|
|
455
|
-
}
|
|
456
|
-
function markTasksAsSkipped(suite) {
|
|
457
|
-
suite.tasks.forEach((t) => {
|
|
458
|
-
t.mode = "skip";
|
|
459
|
-
t.result = { ...t.result, state: "skip" };
|
|
460
|
-
updateTask(t);
|
|
461
|
-
if (t.type === "suite")
|
|
462
|
-
markTasksAsSkipped(t);
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
async function runSuite(suite) {
|
|
466
|
-
var _a;
|
|
467
|
-
if (((_a = suite.result) == null ? void 0 : _a.state) === "fail") {
|
|
468
|
-
markTasksAsSkipped(suite);
|
|
469
|
-
updateTask(suite);
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
const start = now();
|
|
473
|
-
suite.result = {
|
|
474
|
-
state: "run",
|
|
475
|
-
startTime: start
|
|
476
|
-
};
|
|
477
|
-
updateTask(suite);
|
|
478
|
-
const workerState = getWorkerState();
|
|
479
|
-
if (suite.mode === "skip") {
|
|
480
|
-
suite.result.state = "skip";
|
|
481
|
-
} else if (suite.mode === "todo") {
|
|
482
|
-
suite.result.state = "todo";
|
|
483
|
-
} else {
|
|
484
|
-
try {
|
|
485
|
-
const beforeAllCleanups = await callSuiteHook(suite, suite, "beforeAll", [suite]);
|
|
486
|
-
if (isRunningInBenchmark()) {
|
|
487
|
-
await runBenchmarkSuite(suite);
|
|
488
|
-
} else {
|
|
489
|
-
for (let tasksGroup of partitionSuiteChildren(suite)) {
|
|
490
|
-
if (tasksGroup[0].concurrent === true) {
|
|
491
|
-
const mutex = pLimit(workerState.config.maxConcurrency);
|
|
492
|
-
await Promise.all(tasksGroup.map((c) => mutex(() => runSuiteChild(c))));
|
|
493
|
-
} else {
|
|
494
|
-
const { sequence } = workerState.config;
|
|
495
|
-
if (sequence.shuffle || suite.shuffle) {
|
|
496
|
-
const suites = tasksGroup.filter((group) => group.type === "suite");
|
|
497
|
-
const tests = tasksGroup.filter((group) => group.type === "test");
|
|
498
|
-
const groups = shuffle([suites, tests], sequence.seed);
|
|
499
|
-
tasksGroup = groups.flatMap((group) => shuffle(group, sequence.seed));
|
|
500
|
-
}
|
|
501
|
-
for (const c of tasksGroup)
|
|
502
|
-
await runSuiteChild(c);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
await callSuiteHook(suite, suite, "afterAll", [suite]);
|
|
507
|
-
await callCleanupHooks(beforeAllCleanups);
|
|
508
|
-
} catch (e) {
|
|
509
|
-
suite.result.state = "fail";
|
|
510
|
-
suite.result.error = processError(e);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
suite.result.duration = now() - start;
|
|
514
|
-
if (workerState.config.logHeapUsage && isNode)
|
|
515
|
-
suite.result.heap = process.memoryUsage().heapUsed;
|
|
516
|
-
if (suite.mode === "run") {
|
|
517
|
-
if (!hasTests(suite)) {
|
|
518
|
-
suite.result.state = "fail";
|
|
519
|
-
if (!suite.result.error)
|
|
520
|
-
suite.result.error = new Error(`No test found in suite ${suite.name}`);
|
|
521
|
-
} else if (hasFailed(suite)) {
|
|
522
|
-
suite.result.state = "fail";
|
|
523
|
-
} else {
|
|
524
|
-
suite.result.state = "pass";
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
updateTask(suite);
|
|
528
|
-
}
|
|
529
|
-
function createBenchmarkResult(name) {
|
|
530
|
-
return {
|
|
531
|
-
name,
|
|
532
|
-
rank: 0,
|
|
533
|
-
rme: 0,
|
|
534
|
-
samples: []
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
async function runBenchmarkSuite(suite) {
|
|
538
|
-
const { Task, Bench } = await importTinybench();
|
|
539
|
-
const start = performance.now();
|
|
540
|
-
const benchmarkGroup = [];
|
|
541
|
-
const benchmarkSuiteGroup = [];
|
|
542
|
-
for (const task of suite.tasks) {
|
|
543
|
-
if (task.mode !== "run")
|
|
544
|
-
continue;
|
|
545
|
-
if (task.type === "benchmark")
|
|
546
|
-
benchmarkGroup.push(task);
|
|
547
|
-
else if (task.type === "suite")
|
|
548
|
-
benchmarkSuiteGroup.push(task);
|
|
549
|
-
}
|
|
550
|
-
if (benchmarkSuiteGroup.length)
|
|
551
|
-
await Promise.all(benchmarkSuiteGroup.map((subSuite) => runBenchmarkSuite(subSuite)));
|
|
552
|
-
if (benchmarkGroup.length) {
|
|
553
|
-
const defer = createDefer();
|
|
554
|
-
const benchmarkMap = {};
|
|
555
|
-
suite.result = {
|
|
556
|
-
state: "run",
|
|
557
|
-
startTime: start,
|
|
558
|
-
benchmark: createBenchmarkResult(suite.name)
|
|
559
|
-
};
|
|
560
|
-
updateTask(suite);
|
|
561
|
-
benchmarkGroup.forEach((benchmark, idx) => {
|
|
562
|
-
const benchmarkInstance = new Bench(benchmark.options);
|
|
563
|
-
const benchmarkFn = getFn(benchmark);
|
|
564
|
-
benchmark.result = {
|
|
565
|
-
state: "run",
|
|
566
|
-
startTime: start,
|
|
567
|
-
benchmark: createBenchmarkResult(benchmark.name)
|
|
568
|
-
};
|
|
569
|
-
const id = idx.toString();
|
|
570
|
-
benchmarkMap[id] = benchmark;
|
|
571
|
-
const task = new Task(benchmarkInstance, id, benchmarkFn);
|
|
572
|
-
benchmark.task = task;
|
|
573
|
-
updateTask(benchmark);
|
|
574
|
-
});
|
|
575
|
-
benchmarkGroup.forEach((benchmark) => {
|
|
576
|
-
benchmark.task.addEventListener("complete", (e) => {
|
|
577
|
-
const task = e.task;
|
|
578
|
-
const _benchmark = benchmarkMap[task.name || ""];
|
|
579
|
-
if (_benchmark) {
|
|
580
|
-
const taskRes = task.result;
|
|
581
|
-
const result = _benchmark.result.benchmark;
|
|
582
|
-
Object.assign(result, taskRes);
|
|
583
|
-
updateTask(_benchmark);
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
benchmark.task.addEventListener("error", (e) => {
|
|
587
|
-
const task = e.task;
|
|
588
|
-
const _benchmark = benchmarkMap[task.name || ""];
|
|
589
|
-
defer.reject(_benchmark ? task.result.error : e);
|
|
590
|
-
});
|
|
591
|
-
});
|
|
592
|
-
Promise.all(benchmarkGroup.map(async (benchmark) => {
|
|
593
|
-
await benchmark.task.warmup();
|
|
594
|
-
return await new Promise((resolve) => safeSetTimeout(async () => {
|
|
595
|
-
resolve(await benchmark.task.run());
|
|
596
|
-
}));
|
|
597
|
-
})).then((tasks) => {
|
|
598
|
-
suite.result.duration = performance.now() - start;
|
|
599
|
-
suite.result.state = "pass";
|
|
600
|
-
tasks.sort((a, b) => a.result.mean - b.result.mean).forEach((cycle, idx) => {
|
|
601
|
-
const benchmark = benchmarkMap[cycle.name || ""];
|
|
602
|
-
benchmark.result.state = "pass";
|
|
603
|
-
if (benchmark) {
|
|
604
|
-
const result = benchmark.result.benchmark;
|
|
605
|
-
result.rank = Number(idx) + 1;
|
|
606
|
-
updateTask(benchmark);
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
updateTask(suite);
|
|
610
|
-
defer.resolve(null);
|
|
611
|
-
});
|
|
612
|
-
await defer;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
async function runSuiteChild(c) {
|
|
616
|
-
if (c.type === "test")
|
|
617
|
-
return runTest(c);
|
|
618
|
-
else if (c.type === "suite")
|
|
619
|
-
return runSuite(c);
|
|
620
|
-
}
|
|
621
|
-
async function runSuites(suites) {
|
|
622
|
-
for (const suite of suites)
|
|
623
|
-
await runSuite(suite);
|
|
624
|
-
}
|
|
625
|
-
async function runFiles(files, config) {
|
|
626
|
-
var _a;
|
|
627
|
-
for (const file of files) {
|
|
628
|
-
if (!file.tasks.length && !config.passWithNoTests) {
|
|
629
|
-
if (!((_a = file.result) == null ? void 0 : _a.error)) {
|
|
630
|
-
file.result = {
|
|
631
|
-
state: "fail",
|
|
632
|
-
error: new Error(`No test suite found in file ${file.filepath}`)
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
await runSuite(file);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
async function startTestsBrowser(paths, config) {
|
|
640
|
-
if (isNode) {
|
|
641
|
-
rpc().onPathsCollected(paths);
|
|
642
|
-
} else {
|
|
643
|
-
const files = await collectTests(paths, config);
|
|
644
|
-
await rpc().onCollected(files);
|
|
645
|
-
await runSuites(files);
|
|
646
|
-
await sendTasksUpdate();
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
async function startTestsNode(paths, config) {
|
|
650
|
-
const files = await collectTests(paths, config);
|
|
651
|
-
rpc().onCollected(files);
|
|
652
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.37ec5d73.js').then(function (n) { return n.q; });
|
|
653
|
-
getSnapshotClient().clear();
|
|
654
|
-
await runFiles(files, config);
|
|
655
|
-
const coverage = await takeCoverageInsideWorker(config.coverage);
|
|
656
|
-
rpc().onAfterSuiteRun({ coverage });
|
|
657
|
-
await getSnapshotClient().saveCurrent();
|
|
658
|
-
await sendTasksUpdate();
|
|
659
|
-
}
|
|
660
|
-
async function startTests(paths, config) {
|
|
661
|
-
if (config.browser)
|
|
662
|
-
return startTestsBrowser(paths, config);
|
|
663
|
-
else
|
|
664
|
-
return startTestsNode(paths, config);
|
|
665
|
-
}
|
|
666
|
-
function clearModuleMocks() {
|
|
667
|
-
const { clearMocks, mockReset, restoreMocks } = getWorkerState().config;
|
|
668
|
-
if (restoreMocks)
|
|
669
|
-
vi.restoreAllMocks();
|
|
670
|
-
else if (mockReset)
|
|
671
|
-
vi.resetAllMocks();
|
|
672
|
-
else if (clearMocks)
|
|
673
|
-
vi.clearAllMocks();
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
export { setupGlobalEnv as a, startTests as s, withEnv as w };
|