vitest 4.0.0-beta.1 → 4.0.0-beta.11

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 (90) hide show
  1. package/LICENSE.md +83 -2
  2. package/dist/browser.d.ts +19 -16
  3. package/dist/browser.js +11 -7
  4. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.LXhJ0F0X.js} +7 -9
  5. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  6. package/dist/chunks/{browser.d.q8Z0P0q1.d.ts → browser.d.Dx7DO_Ce.d.ts} +5 -5
  7. package/dist/chunks/{cac.D3EzDDZd.js → cac.elvK37c9.js} +71 -153
  8. package/dist/chunks/{cli-api.Dn5gKePv.js → cli-api.C7plPyhs.js} +1376 -1693
  9. package/dist/chunks/{config.d.HJdfX-8k.d.ts → config.d.B_LthbQq.d.ts} +58 -63
  10. package/dist/chunks/{console.CtFJOzRO.js → console.CiTi59Jy.js} +35 -71
  11. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  12. package/dist/chunks/{coverage.Cwa-XhJt.js → coverage.CG6Uhorw.js} +522 -792
  13. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  14. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  15. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  16. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  17. package/dist/chunks/{environment.d.CUq4cUgQ.d.ts → environment.d.BsToaxti.d.ts} +27 -6
  18. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  19. package/dist/chunks/{global.d.CVbXEflG.d.ts → global.d.BK3X7FW1.d.ts} +2 -5
  20. package/dist/chunks/{globals.Cxal6MLI.js → globals.BjvYA-AD.js} +11 -9
  21. package/dist/chunks/{index.BWf_gE5n.js → index.AZOjjqWP.js} +7 -6
  22. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  23. package/dist/chunks/{index.TfbsX-3I.js → index.BhY64fF0.js} +16 -26
  24. package/dist/chunks/{index.CZI_8rVt.js → index.BwBttQPf.js} +340 -663
  25. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  26. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  27. package/dist/chunks/moduleRunner.d.BNa-CL9e.d.ts +201 -0
  28. package/dist/chunks/{node.fjCdwEIl.js → node.BsdMi6DV.js} +2 -2
  29. package/dist/chunks/{plugin.d.C2EcJUjo.d.ts → plugin.d.C5phQR6o.d.ts} +1 -1
  30. package/dist/chunks/{reporters.d.DxZg19fy.d.ts → reporters.d.CVzhsTvK.d.ts} +1233 -1293
  31. package/dist/chunks/resolveSnapshotEnvironment.DQVamkje.js +81 -0
  32. package/dist/chunks/rpc.jKGRSXIH.js +65 -0
  33. package/dist/chunks/{setup-common.D7ZqXFx-.js → setup-common.NAWRuMRP.js} +18 -30
  34. package/dist/chunks/startModuleRunner.oAuCu1yL.js +682 -0
  35. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  36. package/dist/chunks/test.KC5tH8hC.js +214 -0
  37. package/dist/chunks/typechecker.gXq-5P3n.js +1438 -0
  38. package/dist/chunks/{utils.XdZDrNZV.js → utils.DGKhod2J.js} +9 -28
  39. package/dist/chunks/{vi.bdSIJ99Y.js → vi.CiJ0Laa6.js} +159 -306
  40. package/dist/chunks/worker.d.B_Fd9M_w.d.ts +100 -0
  41. package/dist/chunks/worker.rPGLlbkW.js +200 -0
  42. package/dist/cli.js +8 -6
  43. package/dist/config.cjs +3 -9
  44. package/dist/config.d.ts +49 -54
  45. package/dist/config.js +1 -1
  46. package/dist/coverage.d.ts +27 -26
  47. package/dist/coverage.js +6 -8
  48. package/dist/environments.d.ts +9 -13
  49. package/dist/environments.js +1 -1
  50. package/dist/index.d.ts +38 -45
  51. package/dist/index.js +10 -10
  52. package/dist/module-evaluator.d.ts +13 -0
  53. package/dist/module-evaluator.js +276 -0
  54. package/dist/module-runner.js +15 -0
  55. package/dist/node.d.ts +44 -42
  56. package/dist/node.js +30 -36
  57. package/dist/reporters.d.ts +12 -13
  58. package/dist/reporters.js +7 -5
  59. package/dist/runners.d.ts +3 -3
  60. package/dist/runners.js +15 -232
  61. package/dist/snapshot.js +3 -3
  62. package/dist/suite.d.ts +2 -2
  63. package/dist/suite.js +4 -3
  64. package/dist/worker-base.js +203 -0
  65. package/dist/{chunks/vm.BThCzidc.js → worker-vm.js} +179 -228
  66. package/dist/workers/runVmTests.js +39 -56
  67. package/globals.d.ts +17 -17
  68. package/package.json +40 -38
  69. package/browser.d.ts +0 -1
  70. package/dist/chunks/base.Bj3pWTr1.js +0 -38
  71. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  72. package/dist/chunks/index.D-VkfKhf.js +0 -105
  73. package/dist/chunks/rpc.CsFtxqeq.js +0 -83
  74. package/dist/chunks/runBaseTests.BC7ZIH5L.js +0 -129
  75. package/dist/chunks/typechecker.CVytUJuF.js +0 -874
  76. package/dist/chunks/utils.CAioKnHs.js +0 -61
  77. package/dist/chunks/worker.d.CmvJfRGs.d.ts +0 -8
  78. package/dist/chunks/worker.d.DoNjFAiv.d.ts +0 -169
  79. package/dist/execute.d.ts +0 -148
  80. package/dist/execute.js +0 -13
  81. package/dist/worker.js +0 -124
  82. package/dist/workers/forks.js +0 -43
  83. package/dist/workers/threads.js +0 -31
  84. package/dist/workers/vmForks.js +0 -47
  85. package/dist/workers/vmThreads.js +0 -37
  86. package/dist/workers.d.ts +0 -37
  87. package/dist/workers.js +0 -30
  88. package/execute.d.ts +0 -1
  89. package/utils.d.ts +0 -1
  90. package/workers.d.ts +0 -1
