vitest 3.2.0-beta.3 → 3.2.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.
Files changed (65) hide show
  1. package/LICENSE.md +29 -0
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{base.D4119yLM.js → base.Cg0miDlQ.js} +10 -14
  5. package/dist/chunks/{benchmark.Cf_PACH1.js → benchmark.CYdenmiT.js} +4 -6
  6. package/dist/chunks/{cac.DWaWHIIE.js → cac.C8BzMmTW.js} +66 -136
  7. package/dist/chunks/{cli-api.CnmEXkxs.js → cli-api.DmupRhea.js} +1251 -1336
  8. package/dist/chunks/{console.Cwr-MFPV.js → console.CtFJOzRO.js} +24 -45
  9. package/dist/chunks/{coverage.0iPg4Wrz.js → coverage.DVF1vEu8.js} +4 -12
  10. package/dist/chunks/{coverage.C73DaDgS.js → coverage.EIiagJJP.js} +484 -1003
  11. package/dist/chunks/{creator.C8WKy2eW.js → creator.GK6I-cL4.js} +29 -76
  12. package/dist/chunks/{date.ByMsSlOr.js → date.Bq6ZW5rf.js} +3 -8
  13. package/dist/chunks/{defaults.DpVH7vbg.js → defaults.B7q_naMc.js} +1 -1
  14. package/dist/chunks/{env.Dq0hM4Xv.js → env.D4Lgay0q.js} +1 -1
  15. package/dist/chunks/{execute.B3q-2LPV.js → execute.B7h3T_Hc.js} +104 -220
  16. package/dist/chunks/{git.DXfdBEfR.js → git.BVQ8w_Sw.js} +1 -3
  17. package/dist/chunks/{global.d.BNLIi6yo.d.ts → global.d.MAmajcmJ.d.ts} +2 -0
  18. package/dist/chunks/{globals.CI21aWXF.js → globals.DEHgCU4V.js} +5 -5
  19. package/dist/chunks/{index.Bter3jj9.js → index.BZ0g1JD2.js} +366 -628
  20. package/dist/chunks/{index.CbT4iuwc.js → index.BbB8_kAK.js} +22 -24
  21. package/dist/chunks/{index.JOzufsrU.js → index.CIyJn3t1.js} +37 -82
  22. package/dist/chunks/{index.DNgLEKsQ.js → index.CdQS2e2Q.js} +2 -2
  23. package/dist/chunks/{index.2jgTs_Q5.js → index.CmSc2RE5.js} +69 -107
  24. package/dist/chunks/{inspector.BFsh5KO0.js → inspector.C914Efll.js} +1 -1
  25. package/dist/chunks/{node.Be-ntJnD.js → node.fjCdwEIl.js} +1 -1
  26. package/dist/chunks/{reporters.d.Bt4IGtsa.d.ts → reporters.d.C1ogPriE.d.ts} +24 -4
  27. package/dist/chunks/{rpc.BKExFSRG.js → rpc.Iovn4oWe.js} +9 -19
  28. package/dist/chunks/{runBaseTests.B_M1TTsK.js → runBaseTests.Dd85QTll.js} +18 -31
  29. package/dist/chunks/{setup-common.CF-O-dZX.js → setup-common.Dd054P77.js} +15 -42
  30. package/dist/chunks/{typechecker.BgzF-6iO.js → typechecker.DRKU1-1g.js} +106 -186
  31. package/dist/chunks/{utils.DPCq3gzW.js → utils.CAioKnHs.js} +6 -14
  32. package/dist/chunks/{utils.BlI4TC7Y.js → utils.XdZDrNZV.js} +5 -13
  33. package/dist/chunks/{vi.pkoYCV6A.js → vi.bdSIJ99Y.js} +118 -267
  34. package/dist/chunks/{vite.d.B-Kx3KCF.d.ts → vite.d.DqE4-hhK.d.ts} +1 -1
  35. package/dist/chunks/{vm.DPYem2so.js → vm.BThCzidc.js} +98 -214
  36. package/dist/chunks/{worker.d.Bl1O4kuf.d.ts → worker.d.DvqK5Vmu.d.ts} +1 -1
  37. package/dist/chunks/{worker.d.BKbBp2ga.d.ts → worker.d.tQu2eJQy.d.ts} +3 -1
  38. package/dist/cli.js +4 -4
  39. package/dist/config.cjs +1 -1
  40. package/dist/config.d.ts +4 -4
  41. package/dist/config.js +2 -2
  42. package/dist/coverage.d.ts +2 -2
  43. package/dist/coverage.js +5 -5
  44. package/dist/environments.js +1 -1
  45. package/dist/execute.d.ts +1 -1
  46. package/dist/execute.js +1 -1
  47. package/dist/index.d.ts +12 -11
  48. package/dist/index.js +5 -5
  49. package/dist/node.d.ts +7 -7
  50. package/dist/node.js +12 -14
  51. package/dist/reporters.d.ts +2 -2
  52. package/dist/reporters.js +4 -4
  53. package/dist/runners.d.ts +5 -2
  54. package/dist/runners.js +51 -80
  55. package/dist/snapshot.js +2 -2
  56. package/dist/suite.js +2 -2
  57. package/dist/worker.js +36 -42
  58. package/dist/workers/forks.js +4 -4
  59. package/dist/workers/runVmTests.js +15 -21
  60. package/dist/workers/threads.js +4 -4
  61. package/dist/workers/vmForks.js +6 -6
  62. package/dist/workers/vmThreads.js +6 -6
  63. package/dist/workers.d.ts +2 -2
  64. package/dist/workers.js +10 -10
  65. package/package.json +16 -14
