vitest 4.0.0-beta.5 → 4.0.0-beta.7

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.
Files changed (64) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{base.DMfOuRWD.js → base.BXI97p6t.js} +7 -16
  5. package/dist/chunks/{benchmark.CtuRzf-i.js → benchmark.UW6Ezvxy.js} +4 -9
  6. package/dist/chunks/{browser.d.Cawq_X_N.d.ts → browser.d.DOMmqJQx.d.ts} +1 -1
  7. package/dist/chunks/{cac.CKnbxhn2.js → cac.Dsn7ixFt.js} +38 -113
  8. package/dist/chunks/{cli-api.COn58yrl.js → cli-api.DfGJyldU.js} +829 -1232
  9. package/dist/chunks/{config.d.CKNVOKm0.d.ts → config.d._GBBbReY.d.ts} +1 -0
  10. package/dist/chunks/{console.Duv2dVIC.js → console.B0quX7yH.js} +32 -68
  11. package/dist/chunks/{coverage.B6cReEn1.js → coverage.Dvxug1RM.js} +210 -579
  12. package/dist/chunks/{creator.DUVZ6rfm.js → creator.KEg6n5IC.js} +28 -74
  13. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  14. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  15. package/dist/chunks/{globals.CJQ63oO0.js → globals.lgsmH00r.js} +5 -5
  16. package/dist/chunks/{index.QZr3S3vQ.js → index.AR8aAkCC.js} +2 -2
  17. package/dist/chunks/{index.DQhAfQQU.js → index.C3EbxYwt.js} +276 -607
  18. package/dist/chunks/{index.oWRWx-nj.js → index.CsFXYRkW.js} +17 -36
  19. package/dist/chunks/{index.DgN0Zk9a.js → index.D2B6d2vv.js} +14 -24
  20. package/dist/chunks/{index.BRtIe7r8.js → index.DfviD7lX.js} +55 -110
  21. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  22. package/dist/chunks/{moduleRunner.d.mmOmOGrW.d.ts → moduleRunner.d.CX4DuqOx.d.ts} +2 -2
  23. package/dist/chunks/{node.4JV5OXkt.js → node.BOqcT2jW.js} +1 -1
  24. package/dist/chunks/{plugin.d.CvOlgjxK.d.ts → plugin.d.vcD4xbMS.d.ts} +1 -1
  25. package/dist/chunks/{reporters.d.CYE9sT5z.d.ts → reporters.d.BC86JJdB.d.ts} +799 -758
  26. package/dist/chunks/{resolver.D5bG4zy5.js → resolver.Bx6lE0iq.js} +21 -64
  27. package/dist/chunks/{rpc.DGoW_Vl-.js → rpc.RpPylpp0.js} +7 -21
  28. package/dist/chunks/{runBaseTests.B3KcKqlF.js → runBaseTests.D6sfuWBM.js} +25 -54
  29. package/dist/chunks/{setup-common.lgPs-bYv.js → setup-common.hLGRxhC8.js} +9 -22
  30. package/dist/chunks/{startModuleRunner.C8FtT_BY.js → startModuleRunner.C8TW8zTN.js} +83 -205
  31. package/dist/chunks/{typechecker.BgoW4nTA.js → typechecker.DSo_maXz.js} +97 -209
  32. package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
  33. package/dist/chunks/{utils.B9FY3b73.js → utils.C7__0Iv5.js} +5 -14
  34. package/dist/chunks/{vi.DGAfBY4R.js → vi.BfdOiD4j.js} +110 -267
  35. package/dist/chunks/{vm.BKfKvaKl.js → vm.BHBje7cC.js} +73 -177
  36. package/dist/chunks/{worker.d.Db-UVmXc.d.ts → worker.d.BKu8cnnX.d.ts} +1 -1
  37. package/dist/chunks/{worker.d.D9QWnzAe.d.ts → worker.d.DYlqbejz.d.ts} +1 -1
  38. package/dist/cli.js +3 -3
  39. package/dist/config.d.ts +7 -7
  40. package/dist/coverage.d.ts +4 -4
  41. package/dist/coverage.js +2 -2
  42. package/dist/environments.js +1 -1
  43. package/dist/index.d.ts +6 -6
  44. package/dist/index.js +5 -5
  45. package/dist/module-evaluator.d.ts +3 -3
  46. package/dist/module-evaluator.js +33 -84
  47. package/dist/module-runner.js +2 -2
  48. package/dist/node.d.ts +11 -9
  49. package/dist/node.js +16 -27
  50. package/dist/reporters.d.ts +5 -5
  51. package/dist/reporters.js +3 -3
  52. package/dist/runners.d.ts +1 -1
  53. package/dist/runners.js +23 -51
  54. package/dist/snapshot.js +2 -2
  55. package/dist/suite.js +2 -2
  56. package/dist/worker.js +18 -34
  57. package/dist/workers/forks.js +4 -4
  58. package/dist/workers/runVmTests.js +19 -37
  59. package/dist/workers/threads.js +4 -4
  60. package/dist/workers/vmForks.js +7 -7
  61. package/dist/workers/vmThreads.js +7 -7
  62. package/dist/workers.d.ts +3 -3
  63. package/dist/workers.js +11 -11
  64. package/package.json +11 -11