@@ -1,15 +1,16 @@
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';
6
- import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
4
+ import { g as getWorkerState, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.DGKhod2J.js';
5
+ import { getSafeTimers } from '@vitest/utils/timers';
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 { assertTypes, createSimpleStackTrace } from '@vitest/utils/helpers';
10
+ import { fn, spyOn, restoreAllMocks, resetAllMocks, clearAllMocks, isMockFunction } from '@vitest/spy';
11
+ import '@vitest/utils/offset';
11
12
  import { parseSingleStack } from '@vitest/utils/source-map';
12
- import { R as RealDate, r as resetDate, m as mockDate } from './date.Bq6ZW5rf.js';
13
+ import { R as RealDate, r as resetDate, m as mockDate } from './date.-jtEtIeV.js';
13
14
 
14
15
  // these matchers are not supported because they don't make sense with poll
15
16
  const unsupported = [
@@ -26,11 +27,7 @@ const unsupported = [
26
27
  ];
27
28
  function createExpectPoll(expect) {
28
29
  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 });
30
+ 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
31
  fn = fn.bind(assertion);
35
32
  const test = chai$1.util.flag(assertion, "vitest-test");
36
33
  if (!test) throw new Error("expect.poll() must be called inside a test");
@@ -40,43 +37,30 @@ function createExpectPoll(expect) {
40
37
  if (key === "assert") return assertionFunction;
41
38
  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
39
  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 () => {
40
+ const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR"), promise = () => new Promise((resolve, reject) => {
41
+ let intervalId, timeoutId, lastError;
42
+ const { setTimeout, clearTimeout } = getSafeTimers(), check = async () => {
50
43
  try {
51
44
  chai$1.util.flag(assertion, "_name", key);
52
45
  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);
46
+ chai$1.util.flag(assertion, "object", obj), resolve(await assertionFunction.call(assertion, ...args)), clearTimeout(intervalId), clearTimeout(timeoutId);
57
47
  } catch (err) {
58
- lastError = err;
59
- if (!chai$1.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
48
+ if (lastError = err, !chai$1.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
60
49
  }
61
50
  };
62
51
  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));
52
+ clearTimeout(intervalId), chai$1.util.flag(assertion, "_isLastPollAttempt", true);
53
+ const rejectWithCause = (error) => {
54
+ if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
55
+ reject(copyStackTrace$1(error, STACK_TRACE_ERROR));
67
56
  };
68
57
  check().then(() => rejectWithCause(lastError)).catch((e) => rejectWithCause(e));
69
- }, timeout);
70
- check();
58
+ }, timeout), check();
71
59
  });
72
60
  let awaited = false;
