vitest 3.2.4 → 4.0.0-beta.10

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 (88) hide show
  1. package/LICENSE.md +2 -2
  2. package/dist/browser.d.ts +13 -16
  3. package/dist/browser.js +6 -5
  4. package/dist/chunks/base.Cjha6usc.js +129 -0
  5. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.CJUa-Hsa.js} +6 -8
  6. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  7. package/dist/chunks/browser.d.yFAklsD1.d.ts +18 -0
  8. package/dist/chunks/{cac.Cb-PYCCB.js → cac.DCxo_nSu.js} +72 -163
  9. package/dist/chunks/{cli-api.BkDphVBG.js → cli-api.BJJXh9BV.js} +1331 -1678
  10. package/dist/chunks/{config.d.D2ROskhv.d.ts → config.d.B_LthbQq.d.ts} +59 -65
  11. package/dist/chunks/{console.CtFJOzRO.js → console.7h5kHUIf.js} +34 -70
  12. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  13. package/dist/chunks/{coverage.DL5VHqXY.js → coverage.BCU-r2QL.js} +538 -765
  14. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  15. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  16. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  17. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  18. package/dist/chunks/{defaults.B7q_naMc.js → defaults.CXFFjsi8.js} +2 -42
  19. package/dist/chunks/environment.d.BsToaxti.d.ts +65 -0
  20. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  21. package/dist/chunks/{global.d.MAmajcmJ.d.ts → global.d.BK3X7FW1.d.ts} +7 -32
  22. package/dist/chunks/{globals.DEHgCU4V.js → globals.DG-S3xFe.js} +8 -8
  23. package/dist/chunks/{index.VByaPkjc.js → index.BIP7prJq.js} +472 -803
  24. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  25. package/dist/chunks/{index.BCWujgDG.js → index.BjKEiSn0.js} +14 -24
  26. package/dist/chunks/{index.CdQS2e2Q.js → index.CMfqw92x.js} +7 -8
  27. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  28. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  29. package/dist/chunks/moduleRunner.d.D9nBoC4p.d.ts +201 -0
  30. package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
  31. package/dist/chunks/{node.fjCdwEIl.js → node.CyipiPvJ.js} +1 -1
  32. package/dist/chunks/plugin.d.BMVSnsGV.d.ts +9 -0
  33. package/dist/chunks/{reporters.d.BFLkQcL6.d.ts → reporters.d.BUWjmRYq.d.ts} +2086 -2146
  34. package/dist/chunks/resolveSnapshotEnvironment.Bkht6Yor.js +81 -0
  35. package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
  36. package/dist/chunks/rpc.BKr6mtxz.js +65 -0
  37. package/dist/chunks/{setup-common.Dd054P77.js → setup-common.uiMcU3cv.js} +17 -29
  38. package/dist/chunks/startModuleRunner.p67gbNo9.js +665 -0
  39. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  40. package/dist/chunks/test.BiqSKISg.js +214 -0
  41. package/dist/chunks/{typechecker.DRKU1-1g.js → typechecker.DB-fIMaH.js} +165 -234
  42. package/dist/chunks/{utils.CAioKnHs.js → utils.C2YI6McM.js} +5 -14
  43. package/dist/chunks/{utils.XdZDrNZV.js → utils.D2R2NiOH.js} +8 -27
  44. package/dist/chunks/{vi.bdSIJ99Y.js → vi.ZPgvtBao.js} +156 -305
  45. package/dist/chunks/{vm.BThCzidc.js → vm.Ca0Y0W5f.js} +116 -226
  46. package/dist/chunks/{worker.d.1GmBbd7G.d.ts → worker.d.BDsXGkwh.d.ts} +31 -32
  47. package/dist/chunks/{worker.d.CKwWzBSj.d.ts → worker.d.BNcX_2mH.d.ts} +1 -1
  48. package/dist/cli.js +10 -10
  49. package/dist/config.cjs +5 -58
  50. package/dist/config.d.ts +72 -71
  51. package/dist/config.js +3 -9
  52. package/dist/coverage.d.ts +31 -24
  53. package/dist/coverage.js +9 -9
  54. package/dist/environments.d.ts +9 -14
  55. package/dist/environments.js +1 -1
  56. package/dist/index.d.ts +52 -213
  57. package/dist/index.js +7 -9
  58. package/dist/module-evaluator.d.ts +13 -0
  59. package/dist/module-evaluator.js +276 -0
  60. package/dist/module-runner.js +15 -0
  61. package/dist/node.d.ts +62 -51
  62. package/dist/node.js +26 -42
  63. package/dist/reporters.d.ts +11 -12
  64. package/dist/reporters.js +12 -12
  65. package/dist/runners.d.ts +3 -4
  66. package/dist/runners.js +13 -231
  67. package/dist/snapshot.js +2 -2
  68. package/dist/suite.d.ts +2 -2
  69. package/dist/suite.js +2 -2
  70. package/dist/worker.js +90 -47
  71. package/dist/workers/forks.js +34 -10
  72. package/dist/workers/runVmTests.js +36 -56
  73. package/dist/workers/threads.js +34 -10
  74. package/dist/workers/vmForks.js +11 -10
  75. package/dist/workers/vmThreads.js +11 -10
  76. package/dist/workers.d.ts +5 -7
  77. package/dist/workers.js +35 -17
  78. package/globals.d.ts +17 -17
  79. package/package.json +32 -31
  80. package/dist/chunks/base.DfmxU-tU.js +0 -38
  81. package/dist/chunks/environment.d.cL3nLXbE.d.ts +0 -119
  82. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  83. package/dist/chunks/index.CwejwG0H.js +0 -105
  84. package/dist/chunks/rpc.-pEldfrD.js +0 -83
  85. package/dist/chunks/runBaseTests.9Ij9_de-.js +0 -129
  86. package/dist/chunks/vite.d.CMLlLIFP.d.ts +0 -25
  87. package/dist/execute.d.ts +0 -150
  88. package/dist/execute.js +0 -13
