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