73
- test.onFinished ??= [];
74
- test.onFinished.push(() => {
61
+ test.onFinished ??= [], test.onFinished.push(() => {
75
62
  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`);
63
+ 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
64
  throw copyStackTrace$1(error, STACK_TRACE_ERROR);
81
65
  }
82
66
  });
@@ -85,8 +69,7 @@ function createExpectPoll(expect) {
85
69
  // so let's follow it
86
70
  return {
87
71
  then(onFulfilled, onRejected) {
88
- awaited = true;
89
- return (resultPromise ||= promise()).then(onFulfilled, onRejected);
72
+ return awaited = true, (resultPromise ||= promise()).then(onFulfilled, onRejected);
90
73
  },
91
74
  catch(onRejected) {
92
75
  return (resultPromise ||= promise()).catch(onRejected);
@@ -206,31 +189,24 @@ var chaiSubsetExports = requireChaiSubset();
206
189
  var Subset = /*@__PURE__*/getDefaultExportFromCjs(chaiSubsetExports);
207
190
 
208
191
  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}` : "";
192
+ const not = util.flag(assertion, "negate") ? "not." : "", name = `${util.flag(assertion, "_name")}(${"expected" })`, promiseName = util.flag(assertion, "promise"), promise = promiseName ? `.${promiseName}` : "";
213
193
  return `expect(actual)${promise}.${not}${name}`;
214
194
  }
215
195
  function recordAsyncExpect(_test, promise, assertion, error) {
216
196
  const test = _test;
217
197
  // record promise for test, that resolves before test ends
218
198
  if (test && promise instanceof Promise) {
219
- // if promise is explicitly awaited, remove it from the list
220
- promise = promise.finally(() => {
199
+ // record promise
200
+ if (promise = promise.finally(() => {
221
201
  if (!test.promises) return;
222
202
  const index = test.promises.indexOf(promise);
223
203
  if (index !== -1) test.promises.splice(index, 1);
224
- });
225
- // record promise
226
- if (!test.promises) test.promises = [];
204
+ }), !test.promises) test.promises = [];
227
205
  test.promises.push(promise);
228
206
  let resolved = false;
229
- test.onFinished ??= [];
230
- test.onFinished.push(() => {
207
+ return test.onFinished ??= [], test.onFinished.push(() => {
231
208
  if (!resolved) {
232
- const processor = globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || "");
233
- const stack = processor(error.stack);
209
+ const processor = globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || ""), stack = processor(error.stack);
234
210
  console.warn([
235
211
  `Promise returned by \`${assertion}\` was not awaited. `,
236
212
  "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 +214,9 @@ function recordAsyncExpect(_test, promise, assertion, error) {
238
214
  stack
239
215
  ].join(""));
240
216
  }
241
- });
242
- return {
217
+ }), {
243
218
  then(onFulfilled, onRejected) {
244
- resolved = true;
245
- return promise.then(onFulfilled, onRejected);
219
+ return resolved = true, promise.then(onFulfilled, onRejected);
246
220
  },
247
221
  catch(onRejected) {
248
222
  return promise.catch(onRejected);
@@ -293,12 +267,8 @@ const SnapshotPlugin = (chai, utils) => {
293
267
  utils.flag(this, "_name", key);
294
268
  const isNot = utils.flag(this, "negate");
295
269
  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
- }
270
+ const expected = utils.flag(this, "object"), test = getTest(key, this);
271
+ if (typeof properties === "string" && typeof message === "undefined") message = properties, properties = void 0;
302
272
  const errorMessage = utils.flag(this, "message");
303
273
  getSnapshotClient().assert({
304
274
  received: expected,
@@ -313,11 +283,7 @@ const SnapshotPlugin = (chai, utils) => {
313
283
  utils.flag(this, "_name", "toMatchFileSnapshot");
314
284
  const isNot = utils.flag(this, "negate");
315
285
  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({
286
+ const error = /* @__PURE__ */ new Error("resolves"), expected = utils.flag(this, "object"), test = getTest("toMatchFileSnapshot", this), errorMessage = utils.flag(this, "message"), promise = getSnapshotClient().assertRaw({
321
287
  received: expected,
322
288
  message,
323
289
  isInline: false,
@@ -326,21 +292,14 @@ const SnapshotPlugin = (chai, utils) => {
326
292
  ...getTestNames(test)
327
293
  });
328
294
  return recordAsyncExpect(test, promise, createAssertionMessage(utils, this), error);
329
- });
330
- utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
295
+ }), utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
331
296
  utils.flag(this, "_name", "toMatchInlineSnapshot");
332
297
  const isNot = utils.flag(this, "negate");
333
298
  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;
299
+ const test = getTest("toMatchInlineSnapshot", this), isInsideEach = test.each || test.suite?.each;
336
300
  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
- }
301
+ const expected = utils.flag(this, "object"), error = utils.flag(this, "error");
302
+ if (typeof properties === "string") message = inlineSnapshot, inlineSnapshot = properties, properties = void 0;
344
303
  if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
345
304
  const errorMessage = utils.flag(this, "message");
346
305
  getSnapshotClient().assert({
@@ -353,32 +312,23 @@ const SnapshotPlugin = (chai, utils) => {
353
312
  errorMessage,
354
313
  ...getTestNames(test)
355
314
  });
356
- });
357
- utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
315
+ }), utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
358
316
  utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
359
317
  const isNot = utils.flag(this, "negate");
360
318
  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");
319
+ const expected = utils.flag(this, "object"), test = getTest("toThrowErrorMatchingSnapshot", this), promise = utils.flag(this, "promise"), errorMessage = utils.flag(this, "message");
365
320
  getSnapshotClient().assert({
366
321
  received: getError(expected, promise),
367
322
  message,
368
323
  errorMessage,
369
324
  ...getTestNames(test)
370
325
  });
371
- });
372
- utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
326
+ }), utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
373
327
  const isNot = utils.flag(this, "negate");
374
328
  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;
329
+ const test = getTest("toThrowErrorMatchingInlineSnapshot", this), isInsideEach = test.each || test.suite?.each;
377
330
  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");