@@ -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.BlI4TC7Y.js';
5
+ import { g as getWorkerState, a as getCurrentEnvironment, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.XdZDrNZV.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
10
  import { fn, spyOn, mocks, 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.ByMsSlOr.js';
12
+ import { R as RealDate, r as resetDate, m as mockDate } from './date.Bq6ZW5rf.js';
13
13
 
14
14
  // these matchers are not supported because they don't make sense with poll
15
15
  const unsupported = [
@@ -33,20 +33,12 @@ function createExpectPoll(expect) {
33
33
  const assertion = expect(null, message).withContext({ poll: true });
34
34
  fn = fn.bind(assertion);
35
35
  const test = chai$1.util.flag(assertion, "vitest-test");
36
- if (!test) {
37
- throw new Error("expect.poll() must be called inside a test");
38
- }
36
+ if (!test) throw new Error("expect.poll() must be called inside a test");
39
37
  const proxy = new Proxy(assertion, { get(target, key, receiver) {
40
38
  const assertionFunction = Reflect.get(target, key, receiver);
41
- if (typeof assertionFunction !== "function") {
42
- return assertionFunction instanceof chai$1.Assertion ? proxy : assertionFunction;
43
- }
44
- if (key === "assert") {
45
- return assertionFunction;
46
- }
47
- if (typeof key === "string" && unsupported.includes(key)) {
48
- throw new SyntaxError(`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`);
49
- }
39
+ if (typeof assertionFunction !== "function") return assertionFunction instanceof chai$1.Assertion ? proxy : assertionFunction;
40
+ if (key === "assert") return assertionFunction;
41
+ 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.`);
50
42
  return function(...args) {
51
43
  const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
52
44
  const promise = () => new Promise((resolve, reject) => {
@@ -64,9 +56,7 @@ function createExpectPoll(expect) {
64
56
  clearTimeout(timeoutId);
65
57
  } catch (err) {
66
58
  lastError = err;
67
- if (!chai$1.util.flag(assertion, "_isLastPollAttempt")) {
68
- intervalId = setTimeout(check, interval);
69
- }
59
+ if (!chai$1.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
70
60
  }
71
61
  };
72
62
  timeoutId = setTimeout(() => {
@@ -112,9 +102,7 @@ function createExpectPoll(expect) {
112
102
  };
113
103
  }
114
104
  function copyStackTrace$1(target, source) {
115
- if (source.stack !== undefined) {
116
- target.stack = source.stack.replace(source.message, target.message);
117
- }
105
+ if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
118
106
  return target;
119
107
  }
120
108
 
@@ -230,18 +218,12 @@ function recordAsyncExpect(_test, promise, assertion, error) {
230
218
  if (test && promise instanceof Promise) {
231
219
  // if promise is explicitly awaited, remove it from the list
232
220
  promise = promise.finally(() => {
233
- if (!test.promises) {
234
- return;
235
- }
221
+ if (!test.promises) return;
236
222
  const index = test.promises.indexOf(promise);
237
- if (index !== -1) {
238
- test.promises.splice(index, 1);
239
- }
223
+ if (index !== -1) test.promises.splice(index, 1);
240
224
  });
241
225
  // record promise
242
- if (!test.promises) {
243
- test.promises = [];
244
- }
226
+ if (!test.promises) test.promises = [];
245
227
  test.promises.push(promise);
246
228
  let resolved = false;
247
229
  test.onFinished ??= [];
@@ -276,18 +258,14 @@ function recordAsyncExpect(_test, promise, assertion, error) {
276
258
 
277
259
  let _client;
278
260
  function getSnapshotClient() {
279
- if (!_client) {
280
- _client = new SnapshotClient({ isEqual: (received, expected) => {
281
- return equals(received, expected, [iterableEquality, subsetEquality]);
282
- } });
283
- }
261
+ if (!_client) _client = new SnapshotClient({ isEqual: (received, expected) => {
262
+ return equals(received, expected, [iterableEquality, subsetEquality]);
263
+ } });
284
264
  return _client;
285
265
  }
286
266
  function getError(expected, promise) {
287
267
  if (typeof expected !== "function") {
288
- if (!promise) {
289
- throw new Error(`expected must be a function, received ${typeof expected}`);
290
- }
268
+ if (!promise) throw new Error(`expected must be a function, received ${typeof expected}`);
291
269
  // when "promised", it receives thrown error
292
270
  return expected;
293
271
  }
@@ -308,41 +286,33 @@ function getTestNames(test) {
308
286
  const SnapshotPlugin = (chai, utils) => {
309
287
  function getTest(assertionName, obj) {
310
288
  const test = utils.flag(obj, "vitest-test");
311
- if (!test) {
312
- throw new Error(`'${assertionName}' cannot be used without test context`);
313
- }
289
+ if (!test) throw new Error(`'${assertionName}' cannot be used without test context`);
314
290
  return test;
315
291
  }
316
- for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
317
- utils.addMethod(chai.Assertion.prototype, key, function(properties, message) {
318
- utils.flag(this, "_name", key);
319
- const isNot = utils.flag(this, "negate");
320
- if (isNot) {
321
- throw new Error(`${key} cannot be used with "not"`);
322
- }
323
- const expected = utils.flag(this, "object");
324
- const test = getTest(key, this);
325
- if (typeof properties === "string" && typeof message === "undefined") {
326
- message = properties;
327
- properties = undefined;
328
- }
329
- const errorMessage = utils.flag(this, "message");
330
- getSnapshotClient().assert({
331
- received: expected,
332
- message,
333
- isInline: false,
334
- properties,
335
- errorMessage,
336
- ...getTestNames(test)
337
- });
292
+ for (const key of ["matchSnapshot", "toMatchSnapshot"]) utils.addMethod(chai.Assertion.prototype, key, function(properties, message) {
293
+ utils.flag(this, "_name", key);
294
+ const isNot = utils.flag(this, "negate");
295
+ 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
+ }
302
+ const errorMessage = utils.flag(this, "message");
303
+ getSnapshotClient().assert({
304
+ received: expected,
305
+ message,
306
+ isInline: false,
307
+ properties,
308
+ errorMessage,
309
+ ...getTestNames(test)
338
310
  });
339
- }
311
+ });
340
312
  utils.addMethod(chai.Assertion.prototype, "toMatchFileSnapshot", function(file, message) {
341
313
  utils.flag(this, "_name", "toMatchFileSnapshot");
342
314
  const isNot = utils.flag(this, "negate");
343
- if (isNot) {
344
- throw new Error("toMatchFileSnapshot cannot be used with \"not\"");
345
- }
315
+ if (isNot) throw new Error("toMatchFileSnapshot cannot be used with \"not\"");
346
316
  const error = new Error("resolves");
347
317
  const expected = utils.flag(this, "object");
348
318
  const test = getTest("toMatchFileSnapshot", this);
@@ -360,24 +330,18 @@ const SnapshotPlugin = (chai, utils) => {
360
330
  utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
361
331
  utils.flag(this, "_name", "toMatchInlineSnapshot");
362
332
  const isNot = utils.flag(this, "negate");
363
- if (isNot) {
364
- throw new Error("toMatchInlineSnapshot cannot be used with \"not\"");
365
- }
333
+ if (isNot) throw new Error("toMatchInlineSnapshot cannot be used with \"not\"");
366
334
  const test = getTest("toMatchInlineSnapshot", this);
367
335
  const isInsideEach = test.each || test.suite?.each;
368
- if (isInsideEach) {
369
- throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
370
- }
336
+ if (isInsideEach) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
371
337
  const expected = utils.flag(this, "object");
372
338
  const error = utils.flag(this, "error");
373
339
  if (typeof properties === "string") {
374
340
  message = inlineSnapshot;
375
341
  inlineSnapshot = properties;
376
- properties = undefined;
377
- }
378
- if (inlineSnapshot) {
379
- inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
342
+ properties = void 0;
380
343
  }
344
+ if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
381
345
  const errorMessage = utils.flag(this, "message");
382
346
  getSnapshotClient().assert({
383
347
  received: expected,
@@ -393,9 +357,7 @@ const SnapshotPlugin = (chai, utils) => {
393
357
  utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
394
358
  utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
395
359
  const isNot = utils.flag(this, "negate");
396
- if (isNot) {
397
- throw new Error("toThrowErrorMatchingSnapshot cannot be used with \"not\"");
398
- }
360
+ if (isNot) throw new Error("toThrowErrorMatchingSnapshot cannot be used with \"not\"");
399
361
  const expected = utils.flag(this, "object");
400
362
  const test = getTest("toThrowErrorMatchingSnapshot", this);
401
363
  const promise = utils.flag(this, "promise");
@@ -409,21 +371,15 @@ const SnapshotPlugin = (chai, utils) => {
409
371
  });
410
372
  utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
411
373
  const isNot = utils.flag(this, "negate");
412
- if (isNot) {
413
- throw new Error("toThrowErrorMatchingInlineSnapshot cannot be used with \"not\"");
414
- }
374
+ if (isNot) throw new Error("toThrowErrorMatchingInlineSnapshot cannot be used with \"not\"");
415
375
  const test = getTest("toThrowErrorMatchingInlineSnapshot", this);
416
376
  const isInsideEach = test.each || test.suite?.each;
417
- if (isInsideEach) {
418
- throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
419
- }
377
+ if (isInsideEach) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
420
378
  const expected = utils.flag(this, "object");
421
379
  const error = utils.flag(this, "error");
422
380
  const promise = utils.flag(this, "promise");
423
381
  const errorMessage = utils.flag(this, "message");
424
- if (inlineSnapshot) {
425
- inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
426
- }
382
+ if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
427
383
  getSnapshotClient().assert({
428
384
  received: getError(expected, promise),
429
385
  message,
@@ -449,12 +405,10 @@ function createExpect(test) {
449
405
  setState({ assertionCalls: assertionCalls + 1 }, expect);
450
406
  const assert = chai$1.expect(value, message);
451
407
  const _test = test || getCurrentTest();
452
- if (_test) {
453
- // @ts-expect-error internal
454
- return assert.withTest(_test);
455
- } else {
456
- return assert;
457
- }
408
+ if (_test)
409
+ // @ts-expect-error internal
410
+ return assert.withTest(_test);
411
+ else return assert;
458
412
  };
459
413
  Object.assign(expect, chai$1.expect);
460
414
  Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
@@ -488,9 +442,7 @@ function createExpect(test) {
488
442
  };
489
443
  function assertions(expected) {
490
444
  const errorGen = () => new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
491
- if (Error.captureStackTrace) {
492
- Error.captureStackTrace(errorGen(), assertions);
493
- }
445
+ if (Error.captureStackTrace) Error.captureStackTrace(errorGen(), assertions);
494
446
  expect.setState({
495
447
  expectedAssertionsNumber: expected,
496
448
  expectedAssertionsNumberErrorGen: errorGen
@@ -498,9 +450,7 @@ function createExpect(test) {
498
450
  }
499
451
  function hasAssertions() {
500
452
  const error = new Error("expected any number of assertion, but got none");
501
- if (Error.captureStackTrace) {
502
- Error.captureStackTrace(error, hasAssertions);
503
- }
453
+ if (Error.captureStackTrace) Error.captureStackTrace(error, hasAssertions);
504
454
  expect.setState({
505
455
  isExpectingAssertions: true,
506
456
  isExpectingAssertionsError: error
@@ -3642,77 +3592,52 @@ class FakeTimers {
3642
3592
  this._global = global;
3643
3593
  }
3644
3594
  clearAllTimers() {
3645
- if (this._fakingTime) {
3646
- this._clock.reset();
3647
- }
3595
+ if (this._fakingTime) this._clock.reset();
3648
3596
  }
3649
3597
  dispose() {
3650
3598
  this.useRealTimers();
3651
3599
  }
3652
3600
  runAllTimers() {
3653
- if (this._checkFakeTimers()) {
3654
- this._clock.runAll();
3655
- }
3601
+ if (this._checkFakeTimers()) this._clock.runAll();
3656
3602
  }
3657
3603
  async runAllTimersAsync() {
3658
- if (this._checkFakeTimers()) {
3659
- await this._clock.runAllAsync();
3660
- }
3604
+ if (this._checkFakeTimers()) await this._clock.runAllAsync();
3661
3605
  }
3662
3606
  runOnlyPendingTimers() {
3663
- if (this._checkFakeTimers()) {
3664
- this._clock.runToLast();
3665
- }
3607
+ if (this._checkFakeTimers()) this._clock.runToLast();
3666
3608
  }
3667
3609
  async runOnlyPendingTimersAsync() {
3668
- if (this._checkFakeTimers()) {
3669
- await this._clock.runToLastAsync();
3670
- }
3610
+ if (this._checkFakeTimers()) await this._clock.runToLastAsync();
3671
3611
  }
3672
3612
  advanceTimersToNextTimer(steps = 1) {
3673
- if (this._checkFakeTimers()) {
3674
- for (let i = steps; i > 0; i--) {
3675
- this._clock.next();
3676
- // Fire all timers at this point: https://github.com/sinonjs/fake-timers/issues/250
3677
- this._clock.tick(0);
3678
- if (this._clock.countTimers() === 0) {
3679
- break;
3680
- }
3681
- }
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;
3682
3618
  }
3683
3619
  }
3684
3620
  async advanceTimersToNextTimerAsync(steps = 1) {
3685
- if (this._checkFakeTimers()) {
3686
- for (let i = steps; i > 0; i--) {
3687
- await this._clock.nextAsync();
3688
- // Fire all timers at this point: https://github.com/sinonjs/fake-timers/issues/250
3689
- this._clock.tick(0);
3690
- if (this._clock.countTimers() === 0) {
3691
- break;
3692
- }
3693
- }
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;
3694
3626
  }
3695
3627
  }
3696
3628
  advanceTimersByTime(msToRun) {
3697
- if (this._checkFakeTimers()) {
3698
- this._clock.tick(msToRun);
3699
- }
3629
+ if (this._checkFakeTimers()) this._clock.tick(msToRun);
3700
3630
  }
3701
3631
  async advanceTimersByTimeAsync(msToRun) {
3702
- if (this._checkFakeTimers()) {
3703
- await this._clock.tickAsync(msToRun);
3704
- }
3632
+ if (this._checkFakeTimers()) await this._clock.tickAsync(msToRun);
3705
3633
  }
3706
3634
  advanceTimersToNextFrame() {
3707
- if (this._checkFakeTimers()) {
3708
- this._clock.runToFrame();
3709
- }
3635
+ if (this._checkFakeTimers()) this._clock.runToFrame();
3710
3636
  }
3711
3637
  runAllTicks() {
3712
- if (this._checkFakeTimers()) {
3713
- // @ts-expect-error method not exposed
3714
- this._clock.runMicrotasks();
3715
- }
3638
+ if (this._checkFakeTimers())
3639
+ // @ts-expect-error method not exposed
3640
+ this._clock.runMicrotasks();
3716
3641
  }
3717
3642
  useRealTimers() {
3718
3643
  if (this._fakingDate) {
@@ -3725,14 +3650,10 @@ class FakeTimers {
3725
3650
  }
3726
3651
  }
3727
3652
  useFakeTimers() {
3728
- if (this._fakingDate) {
3729
- throw new Error("\"setSystemTime\" was called already and date was mocked. Reset timers using `vi.useRealTimers()` if you want to use fake timers again.");
3730
- }
3653
+ 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.");
3731
3654
  if (!this._fakingTime) {
3732
3655
  const toFake = Object.keys(this._fakeTimers.timers).filter((timer) => timer !== "nextTick" && timer !== "queueMicrotask");
3733
- if (this._userConfig?.toFake?.includes("nextTick") && isChildProcess()) {
3734
- throw new Error("process.nextTick cannot be mocked inside child_process");
3735
- }
3656
+ if (this._userConfig?.toFake?.includes("nextTick") && isChildProcess()) throw new Error("process.nextTick cannot be mocked inside child_process");
3736
3657
  this._clock = this._fakeTimers.install({
3737
3658
  now: Date.now(),
3738
3659
  ...this._userConfig,
@@ -3751,9 +3672,8 @@ class FakeTimers {
3751
3672
  }
3752
3673
  setSystemTime(now) {
3753
3674
  const date = typeof now === "undefined" || now instanceof Date ? now : new Date(now);
3754
- if (this._fakingTime) {
3755
- this._clock.setSystemTime(date);
3756
- } else {
3675
+ if (this._fakingTime) this._clock.setSystemTime(date);
3676
+ else {
3757
3677
  this._fakingDate = date ?? new Date(this.getRealSystemTime());
3758
3678
  mockDate(this._fakingDate);
3759
3679
  }
@@ -3765,9 +3685,7 @@ class FakeTimers {
3765
3685
  return this._now();
3766
3686
  }
3767
3687
  getTimerCount() {
3768
- if (this._checkFakeTimers()) {
3769
- return this._clock.countTimers();
3770
- }
3688
+ if (this._checkFakeTimers()) return this._clock.countTimers();
3771
3689
  return 0;
3772
3690
  }
3773
3691
  configure(config) {
@@ -3777,17 +3695,13 @@ class FakeTimers {
3777
3695
  return this._fakingTime;
3778
3696
  }
3779
3697
  _checkFakeTimers() {
3780
- if (!this._fakingTime) {
3781
- throw new Error("Timers are not mocked. Try calling \"vi.useFakeTimers()\" first.");
3782
- }
3698
+ if (!this._fakingTime) throw new Error("Timers are not mocked. Try calling \"vi.useFakeTimers()\" first.");
3783
3699
  return this._fakingTime;
3784
3700
  }
3785
3701
  }
3786
3702
 
3787
3703
  function copyStackTrace(target, source) {
3788
- if (source.stack !== undefined) {
3789
- target.stack = source.stack.replace(source.message, target.message);
3790
- }
3704
+ if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
3791
3705
  return target;
3792
3706
  }
3793
3707
  function waitFor(callback, options = {}) {
@@ -3800,31 +3714,19 @@ function waitFor(callback, options = {}) {
3800
3714
  let timeoutId;
3801
3715
  let intervalId;
3802
3716
  const onResolve = (result) => {
3803
- if (timeoutId) {
3804
- clearTimeout(timeoutId);
3805
- }
3806
- if (intervalId) {
3807
- clearInterval(intervalId);
3808
- }
3717
+ if (timeoutId) clearTimeout(timeoutId);
3718
+ if (intervalId) clearInterval(intervalId);
3809
3719
  resolve(result);
3810
3720
  };
3811
3721
  const handleTimeout = () => {
3812
- if (intervalId) {
3813
- clearInterval(intervalId);
3814
- }
3722
+ if (intervalId) clearInterval(intervalId);
3815
3723
  let error = lastError;
3816
- if (!error) {
3817
- error = copyStackTrace(new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
3818
- }
3724
+ if (!error) error = copyStackTrace(new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
3819
3725
  reject(error);
3820
3726
  };
3821
3727
  const checkCallback = () => {
3822
- if (vi.isFakeTimers()) {
3823
- vi.advanceTimersByTime(interval);
3824
- }
3825
- if (promiseStatus === "pending") {
3826
- return;
3827
- }
3728
+ if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
3729
+ if (promiseStatus === "pending") return;
3828
3730
  try {
3829
3731
  const result = callback();
3830
3732
  if (result !== null && typeof result === "object" && typeof result.then === "function") {
@@ -3845,9 +3747,7 @@ function waitFor(callback, options = {}) {
3845
3747
  lastError = error;
3846
3748
  }
3847
3749
  };
3848
- if (checkCallback() === true) {
3849
- return;
3850
- }
3750
+ if (checkCallback() === true) return;
3851
3751
  timeoutId = setTimeout(handleTimeout, timeout);
3852
3752
  intervalId = setInterval(checkCallback, interval);
3853
3753
  });
@@ -3861,34 +3761,20 @@ function waitUntil(callback, options = {}) {
3861
3761
  let timeoutId;
3862
3762
  let intervalId;
3863
3763
  const onReject = (error) => {
3864
- if (intervalId) {
3865
- clearInterval(intervalId);
3866
- }
3867
- if (!error) {
3868
- error = copyStackTrace(new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
3869
- }
3764
+ if (intervalId) clearInterval(intervalId);
3765
+ if (!error) error = copyStackTrace(new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
3870
3766
  reject(error);
3871
3767
  };
3872
3768
  const onResolve = (result) => {
3873
- if (!result) {
3874
- return;
3875
- }
3876
- if (timeoutId) {
3877
- clearTimeout(timeoutId);
3878
- }
3879
- if (intervalId) {
3880
- clearInterval(intervalId);
3881
- }
3769
+ if (!result) return;
3770
+ if (timeoutId) clearTimeout(timeoutId);
3771
+ if (intervalId) clearInterval(intervalId);
3882
3772
  resolve(result);
3883
3773
  return true;
3884
3774
  };
3885
3775
  const checkCallback = () => {
3886
- if (vi.isFakeTimers()) {
3887
- vi.advanceTimersByTime(interval);
3888
- }
3889
- if (promiseStatus === "pending") {
3890
- return;
3891
- }
3776
+ if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
3777
+ if (promiseStatus === "pending") return;
3892
3778
  try {
3893
3779
  const result = callback();
3894
3780
  if (result !== null && typeof result === "object" && typeof result.then === "function") {
@@ -3901,16 +3787,12 @@ function waitUntil(callback, options = {}) {
3901
3787
  promiseStatus = "rejected";
3902
3788
  onReject(rejectedValue);
3903
3789
  });
3904
- } else {
3905
- return onResolve(result);
3906
- }
3790
+ } else return onResolve(result);
3907
3791
  } catch (error) {
3908
3792
  onReject(error);
3909
3793
  }
3910
3794
  };
3911
- if (checkCallback() === true) {
3912
- return;
3913
- }
3795
+ if (checkCallback() === true) return;
3914
3796
  timeoutId = setTimeout(onReject, timeout);
3915
3797
  intervalId = setInterval(checkCallback, interval);
3916
3798
  });
@@ -3924,8 +3806,8 @@ function createVitest() {
3924
3806
  global: globalThis,
3925
3807
  config: workerState.config.fakeTimers
3926
3808
  });
3927
- const _stubsGlobal = new Map();
3928
- const _stubsEnv = new Map();
3809
+ const _stubsGlobal = /* @__PURE__ */ new Map();
3810
+ const _stubsEnv = /* @__PURE__ */ new Map();
3929
3811
  const _envBooleans = [
3930
3812
  "PROD",
3931
3813
  "DEV",
@@ -3934,18 +3816,13 @@ function createVitest() {
3934
3816
  const utils = {
3935
3817
  useFakeTimers(config) {
3936
3818
  if (isChildProcess()) {
3937
- if (config?.toFake?.includes("nextTick") || workerState.config?.fakeTimers?.toFake?.includes("nextTick")) {
3938
- throw new Error("vi.useFakeTimers({ toFake: [\"nextTick\"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.");
3939
- }
3940
- }
3941
- if (config) {
3942
- timers().configure({
3943
- ...workerState.config.fakeTimers,
3944
- ...config
3945
- });
3946
- } else {
3947
- timers().configure(workerState.config.fakeTimers);
3819
+ 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.");
3948
3820
  }
3821
+ if (config) timers().configure({
3822
+ ...workerState.config.fakeTimers,
3823
+ ...config
3824
+ });
3825
+ else timers().configure(workerState.config.fakeTimers);
3949
3826
  timers().useFakeTimers();
3950
3827
  return utils;
3951
3828
  },
@@ -4022,29 +3899,21 @@ function createVitest() {
4022
3899
  return factory();
4023
3900
  },
4024
3901
  mock(path, factory) {
4025
- if (typeof path !== "string") {
4026
- throw new TypeError(`vi.mock() expects a string path, but received a ${typeof path}`);
4027
- }
3902
+ if (typeof path !== "string") throw new TypeError(`vi.mock() expects a string path, but received a ${typeof path}`);
4028
3903
  const importer = getImporter("mock");
4029
3904
  _mocker().queueMock(path, importer, typeof factory === "function" ? () => factory(() => _mocker().importActual(path, importer, _mocker().getMockContext().callstack)) : factory);
4030
3905
  },
4031
3906
  unmock(path) {
4032
- if (typeof path !== "string") {
4033
- throw new TypeError(`vi.unmock() expects a string path, but received a ${typeof path}`);
4034
- }
3907
+ if (typeof path !== "string") throw new TypeError(`vi.unmock() expects a string path, but received a ${typeof path}`);
4035
3908
  _mocker().queueUnmock(path, getImporter("unmock"));
4036
3909
  },
4037
3910
  doMock(path, factory) {
4038
- if (typeof path !== "string") {
4039
- throw new TypeError(`vi.doMock() expects a string path, but received a ${typeof path}`);
4040
- }
3911
+ if (typeof path !== "string") throw new TypeError(`vi.doMock() expects a string path, but received a ${typeof path}`);
4041
3912
  const importer = getImporter("doMock");
4042
3913
  _mocker().queueMock(path, importer, typeof factory === "function" ? () => factory(() => _mocker().importActual(path, importer, _mocker().getMockContext().callstack)) : factory);
4043
3914
  },
4044
3915
  doUnmock(path) {
4045
- if (typeof path !== "string") {
4046
- throw new TypeError(`vi.doUnmock() expects a string path, but received a ${typeof path}`);
4047
- }
3916
+ if (typeof path !== "string") throw new TypeError(`vi.doUnmock() expects a string path, but received a ${typeof path}`);
4048
3917
  _mocker().queueUnmock(path, getImporter("doUnmock"));
4049
3918
  },
4050
3919
  async importActual(path) {
@@ -4075,9 +3944,7 @@ function createVitest() {
4075
3944
  return utils;
4076
3945
  },
4077
3946
  stubGlobal(name, value) {
4078
- if (!_stubsGlobal.has(name)) {
4079
- _stubsGlobal.set(name, Object.getOwnPropertyDescriptor(globalThis, name));
4080
- }
3947
+ if (!_stubsGlobal.has(name)) _stubsGlobal.set(name, Object.getOwnPropertyDescriptor(globalThis, name));
4081
3948
  Object.defineProperty(globalThis, name, {
4082
3949
  value,
4083
3950
  writable: true,
@@ -4087,36 +3954,24 @@ function createVitest() {
4087
3954
  return utils;
4088
3955
  },
4089
3956
  stubEnv(name, value) {
4090
- if (!_stubsEnv.has(name)) {
4091
- _stubsEnv.set(name, process.env[name]);
4092
- }
4093
- if (_envBooleans.includes(name)) {
4094
- process.env[name] = value ? "1" : "";
4095
- } else if (value === undefined) {
4096
- delete process.env[name];
4097
- } else {
4098
- process.env[name] = String(value);
4099
- }
3957
+ if (!_stubsEnv.has(name)) _stubsEnv.set(name, process.env[name]);
3958
+ if (_envBooleans.includes(name)) process.env[name] = value ? "1" : "";
3959
+ else if (value === void 0) delete process.env[name];
3960
+ else process.env[name] = String(value);
4100
3961
  return utils;
4101
3962
  },
4102
3963
  unstubAllGlobals() {
4103
3964
  _stubsGlobal.forEach((original, name) => {
4104
- if (!original) {
4105
- Reflect.deleteProperty(globalThis, name);
4106
- } else {
4107
- Object.defineProperty(globalThis, name, original);
4108
- }
3965
+ if (!original) Reflect.deleteProperty(globalThis, name);
3966
+ else Object.defineProperty(globalThis, name, original);
4109
3967
  });
4110
3968
  _stubsGlobal.clear();
4111
3969
  return utils;
4112
3970
  },
4113
3971
  unstubAllEnvs() {
4114
3972
  _stubsEnv.forEach((original, name) => {
4115
- if (original === undefined) {
4116
- delete process.env[name];
4117
- } else {
4118
- process.env[name] = original;
4119
- }
3973
+ if (original === void 0) delete process.env[name];
3974
+ else process.env[name] = original;
4120
3975
  });
4121
3976
  _stubsEnv.clear();
4122
3977
  return utils;
@@ -4129,15 +3984,11 @@ function createVitest() {
4129
3984
  return waitForImportsToResolve();
4130
3985
  },
4131
3986
  setConfig(config) {
4132
- if (!_config) {
4133
- _config = { ...workerState.config };
4134
- }
3987
+ if (!_config) _config = { ...workerState.config };
4135
3988
  Object.assign(workerState.config, config);
4136
3989
  },
4137
3990
  resetConfig() {
4138
- if (_config) {
4139
- Object.assign(workerState.config, _config);
4140
- }
3991
+ if (_config) Object.assign(workerState.config, _config);
4141
3992
  }
4142
3993
  };
4143
3994
  return utils;
@@ -4147,7 +3998,7 @@ const vi = vitest;
4147
3998
  function _mocker() {
4148
3999
  // @ts-expect-error injected by vite-nide
4149
4000
  return typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy({}, { get(_, name) {
4150
- throw new Error("Vitest mocker was not initialized in this environment. " + `vi.${String(name)}() is forbidden.`);
4001
+ throw new Error(`Vitest mocker was not initialized in this environment. vi.${String(name)}() is forbidden.`);
4151
4002
  } });
4152
4003
  }
4153
4004
  function getImporter(name) {