@@ -2,14 +2,14 @@ import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, J
2
2
  import { getCurrentTest } from '@vitest/runner';
3
3
  import { getNames, getTestName } from '@vitest/runner/utils';
4
4
  import * as chai$1 from 'chai';
5
- import { g as getWorkerState, a as getCurrentEnvironment, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.B9FY3b73.js';
5
+ import { g as getWorkerState, a as getCurrentEnvironment, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.C7__0Iv5.js';
6
6
  import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
7
7
  import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './_commonjsHelpers.BFTU3MAI.js';
8
8
  import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
9
9
  import '@vitest/utils/error';
10
- import { fn, spyOn, mocks, isMockFunction } from '@vitest/spy';
10
+ import { fn, spyOn, restoreAllMocks, resetAllMocks, clearAllMocks, isMockFunction } from '@vitest/spy';
11
11
  import { parseSingleStack } from '@vitest/utils/source-map';
12
- import { R as RealDate, r as resetDate, m as mockDate } from './date.Bq6ZW5rf.js';
12
+ import { R as RealDate, r as resetDate, m as mockDate } from './date.-jtEtIeV.js';
13
13
 
14
14
  // these matchers are not supported because they don't make sense with poll
15
15
  const unsupported = [
@@ -26,11 +26,7 @@ const unsupported = [
26
26
  ];
27
27
  function createExpectPoll(expect) {
28
28
  return function poll(fn, options = {}) {
29
- const state = getWorkerState();
30
- const defaults = state.config.expect?.poll ?? {};
31
- const { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options;
32
- // @ts-expect-error private poll access
33
- const assertion = expect(null, message).withContext({ poll: true });
29
+ const state = getWorkerState(), defaults = state.config.expect?.poll ?? {}, { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options, assertion = expect(null, message).withContext({ poll: true });
34
30
  fn = fn.bind(assertion);
35
31
  const test = chai$1.util.flag(assertion, "vitest-test");
36
32
  if (!test) throw new Error("expect.poll() must be called inside a test");
@@ -40,43 +36,29 @@ function createExpectPoll(expect) {
40
36
  if (key === "assert") return assertionFunction;
41
37
  if (typeof key === "string" && unsupported.includes(key)) throw new SyntaxError(`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`);
42
38
  return function(...args) {
43
- const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
44
- const promise = () => new Promise((resolve, reject) => {
45
- let intervalId;
46
- let timeoutId;
47
- let lastError;
48
- const { setTimeout, clearTimeout } = getSafeTimers();
49
- const check = async () => {
39
+ const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR"), promise = () => new Promise((resolve, reject) => {
40
+ let intervalId, timeoutId, lastError;
41
+ const { setTimeout, clearTimeout } = getSafeTimers(), check = async () => {
50
42
  try {
51
43
  chai$1.util.flag(assertion, "_name", key);
52
44
  const obj = await fn();
53
- chai$1.util.flag(assertion, "object", obj);
54
- resolve(await assertionFunction.call(assertion, ...args));
55
- clearTimeout(intervalId);
56
- clearTimeout(timeoutId);
45
+ chai$1.util.flag(assertion, "object", obj), resolve(await assertionFunction.call(assertion, ...args)), clearTimeout(intervalId), clearTimeout(timeoutId);
57
46
  } catch (err) {
58
- lastError = err;
59
- if (!chai$1.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
47
+ if (lastError = err, !chai$1.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
60
48
  }
61
49
  };
62
50
  timeoutId = setTimeout(() => {
63
- clearTimeout(intervalId);
64
- chai$1.util.flag(assertion, "_isLastPollAttempt", true);
51
+ clearTimeout(intervalId), chai$1.util.flag(assertion, "_isLastPollAttempt", true);
65
52
  const rejectWithCause = (cause) => {
66
53
  reject(copyStackTrace$1(new Error("Matcher did not succeed in time.", { cause }), STACK_TRACE_ERROR));
67
54
  };
68
55
  check().then(() => rejectWithCause(lastError)).catch((e) => rejectWithCause(e));
69
- }, timeout);
70
- check();
56
+ }, timeout), check();
71
57
  });
72
58
  let awaited = false;
73
- test.onFinished ??= [];
74
- test.onFinished.push(() => {
59
+ test.onFinished ??= [], test.onFinished.push(() => {
75
60
  if (!awaited) {
76
- const negated = chai$1.util.flag(assertion, "negate") ? "not." : "";
77
- const name = chai$1.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)";
78
- const assertionString = `expect.${name}.${negated}${String(key)}()`;
79
- const error = /* @__PURE__ */ new Error(`${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:\n\nawait ${assertionString}\n`);
61
+ const negated = chai$1.util.flag(assertion, "negate") ? "not." : "", name = chai$1.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)", assertionString = `expect.${name}.${negated}${String(key)}()`, error = /* @__PURE__ */ new Error(`${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:\n\nawait ${assertionString}\n`);
80
62
  throw copyStackTrace$1(error, STACK_TRACE_ERROR);
81
63
  }
82
64
  });
@@ -85,8 +67,7 @@ function createExpectPoll(expect) {
85
67
  // so let's follow it
86
68
  return {
87
69
  then(onFulfilled, onRejected) {
88
- awaited = true;
89
- return (resultPromise ||= promise()).then(onFulfilled, onRejected);
70
+ return awaited = true, (resultPromise ||= promise()).then(onFulfilled, onRejected);
90
71
  },
91
72
  catch(onRejected) {
92
73
  return (resultPromise ||= promise()).catch(onRejected);
@@ -206,31 +187,24 @@ var chaiSubsetExports = requireChaiSubset();
206
187
  var Subset = /*@__PURE__*/getDefaultExportFromCjs(chaiSubsetExports);
207
188
 
208
189
  function createAssertionMessage(util, assertion, hasArgs) {
209
- const not = util.flag(assertion, "negate") ? "not." : "";
210
- const name = `${util.flag(assertion, "_name")}(${"expected" })`;
211
- const promiseName = util.flag(assertion, "promise");
212
- const promise = promiseName ? `.${promiseName}` : "";
190
+ const not = util.flag(assertion, "negate") ? "not." : "", name = `${util.flag(assertion, "_name")}(${"expected" })`, promiseName = util.flag(assertion, "promise"), promise = promiseName ? `.${promiseName}` : "";
213
191
  return `expect(actual)${promise}.${not}${name}`;
214
192
  }
215
193
  function recordAsyncExpect(_test, promise, assertion, error) {
216
194
  const test = _test;
217
195
  // record promise for test, that resolves before test ends
218
196
  if (test && promise instanceof Promise) {
219
- // if promise is explicitly awaited, remove it from the list
220
- promise = promise.finally(() => {
197
+ // record promise
198
+ if (promise = promise.finally(() => {
221
199
  if (!test.promises) return;
222
200
  const index = test.promises.indexOf(promise);
223
201
  if (index !== -1) test.promises.splice(index, 1);
224
- });
225
- // record promise
226
- if (!test.promises) test.promises = [];
202
+ }), !test.promises) test.promises = [];
227
203
  test.promises.push(promise);
228
204
  let resolved = false;
229
- test.onFinished ??= [];
230
- test.onFinished.push(() => {
205
+ return test.onFinished ??= [], test.onFinished.push(() => {
231
206
  if (!resolved) {
232
- const processor = globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || "");
233
- const stack = processor(error.stack);
207
+ const processor = globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || ""), stack = processor(error.stack);
234
208
  console.warn([
235
209
  `Promise returned by \`${assertion}\` was not awaited. `,
236
210
  "Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. ",
@@ -238,11 +212,9 @@ function recordAsyncExpect(_test, promise, assertion, error) {
238
212
  stack
239
213
  ].join(""));
240
214
  }
241
- });
242
- return {
215
+ }), {
243
216
  then(onFulfilled, onRejected) {
244
- resolved = true;
245
- return promise.then(onFulfilled, onRejected);
217
+ return resolved = true, promise.then(onFulfilled, onRejected);
246
218
  },
247
219
  catch(onRejected) {
248
220
  return promise.catch(onRejected);
@@ -293,12 +265,8 @@ const SnapshotPlugin = (chai, utils) => {
293
265
  utils.flag(this, "_name", key);
294
266
  const isNot = utils.flag(this, "negate");
295
267
  if (isNot) throw new Error(`${key} cannot be used with "not"`);
296
- const expected = utils.flag(this, "object");
297
- const test = getTest(key, this);
298
- if (typeof properties === "string" && typeof message === "undefined") {
299
- message = properties;
300
- properties = void 0;
301
- }
268
+ const expected = utils.flag(this, "object"), test = getTest(key, this);
269
+ if (typeof properties === "string" && typeof message === "undefined") message = properties, properties = void 0;
302
270
  const errorMessage = utils.flag(this, "message");
303
271
  getSnapshotClient().assert({
304
272
  received: expected,
@@ -313,11 +281,7 @@ const SnapshotPlugin = (chai, utils) => {
313
281
  utils.flag(this, "_name", "toMatchFileSnapshot");
314
282
  const isNot = utils.flag(this, "negate");
315
283
  if (isNot) throw new Error("toMatchFileSnapshot cannot be used with \"not\"");
316
- const error = /* @__PURE__ */ new Error("resolves");
317
- const expected = utils.flag(this, "object");
318
- const test = getTest("toMatchFileSnapshot", this);
319
- const errorMessage = utils.flag(this, "message");
320
- const promise = getSnapshotClient().assertRaw({
284
+ const error = /* @__PURE__ */ new Error("resolves"), expected = utils.flag(this, "object"), test = getTest("toMatchFileSnapshot", this), errorMessage = utils.flag(this, "message"), promise = getSnapshotClient().assertRaw({
321
285
  received: expected,
322
286
  message,
323
287
  isInline: false,
@@ -326,21 +290,14 @@ const SnapshotPlugin = (chai, utils) => {
326
290
  ...getTestNames(test)
327
291
  });
328
292
  return recordAsyncExpect(test, promise, createAssertionMessage(utils, this), error);
329
- });
330
- utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
293
+ }), utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
331
294
  utils.flag(this, "_name", "toMatchInlineSnapshot");
332
295
  const isNot = utils.flag(this, "negate");
333
296
  if (isNot) throw new Error("toMatchInlineSnapshot cannot be used with \"not\"");
334
- const test = getTest("toMatchInlineSnapshot", this);
335
- const isInsideEach = test.each || test.suite?.each;
297
+ const test = getTest("toMatchInlineSnapshot", this), isInsideEach = test.each || test.suite?.each;
336
298
  if (isInsideEach) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
337
- const expected = utils.flag(this, "object");
338
- const error = utils.flag(this, "error");
339
- if (typeof properties === "string") {
340
- message = inlineSnapshot;
341
- inlineSnapshot = properties;
342
- properties = void 0;
343
- }
299
+ const expected = utils.flag(this, "object"), error = utils.flag(this, "error");
300
+ if (typeof properties === "string") message = inlineSnapshot, inlineSnapshot = properties, properties = void 0;
344
301
  if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
345
302
  const errorMessage = utils.flag(this, "message");
346
303
  getSnapshotClient().assert({
@@ -353,32 +310,23 @@ const SnapshotPlugin = (chai, utils) => {
353
310
  errorMessage,
354
311
  ...getTestNames(test)
355
312
  });
356
- });
357
- utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
313
+ }), utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
358
314
  utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
359
315
  const isNot = utils.flag(this, "negate");
360
316
  if (isNot) throw new Error("toThrowErrorMatchingSnapshot cannot be used with \"not\"");
361
- const expected = utils.flag(this, "object");
362
- const test = getTest("toThrowErrorMatchingSnapshot", this);
363
- const promise = utils.flag(this, "promise");
364
- const errorMessage = utils.flag(this, "message");
317
+ const expected = utils.flag(this, "object"), test = getTest("toThrowErrorMatchingSnapshot", this), promise = utils.flag(this, "promise"), errorMessage = utils.flag(this, "message");
365
318
  getSnapshotClient().assert({
366
319
  received: getError(expected, promise),
367
320
  message,
368
321
  errorMessage,
369
322
  ...getTestNames(test)
370
323
  });
371
- });
372
- utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
324
+ }), utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
373
325
  const isNot = utils.flag(this, "negate");
374
326
  if (isNot) throw new Error("toThrowErrorMatchingInlineSnapshot cannot be used with \"not\"");
375
- const test = getTest("toThrowErrorMatchingInlineSnapshot", this);
376
- const isInsideEach = test.each || test.suite?.each;
327
+ const test = getTest("toThrowErrorMatchingInlineSnapshot", this), isInsideEach = test.each || test.suite?.each;
377
328
  if (isInsideEach) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
378
- const expected = utils.flag(this, "object");
379
- const error = utils.flag(this, "error");
380
- const promise = utils.flag(this, "promise");
381
- const errorMessage = utils.flag(this, "message");
329
+ const expected = utils.flag(this, "object"), error = utils.flag(this, "error"), promise = utils.flag(this, "promise"), errorMessage = utils.flag(this, "message");
382
330
  if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
383
331
  getSnapshotClient().assert({
384
332
  received: getError(expected, promise),
@@ -389,31 +337,19 @@ const SnapshotPlugin = (chai, utils) => {
389
337
  errorMessage,
390
338
  ...getTestNames(test)
391
339
  });
392
- });
393
- utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
340
+ }), utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
394
341
  };
395
342
 
396
- chai$1.use(JestExtend);
397
- chai$1.use(JestChaiExpect);
398
- chai$1.use(Subset);
399
- chai$1.use(SnapshotPlugin);
400
- chai$1.use(JestAsymmetricMatchers);
343
+ chai$1.use(JestExtend), chai$1.use(JestChaiExpect), chai$1.use(Subset), chai$1.use(SnapshotPlugin), chai$1.use(JestAsymmetricMatchers);
401
344
 
402
345
  function createExpect(test) {
403
- const expect = (value, message) => {
346
+ const expect = ((value, message) => {
404
347
  const { assertionCalls } = getState(expect);
405
348
  setState({ assertionCalls: assertionCalls + 1 }, expect);
406
- const assert = chai$1.expect(value, message);
407
- const _test = test || getCurrentTest();
408
- if (_test)
409
- // @ts-expect-error internal
410
- return assert.withTest(_test);
411
- else return assert;
412
- };
413
- Object.assign(expect, chai$1.expect);
414
- Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
415
- expect.getState = () => getState(expect);
416
- expect.setState = (state) => setState(state, expect);
349
+ const assert = chai$1.expect(value, message), _test = test || getCurrentTest();
350
+ return _test ? assert.withTest(_test) : assert;
351
+ });
352
+ Object.assign(expect, chai$1.expect), Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]), expect.getState = () => getState(expect), expect.setState = (state) => setState(state, expect);
417
353
  // @ts-expect-error global is not typed
418
354
  const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
419
355
  setState({
@@ -428,16 +364,10 @@ function createExpect(test) {
428
364
  return getWorkerState().filepath;
429
365
  },
430
366
  currentTestName: test ? getTestName(test) : globalState.currentTestName
431
- }, expect);
432
- // @ts-expect-error untyped
433
- expect.extend = (matchers) => chai$1.expect.extend(expect, matchers);
434
- expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
435
- expect.soft = (...args) => {
367
+ }, expect), expect.extend = (matchers) => chai$1.expect.extend(expect, matchers), expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters), expect.soft = (...args) => {
436
368
  // @ts-expect-error private soft access
437
369
  return expect(...args).withContext({ soft: true });
438
- };
439
- expect.poll = createExpectPoll(expect);
440
- expect.unreachable = (message) => {
370
+ }, expect.poll = createExpectPoll(expect), expect.unreachable = (message) => {
441
371
  chai$1.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
442
372
  };
443
373
  function assertions(expected) {
@@ -456,10 +386,7 @@ function createExpect(test) {
456
386
  isExpectingAssertionsError: error
457
387
  });
458
388
  }
459
- chai$1.util.addMethod(expect, "assertions", assertions);
460
- chai$1.util.addMethod(expect, "hasAssertions", hasAssertions);
461
- expect.extend(customMatchers);
462
- return expect;
389
+ return chai$1.util.addMethod(expect, "assertions", assertions), chai$1.util.addMethod(expect, "hasAssertions", hasAssertions), expect.extend(customMatchers), expect;
463
390
  }
464
391
  const globalExpect = createExpect();
465
392
  Object.defineProperty(globalThis, GLOBAL_EXPECT, {
@@ -3585,11 +3512,7 @@ class FakeTimers {
3585
3512
  _userConfig;
3586
3513
  _now = RealDate.now;
3587
3514
  constructor({ global, config }) {
3588
- this._userConfig = config;
3589
- this._fakingDate = null;
3590
- this._fakingTime = false;
3591
- this._fakeTimers = fakeTimersSrcExports.withGlobal(global);
3592
- this._global = global;
3515
+ this._userConfig = config, this._fakingDate = null, this._fakingTime = false, this._fakeTimers = fakeTimersSrcExports.withGlobal(global), this._global = global;
3593
3516
  }
3594
3517
  clearAllTimers() {
3595
3518
  if (this._fakingTime) this._clock.reset();
@@ -3610,19 +3533,13 @@ class FakeTimers {
3610
3533
  if (this._checkFakeTimers()) await this._clock.runToLastAsync();
3611
3534
  }
3612
3535
  advanceTimersToNextTimer(steps = 1) {
3613
- if (this._checkFakeTimers()) for (let i = steps; i > 0; i--) {
3614
- this._clock.next();
3615
- // Fire all timers at this point: https://github.com/sinonjs/fake-timers/issues/250
3616
- this._clock.tick(0);
3617
- if (this._clock.countTimers() === 0) break;
3536
+ if (this._checkFakeTimers()) {
3537
+ for (let i = steps; i > 0; i--) if (this._clock.next(), this._clock.tick(0), this._clock.countTimers() === 0) break;
3618
3538
  }
3619
3539
  }
3620
3540
  async advanceTimersToNextTimerAsync(steps = 1) {
3621
- if (this._checkFakeTimers()) for (let i = steps; i > 0; i--) {
3622
- await this._clock.nextAsync();
3623
- // Fire all timers at this point: https://github.com/sinonjs/fake-timers/issues/250
3624
- this._clock.tick(0);
3625
- if (this._clock.countTimers() === 0) break;
3541
+ if (this._checkFakeTimers()) {
3542
+ for (let i = steps; i > 0; i--) if (await this._clock.nextAsync(), this._clock.tick(0), this._clock.countTimers() === 0) break;
3626
3543
  }
3627
3544
  }
3628
3545
  advanceTimersByTime(msToRun) {
@@ -3640,14 +3557,8 @@ class FakeTimers {
3640
3557
  this._clock.runMicrotasks();
3641
3558
  }
3642
3559
  useRealTimers() {
3643
- if (this._fakingDate) {
3644
- resetDate();
3645
- this._fakingDate = null;
3646
- }
3647
- if (this._fakingTime) {
3648
- this._clock.uninstall();
3649
- this._fakingTime = false;
3650
- }
3560
+ if (this._fakingDate) resetDate(), this._fakingDate = null;
3561
+ if (this._fakingTime) this._clock.uninstall(), this._fakingTime = false;
3651
3562
  }
3652
3563
  useFakeTimers() {
3653
3564
  if (this._fakingDate) throw new Error("\"setSystemTime\" was called already and date was mocked. Reset timers using `vi.useRealTimers()` if you want to use fake timers again.");
@@ -3659,24 +3570,19 @@ class FakeTimers {
3659
3570
  ...this._userConfig,
3660
3571
  toFake: this._userConfig?.toFake || toFake,
3661
3572
  ignoreMissingTimers: true
3662
- });
3663
- this._fakingTime = true;
3573
+ }), this._fakingTime = true;
3664
3574
  }
3665
3575
  }
3666
3576
  reset() {
3667
3577
  if (this._checkFakeTimers()) {
3668
3578
  const { now } = this._clock;
3669
- this._clock.reset();
3670
- this._clock.setSystemTime(now);
3579
+ this._clock.reset(), this._clock.setSystemTime(now);
3671
3580
  }
3672
3581
  }
3673
3582
  setSystemTime(now) {
3674
3583
  const date = typeof now === "undefined" || now instanceof Date ? now : new Date(now);
3675
3584
  if (this._fakingTime) this._clock.setSystemTime(date);
3676
- else {
3677
- this._fakingDate = date ?? new Date(this.getRealSystemTime());
3678
- mockDate(this._fakingDate);
3679
- }
3585
+ else this._fakingDate = date ?? new Date(this.getRealSystemTime()), mockDate(this._fakingDate);
3680
3586
  }
3681
3587
  getMockedSystemTime() {
3682
3588
  return this._fakingTime ? new Date(this._clock.now) : this._fakingDate;
@@ -3685,8 +3591,7 @@ class FakeTimers {
3685
3591
  return this._now();
3686
3592
  }
3687
3593
  getTimerCount() {
3688
- if (this._checkFakeTimers()) return this._clock.countTimers();
3689
- return 0;
3594
+ return this._checkFakeTimers() ? this._clock.countTimers() : 0;
3690
3595
  }
3691
3596
  configure(config) {
3692
3597
  this._userConfig = config;
@@ -3705,96 +3610,68 @@ function copyStackTrace(target, source) {
3705
3610
  return target;
3706
3611
  }
3707
3612
  function waitFor(callback, options = {}) {
3708
- const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
3709
- const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
3710
- const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
3613
+ const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers(), { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options, STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
3711
3614
  return new Promise((resolve, reject) => {
3712
- let lastError;
3713
- let promiseStatus = "idle";
3714
- let timeoutId;
3715
- let intervalId;
3615
+ let lastError, promiseStatus = "idle", timeoutId, intervalId;
3716
3616
  const onResolve = (result) => {
3717
3617
  if (timeoutId) clearTimeout(timeoutId);
3718
3618
  if (intervalId) clearInterval(intervalId);
3719
3619
  resolve(result);
3720
- };
3721
- const handleTimeout = () => {
3620
+ }, handleTimeout = () => {
3722
3621
  if (intervalId) clearInterval(intervalId);
3723
3622
  let error = lastError;
3724
3623
  if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
3725
3624
  reject(error);
3726
- };
3727
- const checkCallback = () => {
3625
+ }, checkCallback = () => {
3728
3626
  if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
3729
- if (promiseStatus === "pending") return;
3730
- try {
3627
+ if (promiseStatus !== "pending") try {
3731
3628
  const result = callback();
3732
3629
  if (result !== null && typeof result === "object" && typeof result.then === "function") {
3733
3630
  const thenable = result;
3734
- promiseStatus = "pending";
3735
- thenable.then((resolvedValue) => {
3736
- promiseStatus = "resolved";
3737
- onResolve(resolvedValue);
3631
+ promiseStatus = "pending", thenable.then((resolvedValue) => {
3632
+ promiseStatus = "resolved", onResolve(resolvedValue);
3738
3633
  }, (rejectedValue) => {
3739
- promiseStatus = "rejected";
3740
- lastError = rejectedValue;
3634
+ promiseStatus = "rejected", lastError = rejectedValue;
3741
3635
  });
3742
- } else {
3743
- onResolve(result);
3744
- return true;
3745
- }
3636
+ } else return onResolve(result), true;
3746
3637
  } catch (error) {
3747
3638
  lastError = error;
3748
3639
  }
3749
3640
  };
3750
- if (checkCallback() === true) return;
3751
- timeoutId = setTimeout(handleTimeout, timeout);
3752
- intervalId = setInterval(checkCallback, interval);
3641
+ checkCallback() !== true && (timeoutId = setTimeout(handleTimeout, timeout), intervalId = setInterval(checkCallback, interval));
3753
3642
  });
3754
3643
  }
3755
3644
  function waitUntil(callback, options = {}) {
3756
- const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
3757
- const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
3758
- const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
3645
+ const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers(), { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options, STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
3759
3646
  return new Promise((resolve, reject) => {
3760
- let promiseStatus = "idle";
3761
- let timeoutId;
3762
- let intervalId;
3647
+ let promiseStatus = "idle", timeoutId, intervalId;
3763
3648
  const onReject = (error) => {
3764
3649
  if (intervalId) clearInterval(intervalId);
3765
3650
  if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
3766
3651
  reject(error);
3767
- };
3768
- const onResolve = (result) => {
3769
- if (!result) return;
3770
- if (timeoutId) clearTimeout(timeoutId);
3771
- if (intervalId) clearInterval(intervalId);
3772
- resolve(result);
3773
- return true;
3774
- };
3775
- const checkCallback = () => {
3652
+ }, onResolve = (result) => {
3653
+ if (result) {
3654
+ if (timeoutId) clearTimeout(timeoutId);
3655
+ if (intervalId) clearInterval(intervalId);
3656
+ return resolve(result), true;
3657
+ }
3658
+ }, checkCallback = () => {
3776
3659
  if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
3777
- if (promiseStatus === "pending") return;
3778
- try {
3660
+ if (promiseStatus !== "pending") try {
3779
3661
  const result = callback();
3780
3662
  if (result !== null && typeof result === "object" && typeof result.then === "function") {
3781
3663
  const thenable = result;
3782
- promiseStatus = "pending";
3783
- thenable.then((resolvedValue) => {
3784
- promiseStatus = "resolved";
3785
- onResolve(resolvedValue);
3664
+ promiseStatus = "pending", thenable.then((resolvedValue) => {
3665
+ promiseStatus = "resolved", onResolve(resolvedValue);
3786
3666
  }, (rejectedValue) => {
3787
- promiseStatus = "rejected";
3788
- onReject(rejectedValue);
3667
+ promiseStatus = "rejected", onReject(rejectedValue);
3789
3668
  });
3790
3669
  } else return onResolve(result);
3791
3670
  } catch (error) {
3792
3671
  onReject(error);
3793
3672
  }
3794
3673
  };
3795
- if (checkCallback() === true) return;
3796
- timeoutId = setTimeout(onReject, timeout);
3797
- intervalId = setInterval(checkCallback, interval);
3674
+ checkCallback() !== true && (timeoutId = setTimeout(onReject, timeout), intervalId = setInterval(checkCallback, interval));
3798
3675
  });
3799
3676
  }
3800
3677
 
@@ -3805,15 +3682,11 @@ function createVitest() {
3805
3682
  const timers = () => _timers ||= new FakeTimers({
3806
3683
  global: globalThis,
3807
3684
  config: workerState.config.fakeTimers
3808
- });
3809
- const _stubsGlobal = /* @__PURE__ */ new Map();
3810
- const _stubsEnv = /* @__PURE__ */ new Map();
3811
- const _envBooleans = [
3685
+ }), _stubsGlobal = /* @__PURE__ */ new Map(), _stubsEnv = /* @__PURE__ */ new Map(), _envBooleans = [
3812
3686
  "PROD",
3813
3687
  "DEV",
3814
3688
  "SSR"
3815
- ];
3816
- const utils = {
3689
+ ], utils = {
3817
3690
  useFakeTimers(config) {
3818
3691
  if (isChildProcess()) {
3819
3692
  if (config?.toFake?.includes("nextTick") || workerState.config?.fakeTimers?.toFake?.includes("nextTick")) throw new Error("vi.useFakeTimers({ toFake: [\"nextTick\"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.");
@@ -3823,62 +3696,49 @@ function createVitest() {
3823
3696
  ...config
3824
3697
  });
3825
3698
  else timers().configure(workerState.config.fakeTimers);
3826
- timers().useFakeTimers();
3827
- return utils;
3699
+ return timers().useFakeTimers(), utils;
3828
3700
  },
3829
3701
  isFakeTimers() {
3830
3702
  return timers().isFakeTimers();
3831
3703
  },
3832
3704
  useRealTimers() {
3833
- timers().useRealTimers();
3834
- return utils;
3705
+ return timers().useRealTimers(), utils;
3835
3706
  },
3836
3707
  runOnlyPendingTimers() {
3837
- timers().runOnlyPendingTimers();
3838
- return utils;
3708
+ return timers().runOnlyPendingTimers(), utils;
3839
3709
  },
3840
3710
  async runOnlyPendingTimersAsync() {
3841
- await timers().runOnlyPendingTimersAsync();
3842
- return utils;
3711
+ return await timers().runOnlyPendingTimersAsync(), utils;
3843
3712
  },
3844
3713
  runAllTimers() {
3845
- timers().runAllTimers();
3846
- return utils;
3714
+ return timers().runAllTimers(), utils;
3847
3715
  },
3848
3716
  async runAllTimersAsync() {
3849
- await timers().runAllTimersAsync();
3850
- return utils;
3717
+ return await timers().runAllTimersAsync(), utils;
3851
3718
  },
3852
3719
  runAllTicks() {
3853
- timers().runAllTicks();
3854
- return utils;
3720
+ return timers().runAllTicks(), utils;
3855
3721
  },
3856
3722
  advanceTimersByTime(ms) {
3857
- timers().advanceTimersByTime(ms);
3858
- return utils;
3723
+ return timers().advanceTimersByTime(ms), utils;
3859
3724
  },
3860
3725
  async advanceTimersByTimeAsync(ms) {
3861
- await timers().advanceTimersByTimeAsync(ms);
3862
- return utils;
3726
+ return await timers().advanceTimersByTimeAsync(ms), utils;
3863
3727
  },
3864
3728
  advanceTimersToNextTimer() {
3865
- timers().advanceTimersToNextTimer();
3866
- return utils;
3729
+ return timers().advanceTimersToNextTimer(), utils;
3867
3730
  },
3868
3731
  async advanceTimersToNextTimerAsync() {
3869
- await timers().advanceTimersToNextTimerAsync();
3870
- return utils;
3732
+ return await timers().advanceTimersToNextTimerAsync(), utils;
3871
3733
  },
3872
3734
  advanceTimersToNextFrame() {
3873
- timers().advanceTimersToNextFrame();
3874
- return utils;
3735
+ return timers().advanceTimersToNextFrame(), utils;
3875
3736
  },
3876
3737
  getTimerCount() {
3877
3738
  return timers().getTimerCount();
3878
3739
  },
3879
3740
  setSystemTime(time) {
3880
- timers().setSystemTime(time);
3881
- return utils;
3741
+ return timers().setSystemTime(time), utils;
3882
3742
  },
3883
3743
  getMockedSystemTime() {
3884
3744
  return timers().getMockedSystemTime();
@@ -3887,16 +3747,14 @@ function createVitest() {
3887
3747
  return timers().getRealSystemTime();
3888
3748
  },
3889
3749
  clearAllTimers() {
3890
- timers().clearAllTimers();
3891
- return utils;
3750
+ return timers().clearAllTimers(), utils;
3892
3751
  },
3893
3752
  spyOn,
3894
3753
  fn,
3895
3754
  waitFor,
3896
3755
  waitUntil,
3897
3756
  hoisted(factory) {
3898
- assertTypes(factory, "\"vi.hoisted\" factory", ["function"]);
3899
- return factory();
3757
+ return assertTypes(factory, "\"vi.hoisted\" factory", ["function"]), factory();
3900
3758
  },
3901
3759
  mock(path, factory) {
3902
3760
  if (typeof path !== "string") throw new TypeError(`vi.mock() expects a string path, but received a ${typeof path}`);
@@ -3932,30 +3790,25 @@ function createVitest() {
3932
3790
  return isMockFunction(fn);
3933
3791
  },
3934
3792
  clearAllMocks() {
3935
- [...mocks].reverse().forEach((spy) => spy.mockClear());
3936
- return utils;
3793
+ return clearAllMocks(), utils;
3937
3794
  },
3938
3795
  resetAllMocks() {
3939
- [...mocks].reverse().forEach((spy) => spy.mockReset());
3940
- return utils;
3796
+ return resetAllMocks(), utils;
3941
3797
  },
3942
3798
  restoreAllMocks() {
3943
- [...mocks].reverse().forEach((spy) => spy.mockRestore());
3944
- return utils;
3799
+ return restoreAllMocks(), utils;
3945
3800
  },
3946
3801
  stubGlobal(name, value) {
3947
3802
  if (!_stubsGlobal.has(name)) _stubsGlobal.set(name, Object.getOwnPropertyDescriptor(globalThis, name));
3948
- Object.defineProperty(globalThis, name, {
3803
+ return Object.defineProperty(globalThis, name, {
3949
3804
  value,
3950
3805
  writable: true,
3951
3806
  configurable: true,
3952
3807
  enumerable: true
3953
- });
3954
- return utils;
3808
+ }), utils;
3955
3809
  },
3956
3810
  stubEnv(name, value) {
3957
- const state = getWorkerState();
3958
- const env = state.metaEnv;
3811
+ const state = getWorkerState(), env = state.metaEnv;
3959
3812
  if (!_stubsEnv.has(name)) _stubsEnv.set(name, env[name]);
3960
3813
  if (_envBooleans.includes(name)) env[name] = value ? "1" : "";
3961
3814
  else if (value === void 0) delete env[name];
@@ -3963,26 +3816,20 @@ function createVitest() {
3963
3816
  return utils;
3964
3817
  },
3965
3818
  unstubAllGlobals() {
3966
- _stubsGlobal.forEach((original, name) => {
3819
+ return _stubsGlobal.forEach((original, name) => {
3967
3820
  if (!original) Reflect.deleteProperty(globalThis, name);
3968
3821
  else Object.defineProperty(globalThis, name, original);
3969
- });
3970
- _stubsGlobal.clear();
3971
- return utils;
3822
+ }), _stubsGlobal.clear(), utils;
3972
3823
  },
3973
3824
  unstubAllEnvs() {
3974
- const state = getWorkerState();
3975
- const env = state.metaEnv;
3976
- _stubsEnv.forEach((original, name) => {
3825
+ const state = getWorkerState(), env = state.metaEnv;
3826
+ return _stubsEnv.forEach((original, name) => {
3977
3827
  if (original === void 0) delete env[name];
3978
3828
  else env[name] = original;
3979
- });
3980
- _stubsEnv.clear();
3981
- return utils;
3829
+ }), _stubsEnv.clear(), utils;
3982
3830
  },
3983
3831
  resetModules() {
3984
- resetModules(workerState.evaluatedModules);
3985
- return utils;
3832
+ return resetModules(workerState.evaluatedModules), utils;
3986
3833
  },
3987
3834
  async dynamicImportSettled() {
3988
3835
  return waitForImportsToResolve();
@@ -4006,13 +3853,9 @@ function _mocker() {
4006
3853
  } });
4007
3854
  }
4008
3855
  function getImporter(name) {
4009
- const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 });
4010
- const stackArray = stackTrace.split("\n");
4011
- // if there is no message in a stack trace, use the item - 1
4012
- const importerStackIndex = stackArray.findIndex((stack) => {
3856
+ const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 }), stackArray = stackTrace.split("\n"), importerStackIndex = stackArray.findIndex((stack) => {
4013
3857
  return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`);
4014
- });
4015
- const stack = parseSingleStack(stackArray[importerStackIndex + 1]);
3858
+ }), stack = parseSingleStack(stackArray[importerStackIndex + 1]);
4016
3859
  return stack?.file || "";
4017
3860
  }
4018
3861