331
+ const expected = utils.flag(this, "object"), error = utils.flag(this, "error"), promise = utils.flag(this, "promise"), errorMessage = utils.flag(this, "message");
382
332
  if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
383
333
  getSnapshotClient().assert({
384
334
  received: getError(expected, promise),
@@ -389,31 +339,19 @@ const SnapshotPlugin = (chai, utils) => {
389
339
  errorMessage,
390
340
  ...getTestNames(test)
391
341
  });
392
- });
393
- utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
342
+ }), utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
394
343
  };
395
344
 
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);
345
+ chai$1.use(JestExtend), chai$1.use(JestChaiExpect), chai$1.use(Subset), chai$1.use(SnapshotPlugin), chai$1.use(JestAsymmetricMatchers);
401
346
 
402
347
  function createExpect(test) {
403
- const expect = (value, message) => {
348
+ const expect = ((value, message) => {
404
349
  const { assertionCalls } = getState(expect);
405
350
  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);
351
+ const assert = chai$1.expect(value, message), _test = test || getCurrentTest();
352
+ return _test ? assert.withTest(_test) : assert;
353
+ });
354
+ Object.assign(expect, chai$1.expect), Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]), expect.getState = () => getState(expect), expect.setState = (state) => setState(state, expect);
417
355
  // @ts-expect-error global is not typed
418
356
  const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
419
357
  setState({
@@ -423,25 +361,18 @@ function createExpect(test) {
423
361
  isExpectingAssertionsError: null,
424
362
  expectedAssertionsNumber: null,
425
363
  expectedAssertionsNumberErrorGen: null,
426
- environment: getCurrentEnvironment(),
427
364
  get testPath() {
428
365
  return getWorkerState().filepath;
429
366
  },
430
367
  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) => {
368
+ }, expect), expect.extend = (matchers) => chai$1.expect.extend(expect, matchers), expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters), expect.soft = (...args) => {
436
369
  // @ts-expect-error private soft access
437
370
  return expect(...args).withContext({ soft: true });
438
- };
439
- expect.poll = createExpectPoll(expect);
440
- expect.unreachable = (message) => {
371
+ }, expect.poll = createExpectPoll(expect), expect.unreachable = (message) => {
441
372
  chai$1.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
442
373
  };
443
374
  function assertions(expected) {
444
- const errorGen = () => new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
375
+ const errorGen = () => /* @__PURE__ */ new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
445
376
  if (Error.captureStackTrace) Error.captureStackTrace(errorGen(), assertions);
446
377
  expect.setState({
447
378
  expectedAssertionsNumber: expected,
@@ -449,17 +380,14 @@ function createExpect(test) {
449
380
  });
450
381
  }
451
382
  function hasAssertions() {
452
- const error = new Error("expected any number of assertion, but got none");
383
+ const error = /* @__PURE__ */ new Error("expected any number of assertion, but got none");
453
384
  if (Error.captureStackTrace) Error.captureStackTrace(error, hasAssertions);
454
385
  expect.setState({
455
386
  isExpectingAssertions: true,
456
387
  isExpectingAssertionsError: error
457
388
  });
458
389
  }
459
- chai$1.util.addMethod(expect, "assertions", assertions);
460
- chai$1.util.addMethod(expect, "hasAssertions", hasAssertions);
461
- expect.extend(customMatchers);
462
- return expect;
390
+ return chai$1.util.addMethod(expect, "assertions", assertions), chai$1.util.addMethod(expect, "hasAssertions", hasAssertions), expect.extend(customMatchers), expect;
463
391
  }
464
392
  const globalExpect = createExpect();