@@ -1,15 +1,14 @@
1
- import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers } from '@vitest/expect';
1
+ import { chai as chai$1, equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers } from '@vitest/expect';
2
2
  import { getCurrentTest } from '@vitest/runner';
3
3
  import { getNames, getTestName } from '@vitest/runner/utils';
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.XdZDrNZV.js';
4
+ import { g as getWorkerState, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.D2R2NiOH.js';
6
5
  import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
7
6
  import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './_commonjsHelpers.BFTU3MAI.js';
8
7
  import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
9
8
  import '@vitest/utils/error';
10
- import { fn, spyOn, mocks, isMockFunction } from '@vitest/spy';
9
+ import { fn, spyOn, restoreAllMocks, resetAllMocks, clearAllMocks, isMockFunction } from '@vitest/spy';
11
10
  import { parseSingleStack } from '@vitest/utils/source-map';
12
- import { R as RealDate, r as resetDate, m as mockDate } from './date.Bq6ZW5rf.js';
11
+ import { R as RealDate, r as resetDate, m as mockDate } from './date.-jtEtIeV.js';
13
12
 
14
13
  // these matchers are not supported because they don't make sense with poll
15
14
  const unsupported = [
@@ -26,11 +25,7 @@ const unsupported = [
26
25
  ];
27
26
  function createExpectPoll(expect) {
28
27
  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 });
28
+ 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
29
  fn = fn.bind(assertion);
35
30
  const test = chai$1.util.flag(assertion, "vitest-test");
36
31
  if (!test) throw new Error("expect.poll() must be called inside a test");
@@ -40,43 +35,30 @@ function createExpectPoll(expect) {
40
35
  if (key === "assert") return assertionFunction;
41
36
  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
37
  return function(...args) {
43
- const STACK_TRACE_ERROR = 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 () => {
38
+ const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR"), promise = () => new Promise((resolve, reject) => {
39
+ let intervalId, timeoutId, lastError;
40
+ const { setTimeout, clearTimeout } = getSafeTimers(), check = async () => {
50
41
  try {
51
42
  chai$1.util.flag(assertion, "_name", key);
52
43
  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);
44
+ chai$1.util.flag(assertion, "object", obj), resolve(await assertionFunction.call(assertion, ...args)), clearTimeout(intervalId), clearTimeout(timeoutId);
57
45
  } catch (err) {
58
- lastError = err;
59
- if (!chai$1.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
46
+ if (lastError = err, !chai$1.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
60
47
  }
61
48
  };
62
49
  timeoutId = setTimeout(() => {
63
- clearTimeout(intervalId);
64
- chai$1.util.flag(assertion, "_isLastPollAttempt", true);
65
- const rejectWithCause = (cause) => {
66
- reject(copyStackTrace$1(new Error("Matcher did not succeed in time.", { cause }), STACK_TRACE_ERROR));
50
+ clearTimeout(intervalId), chai$1.util.flag(assertion, "_isLastPollAttempt", true);
51
+ const rejectWithCause = (error) => {
52
+ if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
53
+ reject(copyStackTrace$1(error, 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 = 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 = 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({
@@ -423,25 +359,18 @@ function createExpect(test) {
423
359
  isExpectingAssertionsError: null,
424
360
  expectedAssertionsNumber: null,
425
361
  expectedAssertionsNumberErrorGen: null,
426
- environment: getCurrentEnvironment(),
427
362
  get testPath() {
428
363
  return getWorkerState().filepath;
429
364
  },
430
365
  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) => {
366
+ }, expect), expect.extend = (matchers) => chai$1.expect.extend(expect, matchers), expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters), expect.soft = (...args) => {
436
367
  // @ts-expect-error private soft access
437
368
  return expect(...args).withContext({ soft: true });
438
- };
439
- expect.poll = createExpectPoll(expect);
440
- expect.unreachable = (message) => {
369
+ }, expect.poll = createExpectPoll(expect), expect.unreachable = (message) => {
441
370
  chai$1.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
442
371
  };
443
372
  function assertions(expected) {
444
- const errorGen = () => new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
373
+ const errorGen = () => /* @__PURE__ */ new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
445
374
  if (Error.captureStackTrace) Error.captureStackTrace(errorGen(), assertions);
446
375
  expect.setState({
447
376
  expectedAssertionsNumber: expected,
@@ -449,17 +378,14 @@ function createExpect(test) {
449
378
  });
450
379
  }
451
380
  function hasAssertions() {
452
- const error = new Error("expected any number of assertion, but got none");
381
+ const error = /* @__PURE__ */ new Error("expected any number of assertion, but got none");
453
382
  if (Error.captureStackTrace) Error.captureStackTrace(error, hasAssertions);
454
383
  expect.setState({
455
384
  isExpectingAssertions: true,
456
385
  isExpectingAssertionsError: error
457
386
  });
458
387
  }
459
- chai$1.util.addMethod(expect, "assertions", assertions);
460
- chai$1.util.addMethod(expect, "hasAssertions", hasAssertions);
461
- expect.extend(customMatchers);
462
- return expect;
388
+ return chai$1.util.addMethod(expect, "assertions", assertions), chai$1.util.addMethod(expect, "hasAssertions", hasAssertions), expect.extend(customMatchers), expect;
463
389
  }
464
390
  const globalExpect = createExpect();
465
391
  Object.defineProperty(globalThis, GLOBAL_EXPECT, {
@@ -467,6 +393,8 @@ Object.defineProperty(globalThis, GLOBAL_EXPECT, {
467
393
  writable: true,
468
394
  configurable: true
469
395
  });
396
+ const assert = chai$1.assert;
397
+ const should = chai$1.should;
470
398
 
471
399
  /**
472
400
  * Gives access to injected context provided from the main thread.
@@ -3576,20 +3504,16 @@ class FakeTimers {
3576
3504
  // | _fakingTime | _fakingDate |
3577
3505
  // +-------------+-------------+
3578
3506
  // | false | falsy | initial
3579
- // | false | truthy | vi.setSystemTime called first (for mocking only Date without fake timers)
3507
+ // | false | truthy | vi.setSystemTime called first (for mocking only Date without fake timers)
3580
3508
  // | true | falsy | vi.useFakeTimers called first
3581
- // | true | truthy | unreachable
3509
+ // | true | truthy | unreachable
3582
3510
  _fakingTime;
3583
3511
  _fakingDate;
3584
3512
  _fakeTimers;
3585
3513
  _userConfig;
3586
3514
  _now = RealDate.now;
3587
3515
  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;
3516
+ this._userConfig = config, this._fakingDate = null, this._fakingTime = false, this._fakeTimers = fakeTimersSrcExports.withGlobal(global), this._global = global;
3593
3517
  }
3594
3518
  clearAllTimers() {
3595
3519
  if (this._fakingTime) this._clock.reset();
@@ -3610,19 +3534,13 @@ class FakeTimers {
3610
3534
  if (this._checkFakeTimers()) await this._clock.runToLastAsync();
3611
3535
  }
3612
3536
  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;
3537
+ if (this._checkFakeTimers()) {
3538
+ for (let i = steps; i > 0; i--) if (this._clock.next(), this._clock.tick(0), this._clock.countTimers() === 0) break;
3618
3539
  }
3619
3540
  }
3620
3541
  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;
3542
+ if (this._checkFakeTimers()) {
3543
+ for (let i = steps; i > 0; i--) if (await this._clock.nextAsync(), this._clock.tick(0), this._clock.countTimers() === 0) break;
3626
3544
  }
3627
3545
  }
3628
3546
  advanceTimersByTime(msToRun) {
@@ -3640,43 +3558,32 @@ class FakeTimers {
3640
3558
  this._clock.runMicrotasks();
3641
3559
  }
3642
3560
  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
- }
3561
+ if (this._fakingDate) resetDate(), this._fakingDate = null;
3562
+ if (this._fakingTime) this._clock.uninstall(), this._fakingTime = false;
3651
3563
  }
3652
3564
  useFakeTimers() {
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.");
3654
- if (!this._fakingTime) {
3655
- const toFake = Object.keys(this._fakeTimers.timers).filter((timer) => timer !== "nextTick" && timer !== "queueMicrotask");
3656
- if (this._userConfig?.toFake?.includes("nextTick") && isChildProcess()) throw new Error("process.nextTick cannot be mocked inside child_process");
3657
- this._clock = this._fakeTimers.install({
3658
- now: Date.now(),
3659
- ...this._userConfig,
3660
- toFake: this._userConfig?.toFake || toFake,
3661
- ignoreMissingTimers: true
3662
- });
3663
- this._fakingTime = true;
3664
- }
3565
+ const fakeDate = this._fakingDate || Date.now();
3566
+ if (this._fakingDate) resetDate(), this._fakingDate = null;
3567
+ if (this._fakingTime) this._clock.uninstall();
3568
+ const toFake = Object.keys(this._fakeTimers.timers).filter((timer) => timer !== "nextTick" && timer !== "queueMicrotask");
3569
+ if (this._userConfig?.toFake?.includes("nextTick") && isChildProcess()) throw new Error("process.nextTick cannot be mocked inside child_process");
3570
+ this._clock = this._fakeTimers.install({
3571
+ now: fakeDate,
3572
+ ...this._userConfig,
3573
+ toFake: this._userConfig?.toFake || toFake,
3574
+ ignoreMissingTimers: true
3575
+ }), this._fakingTime = true;
3665
3576
  }
3666
3577
  reset() {
3667
3578
  if (this._checkFakeTimers()) {
3668
3579
  const { now } = this._clock;
3669
- this._clock.reset();
3670
- this._clock.setSystemTime(now);
3580
+ this._clock.reset(), this._clock.setSystemTime(now);
3671
3581
  }
3672
3582
  }
3673
3583
  setSystemTime(now) {
3674
3584
  const date = typeof now === "undefined" || now instanceof Date ? now : new Date(now);
3675
3585
  if (this._fakingTime) this._clock.setSystemTime(date);
3676
- else {
3677
- this._fakingDate = date ?? new Date(this.getRealSystemTime());
3678
- mockDate(this._fakingDate);
3679
- }
3586
+ else this._fakingDate = date ?? new Date(this.getRealSystemTime()), mockDate(this._fakingDate);
3680
3587
  }
3681
3588
  getMockedSystemTime() {
3682
3589
  return this._fakingTime ? new Date(this._clock.now) : this._fakingDate;
@@ -3685,8 +3592,7 @@ class FakeTimers {
3685
3592
  return this._now();
3686
3593
  }
3687
3594
  getTimerCount() {
3688
- if (this._checkFakeTimers()) return this._clock.countTimers();
3689
- return 0;
3595
+ return this._checkFakeTimers() ? this._clock.countTimers() : 0;
3690
3596
  }
3691
3597
  configure(config) {
3692
3598
  this._userConfig = config;
@@ -3695,7 +3601,7 @@ class FakeTimers {
3695
3601
  return this._fakingTime;
3696
3602
  }
3697
3603
  _checkFakeTimers() {
3698
- if (!this._fakingTime) throw new Error("Timers are not mocked. Try calling \"vi.useFakeTimers()\" first.");
3604
+ if (!this._fakingTime) throw new Error("A function to advance timers was called but the timers APIs are not mocked. Call `vi.useFakeTimers()` in the test file first.");
3699
3605
  return this._fakingTime;
3700
3606
  }
3701
3607
  }
@@ -3705,180 +3611,135 @@ function copyStackTrace(target, source) {
3705
3611
  return target;
3706
3612
  }
3707
3613
  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 = new Error("STACK_TRACE_ERROR");
3614
+ 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
3615
  return new Promise((resolve, reject) => {
3712
- let lastError;
3713
- let promiseStatus = "idle";
3714
- let timeoutId;
3715
- let intervalId;
3616
+ let lastError, promiseStatus = "idle", timeoutId, intervalId;
3716
3617
  const onResolve = (result) => {
3717
3618
  if (timeoutId) clearTimeout(timeoutId);
3718
3619
  if (intervalId) clearInterval(intervalId);
3719
3620
  resolve(result);
3720
- };
3721
- const handleTimeout = () => {
3621
+ }, handleTimeout = () => {
3722
3622
  if (intervalId) clearInterval(intervalId);
3723
3623
  let error = lastError;
3724
- if (!error) error = copyStackTrace(new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
3624
+ if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
3725
3625
  reject(error);
3726
- };
3727
- const checkCallback = () => {
3626
+ }, checkCallback = () => {
3728
3627
  if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
3729
- if (promiseStatus === "pending") return;
3730
- try {
3628
+ if (promiseStatus !== "pending") try {
3731
3629
  const result = callback();
3732
3630
  if (result !== null && typeof result === "object" && typeof result.then === "function") {
3733
3631
  const thenable = result;
3734
- promiseStatus = "pending";
3735
- thenable.then((resolvedValue) => {
3736
- promiseStatus = "resolved";
3737
- onResolve(resolvedValue);
3632
+ promiseStatus = "pending", thenable.then((resolvedValue) => {
3633
+ promiseStatus = "resolved", onResolve(resolvedValue);
3738
3634
  }, (rejectedValue) => {
3739
- promiseStatus = "rejected";
3740
- lastError = rejectedValue;
3635
+ promiseStatus = "rejected", lastError = rejectedValue;
3741
3636
  });
3742
- } else {
3743
- onResolve(result);
3744
- return true;
3745
- }
3637
+ } else return onResolve(result), true;
3746
3638
  } catch (error) {
3747
3639
  lastError = error;
3748
3640
  }
3749
3641
  };
3750
- if (checkCallback() === true) return;
3751
- timeoutId = setTimeout(handleTimeout, timeout);
3752
- intervalId = setInterval(checkCallback, interval);
3642
+ checkCallback() !== true && (timeoutId = setTimeout(handleTimeout, timeout), intervalId = setInterval(checkCallback, interval));
3753
3643
  });
3754
3644
  }
3755
3645
  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 = new Error("STACK_TRACE_ERROR");
3646
+ 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
3647
  return new Promise((resolve, reject) => {
3760
- let promiseStatus = "idle";
3761
- let timeoutId;
3762
- let intervalId;
3648
+ let promiseStatus = "idle", timeoutId, intervalId;
3763
3649
  const onReject = (error) => {
3764
3650
  if (intervalId) clearInterval(intervalId);
3765
- if (!error) error = copyStackTrace(new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
3651
+ if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
3766
3652
  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 = () => {
3653
+ }, onResolve = (result) => {
3654
+ if (result) {
3655
+ if (timeoutId) clearTimeout(timeoutId);
3656
+ if (intervalId) clearInterval(intervalId);
3657
+ return resolve(result), true;
3658
+ }
3659
+ }, checkCallback = () => {
3776
3660
  if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
3777
- if (promiseStatus === "pending") return;
3778
- try {
3661
+ if (promiseStatus !== "pending") try {
3779
3662
  const result = callback();
3780
3663
  if (result !== null && typeof result === "object" && typeof result.then === "function") {
3781
3664
  const thenable = result;
3782
- promiseStatus = "pending";
3783
- thenable.then((resolvedValue) => {
3784
- promiseStatus = "resolved";
3785
- onResolve(resolvedValue);
3665
+ promiseStatus = "pending", thenable.then((resolvedValue) => {
3666
+ promiseStatus = "resolved", onResolve(resolvedValue);
3786
3667
  }, (rejectedValue) => {
3787
- promiseStatus = "rejected";
3788
- onReject(rejectedValue);
3668
+ promiseStatus = "rejected", onReject(rejectedValue);
3789
3669
  });
3790
3670
  } else return onResolve(result);
3791
3671
  } catch (error) {
3792
3672
  onReject(error);
3793
3673
  }
3794
3674
  };
3795
- if (checkCallback() === true) return;
3796
- timeoutId = setTimeout(onReject, timeout);
3797
- intervalId = setInterval(checkCallback, interval);
3675
+ checkCallback() !== true && (timeoutId = setTimeout(onReject, timeout), intervalId = setInterval(checkCallback, interval));
3798
3676
  });
3799
3677
  }
3800
3678
 
3801
3679
  function createVitest() {
3802
3680
  let _config = null;
3803
- const workerState = getWorkerState();
3681
+ const state = () => getWorkerState();
3804
3682
  let _timers;
3805
3683
  const timers = () => _timers ||= new FakeTimers({
3806
3684
  global: globalThis,
3807
- config: workerState.config.fakeTimers
3808
- });
3809
- const _stubsGlobal = /* @__PURE__ */ new Map();
3810
- const _stubsEnv = /* @__PURE__ */ new Map();
3811
- const _envBooleans = [
3685
+ config: state().config.fakeTimers
3686
+ }), _stubsGlobal = /* @__PURE__ */ new Map(), _stubsEnv = /* @__PURE__ */ new Map(), _envBooleans = [
3812
3687
  "PROD",
3813
3688
  "DEV",
3814
3689
  "SSR"
3815
- ];
3816
- const utils = {
3690
+ ], utils = {
3817
3691
  useFakeTimers(config) {
3818
3692
  if (isChildProcess()) {
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.");
3693
+ if (config?.toFake?.includes("nextTick") || state().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.");
3820
3694
  }
3821
3695
  if (config) timers().configure({
3822
- ...workerState.config.fakeTimers,
3696
+ ...state().config.fakeTimers,
3823
3697
  ...config
3824
3698
  });
3825
- else timers().configure(workerState.config.fakeTimers);
3826
- timers().useFakeTimers();
3827
- return utils;
3699
+ else timers().configure(state().config.fakeTimers);
3700
+ return timers().useFakeTimers(), utils;
3828
3701
  },
3829
3702
  isFakeTimers() {
3830
3703
  return timers().isFakeTimers();
3831
3704
  },
3832
3705
  useRealTimers() {
3833
- timers().useRealTimers();
3834
- return utils;
3706
+ return timers().useRealTimers(), utils;
3835
3707
  },
3836
3708
  runOnlyPendingTimers() {
3837
- timers().runOnlyPendingTimers();
3838
- return utils;
3709
+ return timers().runOnlyPendingTimers(), utils;
3839
3710
  },
3840
3711
  async runOnlyPendingTimersAsync() {
3841
- await timers().runOnlyPendingTimersAsync();
3842
- return utils;
3712
+ return await timers().runOnlyPendingTimersAsync(), utils;
3843
3713
  },
3844
3714
  runAllTimers() {
3845
- timers().runAllTimers();
3846
- return utils;
3715
+ return timers().runAllTimers(), utils;
3847
3716
  },
3848
3717
  async runAllTimersAsync() {
3849
- await timers().runAllTimersAsync();
3850
- return utils;
3718
+ return await timers().runAllTimersAsync(), utils;
3851
3719
  },
3852
3720
  runAllTicks() {
3853
- timers().runAllTicks();
3854
- return utils;
3721
+ return timers().runAllTicks(), utils;
3855
3722
  },
3856
3723
  advanceTimersByTime(ms) {
3857
- timers().advanceTimersByTime(ms);
3858
- return utils;
3724
+ return timers().advanceTimersByTime(ms), utils;
3859
3725
  },
3860
3726
  async advanceTimersByTimeAsync(ms) {
3861
- await timers().advanceTimersByTimeAsync(ms);
3862
- return utils;
3727
+ return await timers().advanceTimersByTimeAsync(ms), utils;
3863
3728
  },
3864
3729
  advanceTimersToNextTimer() {
3865
- timers().advanceTimersToNextTimer();
3866
- return utils;
3730
+ return timers().advanceTimersToNextTimer(), utils;
3867
3731
  },
3868
3732
  async advanceTimersToNextTimerAsync() {
3869
- await timers().advanceTimersToNextTimerAsync();
3870
- return utils;
3733
+ return await timers().advanceTimersToNextTimerAsync(), utils;
3871
3734
  },
3872
3735
  advanceTimersToNextFrame() {
3873
- timers().advanceTimersToNextFrame();
3874
- return utils;
3736
+ return timers().advanceTimersToNextFrame(), utils;
3875
3737
  },
3876
3738
  getTimerCount() {
3877
3739
  return timers().getTimerCount();
3878
3740
  },
3879
3741
  setSystemTime(time) {
3880
- timers().setSystemTime(time);
3881
- return utils;
3742
+ return timers().setSystemTime(time), utils;
3882
3743
  },
3883
3744
  getMockedSystemTime() {
3884
3745
  return timers().getMockedSystemTime();
@@ -3887,16 +3748,14 @@ function createVitest() {
3887
3748
  return timers().getRealSystemTime();
3888
3749
  },
3889
3750
  clearAllTimers() {
3890
- timers().clearAllTimers();
3891
- return utils;
3751
+ return timers().clearAllTimers(), utils;
3892
3752
  },
3893
3753
  spyOn,
3894
3754
  fn,
3895
3755
  waitFor,
3896
3756
  waitUntil,
3897
3757
  hoisted(factory) {
3898
- assertTypes(factory, "\"vi.hoisted\" factory", ["function"]);
3899
- return factory();
3758
+ return assertTypes(factory, "\"vi.hoisted\" factory", ["function"]), factory();
3900
3759
  },
3901
3760
  mock(path, factory) {
3902
3761
  if (typeof path !== "string") throw new TypeError(`vi.mock() expects a string path, but received a ${typeof path}`);
@@ -3914,16 +3773,19 @@ function createVitest() {
3914
3773
  },
3915
3774
  doUnmock(path) {
3916
3775
  if (typeof path !== "string") throw new TypeError(`vi.doUnmock() expects a string path, but received a ${typeof path}`);
3917
- _mocker().queueUnmock(path, getImporter("doUnmock"));
3776
+ const importer = getImporter("doUnmock");
3777
+ _mocker().queueUnmock(path, importer);
3918
3778
  },
3919
3779
  async importActual(path) {
3920
- return _mocker().importActual(path, getImporter("importActual"), _mocker().getMockContext().callstack);
3780
+ const importer = getImporter("importActual");
3781
+ return _mocker().importActual(path, importer, _mocker().getMockContext().callstack);
3921
3782
  },
3922
3783
  async importMock(path) {
3923
- return _mocker().importMock(path, getImporter("importMock"));
3784
+ const importer = getImporter("importMock");
3785
+ return _mocker().importMock(path, importer);
3924
3786
  },
3925
- mockObject(value) {
3926
- return _mocker().mockObject({ value }).value;
3787
+ mockObject(value, options) {
3788
+ return _mocker().mockObject({ value }, void 0, options?.spy ? "autospy" : "automock").value;
3927
3789
  },
3928
3790
  mocked(item, _options = {}) {
3929
3791
  return item;
@@ -3932,63 +3794,56 @@ function createVitest() {
3932
3794
  return isMockFunction(fn);
3933
3795
  },
3934
3796
  clearAllMocks() {
3935
- [...mocks].reverse().forEach((spy) => spy.mockClear());
3936
- return utils;
3797
+ return clearAllMocks(), utils;
3937
3798
  },
3938
3799
  resetAllMocks() {
3939
- [...mocks].reverse().forEach((spy) => spy.mockReset());
3940
- return utils;
3800
+ return resetAllMocks(), utils;
3941
3801
  },
3942
3802
  restoreAllMocks() {
3943
- [...mocks].reverse().forEach((spy) => spy.mockRestore());
3944
- return utils;
3803
+ return restoreAllMocks(), utils;
3945
3804
  },
3946
3805
  stubGlobal(name, value) {
3947
3806
  if (!_stubsGlobal.has(name)) _stubsGlobal.set(name, Object.getOwnPropertyDescriptor(globalThis, name));
3948
- Object.defineProperty(globalThis, name, {
3807
+ return Object.defineProperty(globalThis, name, {
3949
3808
  value,
3950
3809
  writable: true,
3951
3810
  configurable: true,
3952
3811
  enumerable: true
3953
- });
3954
- return utils;
3812
+ }), utils;
3955
3813
  },
3956
3814
  stubEnv(name, value) {
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);
3815
+ const env = state().metaEnv;
3816
+ if (!_stubsEnv.has(name)) _stubsEnv.set(name, env[name]);
3817
+ if (_envBooleans.includes(name)) env[name] = value ? "1" : "";
3818
+ else if (value === void 0) delete env[name];
3819
+ else env[name] = String(value);
3961
3820
  return utils;
3962
3821
  },
3963
3822
  unstubAllGlobals() {
3964
- _stubsGlobal.forEach((original, name) => {
3823
+ return _stubsGlobal.forEach((original, name) => {
3965
3824
  if (!original) Reflect.deleteProperty(globalThis, name);
3966
3825
  else Object.defineProperty(globalThis, name, original);
3967
- });
3968
- _stubsGlobal.clear();
3969
- return utils;
3826
+ }), _stubsGlobal.clear(), utils;
3970
3827
  },
3971
3828
  unstubAllEnvs() {
3972
- _stubsEnv.forEach((original, name) => {
3973
- if (original === void 0) delete process.env[name];
3974
- else process.env[name] = original;
3975
- });
3976
- _stubsEnv.clear();
3977
- return utils;
3829
+ const env = state().metaEnv;
3830
+ return _stubsEnv.forEach((original, name) => {
3831
+ if (original === void 0) delete env[name];
3832
+ else env[name] = original;
3833
+ }), _stubsEnv.clear(), utils;
3978
3834
  },
3979
3835
  resetModules() {
3980
- resetModules(workerState.moduleCache);
3981
- return utils;
3836
+ return resetModules(state().evaluatedModules), utils;
3982
3837
  },
3983
3838
  async dynamicImportSettled() {
3984
3839
  return waitForImportsToResolve();
3985
3840
  },
3986
3841
  setConfig(config) {
3987
- if (!_config) _config = { ...workerState.config };
3988
- Object.assign(workerState.config, config);
3842
+ if (!_config) _config = { ...state().config };
3843
+ Object.assign(state().config, config);
3989
3844
  },
3990
3845
  resetConfig() {
3991
- if (_config) Object.assign(workerState.config, _config);
3846
+ if (_config) Object.assign(state().config, _config);
3992
3847
  }
3993
3848
  };
3994
3849
  return utils;
@@ -4002,14 +3857,10 @@ function _mocker() {
4002
3857
  } });
4003
3858
  }
4004
3859
  function getImporter(name) {
4005
- const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 });
4006
- const stackArray = stackTrace.split("\n");
4007
- // if there is no message in a stack trace, use the item - 1
4008
- const importerStackIndex = stackArray.findIndex((stack) => {
3860
+ const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 }), stackArray = stackTrace.split("\n"), importerStackIndex = stackArray.findLastIndex((stack) => {
4009
3861
  return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`);
4010
- });
4011
- const stack = parseSingleStack(stackArray[importerStackIndex + 1]);
3862
+ }), stack = parseSingleStack(stackArray[importerStackIndex + 1]);
4012
3863
  return stack?.file || "";
4013
3864
  }
4014
3865
 
4015
- export { globalExpect as a, vitest as b, createExpect as c, getSnapshotClient as g, inject as i, vi as v };
3866
+ export { getSnapshotClient as a, assert as b, createExpect as c, vitest as d, globalExpect as g, inject as i, should as s, vi as v };