@vitest/runner 4.0.0-beta.9 → 4.0.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.
@@ -1,2253 +0,0 @@
1
- import { isObject, createDefer, toArray, isNegativeNaN, format, objectAttr, objDisplay, getSafeTimers, shuffle, assertTypes } from '@vitest/utils';
2
- import { processError } from '@vitest/utils/error';
3
- import { stripLiteral } from 'strip-literal';
4
- import { parseSingleStack } from '@vitest/utils/source-map';
5
- import { relative } from 'pathe';
6
-
7
- class PendingError extends Error {
8
- code = "VITEST_PENDING";
9
- taskId;
10
- constructor(message, task, note) {
11
- super(message);
12
- this.message = message;
13
- this.note = note;
14
- this.taskId = task.id;
15
- }
16
- }
17
- class TestRunAbortError extends Error {
18
- name = "TestRunAbortError";
19
- reason;
20
- constructor(message, reason) {
21
- super(message);
22
- this.reason = reason;
23
- }
24
- }
25
-
26
- // use WeakMap here to make the Test and Suite object serializable
27
- const fnMap = new WeakMap();
28
- const testFixtureMap = new WeakMap();
29
- const hooksMap = new WeakMap();
30
- function setFn(key, fn) {
31
- fnMap.set(key, fn);
32
- }
33
- function getFn(key) {
34
- return fnMap.get(key);
35
- }
36
- function setTestFixture(key, fixture) {
37
- testFixtureMap.set(key, fixture);
38
- }
39
- function getTestFixture(key) {
40
- return testFixtureMap.get(key);
41
- }
42
- function setHooks(key, hooks) {
43
- hooksMap.set(key, hooks);
44
- }
45
- function getHooks(key) {
46
- return hooksMap.get(key);
47
- }
48
-
49
- async function runSetupFiles(config, files, runner) {
50
- if (config.sequence.setupFiles === "parallel") {
51
- await Promise.all(files.map(async (fsPath) => {
52
- await runner.importFile(fsPath, "setup");
53
- }));
54
- } else {
55
- for (const fsPath of files) {
56
- await runner.importFile(fsPath, "setup");
57
- }
58
- }
59
- }
60
-
61
- function mergeScopedFixtures(testFixtures, scopedFixtures) {
62
- const scopedFixturesMap = scopedFixtures.reduce((map, fixture) => {
63
- map[fixture.prop] = fixture;
64
- return map;
65
- }, {});
66
- const newFixtures = {};
67
- testFixtures.forEach((fixture) => {
68
- const useFixture = scopedFixturesMap[fixture.prop] || { ...fixture };
69
- newFixtures[useFixture.prop] = useFixture;
70
- });
71
- for (const fixtureKep in newFixtures) {
72
- var _fixture$deps;
73
- const fixture = newFixtures[fixtureKep];
74
- // if the fixture was define before the scope, then its dep
75
- // will reference the original fixture instead of the scope
76
- fixture.deps = (_fixture$deps = fixture.deps) === null || _fixture$deps === void 0 ? void 0 : _fixture$deps.map((dep) => newFixtures[dep.prop]);
77
- }
78
- return Object.values(newFixtures);
79
- }
80
- function mergeContextFixtures(fixtures, context, runner) {
81
- const fixtureOptionKeys = [
82
- "auto",
83
- "injected",
84
- "scope"
85
- ];
86
- const fixtureArray = Object.entries(fixtures).map(([prop, value]) => {
87
- const fixtureItem = { value };
88
- if (Array.isArray(value) && value.length >= 2 && isObject(value[1]) && Object.keys(value[1]).some((key) => fixtureOptionKeys.includes(key))) {
89
- var _runner$injectValue;
90
- // fixture with options
91
- Object.assign(fixtureItem, value[1]);
92
- const userValue = value[0];
93
- fixtureItem.value = fixtureItem.injected ? ((_runner$injectValue = runner.injectValue) === null || _runner$injectValue === void 0 ? void 0 : _runner$injectValue.call(runner, prop)) ?? userValue : userValue;
94
- }
95
- fixtureItem.scope = fixtureItem.scope || "test";
96
- if (fixtureItem.scope === "worker" && !runner.getWorkerContext) {
97
- fixtureItem.scope = "file";
98
- }
99
- fixtureItem.prop = prop;
100
- fixtureItem.isFn = typeof fixtureItem.value === "function";
101
- return fixtureItem;
102
- });
103
- if (Array.isArray(context.fixtures)) {
104
- context.fixtures = context.fixtures.concat(fixtureArray);
105
- } else {
106
- context.fixtures = fixtureArray;
107
- }
108
- // Update dependencies of fixture functions
109
- fixtureArray.forEach((fixture) => {
110
- if (fixture.isFn) {
111
- const usedProps = getUsedProps(fixture.value);
112
- if (usedProps.length) {
113
- fixture.deps = context.fixtures.filter(({ prop }) => prop !== fixture.prop && usedProps.includes(prop));
114
- }
115
- // test can access anything, so we ignore it
116
- if (fixture.scope !== "test") {
117
- var _fixture$deps2;
118
- (_fixture$deps2 = fixture.deps) === null || _fixture$deps2 === void 0 ? void 0 : _fixture$deps2.forEach((dep) => {
119
- if (!dep.isFn) {
120
- // non fn fixtures are always resolved and available to anyone
121
- return;
122
- }
123
- // worker scope can only import from worker scope
124
- if (fixture.scope === "worker" && dep.scope === "worker") {
125
- return;
126
- }
127
- // file scope an import from file and worker scopes
128
- if (fixture.scope === "file" && dep.scope !== "test") {
129
- return;
130
- }
131
- throw new SyntaxError(`cannot use the ${dep.scope} fixture "${dep.prop}" inside the ${fixture.scope} fixture "${fixture.prop}"`);
132
- });
133
- }
134
- }
135
- });
136
- return context;
137
- }
138
- const fixtureValueMaps = new Map();
139
- const cleanupFnArrayMap = new Map();
140
- async function callFixtureCleanup(context) {
141
- const cleanupFnArray = cleanupFnArrayMap.get(context) ?? [];
142
- for (const cleanup of cleanupFnArray.reverse()) {
143
- await cleanup();
144
- }
145
- cleanupFnArrayMap.delete(context);
146
- }
147
- function withFixtures(runner, fn, testContext) {
148
- return (hookContext) => {
149
- const context = hookContext || testContext;
150
- if (!context) {
151
- return fn({});
152
- }
153
- const fixtures = getTestFixture(context);
154
- if (!(fixtures === null || fixtures === void 0 ? void 0 : fixtures.length)) {
155
- return fn(context);
156
- }
157
- const usedProps = getUsedProps(fn);
158
- const hasAutoFixture = fixtures.some(({ auto }) => auto);
159
- if (!usedProps.length && !hasAutoFixture) {
160
- return fn(context);
161
- }
162
- if (!fixtureValueMaps.get(context)) {
163
- fixtureValueMaps.set(context, new Map());
164
- }
165
- const fixtureValueMap = fixtureValueMaps.get(context);
166
- if (!cleanupFnArrayMap.has(context)) {
167
- cleanupFnArrayMap.set(context, []);
168
- }
169
- const cleanupFnArray = cleanupFnArrayMap.get(context);
170
- const usedFixtures = fixtures.filter(({ prop, auto }) => auto || usedProps.includes(prop));
171
- const pendingFixtures = resolveDeps(usedFixtures);
172
- if (!pendingFixtures.length) {
173
- return fn(context);
174
- }
175
- async function resolveFixtures() {
176
- for (const fixture of pendingFixtures) {
177
- // fixture could be already initialized during "before" hook
178
- if (fixtureValueMap.has(fixture)) {
179
- continue;
180
- }
181
- const resolvedValue = await resolveFixtureValue(runner, fixture, context, cleanupFnArray);
182
- context[fixture.prop] = resolvedValue;
183
- fixtureValueMap.set(fixture, resolvedValue);
184
- if (fixture.scope === "test") {
185
- cleanupFnArray.unshift(() => {
186
- fixtureValueMap.delete(fixture);
187
- });
188
- }
189
- }
190
- }
191
- return resolveFixtures().then(() => fn(context));
192
- };
193
- }
194
- const globalFixturePromise = new WeakMap();
195
- function resolveFixtureValue(runner, fixture, context, cleanupFnArray) {
196
- var _runner$getWorkerCont;
197
- const fileContext = getFileContext(context.task.file);
198
- const workerContext = (_runner$getWorkerCont = runner.getWorkerContext) === null || _runner$getWorkerCont === void 0 ? void 0 : _runner$getWorkerCont.call(runner);
199
- if (!fixture.isFn) {
200
- var _fixture$prop;
201
- fileContext[_fixture$prop = fixture.prop] ?? (fileContext[_fixture$prop] = fixture.value);
202
- if (workerContext) {
203
- var _fixture$prop2;
204
- workerContext[_fixture$prop2 = fixture.prop] ?? (workerContext[_fixture$prop2] = fixture.value);
205
- }
206
- return fixture.value;
207
- }
208
- if (fixture.scope === "test") {
209
- return resolveFixtureFunction(fixture.value, context, cleanupFnArray);
210
- }
211
- // in case the test runs in parallel
212
- if (globalFixturePromise.has(fixture)) {
213
- return globalFixturePromise.get(fixture);
214
- }
215
- let fixtureContext;
216
- if (fixture.scope === "worker") {
217
- if (!workerContext) {
218
- throw new TypeError("[@vitest/runner] The worker context is not available in the current test runner. Please, provide the `getWorkerContext` method when initiating the runner.");
219
- }
220
- fixtureContext = workerContext;
221
- } else {
222
- fixtureContext = fileContext;
223
- }
224
- if (fixture.prop in fixtureContext) {
225
- return fixtureContext[fixture.prop];
226
- }
227
- if (!cleanupFnArrayMap.has(fixtureContext)) {
228
- cleanupFnArrayMap.set(fixtureContext, []);
229
- }
230
- const cleanupFnFileArray = cleanupFnArrayMap.get(fixtureContext);
231
- const promise = resolveFixtureFunction(fixture.value, fixtureContext, cleanupFnFileArray).then((value) => {
232
- fixtureContext[fixture.prop] = value;
233
- globalFixturePromise.delete(fixture);
234
- return value;
235
- });
236
- globalFixturePromise.set(fixture, promise);
237
- return promise;
238
- }
239
- async function resolveFixtureFunction(fixtureFn, context, cleanupFnArray) {
240
- // wait for `use` call to extract fixture value
241
- const useFnArgPromise = createDefer();
242
- let isUseFnArgResolved = false;
243
- const fixtureReturn = fixtureFn(context, async (useFnArg) => {
244
- // extract `use` argument
245
- isUseFnArgResolved = true;
246
- useFnArgPromise.resolve(useFnArg);
247
- // suspend fixture teardown by holding off `useReturnPromise` resolution until cleanup
248
- const useReturnPromise = createDefer();
249
- cleanupFnArray.push(async () => {
250
- // start teardown by resolving `use` Promise
251
- useReturnPromise.resolve();
252
- // wait for finishing teardown
253
- await fixtureReturn;
254
- });
255
- await useReturnPromise;
256
- }).catch((e) => {
257
- // treat fixture setup error as test failure
258
- if (!isUseFnArgResolved) {
259
- useFnArgPromise.reject(e);
260
- return;
261
- }
262
- // otherwise re-throw to avoid silencing error during cleanup
263
- throw e;
264
- });
265
- return useFnArgPromise;
266
- }
267
- function resolveDeps(fixtures, depSet = new Set(), pendingFixtures = []) {
268
- fixtures.forEach((fixture) => {
269
- if (pendingFixtures.includes(fixture)) {
270
- return;
271
- }
272
- if (!fixture.isFn || !fixture.deps) {
273
- pendingFixtures.push(fixture);
274
- return;
275
- }
276
- if (depSet.has(fixture)) {
277
- throw new Error(`Circular fixture dependency detected: ${fixture.prop} <- ${[...depSet].reverse().map((d) => d.prop).join(" <- ")}`);
278
- }
279
- depSet.add(fixture);
280
- resolveDeps(fixture.deps, depSet, pendingFixtures);
281
- pendingFixtures.push(fixture);
282
- depSet.clear();
283
- });
284
- return pendingFixtures;
285
- }
286
- function getUsedProps(fn) {
287
- let fnString = stripLiteral(fn.toString());
288
- // match lowered async function and strip it off
289
- // example code on esbuild-try https://esbuild.github.io/try/#YgAwLjI0LjAALS1zdXBwb3J0ZWQ6YXN5bmMtYXdhaXQ9ZmFsc2UAZQBlbnRyeS50cwBjb25zdCBvID0gewogIGYxOiBhc3luYyAoKSA9PiB7fSwKICBmMjogYXN5bmMgKGEpID0+IHt9LAogIGYzOiBhc3luYyAoYSwgYikgPT4ge30sCiAgZjQ6IGFzeW5jIGZ1bmN0aW9uKGEpIHt9LAogIGY1OiBhc3luYyBmdW5jdGlvbiBmZihhKSB7fSwKICBhc3luYyBmNihhKSB7fSwKCiAgZzE6IGFzeW5jICgpID0+IHt9LAogIGcyOiBhc3luYyAoeyBhIH0pID0+IHt9LAogIGczOiBhc3luYyAoeyBhIH0sIGIpID0+IHt9LAogIGc0OiBhc3luYyBmdW5jdGlvbiAoeyBhIH0pIHt9LAogIGc1OiBhc3luYyBmdW5jdGlvbiBnZyh7IGEgfSkge30sCiAgYXN5bmMgZzYoeyBhIH0pIHt9LAoKICBoMTogYXN5bmMgKCkgPT4ge30sCiAgLy8gY29tbWVudCBiZXR3ZWVuCiAgaDI6IGFzeW5jIChhKSA9PiB7fSwKfQ
290
- // __async(this, null, function*
291
- // __async(this, arguments, function*
292
- // __async(this, [_0, _1], function*
293
- if (/__async\((?:this|null), (?:null|arguments|\[[_0-9, ]*\]), function\*/.test(fnString)) {
294
- fnString = fnString.split(/__async\((?:this|null),/)[1];
295
- }
296
- const match = fnString.match(/[^(]*\(([^)]*)/);
297
- if (!match) {
298
- return [];
299
- }
300
- const args = splitByComma(match[1]);
301
- if (!args.length) {
302
- return [];
303
- }
304
- let first = args[0];
305
- if ("__VITEST_FIXTURE_INDEX__" in fn) {
306
- first = args[fn.__VITEST_FIXTURE_INDEX__];
307
- if (!first) {
308
- return [];
309
- }
310
- }
311
- if (!(first.startsWith("{") && first.endsWith("}"))) {
312
- throw new Error(`The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "${first}".`);
313
- }
314
- const _first = first.slice(1, -1).replace(/\s/g, "");
315
- const props = splitByComma(_first).map((prop) => {
316
- return prop.replace(/:.*|=.*/g, "");
317
- });
318
- const last = props.at(-1);
319
- if (last && last.startsWith("...")) {
320
- throw new Error(`Rest parameters are not supported in fixtures, received "${last}".`);
321
- }
322
- return props;
323
- }
324
- function splitByComma(s) {
325
- const result = [];
326
- const stack = [];
327
- let start = 0;
328
- for (let i = 0; i < s.length; i++) {
329
- if (s[i] === "{" || s[i] === "[") {
330
- stack.push(s[i] === "{" ? "}" : "]");
331
- } else if (s[i] === stack[stack.length - 1]) {
332
- stack.pop();
333
- } else if (!stack.length && s[i] === ",") {
334
- const token = s.substring(start, i).trim();
335
- if (token) {
336
- result.push(token);
337
- }
338
- start = i + 1;
339
- }
340
- }
341
- const lastToken = s.substring(start).trim();
342
- if (lastToken) {
343
- result.push(lastToken);
344
- }
345
- return result;
346
- }
347
-
348
- let _test;
349
- function setCurrentTest(test) {
350
- _test = test;
351
- }
352
- function getCurrentTest() {
353
- return _test;
354
- }
355
- const tests = [];
356
- function addRunningTest(test) {
357
- tests.push(test);
358
- return () => {
359
- tests.splice(tests.indexOf(test));
360
- };
361
- }
362
- function getRunningTests() {
363
- return tests;
364
- }
365
-
366
- function createChainable(keys, fn) {
367
- function create(context) {
368
- const chain = function(...args) {
369
- return fn.apply(context, args);
370
- };
371
- Object.assign(chain, fn);
372
- chain.withContext = () => chain.bind(context);
373
- chain.setContext = (key, value) => {
374
- context[key] = value;
375
- };
376
- chain.mergeContext = (ctx) => {
377
- Object.assign(context, ctx);
378
- };
379
- for (const key of keys) {
380
- Object.defineProperty(chain, key, { get() {
381
- return create({
382
- ...context,
383
- [key]: true
384
- });
385
- } });
386
- }
387
- return chain;
388
- }
389
- const chain = create({});
390
- chain.fn = fn;
391
- return chain;
392
- }
393
-
394
- /**
395
- * If any tasks been marked as `only`, mark all other tasks as `skip`.
396
- */
397
- function interpretTaskModes(file, namePattern, testLocations, onlyMode, parentIsOnly, allowOnly) {
398
- const matchedLocations = [];
399
- const traverseSuite = (suite, parentIsOnly, parentMatchedWithLocation) => {
400
- const suiteIsOnly = parentIsOnly || suite.mode === "only";
401
- suite.tasks.forEach((t) => {
402
- // Check if either the parent suite or the task itself are marked as included
403
- const includeTask = suiteIsOnly || t.mode === "only";
404
- if (onlyMode) {
405
- if (t.type === "suite" && (includeTask || someTasksAreOnly(t))) {
406
- // Don't skip this suite
407
- if (t.mode === "only") {
408
- checkAllowOnly(t, allowOnly);
409
- t.mode = "run";
410
- }
411
- } else if (t.mode === "run" && !includeTask) {
412
- t.mode = "skip";
413
- } else if (t.mode === "only") {
414
- checkAllowOnly(t, allowOnly);
415
- t.mode = "run";
416
- }
417
- }
418
- let hasLocationMatch = parentMatchedWithLocation;
419
- // Match test location against provided locations, only run if present
420
- // in `testLocations`. Note: if `includeTaskLocations` is not enabled,
421
- // all test will be skipped.
422
- if (testLocations !== undefined && testLocations.length !== 0) {
423
- if (t.location && (testLocations === null || testLocations === void 0 ? void 0 : testLocations.includes(t.location.line))) {
424
- t.mode = "run";
425
- matchedLocations.push(t.location.line);
426
- hasLocationMatch = true;
427
- } else if (parentMatchedWithLocation) {
428
- t.mode = "run";
429
- } else if (t.type === "test") {
430
- t.mode = "skip";
431
- }
432
- }
433
- if (t.type === "test") {
434
- if (namePattern && !getTaskFullName(t).match(namePattern)) {
435
- t.mode = "skip";
436
- }
437
- } else if (t.type === "suite") {
438
- if (t.mode === "skip") {
439
- skipAllTasks(t);
440
- } else if (t.mode === "todo") {
441
- todoAllTasks(t);
442
- } else {
443
- traverseSuite(t, includeTask, hasLocationMatch);
444
- }
445
- }
446
- });
447
- // if all subtasks are skipped, mark as skip
448
- if (suite.mode === "run" || suite.mode === "queued") {
449
- if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run" && i.mode !== "queued")) {
450
- suite.mode = "skip";
451
- }
452
- }
453
- };
454
- traverseSuite(file, parentIsOnly, false);
455
- const nonMatching = testLocations === null || testLocations === void 0 ? void 0 : testLocations.filter((loc) => !matchedLocations.includes(loc));
456
- if (nonMatching && nonMatching.length !== 0) {
457
- const message = nonMatching.length === 1 ? `line ${nonMatching[0]}` : `lines ${nonMatching.join(", ")}`;
458
- if (file.result === undefined) {
459
- file.result = {
460
- state: "fail",
461
- errors: []
462
- };
463
- }
464
- if (file.result.errors === undefined) {
465
- file.result.errors = [];
466
- }
467
- file.result.errors.push(processError(new Error(`No test found in ${file.name} in ${message}`)));
468
- }
469
- }
470
- function getTaskFullName(task) {
471
- return `${task.suite ? `${getTaskFullName(task.suite)} ` : ""}${task.name}`;
472
- }
473
- function someTasksAreOnly(suite) {
474
- return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
475
- }
476
- function skipAllTasks(suite) {
477
- suite.tasks.forEach((t) => {
478
- if (t.mode === "run" || t.mode === "queued") {
479
- t.mode = "skip";
480
- if (t.type === "suite") {
481
- skipAllTasks(t);
482
- }
483
- }
484
- });
485
- }
486
- function todoAllTasks(suite) {
487
- suite.tasks.forEach((t) => {
488
- if (t.mode === "run" || t.mode === "queued") {
489
- t.mode = "todo";
490
- if (t.type === "suite") {
491
- todoAllTasks(t);
492
- }
493
- }
494
- });
495
- }
496
- function checkAllowOnly(task, allowOnly) {
497
- if (allowOnly) {
498
- return;
499
- }
500
- const error = processError(new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error"));
501
- task.result = {
502
- state: "fail",
503
- errors: [error]
504
- };
505
- }
506
- function generateHash(str) {
507
- let hash = 0;
508
- if (str.length === 0) {
509
- return `${hash}`;
510
- }
511
- for (let i = 0; i < str.length; i++) {
512
- const char = str.charCodeAt(i);
513
- hash = (hash << 5) - hash + char;
514
- hash = hash & hash;
515
- }
516
- return `${hash}`;
517
- }
518
- function calculateSuiteHash(parent) {
519
- parent.tasks.forEach((t, idx) => {
520
- t.id = `${parent.id}_${idx}`;
521
- if (t.type === "suite") {
522
- calculateSuiteHash(t);
523
- }
524
- });
525
- }
526
- function createFileTask(filepath, root, projectName, pool) {
527
- const path = relative(root, filepath);
528
- const file = {
529
- id: generateFileHash(path, projectName),
530
- name: path,
531
- type: "suite",
532
- mode: "queued",
533
- filepath,
534
- tasks: [],
535
- meta: Object.create(null),
536
- projectName,
537
- file: undefined,
538
- pool
539
- };
540
- file.file = file;
541
- setFileContext(file, Object.create(null));
542
- return file;
543
- }
544
- /**
545
- * Generate a unique ID for a file based on its path and project name
546
- * @param file File relative to the root of the project to keep ID the same between different machines
547
- * @param projectName The name of the test project
548
- */
549
- function generateFileHash(file, projectName) {
550
- return generateHash(`${file}${projectName || ""}`);
551
- }
552
- function findTestFileStackTrace(testFilePath, error) {
553
- // first line is the error message
554
- const lines = error.split("\n").slice(1);
555
- for (const line of lines) {
556
- const stack = parseSingleStack(line);
557
- if (stack && stack.file === testFilePath) {
558
- return stack;
559
- }
560
- }
561
- }
562
-
563
- /**
564
- * Return a function for running multiple async operations with limited concurrency.
565
- */
566
- function limitConcurrency(concurrency = Infinity) {
567
- // The number of currently active + pending tasks.
568
- let count = 0;
569
- // The head and tail of the pending task queue, built using a singly linked list.
570
- // Both head and tail are initially undefined, signifying an empty queue.
571
- // They both become undefined again whenever there are no pending tasks.
572
- let head;
573
- let tail;
574
- // A bookkeeping function executed whenever a task has been run to completion.
575
- const finish = () => {
576
- count--;
577
- // Check if there are further pending tasks in the queue.
578
- if (head) {
579
- // Allow the next pending task to run and pop it from the queue.
580
- head[0]();
581
- head = head[1];
582
- // The head may now be undefined if there are no further pending tasks.
583
- // In that case, set tail to undefined as well.
584
- tail = head && tail;
585
- }
586
- };
587
- return (func, ...args) => {
588
- // Create a promise chain that:
589
- // 1. Waits for its turn in the task queue (if necessary).
590
- // 2. Runs the task.
591
- // 3. Allows the next pending task (if any) to run.
592
- return new Promise((resolve) => {
593
- if (count++ < concurrency) {
594
- // No need to queue if fewer than maxConcurrency tasks are running.
595
- resolve();
596
- } else if (tail) {
597
- // There are pending tasks, so append to the queue.
598
- tail = tail[1] = [resolve];
599
- } else {
600
- // No other pending tasks, initialize the queue with a new tail and head.
601
- head = tail = [resolve];
602
- }
603
- }).then(() => {
604
- // Running func here ensures that even a non-thenable result or an
605
- // immediately thrown error gets wrapped into a Promise.
606
- return func(...args);
607
- }).finally(finish);
608
- };
609
- }
610
-
611
- /**
612
- * Partition in tasks groups by consecutive concurrent
613
- */
614
- function partitionSuiteChildren(suite) {
615
- let tasksGroup = [];
616
- const tasksGroups = [];
617
- for (const c of suite.tasks) {
618
- if (tasksGroup.length === 0 || c.concurrent === tasksGroup[0].concurrent) {
619
- tasksGroup.push(c);
620
- } else {
621
- tasksGroups.push(tasksGroup);
622
- tasksGroup = [c];
623
- }
624
- }
625
- if (tasksGroup.length > 0) {
626
- tasksGroups.push(tasksGroup);
627
- }
628
- return tasksGroups;
629
- }
630
-
631
- function isTestCase(s) {
632
- return s.type === "test";
633
- }
634
- function getTests(suite) {
635
- const tests = [];
636
- const arraySuites = toArray(suite);
637
- for (const s of arraySuites) {
638
- if (isTestCase(s)) {
639
- tests.push(s);
640
- } else {
641
- for (const task of s.tasks) {
642
- if (isTestCase(task)) {
643
- tests.push(task);
644
- } else {
645
- const taskTests = getTests(task);
646
- for (const test of taskTests) {
647
- tests.push(test);
648
- }
649
- }
650
- }
651
- }
652
- }
653
- return tests;
654
- }
655
- function getTasks(tasks = []) {
656
- return toArray(tasks).flatMap((s) => isTestCase(s) ? [s] : [s, ...getTasks(s.tasks)]);
657
- }
658
- function getSuites(suite) {
659
- return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []);
660
- }
661
- function hasTests(suite) {
662
- return toArray(suite).some((s) => s.tasks.some((c) => isTestCase(c) || hasTests(c)));
663
- }
664
- function hasFailed(suite) {
665
- return toArray(suite).some((s) => {
666
- var _s$result;
667
- return ((_s$result = s.result) === null || _s$result === void 0 ? void 0 : _s$result.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
668
- });
669
- }
670
- function getNames(task) {
671
- const names = [task.name];
672
- let current = task;
673
- while (current === null || current === void 0 ? void 0 : current.suite) {
674
- current = current.suite;
675
- if (current === null || current === void 0 ? void 0 : current.name) {
676
- names.unshift(current.name);
677
- }
678
- }
679
- if (current !== task.file) {
680
- names.unshift(task.file.name);
681
- }
682
- return names;
683
- }
684
- function getFullName(task, separator = " > ") {
685
- return getNames(task).join(separator);
686
- }
687
- function getTestName(task, separator = " > ") {
688
- return getNames(task).slice(1).join(separator);
689
- }
690
-
691
- /**
692
- * Creates a suite of tests, allowing for grouping and hierarchical organization of tests.
693
- * Suites can contain both tests and other suites, enabling complex test structures.
694
- *
695
- * @param {string} name - The name of the suite, used for identification and reporting.
696
- * @param {Function} fn - A function that defines the tests and suites within this suite.
697
- * @example
698
- * ```ts
699
- * // Define a suite with two tests
700
- * suite('Math operations', () => {
701
- * test('should add two numbers', () => {
702
- * expect(add(1, 2)).toBe(3);
703
- * });
704
- *
705
- * test('should subtract two numbers', () => {
706
- * expect(subtract(5, 2)).toBe(3);
707
- * });
708
- * });
709
- * ```
710
- * @example
711
- * ```ts
712
- * // Define nested suites
713
- * suite('String operations', () => {
714
- * suite('Trimming', () => {
715
- * test('should trim whitespace from start and end', () => {
716
- * expect(' hello '.trim()).toBe('hello');
717
- * });
718
- * });
719
- *
720
- * suite('Concatenation', () => {
721
- * test('should concatenate two strings', () => {
722
- * expect('hello' + ' ' + 'world').toBe('hello world');
723
- * });
724
- * });
725
- * });
726
- * ```
727
- */
728
- const suite = createSuite();
729
- /**
730
- * Defines a test case with a given name and test function. The test function can optionally be configured with test options.
731
- *
732
- * @param {string | Function} name - The name of the test or a function that will be used as a test name.
733
- * @param {TestOptions | TestFunction} [optionsOrFn] - Optional. The test options or the test function if no explicit name is provided.
734
- * @param {number | TestOptions | TestFunction} [optionsOrTest] - Optional. The test function or options, depending on the previous parameters.
735
- * @throws {Error} If called inside another test function.
736
- * @example
737
- * ```ts
738
- * // Define a simple test
739
- * test('should add two numbers', () => {
740
- * expect(add(1, 2)).toBe(3);
741
- * });
742
- * ```
743
- * @example
744
- * ```ts
745
- * // Define a test with options
746
- * test('should subtract two numbers', { retry: 3 }, () => {
747
- * expect(subtract(5, 2)).toBe(3);
748
- * });
749
- * ```
750
- */
751
- const test = createTest(function(name, optionsOrFn, optionsOrTest) {
752
- if (getCurrentTest()) {
753
- throw new Error("Calling the test function inside another test function is not allowed. Please put it inside \"describe\" or \"suite\" so it can be properly collected.");
754
- }
755
- getCurrentSuite().test.fn.call(this, formatName(name), optionsOrFn, optionsOrTest);
756
- });
757
- /**
758
- * Creates a suite of tests, allowing for grouping and hierarchical organization of tests.
759
- * Suites can contain both tests and other suites, enabling complex test structures.
760
- *
761
- * @param {string} name - The name of the suite, used for identification and reporting.
762
- * @param {Function} fn - A function that defines the tests and suites within this suite.
763
- * @example
764
- * ```ts
765
- * // Define a suite with two tests
766
- * describe('Math operations', () => {
767
- * test('should add two numbers', () => {
768
- * expect(add(1, 2)).toBe(3);
769
- * });
770
- *
771
- * test('should subtract two numbers', () => {
772
- * expect(subtract(5, 2)).toBe(3);
773
- * });
774
- * });
775
- * ```
776
- * @example
777
- * ```ts
778
- * // Define nested suites
779
- * describe('String operations', () => {
780
- * describe('Trimming', () => {
781
- * test('should trim whitespace from start and end', () => {
782
- * expect(' hello '.trim()).toBe('hello');
783
- * });
784
- * });
785
- *
786
- * describe('Concatenation', () => {
787
- * test('should concatenate two strings', () => {
788
- * expect('hello' + ' ' + 'world').toBe('hello world');
789
- * });
790
- * });
791
- * });
792
- * ```
793
- */
794
- const describe = suite;
795
- /**
796
- * Defines a test case with a given name and test function. The test function can optionally be configured with test options.
797
- *
798
- * @param {string | Function} name - The name of the test or a function that will be used as a test name.
799
- * @param {TestOptions | TestFunction} [optionsOrFn] - Optional. The test options or the test function if no explicit name is provided.
800
- * @param {number | TestOptions | TestFunction} [optionsOrTest] - Optional. The test function or options, depending on the previous parameters.
801
- * @throws {Error} If called inside another test function.
802
- * @example
803
- * ```ts
804
- * // Define a simple test
805
- * it('adds two numbers', () => {
806
- * expect(add(1, 2)).toBe(3);
807
- * });
808
- * ```
809
- * @example
810
- * ```ts
811
- * // Define a test with options
812
- * it('subtracts two numbers', { retry: 3 }, () => {
813
- * expect(subtract(5, 2)).toBe(3);
814
- * });
815
- * ```
816
- */
817
- const it = test;
818
- let runner;
819
- let defaultSuite;
820
- let currentTestFilepath;
821
- function assert(condition, message) {
822
- if (!condition) {
823
- throw new Error(`Vitest failed to find ${message}. This is a bug in Vitest. Please, open an issue with reproduction.`);
824
- }
825
- }
826
- function getDefaultSuite() {
827
- assert(defaultSuite, "the default suite");
828
- return defaultSuite;
829
- }
830
- function getRunner() {
831
- assert(runner, "the runner");
832
- return runner;
833
- }
834
- function createDefaultSuite(runner) {
835
- const config = runner.config.sequence;
836
- const collector = suite("", { concurrent: config.concurrent }, () => {});
837
- // no parent suite for top-level tests
838
- delete collector.suite;
839
- return collector;
840
- }
841
- function clearCollectorContext(filepath, currentRunner) {
842
- if (!defaultSuite) {
843
- defaultSuite = createDefaultSuite(currentRunner);
844
- }
845
- runner = currentRunner;
846
- currentTestFilepath = filepath;
847
- collectorContext.tasks.length = 0;
848
- defaultSuite.clear();
849
- collectorContext.currentSuite = defaultSuite;
850
- }
851
- function getCurrentSuite() {
852
- const currentSuite = collectorContext.currentSuite || defaultSuite;
853
- assert(currentSuite, "the current suite");
854
- return currentSuite;
855
- }
856
- function createSuiteHooks() {
857
- return {
858
- beforeAll: [],
859
- afterAll: [],
860
- beforeEach: [],
861
- afterEach: []
862
- };
863
- }
864
- function parseArguments(optionsOrFn, optionsOrTest) {
865
- let options = {};
866
- let fn;
867
- // it('', () => {}, { retry: 2 })
868
- if (typeof optionsOrTest === "object") {
869
- // it('', { retry: 2 }, { retry: 3 })
870
- if (typeof optionsOrFn === "object") {
871
- throw new TypeError("Cannot use two objects as arguments. Please provide options and a function callback in that order.");
872
- }
873
- console.warn("Using an object as a third argument is deprecated. Vitest 4 will throw an error if the third argument is not a timeout number. Please use the second argument for options. See more at https://vitest.dev/guide/migration");
874
- options = optionsOrTest;
875
- } else if (typeof optionsOrTest === "number") {
876
- options = { timeout: optionsOrTest };
877
- } else if (typeof optionsOrFn === "object") {
878
- options = optionsOrFn;
879
- }
880
- if (typeof optionsOrFn === "function") {
881
- if (typeof optionsOrTest === "function") {
882
- throw new TypeError("Cannot use two functions as arguments. Please use the second argument for options.");
883
- }
884
- fn = optionsOrFn;
885
- } else if (typeof optionsOrTest === "function") {
886
- fn = optionsOrTest;
887
- }
888
- return {
889
- options,
890
- handler: fn
891
- };
892
- }
893
- // implementations
894
- function createSuiteCollector(name, factory = () => {}, mode, each, suiteOptions, parentCollectorFixtures) {
895
- const tasks = [];
896
- let suite;
897
- initSuite(true);
898
- const task = function(name = "", options = {}) {
899
- var _collectorContext$cur;
900
- const timeout = (options === null || options === void 0 ? void 0 : options.timeout) ?? runner.config.testTimeout;
901
- const task = {
902
- id: "",
903
- name,
904
- suite: (_collectorContext$cur = collectorContext.currentSuite) === null || _collectorContext$cur === void 0 ? void 0 : _collectorContext$cur.suite,
905
- each: options.each,
906
- fails: options.fails,
907
- context: undefined,
908
- type: "test",
909
- file: undefined,
910
- timeout,
911
- retry: options.retry ?? runner.config.retry,
912
- repeats: options.repeats,
913
- mode: options.only ? "only" : options.skip ? "skip" : options.todo ? "todo" : "run",
914
- meta: options.meta ?? Object.create(null),
915
- annotations: []
916
- };
917
- const handler = options.handler;
918
- if (task.mode === "run" && !handler) {
919
- task.mode = "todo";
920
- }
921
- if (options.concurrent || !options.sequential && runner.config.sequence.concurrent) {
922
- task.concurrent = true;
923
- }
924
- task.shuffle = suiteOptions === null || suiteOptions === void 0 ? void 0 : suiteOptions.shuffle;
925
- const context = createTestContext(task, runner);
926
- // create test context
927
- Object.defineProperty(task, "context", {
928
- value: context,
929
- enumerable: false
930
- });
931
- setTestFixture(context, options.fixtures);
932
- // custom can be called from any place, let's assume the limit is 15 stacks
933
- const limit = Error.stackTraceLimit;
934
- Error.stackTraceLimit = 15;
935
- const stackTraceError = new Error("STACK_TRACE_ERROR");
936
- Error.stackTraceLimit = limit;
937
- if (handler) {
938
- setFn(task, withTimeout(withAwaitAsyncAssertions(withFixtures(runner, handler, context), task), timeout, false, stackTraceError, (_, error) => abortIfTimeout([context], error)));
939
- }
940
- if (runner.config.includeTaskLocation) {
941
- const error = stackTraceError.stack;
942
- const stack = findTestFileStackTrace(currentTestFilepath, error);
943
- if (stack) {
944
- task.location = {
945
- line: stack.line,
946
- column: stack.column
947
- };
948
- }
949
- }
950
- tasks.push(task);
951
- return task;
952
- };
953
- const test = createTest(function(name, optionsOrFn, optionsOrTest) {
954
- let { options, handler } = parseArguments(optionsOrFn, optionsOrTest);
955
- // inherit repeats, retry, timeout from suite
956
- if (typeof suiteOptions === "object") {
957
- options = Object.assign({}, suiteOptions, options);
958
- }
959
- // inherit concurrent / sequential from suite
960
- options.concurrent = this.concurrent || !this.sequential && (options === null || options === void 0 ? void 0 : options.concurrent);
961
- options.sequential = this.sequential || !this.concurrent && (options === null || options === void 0 ? void 0 : options.sequential);
962
- const test = task(formatName(name), {
963
- ...this,
964
- ...options,
965
- handler
966
- });
967
- test.type = "test";
968
- });
969
- let collectorFixtures = parentCollectorFixtures;
970
- const collector = {
971
- type: "collector",
972
- name,
973
- mode,
974
- suite,
975
- options: suiteOptions,
976
- test,
977
- tasks,
978
- collect,
979
- task,
980
- clear,
981
- on: addHook,
982
- fixtures() {
983
- return collectorFixtures;
984
- },
985
- scoped(fixtures) {
986
- const parsed = mergeContextFixtures(fixtures, { fixtures: collectorFixtures }, runner);
987
- if (parsed.fixtures) {
988
- collectorFixtures = parsed.fixtures;
989
- }
990
- }
991
- };
992
- function addHook(name, ...fn) {
993
- getHooks(suite)[name].push(...fn);
994
- }
995
- function initSuite(includeLocation) {
996
- var _collectorContext$cur2;
997
- if (typeof suiteOptions === "number") {
998
- suiteOptions = { timeout: suiteOptions };
999
- }
1000
- suite = {
1001
- id: "",
1002
- type: "suite",
1003
- name,
1004
- suite: (_collectorContext$cur2 = collectorContext.currentSuite) === null || _collectorContext$cur2 === void 0 ? void 0 : _collectorContext$cur2.suite,
1005
- mode,
1006
- each,
1007
- file: undefined,
1008
- shuffle: suiteOptions === null || suiteOptions === void 0 ? void 0 : suiteOptions.shuffle,
1009
- tasks: [],
1010
- meta: Object.create(null),
1011
- concurrent: suiteOptions === null || suiteOptions === void 0 ? void 0 : suiteOptions.concurrent
1012
- };
1013
- if (runner && includeLocation && runner.config.includeTaskLocation) {
1014
- const limit = Error.stackTraceLimit;
1015
- Error.stackTraceLimit = 15;
1016
- const error = new Error("stacktrace").stack;
1017
- Error.stackTraceLimit = limit;
1018
- const stack = findTestFileStackTrace(currentTestFilepath, error);
1019
- if (stack) {
1020
- suite.location = {
1021
- line: stack.line,
1022
- column: stack.column
1023
- };
1024
- }
1025
- }
1026
- setHooks(suite, createSuiteHooks());
1027
- }
1028
- function clear() {
1029
- tasks.length = 0;
1030
- initSuite(false);
1031
- }
1032
- async function collect(file) {
1033
- if (!file) {
1034
- throw new TypeError("File is required to collect tasks.");
1035
- }
1036
- if (factory) {
1037
- await runWithSuite(collector, () => factory(test));
1038
- }
1039
- const allChildren = [];
1040
- for (const i of tasks) {
1041
- allChildren.push(i.type === "collector" ? await i.collect(file) : i);
1042
- }
1043
- suite.file = file;
1044
- suite.tasks = allChildren;
1045
- allChildren.forEach((task) => {
1046
- task.file = file;
1047
- });
1048
- return suite;
1049
- }
1050
- collectTask(collector);
1051
- return collector;
1052
- }
1053
- function withAwaitAsyncAssertions(fn, task) {
1054
- return (async (...args) => {
1055
- const fnResult = await fn(...args);
1056
- // some async expect will be added to this array, in case user forget to await them
1057
- if (task.promises) {
1058
- const result = await Promise.allSettled(task.promises);
1059
- const errors = result.map((r) => r.status === "rejected" ? r.reason : undefined).filter(Boolean);
1060
- if (errors.length) {
1061
- throw errors;
1062
- }
1063
- }
1064
- return fnResult;
1065
- });
1066
- }
1067
- function createSuite() {
1068
- function suiteFn(name, factoryOrOptions, optionsOrFactory) {
1069
- var _currentSuite$options;
1070
- let mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
1071
- const currentSuite = collectorContext.currentSuite || defaultSuite;
1072
- let { options, handler: factory } = parseArguments(factoryOrOptions, optionsOrFactory);
1073
- if (mode === "run" && !factory) {
1074
- mode = "todo";
1075
- }
1076
- const isConcurrentSpecified = options.concurrent || this.concurrent || options.sequential === false;
1077
- const isSequentialSpecified = options.sequential || this.sequential || options.concurrent === false;
1078
- // inherit options from current suite
1079
- options = {
1080
- ...currentSuite === null || currentSuite === void 0 ? void 0 : currentSuite.options,
1081
- ...options,
1082
- shuffle: this.shuffle ?? options.shuffle ?? (currentSuite === null || currentSuite === void 0 || (_currentSuite$options = currentSuite.options) === null || _currentSuite$options === void 0 ? void 0 : _currentSuite$options.shuffle) ?? (runner === null || runner === void 0 ? void 0 : runner.config.sequence.shuffle)
1083
- };
1084
- // inherit concurrent / sequential from suite
1085
- const isConcurrent = isConcurrentSpecified || options.concurrent && !isSequentialSpecified;
1086
- const isSequential = isSequentialSpecified || options.sequential && !isConcurrentSpecified;
1087
- options.concurrent = isConcurrent && !isSequential;
1088
- options.sequential = isSequential && !isConcurrent;
1089
- return createSuiteCollector(formatName(name), factory, mode, this.each, options, currentSuite === null || currentSuite === void 0 ? void 0 : currentSuite.fixtures());
1090
- }
1091
- suiteFn.each = function(cases, ...args) {
1092
- const suite = this.withContext();
1093
- this.setContext("each", true);
1094
- if (Array.isArray(cases) && args.length) {
1095
- cases = formatTemplateString(cases, args);
1096
- }
1097
- return (name, optionsOrFn, fnOrOptions) => {
1098
- const _name = formatName(name);
1099
- const arrayOnlyCases = cases.every(Array.isArray);
1100
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
1101
- const fnFirst = typeof optionsOrFn === "function" && typeof fnOrOptions === "object";
1102
- cases.forEach((i, idx) => {
1103
- const items = Array.isArray(i) ? i : [i];
1104
- if (fnFirst) {
1105
- if (arrayOnlyCases) {
1106
- suite(formatTitle(_name, items, idx), handler ? () => handler(...items) : undefined, options);
1107
- } else {
1108
- suite(formatTitle(_name, items, idx), handler ? () => handler(i) : undefined, options);
1109
- }
1110
- } else {
1111
- if (arrayOnlyCases) {
1112
- suite(formatTitle(_name, items, idx), options, handler ? () => handler(...items) : undefined);
1113
- } else {
1114
- suite(formatTitle(_name, items, idx), options, handler ? () => handler(i) : undefined);
1115
- }
1116
- }
1117
- });
1118
- this.setContext("each", undefined);
1119
- };
1120
- };
1121
- suiteFn.for = function(cases, ...args) {
1122
- if (Array.isArray(cases) && args.length) {
1123
- cases = formatTemplateString(cases, args);
1124
- }
1125
- return (name, optionsOrFn, fnOrOptions) => {
1126
- const name_ = formatName(name);
1127
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
1128
- cases.forEach((item, idx) => {
1129
- suite(formatTitle(name_, toArray(item), idx), options, handler ? () => handler(item) : undefined);
1130
- });
1131
- };
1132
- };
1133
- suiteFn.skipIf = (condition) => condition ? suite.skip : suite;
1134
- suiteFn.runIf = (condition) => condition ? suite : suite.skip;
1135
- return createChainable([
1136
- "concurrent",
1137
- "sequential",
1138
- "shuffle",
1139
- "skip",
1140
- "only",
1141
- "todo"
1142
- ], suiteFn);
1143
- }
1144
- function createTaskCollector(fn, context) {
1145
- const taskFn = fn;
1146
- taskFn.each = function(cases, ...args) {
1147
- const test = this.withContext();
1148
- this.setContext("each", true);
1149
- if (Array.isArray(cases) && args.length) {
1150
- cases = formatTemplateString(cases, args);
1151
- }
1152
- return (name, optionsOrFn, fnOrOptions) => {
1153
- const _name = formatName(name);
1154
- const arrayOnlyCases = cases.every(Array.isArray);
1155
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
1156
- const fnFirst = typeof optionsOrFn === "function" && typeof fnOrOptions === "object";
1157
- cases.forEach((i, idx) => {
1158
- const items = Array.isArray(i) ? i : [i];
1159
- if (fnFirst) {
1160
- if (arrayOnlyCases) {
1161
- test(formatTitle(_name, items, idx), handler ? () => handler(...items) : undefined, options);
1162
- } else {
1163
- test(formatTitle(_name, items, idx), handler ? () => handler(i) : undefined, options);
1164
- }
1165
- } else {
1166
- if (arrayOnlyCases) {
1167
- test(formatTitle(_name, items, idx), options, handler ? () => handler(...items) : undefined);
1168
- } else {
1169
- test(formatTitle(_name, items, idx), options, handler ? () => handler(i) : undefined);
1170
- }
1171
- }
1172
- });
1173
- this.setContext("each", undefined);
1174
- };
1175
- };
1176
- taskFn.for = function(cases, ...args) {
1177
- const test = this.withContext();
1178
- if (Array.isArray(cases) && args.length) {
1179
- cases = formatTemplateString(cases, args);
1180
- }
1181
- return (name, optionsOrFn, fnOrOptions) => {
1182
- const _name = formatName(name);
1183
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
1184
- cases.forEach((item, idx) => {
1185
- // monkey-patch handler to allow parsing fixture
1186
- const handlerWrapper = handler ? (ctx) => handler(item, ctx) : undefined;
1187
- if (handlerWrapper) {
1188
- handlerWrapper.__VITEST_FIXTURE_INDEX__ = 1;
1189
- handlerWrapper.toString = () => handler.toString();
1190
- }
1191
- test(formatTitle(_name, toArray(item), idx), options, handlerWrapper);
1192
- });
1193
- };
1194
- };
1195
- taskFn.skipIf = function(condition) {
1196
- return condition ? this.skip : this;
1197
- };
1198
- taskFn.runIf = function(condition) {
1199
- return condition ? this : this.skip;
1200
- };
1201
- taskFn.scoped = function(fixtures) {
1202
- const collector = getCurrentSuite();
1203
- collector.scoped(fixtures);
1204
- };
1205
- taskFn.extend = function(fixtures) {
1206
- const _context = mergeContextFixtures(fixtures, context || {}, runner);
1207
- const originalWrapper = fn;
1208
- return createTest(function(name, optionsOrFn, optionsOrTest) {
1209
- var _collector$options;
1210
- const collector = getCurrentSuite();
1211
- const scopedFixtures = collector.fixtures();
1212
- const context = { ...this };
1213
- if (scopedFixtures) {
1214
- context.fixtures = mergeScopedFixtures(context.fixtures || [], scopedFixtures);
1215
- }
1216
- const { handler, options } = parseArguments(optionsOrFn, optionsOrTest);
1217
- const timeout = options.timeout ?? ((_collector$options = collector.options) === null || _collector$options === void 0 ? void 0 : _collector$options.timeout) ?? (runner === null || runner === void 0 ? void 0 : runner.config.testTimeout);
1218
- originalWrapper.call(context, formatName(name), handler, timeout);
1219
- }, _context);
1220
- };
1221
- const _test = createChainable([
1222
- "concurrent",
1223
- "sequential",
1224
- "skip",
1225
- "only",
1226
- "todo",
1227
- "fails"
1228
- ], taskFn);
1229
- if (context) {
1230
- _test.mergeContext(context);
1231
- }
1232
- return _test;
1233
- }
1234
- function createTest(fn, context) {
1235
- return createTaskCollector(fn, context);
1236
- }
1237
- function formatName(name) {
1238
- return typeof name === "string" ? name : typeof name === "function" ? name.name || "<anonymous>" : String(name);
1239
- }
1240
- function formatTitle(template, items, idx) {
1241
- if (template.includes("%#") || template.includes("%$")) {
1242
- // '%#' match index of the test case
1243
- template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/%\$/g, `${idx + 1}`).replace(/__vitest_escaped_%__/g, "%%");
1244
- }
1245
- const count = template.split("%").length - 1;
1246
- if (template.includes("%f")) {
1247
- const placeholders = template.match(/%f/g) || [];
1248
- placeholders.forEach((_, i) => {
1249
- if (isNegativeNaN(items[i]) || Object.is(items[i], -0)) {
1250
- // Replace the i-th occurrence of '%f' with '-%f'
1251
- let occurrence = 0;
1252
- template = template.replace(/%f/g, (match) => {
1253
- occurrence++;
1254
- return occurrence === i + 1 ? "-%f" : match;
1255
- });
1256
- }
1257
- });
1258
- }
1259
- let formatted = format(template, ...items.slice(0, count));
1260
- const isObjectItem = isObject(items[0]);
1261
- formatted = formatted.replace(/\$([$\w.]+)/g, (_, key) => {
1262
- var _runner$config;
1263
- const isArrayKey = /^\d+$/.test(key);
1264
- if (!isObjectItem && !isArrayKey) {
1265
- return `$${key}`;
1266
- }
1267
- const arrayElement = isArrayKey ? objectAttr(items, key) : undefined;
1268
- const value = isObjectItem ? objectAttr(items[0], key, arrayElement) : arrayElement;
1269
- return objDisplay(value, { truncate: runner === null || runner === void 0 || (_runner$config = runner.config) === null || _runner$config === void 0 || (_runner$config = _runner$config.chaiConfig) === null || _runner$config === void 0 ? void 0 : _runner$config.truncateThreshold });
1270
- });
1271
- return formatted;
1272
- }
1273
- function formatTemplateString(cases, args) {
1274
- const header = cases.join("").trim().replace(/ /g, "").split("\n").map((i) => i.split("|"))[0];
1275
- const res = [];
1276
- for (let i = 0; i < Math.floor(args.length / header.length); i++) {
1277
- const oneCase = {};
1278
- for (let j = 0; j < header.length; j++) {
1279
- oneCase[header[j]] = args[i * header.length + j];
1280
- }
1281
- res.push(oneCase);
1282
- }
1283
- return res;
1284
- }
1285
-
1286
- const now$2 = globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
1287
- async function collectTests(specs, runner) {
1288
- const files = [];
1289
- const config = runner.config;
1290
- for (const spec of specs) {
1291
- var _runner$onCollectStar;
1292
- const filepath = typeof spec === "string" ? spec : spec.filepath;
1293
- const testLocations = typeof spec === "string" ? undefined : spec.testLocations;
1294
- const file = createFileTask(filepath, config.root, config.name, runner.pool);
1295
- file.shuffle = config.sequence.shuffle;
1296
- (_runner$onCollectStar = runner.onCollectStart) === null || _runner$onCollectStar === void 0 ? void 0 : _runner$onCollectStar.call(runner, file);
1297
- clearCollectorContext(filepath, runner);
1298
- try {
1299
- var _runner$getImportDura;
1300
- const setupFiles = toArray(config.setupFiles);
1301
- if (setupFiles.length) {
1302
- const setupStart = now$2();
1303
- await runSetupFiles(config, setupFiles, runner);
1304
- const setupEnd = now$2();
1305
- file.setupDuration = setupEnd - setupStart;
1306
- } else {
1307
- file.setupDuration = 0;
1308
- }
1309
- const collectStart = now$2();
1310
- await runner.importFile(filepath, "collect");
1311
- const durations = (_runner$getImportDura = runner.getImportDurations) === null || _runner$getImportDura === void 0 ? void 0 : _runner$getImportDura.call(runner);
1312
- if (durations) {
1313
- file.importDurations = durations;
1314
- }
1315
- const defaultTasks = await getDefaultSuite().collect(file);
1316
- const fileHooks = createSuiteHooks();
1317
- mergeHooks(fileHooks, getHooks(defaultTasks));
1318
- for (const c of [...defaultTasks.tasks, ...collectorContext.tasks]) {
1319
- if (c.type === "test" || c.type === "suite") {
1320
- file.tasks.push(c);
1321
- } else if (c.type === "collector") {
1322
- const suite = await c.collect(file);
1323
- if (suite.name || suite.tasks.length) {
1324
- mergeHooks(fileHooks, getHooks(suite));
1325
- file.tasks.push(suite);
1326
- }
1327
- } else {
1328
- // check that types are exhausted
1329
- c;
1330
- }
1331
- }
1332
- setHooks(file, fileHooks);
1333
- file.collectDuration = now$2() - collectStart;
1334
- } catch (e) {
1335
- var _runner$getImportDura2;
1336
- const error = processError(e);
1337
- file.result = {
1338
- state: "fail",
1339
- errors: [error]
1340
- };
1341
- const durations = (_runner$getImportDura2 = runner.getImportDurations) === null || _runner$getImportDura2 === void 0 ? void 0 : _runner$getImportDura2.call(runner);
1342
- if (durations) {
1343
- file.importDurations = durations;
1344
- }
1345
- }
1346
- calculateSuiteHash(file);
1347
- const hasOnlyTasks = someTasksAreOnly(file);
1348
- interpretTaskModes(file, config.testNamePattern, testLocations, hasOnlyTasks, false, config.allowOnly);
1349
- if (file.mode === "queued") {
1350
- file.mode = "run";
1351
- }
1352
- files.push(file);
1353
- }
1354
- return files;
1355
- }
1356
- function mergeHooks(baseHooks, hooks) {
1357
- for (const _key in hooks) {
1358
- const key = _key;
1359
- baseHooks[key].push(...hooks[key]);
1360
- }
1361
- return baseHooks;
1362
- }
1363
-
1364
- const now$1 = globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
1365
- const unixNow = Date.now;
1366
- const { clearTimeout, setTimeout } = getSafeTimers();
1367
- function updateSuiteHookState(task, name, state, runner) {
1368
- if (!task.result) {
1369
- task.result = { state: "run" };
1370
- }
1371
- if (!task.result.hooks) {
1372
- task.result.hooks = {};
1373
- }
1374
- const suiteHooks = task.result.hooks;
1375
- if (suiteHooks) {
1376
- suiteHooks[name] = state;
1377
- let event = state === "run" ? "before-hook-start" : "before-hook-end";
1378
- if (name === "afterAll" || name === "afterEach") {
1379
- event = state === "run" ? "after-hook-start" : "after-hook-end";
1380
- }
1381
- updateTask(event, task, runner);
1382
- }
1383
- }
1384
- function getSuiteHooks(suite, name, sequence) {
1385
- const hooks = getHooks(suite)[name];
1386
- if (sequence === "stack" && (name === "afterAll" || name === "afterEach")) {
1387
- return hooks.slice().reverse();
1388
- }
1389
- return hooks;
1390
- }
1391
- async function callTestHooks(runner, test, hooks, sequence) {
1392
- if (sequence === "stack") {
1393
- hooks = hooks.slice().reverse();
1394
- }
1395
- if (!hooks.length) {
1396
- return;
1397
- }
1398
- const context = test.context;
1399
- const onTestFailed = test.context.onTestFailed;
1400
- const onTestFinished = test.context.onTestFinished;
1401
- context.onTestFailed = () => {
1402
- throw new Error(`Cannot call "onTestFailed" inside a test hook.`);
1403
- };
1404
- context.onTestFinished = () => {
1405
- throw new Error(`Cannot call "onTestFinished" inside a test hook.`);
1406
- };
1407
- if (sequence === "parallel") {
1408
- try {
1409
- await Promise.all(hooks.map((fn) => fn(test.context)));
1410
- } catch (e) {
1411
- failTask(test.result, e, runner.config.diffOptions);
1412
- }
1413
- } else {
1414
- for (const fn of hooks) {
1415
- try {
1416
- await fn(test.context);
1417
- } catch (e) {
1418
- failTask(test.result, e, runner.config.diffOptions);
1419
- }
1420
- }
1421
- }
1422
- context.onTestFailed = onTestFailed;
1423
- context.onTestFinished = onTestFinished;
1424
- }
1425
- async function callSuiteHook(suite, currentTask, name, runner, args) {
1426
- const sequence = runner.config.sequence.hooks;
1427
- const callbacks = [];
1428
- // stop at file level
1429
- const parentSuite = "filepath" in suite ? null : suite.suite || suite.file;
1430
- if (name === "beforeEach" && parentSuite) {
1431
- callbacks.push(...await callSuiteHook(parentSuite, currentTask, name, runner, args));
1432
- }
1433
- const hooks = getSuiteHooks(suite, name, sequence);
1434
- if (hooks.length > 0) {
1435
- updateSuiteHookState(currentTask, name, "run", runner);
1436
- }
1437
- async function runHook(hook) {
1438
- return getBeforeHookCleanupCallback(hook, await hook(...args), name === "beforeEach" ? args[0] : undefined);
1439
- }
1440
- if (sequence === "parallel") {
1441
- callbacks.push(...await Promise.all(hooks.map((hook) => runHook(hook))));
1442
- } else {
1443
- for (const hook of hooks) {
1444
- callbacks.push(await runHook(hook));
1445
- }
1446
- }
1447
- if (hooks.length > 0) {
1448
- updateSuiteHookState(currentTask, name, "pass", runner);
1449
- }
1450
- if (name === "afterEach" && parentSuite) {
1451
- callbacks.push(...await callSuiteHook(parentSuite, currentTask, name, runner, args));
1452
- }
1453
- return callbacks;
1454
- }
1455
- const packs = new Map();
1456
- const eventsPacks = [];
1457
- const pendingTasksUpdates = [];
1458
- function sendTasksUpdate(runner) {
1459
- if (packs.size) {
1460
- var _runner$onTaskUpdate;
1461
- const taskPacks = Array.from(packs).map(([id, task]) => {
1462
- return [
1463
- id,
1464
- task[0],
1465
- task[1]
1466
- ];
1467
- });
1468
- const p = (_runner$onTaskUpdate = runner.onTaskUpdate) === null || _runner$onTaskUpdate === void 0 ? void 0 : _runner$onTaskUpdate.call(runner, taskPacks, eventsPacks);
1469
- if (p) {
1470
- pendingTasksUpdates.push(p);
1471
- // remove successful promise to not grow array indefnitely,
1472
- // but keep rejections so finishSendTasksUpdate can handle them
1473
- p.then(() => pendingTasksUpdates.splice(pendingTasksUpdates.indexOf(p), 1), () => {});
1474
- }
1475
- eventsPacks.length = 0;
1476
- packs.clear();
1477
- }
1478
- }
1479
- async function finishSendTasksUpdate(runner) {
1480
- sendTasksUpdate(runner);
1481
- await Promise.all(pendingTasksUpdates);
1482
- }
1483
- function throttle(fn, ms) {
1484
- let last = 0;
1485
- let pendingCall;
1486
- return function call(...args) {
1487
- const now = unixNow();
1488
- if (now - last > ms) {
1489
- last = now;
1490
- clearTimeout(pendingCall);
1491
- pendingCall = undefined;
1492
- return fn.apply(this, args);
1493
- }
1494
- // Make sure fn is still called even if there are no further calls
1495
- pendingCall ?? (pendingCall = setTimeout(() => call.bind(this)(...args), ms));
1496
- };
1497
- }
1498
- // throttle based on summary reporter's DURATION_UPDATE_INTERVAL_MS
1499
- const sendTasksUpdateThrottled = throttle(sendTasksUpdate, 100);
1500
- function updateTask(event, task, runner) {
1501
- eventsPacks.push([
1502
- task.id,
1503
- event,
1504
- undefined
1505
- ]);
1506
- packs.set(task.id, [task.result, task.meta]);
1507
- sendTasksUpdateThrottled(runner);
1508
- }
1509
- async function callCleanupHooks(runner, cleanups) {
1510
- const sequence = runner.config.sequence.hooks;
1511
- if (sequence === "stack") {
1512
- cleanups = cleanups.slice().reverse();
1513
- }
1514
- if (sequence === "parallel") {
1515
- await Promise.all(cleanups.map(async (fn) => {
1516
- if (typeof fn !== "function") {
1517
- return;
1518
- }
1519
- await fn();
1520
- }));
1521
- } else {
1522
- for (const fn of cleanups) {
1523
- if (typeof fn !== "function") {
1524
- continue;
1525
- }
1526
- await fn();
1527
- }
1528
- }
1529
- }
1530
- async function runTest(test, runner) {
1531
- var _runner$onBeforeRunTa, _test$result, _runner$onAfterRunTas;
1532
- await ((_runner$onBeforeRunTa = runner.onBeforeRunTask) === null || _runner$onBeforeRunTa === void 0 ? void 0 : _runner$onBeforeRunTa.call(runner, test));
1533
- if (test.mode !== "run" && test.mode !== "queued") {
1534
- updateTask("test-prepare", test, runner);
1535
- updateTask("test-finished", test, runner);
1536
- return;
1537
- }
1538
- if (((_test$result = test.result) === null || _test$result === void 0 ? void 0 : _test$result.state) === "fail") {
1539
- // should not be possible to get here, I think this is just copy pasted from suite
1540
- // TODO: maybe someone fails tests in `beforeAll` hooks?
1541
- // https://github.com/vitest-dev/vitest/pull/7069
1542
- updateTask("test-failed-early", test, runner);
1543
- return;
1544
- }
1545
- const start = now$1();
1546
- test.result = {
1547
- state: "run",
1548
- startTime: unixNow(),
1549
- retryCount: 0
1550
- };
1551
- updateTask("test-prepare", test, runner);
1552
- const cleanupRunningTest = addRunningTest(test);
1553
- setCurrentTest(test);
1554
- const suite = test.suite || test.file;
1555
- const repeats = test.repeats ?? 0;
1556
- for (let repeatCount = 0; repeatCount <= repeats; repeatCount++) {
1557
- const retry = test.retry ?? 0;
1558
- for (let retryCount = 0; retryCount <= retry; retryCount++) {
1559
- var _test$result2, _test$result3;
1560
- let beforeEachCleanups = [];
1561
- try {
1562
- var _runner$onBeforeTryTa, _runner$onAfterTryTas;
1563
- await ((_runner$onBeforeTryTa = runner.onBeforeTryTask) === null || _runner$onBeforeTryTa === void 0 ? void 0 : _runner$onBeforeTryTa.call(runner, test, {
1564
- retry: retryCount,
1565
- repeats: repeatCount
1566
- }));
1567
- test.result.repeatCount = repeatCount;
1568
- beforeEachCleanups = await callSuiteHook(suite, test, "beforeEach", runner, [test.context, suite]);
1569
- if (runner.runTask) {
1570
- await runner.runTask(test);
1571
- } else {
1572
- const fn = getFn(test);
1573
- if (!fn) {
1574
- throw new Error("Test function is not found. Did you add it using `setFn`?");
1575
- }
1576
- await fn();
1577
- }
1578
- await ((_runner$onAfterTryTas = runner.onAfterTryTask) === null || _runner$onAfterTryTas === void 0 ? void 0 : _runner$onAfterTryTas.call(runner, test, {
1579
- retry: retryCount,
1580
- repeats: repeatCount
1581
- }));
1582
- if (test.result.state !== "fail") {
1583
- if (!test.repeats) {
1584
- test.result.state = "pass";
1585
- } else if (test.repeats && retry === retryCount) {
1586
- test.result.state = "pass";
1587
- }
1588
- }
1589
- } catch (e) {
1590
- failTask(test.result, e, runner.config.diffOptions);
1591
- }
1592
- try {
1593
- var _runner$onTaskFinishe;
1594
- await ((_runner$onTaskFinishe = runner.onTaskFinished) === null || _runner$onTaskFinishe === void 0 ? void 0 : _runner$onTaskFinishe.call(runner, test));
1595
- } catch (e) {
1596
- failTask(test.result, e, runner.config.diffOptions);
1597
- }
1598
- try {
1599
- await callSuiteHook(suite, test, "afterEach", runner, [test.context, suite]);
1600
- await callCleanupHooks(runner, beforeEachCleanups);
1601
- await callFixtureCleanup(test.context);
1602
- } catch (e) {
1603
- failTask(test.result, e, runner.config.diffOptions);
1604
- }
1605
- await callTestHooks(runner, test, test.onFinished || [], "stack");
1606
- if (test.result.state === "fail") {
1607
- await callTestHooks(runner, test, test.onFailed || [], runner.config.sequence.hooks);
1608
- }
1609
- test.onFailed = undefined;
1610
- test.onFinished = undefined;
1611
- // skipped with new PendingError
1612
- if (((_test$result2 = test.result) === null || _test$result2 === void 0 ? void 0 : _test$result2.pending) || ((_test$result3 = test.result) === null || _test$result3 === void 0 ? void 0 : _test$result3.state) === "skip") {
1613
- var _test$result4;
1614
- test.mode = "skip";
1615
- test.result = {
1616
- state: "skip",
1617
- note: (_test$result4 = test.result) === null || _test$result4 === void 0 ? void 0 : _test$result4.note,
1618
- pending: true,
1619
- duration: now$1() - start
1620
- };
1621
- updateTask("test-finished", test, runner);
1622
- setCurrentTest(undefined);
1623
- cleanupRunningTest();
1624
- return;
1625
- }
1626
- if (test.result.state === "pass") {
1627
- break;
1628
- }
1629
- if (retryCount < retry) {
1630
- // reset state when retry test
1631
- test.result.state = "run";
1632
- test.result.retryCount = (test.result.retryCount ?? 0) + 1;
1633
- }
1634
- // update retry info
1635
- updateTask("test-retried", test, runner);
1636
- }
1637
- }
1638
- // if test is marked to be failed, flip the result
1639
- if (test.fails) {
1640
- if (test.result.state === "pass") {
1641
- const error = processError(new Error("Expect test to fail"));
1642
- test.result.state = "fail";
1643
- test.result.errors = [error];
1644
- } else {
1645
- test.result.state = "pass";
1646
- test.result.errors = undefined;
1647
- }
1648
- }
1649
- cleanupRunningTest();
1650
- setCurrentTest(undefined);
1651
- test.result.duration = now$1() - start;
1652
- await ((_runner$onAfterRunTas = runner.onAfterRunTask) === null || _runner$onAfterRunTas === void 0 ? void 0 : _runner$onAfterRunTas.call(runner, test));
1653
- updateTask("test-finished", test, runner);
1654
- }
1655
- function failTask(result, err, diffOptions) {
1656
- if (err instanceof PendingError) {
1657
- result.state = "skip";
1658
- result.note = err.note;
1659
- result.pending = true;
1660
- return;
1661
- }
1662
- result.state = "fail";
1663
- const errors = Array.isArray(err) ? err : [err];
1664
- for (const e of errors) {
1665
- const error = processError(e, diffOptions);
1666
- result.errors ?? (result.errors = []);
1667
- result.errors.push(error);
1668
- }
1669
- }
1670
- function markTasksAsSkipped(suite, runner) {
1671
- suite.tasks.forEach((t) => {
1672
- t.mode = "skip";
1673
- t.result = {
1674
- ...t.result,
1675
- state: "skip"
1676
- };
1677
- updateTask("test-finished", t, runner);
1678
- if (t.type === "suite") {
1679
- markTasksAsSkipped(t, runner);
1680
- }
1681
- });
1682
- }
1683
- async function runSuite(suite, runner) {
1684
- var _runner$onBeforeRunSu, _suite$result;
1685
- await ((_runner$onBeforeRunSu = runner.onBeforeRunSuite) === null || _runner$onBeforeRunSu === void 0 ? void 0 : _runner$onBeforeRunSu.call(runner, suite));
1686
- if (((_suite$result = suite.result) === null || _suite$result === void 0 ? void 0 : _suite$result.state) === "fail") {
1687
- markTasksAsSkipped(suite, runner);
1688
- // failed during collection
1689
- updateTask("suite-failed-early", suite, runner);
1690
- return;
1691
- }
1692
- const start = now$1();
1693
- const mode = suite.mode;
1694
- suite.result = {
1695
- state: mode === "skip" || mode === "todo" ? mode : "run",
1696
- startTime: unixNow()
1697
- };
1698
- updateTask("suite-prepare", suite, runner);
1699
- let beforeAllCleanups = [];
1700
- if (suite.mode === "skip") {
1701
- suite.result.state = "skip";
1702
- updateTask("suite-finished", suite, runner);
1703
- } else if (suite.mode === "todo") {
1704
- suite.result.state = "todo";
1705
- updateTask("suite-finished", suite, runner);
1706
- } else {
1707
- var _runner$onAfterRunSui;
1708
- try {
1709
- try {
1710
- beforeAllCleanups = await callSuiteHook(suite, suite, "beforeAll", runner, [suite]);
1711
- } catch (e) {
1712
- markTasksAsSkipped(suite, runner);
1713
- throw e;
1714
- }
1715
- if (runner.runSuite) {
1716
- await runner.runSuite(suite);
1717
- } else {
1718
- for (let tasksGroup of partitionSuiteChildren(suite)) {
1719
- if (tasksGroup[0].concurrent === true) {
1720
- await Promise.all(tasksGroup.map((c) => runSuiteChild(c, runner)));
1721
- } else {
1722
- const { sequence } = runner.config;
1723
- if (suite.shuffle) {
1724
- // run describe block independently from tests
1725
- const suites = tasksGroup.filter((group) => group.type === "suite");
1726
- const tests = tasksGroup.filter((group) => group.type === "test");
1727
- const groups = shuffle([suites, tests], sequence.seed);
1728
- tasksGroup = groups.flatMap((group) => shuffle(group, sequence.seed));
1729
- }
1730
- for (const c of tasksGroup) {
1731
- await runSuiteChild(c, runner);
1732
- }
1733
- }
1734
- }
1735
- }
1736
- } catch (e) {
1737
- failTask(suite.result, e, runner.config.diffOptions);
1738
- }
1739
- try {
1740
- await callSuiteHook(suite, suite, "afterAll", runner, [suite]);
1741
- await callCleanupHooks(runner, beforeAllCleanups);
1742
- if (suite.file === suite) {
1743
- const context = getFileContext(suite);
1744
- await callFixtureCleanup(context);
1745
- }
1746
- } catch (e) {
1747
- failTask(suite.result, e, runner.config.diffOptions);
1748
- }
1749
- if (suite.mode === "run" || suite.mode === "queued") {
1750
- if (!runner.config.passWithNoTests && !hasTests(suite)) {
1751
- var _suite$result$errors;
1752
- suite.result.state = "fail";
1753
- if (!((_suite$result$errors = suite.result.errors) === null || _suite$result$errors === void 0 ? void 0 : _suite$result$errors.length)) {
1754
- const error = processError(new Error(`No test found in suite ${suite.name}`));
1755
- suite.result.errors = [error];
1756
- }
1757
- } else if (hasFailed(suite)) {
1758
- suite.result.state = "fail";
1759
- } else {
1760
- suite.result.state = "pass";
1761
- }
1762
- }
1763
- suite.result.duration = now$1() - start;
1764
- await ((_runner$onAfterRunSui = runner.onAfterRunSuite) === null || _runner$onAfterRunSui === void 0 ? void 0 : _runner$onAfterRunSui.call(runner, suite));
1765
- updateTask("suite-finished", suite, runner);
1766
- }
1767
- }
1768
- let limitMaxConcurrency;
1769
- async function runSuiteChild(c, runner) {
1770
- if (c.type === "test") {
1771
- return limitMaxConcurrency(() => runTest(c, runner));
1772
- } else if (c.type === "suite") {
1773
- return runSuite(c, runner);
1774
- }
1775
- }
1776
- async function runFiles(files, runner) {
1777
- limitMaxConcurrency ?? (limitMaxConcurrency = limitConcurrency(runner.config.maxConcurrency));
1778
- for (const file of files) {
1779
- if (!file.tasks.length && !runner.config.passWithNoTests) {
1780
- var _file$result;
1781
- if (!((_file$result = file.result) === null || _file$result === void 0 || (_file$result = _file$result.errors) === null || _file$result === void 0 ? void 0 : _file$result.length)) {
1782
- const error = processError(new Error(`No test suite found in file ${file.filepath}`));
1783
- file.result = {
1784
- state: "fail",
1785
- errors: [error]
1786
- };
1787
- }
1788
- }
1789
- await runSuite(file, runner);
1790
- }
1791
- }
1792
- const workerRunners = new WeakSet();
1793
- async function startTests(specs, runner) {
1794
- var _runner$cancel;
1795
- const cancel = (_runner$cancel = runner.cancel) === null || _runner$cancel === void 0 ? void 0 : _runner$cancel.bind(runner);
1796
- // Ideally, we need to have an event listener for this, but only have a runner here.
1797
- // Adding another onCancel felt wrong (maybe it needs to be refactored)
1798
- runner.cancel = (reason) => {
1799
- // We intentionally create only one error since there is only one test run that can be cancelled
1800
- const error = new TestRunAbortError("The test run was aborted by the user.", reason);
1801
- getRunningTests().forEach((test) => abortContextSignal(test.context, error));
1802
- return cancel === null || cancel === void 0 ? void 0 : cancel(reason);
1803
- };
1804
- if (!workerRunners.has(runner)) {
1805
- var _runner$onCleanupWork;
1806
- (_runner$onCleanupWork = runner.onCleanupWorkerContext) === null || _runner$onCleanupWork === void 0 ? void 0 : _runner$onCleanupWork.call(runner, async () => {
1807
- var _runner$getWorkerCont;
1808
- const context = (_runner$getWorkerCont = runner.getWorkerContext) === null || _runner$getWorkerCont === void 0 ? void 0 : _runner$getWorkerCont.call(runner);
1809
- if (context) {
1810
- await callFixtureCleanup(context);
1811
- }
1812
- });
1813
- workerRunners.add(runner);
1814
- }
1815
- try {
1816
- var _runner$onBeforeColle, _runner$onCollected, _runner$onBeforeRunFi, _runner$onAfterRunFil;
1817
- const paths = specs.map((f) => typeof f === "string" ? f : f.filepath);
1818
- await ((_runner$onBeforeColle = runner.onBeforeCollect) === null || _runner$onBeforeColle === void 0 ? void 0 : _runner$onBeforeColle.call(runner, paths));
1819
- const files = await collectTests(specs, runner);
1820
- await ((_runner$onCollected = runner.onCollected) === null || _runner$onCollected === void 0 ? void 0 : _runner$onCollected.call(runner, files));
1821
- await ((_runner$onBeforeRunFi = runner.onBeforeRunFiles) === null || _runner$onBeforeRunFi === void 0 ? void 0 : _runner$onBeforeRunFi.call(runner, files));
1822
- await runFiles(files, runner);
1823
- await ((_runner$onAfterRunFil = runner.onAfterRunFiles) === null || _runner$onAfterRunFil === void 0 ? void 0 : _runner$onAfterRunFil.call(runner, files));
1824
- await finishSendTasksUpdate(runner);
1825
- return files;
1826
- } finally {
1827
- runner.cancel = cancel;
1828
- }
1829
- }
1830
- async function publicCollect(specs, runner) {
1831
- var _runner$onBeforeColle2, _runner$onCollected2;
1832
- const paths = specs.map((f) => typeof f === "string" ? f : f.filepath);
1833
- await ((_runner$onBeforeColle2 = runner.onBeforeCollect) === null || _runner$onBeforeColle2 === void 0 ? void 0 : _runner$onBeforeColle2.call(runner, paths));
1834
- const files = await collectTests(specs, runner);
1835
- await ((_runner$onCollected2 = runner.onCollected) === null || _runner$onCollected2 === void 0 ? void 0 : _runner$onCollected2.call(runner, files));
1836
- return files;
1837
- }
1838
-
1839
- const now = Date.now;
1840
- const collectorContext = {
1841
- tasks: [],
1842
- currentSuite: null
1843
- };
1844
- function collectTask(task) {
1845
- var _collectorContext$cur;
1846
- (_collectorContext$cur = collectorContext.currentSuite) === null || _collectorContext$cur === void 0 ? void 0 : _collectorContext$cur.tasks.push(task);
1847
- }
1848
- async function runWithSuite(suite, fn) {
1849
- const prev = collectorContext.currentSuite;
1850
- collectorContext.currentSuite = suite;
1851
- await fn();
1852
- collectorContext.currentSuite = prev;
1853
- }
1854
- function withTimeout(fn, timeout, isHook = false, stackTraceError, onTimeout) {
1855
- if (timeout <= 0 || timeout === Number.POSITIVE_INFINITY) {
1856
- return fn;
1857
- }
1858
- const { setTimeout, clearTimeout } = getSafeTimers();
1859
- // this function name is used to filter error in test/cli/test/fails.test.ts
1860
- return (function runWithTimeout(...args) {
1861
- const startTime = now();
1862
- const runner = getRunner();
1863
- runner._currentTaskStartTime = startTime;
1864
- runner._currentTaskTimeout = timeout;
1865
- return new Promise((resolve_, reject_) => {
1866
- var _timer$unref;
1867
- const timer = setTimeout(() => {
1868
- clearTimeout(timer);
1869
- rejectTimeoutError();
1870
- }, timeout);
1871
- // `unref` might not exist in browser
1872
- (_timer$unref = timer.unref) === null || _timer$unref === void 0 ? void 0 : _timer$unref.call(timer);
1873
- function rejectTimeoutError() {
1874
- const error = makeTimeoutError(isHook, timeout, stackTraceError);
1875
- onTimeout === null || onTimeout === void 0 ? void 0 : onTimeout(args, error);
1876
- reject_(error);
1877
- }
1878
- function resolve(result) {
1879
- runner._currentTaskStartTime = undefined;
1880
- runner._currentTaskTimeout = undefined;
1881
- clearTimeout(timer);
1882
- // if test/hook took too long in microtask, setTimeout won't be triggered,
1883
- // but we still need to fail the test, see
1884
- // https://github.com/vitest-dev/vitest/issues/2920
1885
- if (now() - startTime >= timeout) {
1886
- rejectTimeoutError();
1887
- return;
1888
- }
1889
- resolve_(result);
1890
- }
1891
- function reject(error) {
1892
- runner._currentTaskStartTime = undefined;
1893
- runner._currentTaskTimeout = undefined;
1894
- clearTimeout(timer);
1895
- reject_(error);
1896
- }
1897
- // sync test/hook will be caught by try/catch
1898
- try {
1899
- const result = fn(...args);
1900
- // the result is a thenable, we don't wrap this in Promise.resolve
1901
- // to avoid creating new promises
1902
- if (typeof result === "object" && result != null && typeof result.then === "function") {
1903
- result.then(resolve, reject);
1904
- } else {
1905
- resolve(result);
1906
- }
1907
- }
1908
- // user sync test/hook throws an error
1909
- catch (error) {
1910
- reject(error);
1911
- }
1912
- });
1913
- });
1914
- }
1915
- const abortControllers = new WeakMap();
1916
- function abortIfTimeout([context], error) {
1917
- if (context) {
1918
- abortContextSignal(context, error);
1919
- }
1920
- }
1921
- function abortContextSignal(context, error) {
1922
- const abortController = abortControllers.get(context);
1923
- abortController === null || abortController === void 0 ? void 0 : abortController.abort(error);
1924
- }
1925
- function createTestContext(test, runner) {
1926
- var _runner$extendTaskCon;
1927
- const context = function() {
1928
- throw new Error("done() callback is deprecated, use promise instead");
1929
- };
1930
- let abortController = abortControllers.get(context);
1931
- if (!abortController) {
1932
- abortController = new AbortController();
1933
- abortControllers.set(context, abortController);
1934
- }
1935
- context.signal = abortController.signal;
1936
- context.task = test;
1937
- context.skip = (condition, note) => {
1938
- if (condition === false) {
1939
- // do nothing
1940
- return undefined;
1941
- }
1942
- test.result ?? (test.result = { state: "skip" });
1943
- test.result.pending = true;
1944
- throw new PendingError("test is skipped; abort execution", test, typeof condition === "string" ? condition : note);
1945
- };
1946
- async function annotate(message, location, type, attachment) {
1947
- const annotation = {
1948
- message,
1949
- type: type || "notice"
1950
- };
1951
- if (attachment) {
1952
- if (!attachment.body && !attachment.path) {
1953
- throw new TypeError(`Test attachment requires body or path to be set. Both are missing.`);
1954
- }
1955
- if (attachment.body && attachment.path) {
1956
- throw new TypeError(`Test attachment requires only one of "body" or "path" to be set. Both are specified.`);
1957
- }
1958
- annotation.attachment = attachment;
1959
- // convert to a string so it's easier to serialise
1960
- if (attachment.body instanceof Uint8Array) {
1961
- attachment.body = encodeUint8Array(attachment.body);
1962
- }
1963
- }
1964
- if (location) {
1965
- annotation.location = location;
1966
- }
1967
- if (!runner.onTestAnnotate) {
1968
- throw new Error(`Test runner doesn't support test annotations.`);
1969
- }
1970
- await finishSendTasksUpdate(runner);
1971
- const resolvedAnnotation = await runner.onTestAnnotate(test, annotation);
1972
- test.annotations.push(resolvedAnnotation);
1973
- return resolvedAnnotation;
1974
- }
1975
- context.annotate = ((message, type, attachment) => {
1976
- if (test.result && test.result.state !== "run") {
1977
- throw new Error(`Cannot annotate tests outside of the test run. The test "${test.name}" finished running with the "${test.result.state}" state already.`);
1978
- }
1979
- const stack = findTestFileStackTrace(test.file.filepath, new Error("STACK_TRACE").stack);
1980
- let location;
1981
- if (stack) {
1982
- location = {
1983
- file: stack.file,
1984
- line: stack.line,
1985
- column: stack.column
1986
- };
1987
- }
1988
- if (typeof type === "object") {
1989
- return recordAsyncAnnotation(test, annotate(message, location, undefined, type));
1990
- } else {
1991
- return recordAsyncAnnotation(test, annotate(message, location, type, attachment));
1992
- }
1993
- });
1994
- context.onTestFailed = (handler, timeout) => {
1995
- test.onFailed || (test.onFailed = []);
1996
- test.onFailed.push(withTimeout(handler, timeout ?? runner.config.hookTimeout, true, new Error("STACK_TRACE_ERROR"), (_, error) => abortController.abort(error)));
1997
- };
1998
- context.onTestFinished = (handler, timeout) => {
1999
- test.onFinished || (test.onFinished = []);
2000
- test.onFinished.push(withTimeout(handler, timeout ?? runner.config.hookTimeout, true, new Error("STACK_TRACE_ERROR"), (_, error) => abortController.abort(error)));
2001
- };
2002
- return ((_runner$extendTaskCon = runner.extendTaskContext) === null || _runner$extendTaskCon === void 0 ? void 0 : _runner$extendTaskCon.call(runner, context)) || context;
2003
- }
2004
- function makeTimeoutError(isHook, timeout, stackTraceError) {
2005
- const message = `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.\nIf this is a long-running ${isHook ? "hook" : "test"}, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
2006
- const error = new Error(message);
2007
- if (stackTraceError === null || stackTraceError === void 0 ? void 0 : stackTraceError.stack) {
2008
- error.stack = stackTraceError.stack.replace(error.message, stackTraceError.message);
2009
- }
2010
- return error;
2011
- }
2012
- const fileContexts = new WeakMap();
2013
- function getFileContext(file) {
2014
- const context = fileContexts.get(file);
2015
- if (!context) {
2016
- throw new Error(`Cannot find file context for ${file.name}`);
2017
- }
2018
- return context;
2019
- }
2020
- function setFileContext(file, context) {
2021
- fileContexts.set(file, context);
2022
- }
2023
- const table = [];
2024
- for (let i = 65; i < 91; i++) {
2025
- table.push(String.fromCharCode(i));
2026
- }
2027
- for (let i = 97; i < 123; i++) {
2028
- table.push(String.fromCharCode(i));
2029
- }
2030
- for (let i = 0; i < 10; i++) {
2031
- table.push(i.toString(10));
2032
- }
2033
- function encodeUint8Array(bytes) {
2034
- let base64 = "";
2035
- const len = bytes.byteLength;
2036
- for (let i = 0; i < len; i += 3) {
2037
- if (len === i + 1) {
2038
- const a = (bytes[i] & 252) >> 2;
2039
- const b = (bytes[i] & 3) << 4;
2040
- base64 += table[a];
2041
- base64 += table[b];
2042
- base64 += "==";
2043
- } else if (len === i + 2) {
2044
- const a = (bytes[i] & 252) >> 2;
2045
- const b = (bytes[i] & 3) << 4 | (bytes[i + 1] & 240) >> 4;
2046
- const c = (bytes[i + 1] & 15) << 2;
2047
- base64 += table[a];
2048
- base64 += table[b];
2049
- base64 += table[c];
2050
- base64 += "=";
2051
- } else {
2052
- const a = (bytes[i] & 252) >> 2;
2053
- const b = (bytes[i] & 3) << 4 | (bytes[i + 1] & 240) >> 4;
2054
- const c = (bytes[i + 1] & 15) << 2 | (bytes[i + 2] & 192) >> 6;
2055
- const d = bytes[i + 2] & 63;
2056
- base64 += table[a];
2057
- base64 += table[b];
2058
- base64 += table[c];
2059
- base64 += table[d];
2060
- }
2061
- }
2062
- return base64;
2063
- }
2064
- function recordAsyncAnnotation(test, promise) {
2065
- // if promise is explicitly awaited, remove it from the list
2066
- promise = promise.finally(() => {
2067
- if (!test.promises) {
2068
- return;
2069
- }
2070
- const index = test.promises.indexOf(promise);
2071
- if (index !== -1) {
2072
- test.promises.splice(index, 1);
2073
- }
2074
- });
2075
- // record promise
2076
- if (!test.promises) {
2077
- test.promises = [];
2078
- }
2079
- test.promises.push(promise);
2080
- return promise;
2081
- }
2082
-
2083
- function getDefaultHookTimeout() {
2084
- return getRunner().config.hookTimeout;
2085
- }
2086
- const CLEANUP_TIMEOUT_KEY = Symbol.for("VITEST_CLEANUP_TIMEOUT");
2087
- const CLEANUP_STACK_TRACE_KEY = Symbol.for("VITEST_CLEANUP_STACK_TRACE");
2088
- function getBeforeHookCleanupCallback(hook, result, context) {
2089
- if (typeof result === "function") {
2090
- const timeout = CLEANUP_TIMEOUT_KEY in hook && typeof hook[CLEANUP_TIMEOUT_KEY] === "number" ? hook[CLEANUP_TIMEOUT_KEY] : getDefaultHookTimeout();
2091
- const stackTraceError = CLEANUP_STACK_TRACE_KEY in hook && hook[CLEANUP_STACK_TRACE_KEY] instanceof Error ? hook[CLEANUP_STACK_TRACE_KEY] : undefined;
2092
- return withTimeout(result, timeout, true, stackTraceError, (_, error) => {
2093
- if (context) {
2094
- abortContextSignal(context, error);
2095
- }
2096
- });
2097
- }
2098
- }
2099
- /**
2100
- * Registers a callback function to be executed once before all tests within the current suite.
2101
- * This hook is useful for scenarios where you need to perform setup operations that are common to all tests in a suite, such as initializing a database connection or setting up a test environment.
2102
- *
2103
- * **Note:** The `beforeAll` hooks are executed in the order they are defined one after another. You can configure this by changing the `sequence.hooks` option in the config file.
2104
- *
2105
- * @param {Function} fn - The callback function to be executed before all tests.
2106
- * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
2107
- * @returns {void}
2108
- * @example
2109
- * ```ts
2110
- * // Example of using beforeAll to set up a database connection
2111
- * beforeAll(async () => {
2112
- * await database.connect();
2113
- * });
2114
- * ```
2115
- */
2116
- function beforeAll(fn, timeout = getDefaultHookTimeout()) {
2117
- assertTypes(fn, "\"beforeAll\" callback", ["function"]);
2118
- const stackTraceError = new Error("STACK_TRACE_ERROR");
2119
- return getCurrentSuite().on("beforeAll", Object.assign(withTimeout(fn, timeout, true, stackTraceError), {
2120
- [CLEANUP_TIMEOUT_KEY]: timeout,
2121
- [CLEANUP_STACK_TRACE_KEY]: stackTraceError
2122
- }));
2123
- }
2124
- /**
2125
- * Registers a callback function to be executed once after all tests within the current suite have completed.
2126
- * This hook is useful for scenarios where you need to perform cleanup operations after all tests in a suite have run, such as closing database connections or cleaning up temporary files.
2127
- *
2128
- * **Note:** The `afterAll` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
2129
- *
2130
- * @param {Function} fn - The callback function to be executed after all tests.
2131
- * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
2132
- * @returns {void}
2133
- * @example
2134
- * ```ts
2135
- * // Example of using afterAll to close a database connection
2136
- * afterAll(async () => {
2137
- * await database.disconnect();
2138
- * });
2139
- * ```
2140
- */
2141
- function afterAll(fn, timeout) {
2142
- assertTypes(fn, "\"afterAll\" callback", ["function"]);
2143
- return getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true, new Error("STACK_TRACE_ERROR")));
2144
- }
2145
- /**
2146
- * Registers a callback function to be executed before each test within the current suite.
2147
- * This hook is useful for scenarios where you need to reset or reinitialize the test environment before each test runs, such as resetting database states, clearing caches, or reinitializing variables.
2148
- *
2149
- * **Note:** The `beforeEach` hooks are executed in the order they are defined one after another. You can configure this by changing the `sequence.hooks` option in the config file.
2150
- *
2151
- * @param {Function} fn - The callback function to be executed before each test. This function receives an `TestContext` parameter if additional test context is needed.
2152
- * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
2153
- * @returns {void}
2154
- * @example
2155
- * ```ts
2156
- * // Example of using beforeEach to reset a database state
2157
- * beforeEach(async () => {
2158
- * await database.reset();
2159
- * });
2160
- * ```
2161
- */
2162
- function beforeEach(fn, timeout = getDefaultHookTimeout()) {
2163
- assertTypes(fn, "\"beforeEach\" callback", ["function"]);
2164
- const stackTraceError = new Error("STACK_TRACE_ERROR");
2165
- const runner = getRunner();
2166
- return getCurrentSuite().on("beforeEach", Object.assign(withTimeout(withFixtures(runner, fn), timeout ?? getDefaultHookTimeout(), true, stackTraceError, abortIfTimeout), {
2167
- [CLEANUP_TIMEOUT_KEY]: timeout,
2168
- [CLEANUP_STACK_TRACE_KEY]: stackTraceError
2169
- }));
2170
- }
2171
- /**
2172
- * Registers a callback function to be executed after each test within the current suite has completed.
2173
- * This hook is useful for scenarios where you need to clean up or reset the test environment after each test runs, such as deleting temporary files, clearing test-specific database entries, or resetting mocked functions.
2174
- *
2175
- * **Note:** The `afterEach` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
2176
- *
2177
- * @param {Function} fn - The callback function to be executed after each test. This function receives an `TestContext` parameter if additional test context is needed.
2178
- * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
2179
- * @returns {void}
2180
- * @example
2181
- * ```ts
2182
- * // Example of using afterEach to delete temporary files created during a test
2183
- * afterEach(async () => {
2184
- * await fileSystem.deleteTempFiles();
2185
- * });
2186
- * ```
2187
- */
2188
- function afterEach(fn, timeout) {
2189
- assertTypes(fn, "\"afterEach\" callback", ["function"]);
2190
- const runner = getRunner();
2191
- return getCurrentSuite().on("afterEach", withTimeout(withFixtures(runner, fn), timeout ?? getDefaultHookTimeout(), true, new Error("STACK_TRACE_ERROR"), abortIfTimeout));
2192
- }
2193
- /**
2194
- * Registers a callback function to be executed when a test fails within the current suite.
2195
- * This function allows for custom actions to be performed in response to test failures, such as logging, cleanup, or additional diagnostics.
2196
- *
2197
- * **Note:** The `onTestFailed` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
2198
- *
2199
- * @param {Function} fn - The callback function to be executed upon a test failure. The function receives the test result (including errors).
2200
- * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
2201
- * @throws {Error} Throws an error if the function is not called within a test.
2202
- * @returns {void}
2203
- * @example
2204
- * ```ts
2205
- * // Example of using onTestFailed to log failure details
2206
- * onTestFailed(({ errors }) => {
2207
- * console.log(`Test failed: ${test.name}`, errors);
2208
- * });
2209
- * ```
2210
- */
2211
- const onTestFailed = createTestHook("onTestFailed", (test, handler, timeout) => {
2212
- test.onFailed || (test.onFailed = []);
2213
- test.onFailed.push(withTimeout(handler, timeout ?? getDefaultHookTimeout(), true, new Error("STACK_TRACE_ERROR"), abortIfTimeout));
2214
- });
2215
- /**
2216
- * Registers a callback function to be executed when the current test finishes, regardless of the outcome (pass or fail).
2217
- * This function is ideal for performing actions that should occur after every test execution, such as cleanup, logging, or resetting shared resources.
2218
- *
2219
- * This hook is useful if you have access to a resource in the test itself and you want to clean it up after the test finishes. It is a more compact way to clean up resources than using the combination of `beforeEach` and `afterEach`.
2220
- *
2221
- * **Note:** The `onTestFinished` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
2222
- *
2223
- * **Note:** The `onTestFinished` hook is not called if the test is canceled with a dynamic `ctx.skip()` call.
2224
- *
2225
- * @param {Function} fn - The callback function to be executed after a test finishes. The function can receive parameters providing details about the completed test, including its success or failure status.
2226
- * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
2227
- * @throws {Error} Throws an error if the function is not called within a test.
2228
- * @returns {void}
2229
- * @example
2230
- * ```ts
2231
- * // Example of using onTestFinished for cleanup
2232
- * const db = await connectToDatabase();
2233
- * onTestFinished(async () => {
2234
- * await db.disconnect();
2235
- * });
2236
- * ```
2237
- */
2238
- const onTestFinished = createTestHook("onTestFinished", (test, handler, timeout) => {
2239
- test.onFinished || (test.onFinished = []);
2240
- test.onFinished.push(withTimeout(handler, timeout ?? getDefaultHookTimeout(), true, new Error("STACK_TRACE_ERROR"), abortIfTimeout));
2241
- });
2242
- function createTestHook(name, handler) {
2243
- return (fn, timeout) => {
2244
- assertTypes(fn, `"${name}" callback`, ["function"]);
2245
- const current = getCurrentTest();
2246
- if (!current) {
2247
- throw new Error(`Hook ${name}() can only be called inside a test`);
2248
- }
2249
- return handler(current, fn, timeout);
2250
- };
2251
- }
2252
-
2253
- export { interpretTaskModes as A, someTasksAreOnly as B, limitConcurrency as C, partitionSuiteChildren as D, getFullName as E, getNames as F, getSuites as G, getTasks as H, getTestName as I, getTests as J, hasFailed as K, hasTests as L, isTestCase as M, afterAll as a, afterEach as b, beforeAll as c, beforeEach as d, onTestFinished as e, getHooks as f, getFn as g, setHooks as h, startTests as i, createTaskCollector as j, describe as k, getCurrentSuite as l, it as m, suite as n, onTestFailed as o, publicCollect as p, getCurrentTest as q, createChainable as r, setFn as s, test as t, updateTask as u, calculateSuiteHash as v, createFileTask as w, findTestFileStackTrace as x, generateFileHash as y, generateHash as z };