465
393
  Object.defineProperty(globalThis, GLOBAL_EXPECT, {
@@ -467,6 +395,8 @@ Object.defineProperty(globalThis, GLOBAL_EXPECT, {
467
395
  writable: true,
468
396
  configurable: true
469
397
  });
398
+ const assert = chai$1.assert;
399
+ const should = chai$1.should;
470
400
 
471
401
  /**
472
402
  * Gives access to injected context provided from the main thread.
@@ -3576,20 +3506,16 @@ class FakeTimers {
3576
3506
  // | _fakingTime | _fakingDate |
3577
3507
  // +-------------+-------------+
3578
3508
  // | false | falsy | initial
3579
- // | false | truthy | vi.setSystemTime called first (for mocking only Date without fake timers)
3509
+ // | false | truthy | vi.setSystemTime called first (for mocking only Date without fake timers)
3580
3510
  // | true | falsy | vi.useFakeTimers called first
3581
- // | true | truthy | unreachable
3511
+ // | true | truthy | unreachable
3582
3512
  _fakingTime;
3583
3513
  _fakingDate;
3584
3514
  _fakeTimers;
3585
3515
  _userConfig;
3586
3516
  _now = RealDate.now;
3587
3517
  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;
3518
+ this._userConfig = config, this._fakingDate = null, this._fakingTime = false, this._fakeTimers = fakeTimersSrcExports.withGlobal(global), this._global = global;
3593
3519
  }
3594
3520
  clearAllTimers() {
3595
3521
  if (this._fakingTime) this._clock.reset();
@@ -3610,19 +3536,13 @@ class FakeTimers {
3610
3536
  if (this._checkFakeTimers()) await this._clock.runToLastAsync();
3611
3537
  }
3612
3538
  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;
3539
+ if (this._checkFakeTimers()) {
3540
+ for (let i = steps; i > 0; i--) if (this._clock.next(), this._clock.tick(0), this._clock.countTimers() === 0) break;
3618
3541
  }
3619
3542
  }
3620
3543
  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;
3544
+ if (this._checkFakeTimers()) {
3545
+ for (let i = steps; i > 0; i--) if (await this._clock.nextAsync(), this._clock.tick(0), this._clock.countTimers() === 0) break;
3626
3546
  }
3627
3547
  }
3628
3548
  advanceTimersByTime(msToRun) {
@@ -3640,43 +3560,32 @@ class FakeTimers {
3640
3560
  this._clock.runMicrotasks();
3641
3561
  }
3642
3562
  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
- }
3563
+ if (this._fakingDate) resetDate(), this._fakingDate = null;
3564
+ if (this._fakingTime) this._clock.uninstall(), this._fakingTime = false;
3651
3565
  }
3652
3566
  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
- }
3567
+ const fakeDate = this._fakingDate || Date.now();
3568
+ if (this._fakingDate) resetDate(), this._fakingDate = null;
3569
+ if (this._fakingTime) this._clock.uninstall();
3570
+ const toFake = Object.keys(this._fakeTimers.timers).filter((timer) => timer !== "nextTick" && timer !== "queueMicrotask");
3571
+ if (this._userConfig?.toFake?.includes("nextTick") && isChildProcess()) throw new Error("process.nextTick cannot be mocked inside child_process");
3572
+ this._clock = this._fakeTimers.install({
3573
+ now: fakeDate,
3574
+ ...this._userConfig,
3575
+ toFake: this._userConfig?.toFake || toFake,
3576
+ ignoreMissingTimers: true
3577
+ }), this._fakingTime = true;
3665
3578
  }
3666
3579
  reset() {
3667
3580
  if (this._checkFakeTimers()) {
3668
3581
  const { now } = this._clock;
3669
- this._clock.reset();
3670
- this._clock.setSystemTime(now);
3582
+ this._clock.reset(), this._clock.setSystemTime(now);
3671
3583
  }
3672
3584
  }
3673
3585
  setSystemTime(now) {
3674
3586
  const date = typeof now === "undefined" || now instanceof Date ? now : new Date(now);
3675
3587
  if (this._fakingTime) this._clock.setSystemTime(date);
3676
- else {
3677
- this._fakingDate = date ?? new Date(this.getRealSystemTime());
3678
- mockDate(this._fakingDate);
3679
- }
3588
+ else this._fakingDate = date ?? new Date(this.getRealSystemTime()), mockDate(this._fakingDate);
3680
3589
  }
3681
3590
  getMockedSystemTime() {
3682
3591
  return this._fakingTime ? new Date(this._clock.now) : this._fakingDate;
@@ -3685,8 +3594,7 @@ class FakeTimers {
3685
3594
  return this._now();
3686
3595
  }
3687
3596
  getTimerCount() {
3688
- if (this._checkFakeTimers()) return this._clock.countTimers();
3689
- return 0;
3597
+ return this._checkFakeTimers() ? this._clock.countTimers() : 0;
3690
3598
  }
3691
3599
  configure(config) {
3692
3600
  this._userConfig = config;
@@ -3695,7 +3603,7 @@ class FakeTimers {
3695
3603
  return this._fakingTime;
3696
3604
  }
3697
3605
  _checkFakeTimers() {
3698
- if (!this._fakingTime) throw new Error("Timers are not mocked. Try calling \"vi.useFakeTimers()\" first.");
3606
+ 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
3607
  return this._fakingTime;
3700
3608
  }
3701
3609
  }
@@ -3705,180 +3613,135 @@ function copyStackTrace(target, source) {
3705
3613
  return target;
3706
3614
  }
3707
3615
  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");
3616
+ 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
3617
  return new Promise((resolve, reject) => {
3712
- let lastError;
3713
- let promiseStatus = "idle";
3714
- let timeoutId;
3715
- let intervalId;
3618
+ let lastError, promiseStatus = "idle", timeoutId, intervalId;
3716
3619
  const onResolve = (result) => {
3717
3620
  if (timeoutId) clearTimeout(timeoutId);
3718
3621
  if (intervalId) clearInterval(intervalId);
3719
3622
  resolve(result);
3720
- };
3721
- const handleTimeout = () => {
3623
+ }, handleTimeout = () => {
3722
3624
  if (intervalId) clearInterval(intervalId);
3723
3625
  let error = lastError;
3724
- if (!error) error = copyStackTrace(new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
3626
+ if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
3725
3627
  reject(error);
3726
- };
3727
- const checkCallback = () => {
3628
+ }, checkCallback = () => {
3728
3629
  if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
3729
- if (promiseStatus === "pending") return;
3730
- try {
3630
+ if (promiseStatus !== "pending") try {
3731
3631
  const result = callback();
3732
3632
  if (result !== null && typeof result === "object" && typeof result.then === "function") {
3733
3633
  const thenable = result;
3734
- promiseStatus = "pending";
3735
- thenable.then((resolvedValue) => {
3736
- promiseStatus = "resolved";
3737
- onResolve(resolvedValue);
3634
+ promiseStatus = "pending", thenable.then((resolvedValue) => {
3635
+ promiseStatus = "resolved", onResolve(resolvedValue);
3738
3636
  }, (rejectedValue) => {
3739
- promiseStatus = "rejected";
3740
- lastError = rejectedValue;
3637
+ promiseStatus = "rejected", lastError = rejectedValue;
3741
3638
  });
3742
- } else {
3743
- onResolve(result);
3744
- return true;
3745
- }
3639
+ } else return onResolve(result), true;
3746
3640
  } catch (error) {
3747
3641
  lastError = error;
3748
3642
  }
3749
3643
  };
3750
- if (checkCallback() === true) return;
3751
- timeoutId = setTimeout(handleTimeout, timeout);
3752
- intervalId = setInterval(checkCallback, interval);
3644
+ checkCallback() !== true && (timeoutId = setTimeout(handleTimeout, timeout), intervalId = setInterval(checkCallback, interval));
3753
3645
  });
3754
3646
  }
3755
3647
  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");
3648
+ 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
3649
  return new Promise((resolve, reject) => {
3760
- let promiseStatus = "idle";
3761
- let timeoutId;
3762
- let intervalId;
3650
+ let promiseStatus = "idle", timeoutId, intervalId;
3763
3651
  const onReject = (error) => {
3764
3652
  if (intervalId) clearInterval(intervalId);
3765
- if (!error) error = copyStackTrace(new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
3653
+ if (!error) error = copyStackTrace(/* @__PURE__ */ new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
3766
3654
  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 = () => {
3655
+ }, onResolve = (result) => {
3656
+ if (result) {
3657
+ if (timeoutId) clearTimeout(timeoutId);
3658
+ if (intervalId) clearInterval(intervalId);
3659
+ return resolve(result), true;
3660
+ }
3661
+ }, checkCallback = () => {
3776
3662
  if (vi.isFakeTimers()) vi.advanceTimersByTime(interval);
3777
- if (promiseStatus === "pending") return;
3778
- try {
3663
+ if (promiseStatus !== "pending") try {
3779
3664
  const result = callback();
3780
3665
  if (result !== null && typeof result === "object" && typeof result.then === "function") {
3781
3666
  const thenable = result;
3782
- promiseStatus = "pending";
3783
- thenable.then((resolvedValue) => {
3784
- promiseStatus = "resolved";
3785
- onResolve(resolvedValue);
3667
+ promiseStatus = "pending", thenable.then((resolvedValue) => {
3668
+ promiseStatus = "resolved", onResolve(resolvedValue);
3786
3669
  }, (rejectedValue) => {
3787
- promiseStatus = "rejected";
3788
- onReject(rejectedValue);
3670
+ promiseStatus = "rejected", onReject(rejectedValue);
3789
3671
  });
3790
3672
  } else return onResolve(result);
3791
3673
  } catch (error) {
3792
3674
  onReject(error);
3793
3675
  }
3794
3676
  };
3795
- if (checkCallback() === true) return;
3796
- timeoutId = setTimeout(onReject, timeout);
3797
- intervalId = setInterval(checkCallback, interval);
3677
+ checkCallback() !== true && (timeoutId = setTimeout(onReject, timeout), intervalId = setInterval(checkCallback, interval));
3798
3678
  });
3799
3679
  }
3800
3680
 
3801
3681
  function createVitest() {
3802
3682
  let _config = null;
3803
- const workerState = getWorkerState();
3683
+ const state = () => getWorkerState();
3804
3684
  let _timers;
3805
3685
  const timers = () => _timers ||= new FakeTimers({
3806
3686
  global: globalThis,
3807
- config: workerState.config.fakeTimers
3808
- });
3809
- const _stubsGlobal = /* @__PURE__ */ new Map();
3810
- const _stubsEnv = /* @__PURE__ */ new Map();
3811
- const _envBooleans = [
3687
+ config: state().config.fakeTimers
3688
+ }), _stubsGlobal = /* @__PURE__ */ new Map(), _stubsEnv = /* @__PURE__ */ new Map(), _envBooleans = [
3812
3689
  "PROD",
3813
3690
  "DEV",
3814
3691
  "SSR"
3815
- ];
3816
- const utils = {
3692
+ ], utils = {
3817
3693
  useFakeTimers(config) {
3818
3694
  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.");
3695
+ 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
3696
  }
3821
3697
  if (config) timers().configure({
3822
- ...workerState.config.fakeTimers,
3698
+ ...state().config.fakeTimers,
3823
3699
  ...config
3824
3700
  });
3825
- else timers().configure(workerState.config.fakeTimers);
3826
- timers().useFakeTimers();
3827
- return utils;
3701
+ else timers().configure(state().config.fakeTimers);
3702
+ return timers().useFakeTimers(), utils;
3828
3703
  },
3829
3704
  isFakeTimers() {
3830
3705
  return timers().isFakeTimers();
3831
3706
  },
3832
3707
  useRealTimers() {
3833
- timers().useRealTimers();
3834
- return utils;
3708
+ return timers().useRealTimers(), utils;
3835
3709
  },
3836
3710
  runOnlyPendingTimers() {
3837
- timers().runOnlyPendingTimers();
3838
- return utils;
3711
+ return timers().runOnlyPendingTimers(), utils;
3839
3712
  },
3840
3713
  async runOnlyPendingTimersAsync() {
3841
- await timers().runOnlyPendingTimersAsync();
3842
- return utils;
3714
+ return await timers().runOnlyPendingTimersAsync(), utils;
3843
3715
  },
3844
3716
  runAllTimers() {
3845
- timers().runAllTimers();
3846
- return utils;
3717
+ return timers().runAllTimers(), utils;
3847
3718
  },
3848
3719
  async runAllTimersAsync() {
3849
- await timers().runAllTimersAsync();
3850
- return utils;
3720
+ return await timers().runAllTimersAsync(), utils;
3851
3721
  },
3852
3722
  runAllTicks() {
3853
- timers().runAllTicks();
3854
- return utils;
3723
+ return timers().runAllTicks(), utils;
3855
3724
  },
3856
3725
  advanceTimersByTime(ms) {
3857
- timers().advanceTimersByTime(ms);
3858
- return utils;
3726
+ return timers().advanceTimersByTime(ms), utils;
3859
3727
  },
3860
3728
  async advanceTimersByTimeAsync(ms) {
3861
- await timers().advanceTimersByTimeAsync(ms);
3862
- return utils;
3729
+ return await timers().advanceTimersByTimeAsync(ms), utils;
3863
3730
  },
3864
3731
  advanceTimersToNextTimer() {
3865
- timers().advanceTimersToNextTimer();
3866
- return utils;
3732
+ return timers().advanceTimersToNextTimer(), utils;
3867
3733
  },
3868
3734
  async advanceTimersToNextTimerAsync() {
3869
- await timers().advanceTimersToNextTimerAsync();
3870
- return utils;
3735
+ return await timers().advanceTimersToNextTimerAsync(), utils;
3871
3736
  },
3872
3737
  advanceTimersToNextFrame() {
3873
- timers().advanceTimersToNextFrame();
3874
- return utils;
3738
+ return timers().advanceTimersToNextFrame(), utils;
3875
3739
  },
3876
3740
  getTimerCount() {
3877
3741
  return timers().getTimerCount();
3878
3742
  },
3879
3743
  setSystemTime(time) {
3880
- timers().setSystemTime(time);
3881
- return utils;
3744
+ return timers().setSystemTime(time), utils;
3882
3745
  },
3883
3746
  getMockedSystemTime() {
3884
3747
  return timers().getMockedSystemTime();
@@ -3887,16 +3750,14 @@ function createVitest() {
3887
3750
  return timers().getRealSystemTime();
3888
3751
  },
3889
3752
  clearAllTimers() {
3890
- timers().clearAllTimers();
3891
- return utils;
3753
+ return timers().clearAllTimers(), utils;
3892
3754
  },
3893
3755
  spyOn,
3894
3756
  fn,
3895
3757
  waitFor,
3896
3758
  waitUntil,
3897
3759
  hoisted(factory) {
3898
- assertTypes(factory, "\"vi.hoisted\" factory", ["function"]);
3899
- return factory();
3760
+ return assertTypes(factory, "\"vi.hoisted\" factory", ["function"]), factory();
3900
3761
  },
3901
3762
  mock(path, factory) {
3902
3763
  if (typeof path !== "string") throw new TypeError(`vi.mock() expects a string path, but received a ${typeof path}`);
@@ -3914,16 +3775,19 @@ function createVitest() {
3914
3775
  },
3915
3776
  doUnmock(path) {
3916
3777
  if (typeof path !== "string") throw new TypeError(`vi.doUnmock() expects a string path, but received a ${typeof path}`);
3917
- _mocker().queueUnmock(path, getImporter("doUnmock"));
3778
+ const importer = getImporter("doUnmock");
3779
+ _mocker().queueUnmock(path, importer);
3918
3780
  },
3919
3781
  async importActual(path) {
3920
- return _mocker().importActual(path, getImporter("importActual"), _mocker().getMockContext().callstack);
3782
+ const importer = getImporter("importActual");
3783
+ return _mocker().importActual(path, importer, _mocker().getMockContext().callstack);
3921
3784
  },
3922
3785
  async importMock(path) {
3923
- return _mocker().importMock(path, getImporter("importMock"));
3786
+ const importer = getImporter("importMock");
3787
+ return _mocker().importMock(path, importer);
3924
3788
  },
3925
- mockObject(value) {
3926
- return _mocker().mockObject({ value }).value;
3789
+ mockObject(value, options) {
3790
+ return _mocker().mockObject({ value }, void 0, options?.spy ? "autospy" : "automock").value;
3927
3791
  },
3928
3792
  mocked(item, _options = {}) {
3929
3793
  return item;
@@ -3932,63 +3796,56 @@ function createVitest() {
3932
3796
  return isMockFunction(fn);
3933
3797
  },
3934
3798
  clearAllMocks() {
3935
- [...mocks].reverse().forEach((spy) => spy.mockClear());
3936
- return utils;
3799
+ return clearAllMocks(), utils;
3937
3800
  },
3938
3801
  resetAllMocks() {
3939
- [...mocks].reverse().forEach((spy) => spy.mockReset());
3940
- return utils;
3802
+ return resetAllMocks(), utils;
3941
3803
  },
3942
3804
  restoreAllMocks() {
3943
- [...mocks].reverse().forEach((spy) => spy.mockRestore());
3944
- return utils;
3805
+ return restoreAllMocks(), utils;
3945
3806
  },
3946
3807
  stubGlobal(name, value) {
3947
3808
  if (!_stubsGlobal.has(name)) _stubsGlobal.set(name, Object.getOwnPropertyDescriptor(globalThis, name));
3948
- Object.defineProperty(globalThis, name, {
3809
+ return Object.defineProperty(globalThis, name, {
3949
3810
  value,
3950
3811
  writable: true,
3951
3812
  configurable: true,
3952
3813
  enumerable: true
3953
- });
3954
- return utils;
3814
+ }), utils;
3955
3815
  },
3956
3816
  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);
3817
+ const env = state().metaEnv;
3818
+ if (!_stubsEnv.has(name)) _stubsEnv.set(name, env[name]);
3819
+ if (_envBooleans.includes(name)) env[name] = value ? "1" : "";
3820
+ else if (value === void 0) delete env[name];
3821
+ else env[name] = String(value);
3961
3822
  return utils;
3962
3823
  },
3963
3824
  unstubAllGlobals() {
3964
- _stubsGlobal.forEach((original, name) => {
3825
+ return _stubsGlobal.forEach((original, name) => {
3965
3826
  if (!original) Reflect.deleteProperty(globalThis, name);
3966
3827
  else Object.defineProperty(globalThis, name, original);
3967
- });
3968
- _stubsGlobal.clear();
3969
- return utils;
3828
+ }), _stubsGlobal.clear(), utils;
3970
3829
  },
3971
3830
  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;
3831
+ const env = state().metaEnv;
3832
+ return _stubsEnv.forEach((original, name) => {
3833
+ if (original === void 0) delete env[name];
3834
+ else env[name] = original;
3835
+ }), _stubsEnv.clear(), utils;
3978
3836
  },
3979
3837
  resetModules() {
3980
- resetModules(workerState.moduleCache);
3981
- return utils;
3838
+ return resetModules(state().evaluatedModules), utils;
3982
3839
  },
3983
3840
  async dynamicImportSettled() {
3984
3841
  return waitForImportsToResolve();
3985
3842
  },
3986
3843
  setConfig(config) {
3987
- if (!_config) _config = { ...workerState.config };
3988
- Object.assign(workerState.config, config);
3844
+ if (!_config) _config = { ...state().config };
3845
+ Object.assign(state().config, config);
3989
3846
  },
3990
3847
  resetConfig() {
3991
- if (_config) Object.assign(workerState.config, _config);
3848
+ if (_config) Object.assign(state().config, _config);
3992
3849
  }
3993
3850
  };
3994
3851
  return utils;
@@ -4002,14 +3859,10 @@ function _mocker() {
4002
3859
  } });
4003
3860
  }
4004
3861
  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) => {
3862
+ const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 }), stackArray = stackTrace.split("\n"), importerStackIndex = stackArray.findLastIndex((stack) => {
4009
3863
  return stack.includes(` at Object.${name}`) || stack.includes(`${name}@`);
4010
- });
4011
- const stack = parseSingleStack(stackArray[importerStackIndex + 1]);
3864
+ }), stack = parseSingleStack(stackArray[importerStackIndex + 1]);
4012
3865
  return stack?.file || "";
4013
3866
  }
4014
3867
 
4015
- export { globalExpect as a, vitest as b, createExpect as c, getSnapshotClient as g, inject as i, vi as v };
3868
+ 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 };