vitest 0.16.0 → 0.18.0

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 (27) hide show
  1. package/dist/{chunk-api-setup.f43cd039.mjs → chunk-api-setup.63babd7c.mjs} +4 -4
  2. package/dist/{chunk-constants.7b9cfc82.mjs → chunk-constants.8eb2ed35.mjs} +8 -2
  3. package/dist/chunk-env-node.26c72624.mjs +675 -0
  4. package/dist/{chunk-install-pkg.3fa50769.mjs → chunk-install-pkg.2dcb2c04.mjs} +1 -1
  5. package/dist/{chunk-integrations-globals.d0c363a6.mjs → chunk-integrations-globals.61e4d6ae.mjs} +8 -8
  6. package/dist/{chunk-runtime-chain.7103058b.mjs → chunk-runtime-chain.eb764dff.mjs} +55 -188
  7. package/dist/{chunk-runtime-mocker.110e3634.mjs → chunk-runtime-mocker.79ccc3de.mjs} +36 -62
  8. package/dist/{chunk-runtime-rpc.5e78af38.mjs → chunk-runtime-rpc.cc6a06a2.mjs} +1 -1
  9. package/dist/{chunk-utils-global.79a8b1cc.mjs → chunk-utils-global.1b22c4fd.mjs} +69 -5
  10. package/dist/{chunk-utils-source-map.2556cba8.mjs → chunk-utils-source-map.957e7756.mjs} +10 -24
  11. package/dist/{chunk-vite-node-externalize.58e10976.mjs → chunk-vite-node-externalize.0791f2ed.mjs} +2683 -2553
  12. package/dist/{chunk-vite-node-utils.7450fc0c.mjs → chunk-vite-node-utils.af8ead96.mjs} +28 -13
  13. package/dist/cli.mjs +15 -15
  14. package/dist/config.cjs +5 -1
  15. package/dist/config.d.ts +1 -1
  16. package/dist/config.mjs +5 -1
  17. package/dist/entry.mjs +8 -8
  18. package/dist/index.d.ts +223 -18
  19. package/dist/index.mjs +4 -4
  20. package/dist/node.d.ts +236 -38
  21. package/dist/node.mjs +16 -16
  22. package/dist/{vendor-entry.efeeaa5c.mjs → vendor-entry.78de67ab.mjs} +18 -424
  23. package/dist/{vendor-index.e5dc6622.mjs → vendor-index.4bf9c627.mjs} +405 -405
  24. package/dist/{vendor-index.98e769c1.mjs → vendor-index.de788b6a.mjs} +7 -7
  25. package/dist/worker.mjs +8 -8
  26. package/package.json +9 -4
  27. package/dist/chunk-defaults.dc6dc23d.mjs +0 -302
@@ -2,7 +2,7 @@ import path$2 from 'path';
2
2
  import fs$2 from 'fs';
3
3
  import require$$0 from 'util';
4
4
  import childProcess$1 from 'child_process';
5
- import { p as pathKey, s as signalExit, m as mergeStream$1, g as getStream$1, c as crossSpawn$1, o as onetime$1 } from './vendor-index.e5dc6622.mjs';
5
+ import { p as pathKey, s as signalExit, m as mergeStream$1, g as getStream$1, c as crossSpawn$1, o as onetime$1 } from './vendor-index.4bf9c627.mjs';
6
6
  import require$$0$1 from 'os';
7
7
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
8
8
  import 'assert';
@@ -1,21 +1,21 @@
1
- import { g as globalApis } from './chunk-constants.7b9cfc82.mjs';
2
- import { i as index } from './vendor-entry.efeeaa5c.mjs';
1
+ import { g as globalApis } from './chunk-constants.8eb2ed35.mjs';
2
+ import { i as index } from './vendor-entry.78de67ab.mjs';
3
3
  import 'url';
4
- import './chunk-utils-global.79a8b1cc.mjs';
4
+ import './chunk-utils-global.1b22c4fd.mjs';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
8
8
  import 'fs';
9
- import './chunk-runtime-chain.7103058b.mjs';
9
+ import './chunk-env-node.26c72624.mjs';
10
+ import 'module';
11
+ import './chunk-runtime-chain.eb764dff.mjs';
10
12
  import 'chai';
11
13
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
12
- import './chunk-runtime-rpc.5e78af38.mjs';
13
- import './chunk-utils-source-map.2556cba8.mjs';
14
+ import './chunk-runtime-rpc.cc6a06a2.mjs';
15
+ import './chunk-utils-source-map.957e7756.mjs';
14
16
  import './chunk-integrations-spy.674b628e.mjs';
15
17
  import 'tinyspy';
16
18
  import 'util';
17
- import './chunk-defaults.dc6dc23d.mjs';
18
- import 'module';
19
19
 
20
20
  function registerApiGlobally() {
21
21
  globalApis.forEach((api) => {
@@ -1,31 +1,12 @@
1
1
  import chai$1, { expect, AssertionError, util } from 'chai';
2
2
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
3
- import { r as rpc } from './chunk-runtime-rpc.5e78af38.mjs';
4
- import { i as isObject, j as join, d as dirname, g as getCallLastIndex, s as slash, a as getWorkerState, b as getNames, c as assertTypes, p as picocolors, e as getFullName, f as safeSetTimeout, h as safeClearTimeout, n as noop, r as resetModules } from './chunk-utils-global.79a8b1cc.mjs';
3
+ import { r as rpc } from './chunk-runtime-rpc.cc6a06a2.mjs';
4
+ import { i as isObject, j as join, d as dirname, g as getCallLastIndex, s as slash, a as getWorkerState, b as getNames, c as assertTypes, p as picocolors, e as getFullName, f as safeSetTimeout, h as safeClearTimeout, n as noop, R as RealDate, r as resetDate, m as mockDate, k as resetModules } from './chunk-utils-global.1b22c4fd.mjs';
5
5
  import fs, { promises } from 'fs';
6
- import { p as plugins_1, f as format_1, g as getOriginalPos, a as posToNumber, n as numberToPos, l as lineSplitRE, b as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils } from './chunk-utils-source-map.2556cba8.mjs';
6
+ import { p as plugins_1, f as format_1, g as getOriginalPos, a as posToNumber, n as numberToPos, l as lineSplitRE, b as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils } from './chunk-utils-source-map.957e7756.mjs';
7
7
  import { i as isMockFunction, s as spyOn, f as fn, a as spies } from './chunk-integrations-spy.674b628e.mjs';
8
8
  import require$$0, { format } from 'util';
9
9
 
10
- var __defProp$5 = Object.defineProperty;
11
- var __defProps$2 = Object.defineProperties;
12
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
13
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
14
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
15
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
16
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
- var __spreadValues$5 = (a, b) => {
18
- for (var prop in b || (b = {}))
19
- if (__hasOwnProp$5.call(b, prop))
20
- __defNormalProp$5(a, prop, b[prop]);
21
- if (__getOwnPropSymbols$5)
22
- for (var prop of __getOwnPropSymbols$5(b)) {
23
- if (__propIsEnum$5.call(b, prop))
24
- __defNormalProp$5(a, prop, b[prop]);
25
- }
26
- return a;
27
- };
28
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
29
10
  function createChainable(keys, fn) {
30
11
  function create(obj) {
31
12
  const chain2 = function(...args) {
@@ -34,7 +15,7 @@ function createChainable(keys, fn) {
34
15
  for (const key of keys) {
35
16
  Object.defineProperty(chain2, key, {
36
17
  get() {
37
- return create(__spreadProps$2(__spreadValues$5({}, obj), { [key]: true }));
18
+ return create({ ...obj, [key]: true });
38
19
  }
39
20
  });
40
21
  }
@@ -466,22 +447,6 @@ const addSerializer = (plugin) => {
466
447
  };
467
448
  const getSerializers = () => PLUGINS;
468
449
 
469
- var __defProp$4 = Object.defineProperty;
470
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
471
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
472
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
473
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
474
- var __spreadValues$4 = (a, b) => {
475
- for (var prop in b || (b = {}))
476
- if (__hasOwnProp$4.call(b, prop))
477
- __defNormalProp$4(a, prop, b[prop]);
478
- if (__getOwnPropSymbols$4)
479
- for (var prop of __getOwnPropSymbols$4(b)) {
480
- if (__propIsEnum$4.call(b, prop))
481
- __defNormalProp$4(a, prop, b[prop]);
482
- }
483
- return a;
484
- };
485
450
  const SNAPSHOT_VERSION = "1";
486
451
  const writeSnapshotVersion = () => `// Vitest Snapshot v${SNAPSHOT_VERSION}`;
487
452
  const testNameToKey = (testName, count) => `${testName} ${count}`;
@@ -514,12 +479,13 @@ const removeExtraLineBreaks = (string) => string.length > 2 && string.startsWith
514
479
  const escapeRegex = true;
515
480
  const printFunctionName = false;
516
481
  function serialize(val, indent = 2, formatOverrides = {}) {
517
- return normalizeNewlines(format_1(val, __spreadValues$4({
482
+ return normalizeNewlines(format_1(val, {
518
483
  escapeRegex,
519
484
  indent,
520
485
  plugins: getSerializers(),
521
- printFunctionName
522
- }, formatOverrides)));
486
+ printFunctionName,
487
+ ...formatOverrides
488
+ }));
523
489
  }
524
490
  function escapeBacktickString(str) {
525
491
  return str.replace(/`|\\|\${/g, "\\$&");
@@ -581,7 +547,7 @@ function deepMergeArray(target = [], source = []) {
581
547
  }
582
548
  function deepMergeSnapshot(target, source) {
583
549
  if (isObject(target) && isObject(source)) {
584
- const mergedOutput = __spreadValues$4({}, target);
550
+ const mergedOutput = { ...target };
585
551
  Object.keys(source).forEach((key) => {
586
552
  if (isObject(source[key]) && !source[key].$$typeof) {
587
553
  if (!(key in target))
@@ -694,22 +660,6 @@ function stripSnapshotIndentation(inlineSnapshot) {
694
660
  return inlineSnapshot;
695
661
  }
696
662
 
697
- var __defProp$3 = Object.defineProperty;
698
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
699
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
700
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
701
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
702
- var __spreadValues$3 = (a, b) => {
703
- for (var prop in b || (b = {}))
704
- if (__hasOwnProp$3.call(b, prop))
705
- __defNormalProp$3(a, prop, b[prop]);
706
- if (__getOwnPropSymbols$3)
707
- for (var prop of __getOwnPropSymbols$3(b)) {
708
- if (__propIsEnum$3.call(b, prop))
709
- __defNormalProp$3(a, prop, b[prop]);
710
- }
711
- return a;
712
- };
713
663
  class SnapshotState {
714
664
  constructor(testFilePath, snapshotPath, options) {
715
665
  this.testFilePath = testFilePath;
@@ -727,9 +677,10 @@ class SnapshotState {
727
677
  this.unmatched = 0;
728
678
  this._updateSnapshot = options.updateSnapshot;
729
679
  this.updated = 0;
730
- this._snapshotFormat = __spreadValues$3({
731
- printBasicPrototype: false
732
- }, options.snapshotFormat);
680
+ this._snapshotFormat = {
681
+ printBasicPrototype: false,
682
+ ...options.snapshotFormat
683
+ };
733
684
  }
734
685
  markSnapshotsAsCheckedForTest(testName) {
735
686
  this._uncheckedKeys.forEach((uncheckedKey) => {
@@ -756,9 +707,10 @@ class SnapshotState {
756
707
  ${JSON.stringify(stacks)}`);
757
708
  }
758
709
  stack.column--;
759
- this._inlineSnapshots.push(__spreadValues$3({
760
- snapshot: receivedSerialized
761
- }, stack));
710
+ this._inlineSnapshots.push({
711
+ snapshot: receivedSerialized,
712
+ ...stack
713
+ });
762
714
  } else {
763
715
  this._snapshotData[key] = receivedSerialized;
764
716
  }
@@ -992,13 +944,21 @@ function getSnapshotClient() {
992
944
  _client = new SnapshotClient();
993
945
  return _client;
994
946
  }
995
- const getErrorString = (expected) => {
947
+ const getErrorMessage = (err) => {
948
+ if (err instanceof Error)
949
+ return err.message;
950
+ return err;
951
+ };
952
+ const getErrorString = (expected, promise) => {
953
+ if (typeof expected !== "function") {
954
+ if (!promise)
955
+ throw new Error(`expected must be a function, received ${typeof expected}`);
956
+ return getErrorMessage(expected);
957
+ }
996
958
  try {
997
959
  expected();
998
960
  } catch (e) {
999
- if (e instanceof Error)
1000
- return e.message;
1001
- return e;
961
+ return getErrorMessage(e);
1002
962
  }
1003
963
  throw new Error("snapshot function didn't threw");
1004
964
  };
@@ -1048,9 +1008,10 @@ const SnapshotPlugin = (chai, utils) => {
1048
1008
  utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
1049
1009
  const expected = utils.flag(this, "object");
1050
1010
  const test = utils.flag(this, "vitest-test");
1011
+ const promise = utils.flag(this, "promise");
1051
1012
  const errorMessage = utils.flag(this, "message");
1052
1013
  getSnapshotClient().assert({
1053
- received: getErrorString(expected),
1014
+ received: getErrorString(expected, promise),
1054
1015
  test,
1055
1016
  message,
1056
1017
  errorMessage
@@ -1060,9 +1021,10 @@ const SnapshotPlugin = (chai, utils) => {
1060
1021
  const expected = utils.flag(this, "object");
1061
1022
  const error = utils.flag(this, "error");
1062
1023
  const test = utils.flag(this, "vitest-test");
1024
+ const promise = utils.flag(this, "promise");
1063
1025
  const errorMessage = utils.flag(this, "message");
1064
1026
  getSnapshotClient().assert({
1065
- received: getErrorString(expected),
1027
+ received: getErrorString(expected, promise),
1066
1028
  test,
1067
1029
  message,
1068
1030
  inlineSnapshot,
@@ -1500,25 +1462,6 @@ function toString(value) {
1500
1462
  }
1501
1463
  }
1502
1464
 
1503
- var __defProp$2 = Object.defineProperty;
1504
- var __defProps$1 = Object.defineProperties;
1505
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1506
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1507
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1508
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1509
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1510
- var __spreadValues$2 = (a, b) => {
1511
- for (var prop in b || (b = {}))
1512
- if (__hasOwnProp$2.call(b, prop))
1513
- __defNormalProp$2(a, prop, b[prop]);
1514
- if (__getOwnPropSymbols$2)
1515
- for (var prop of __getOwnPropSymbols$2(b)) {
1516
- if (__propIsEnum$2.call(b, prop))
1517
- __defNormalProp$2(a, prop, b[prop]);
1518
- }
1519
- return a;
1520
- };
1521
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1522
1465
  class AsymmetricMatcher {
1523
1466
  constructor(sample, inverse = false) {
1524
1467
  this.sample = sample;
@@ -1526,11 +1469,12 @@ class AsymmetricMatcher {
1526
1469
  this.$$typeof = Symbol.for("jest.asymmetricMatcher");
1527
1470
  }
1528
1471
  getMatcherContext(expect) {
1529
- return __spreadProps$1(__spreadValues$2({}, getState(expect || globalThis[GLOBAL_EXPECT])), {
1472
+ return {
1473
+ ...getState(expect || globalThis[GLOBAL_EXPECT]),
1530
1474
  equals,
1531
1475
  isNot: this.inverse,
1532
1476
  utils: matcherUtils
1533
- });
1477
+ };
1534
1478
  }
1535
1479
  }
1536
1480
  class StringContaining extends AsymmetricMatcher {
@@ -1700,42 +1644,25 @@ const JestAsymmetricMatchers = (chai, utils) => {
1700
1644
  };
1701
1645
  };
1702
1646
 
1703
- var __defProp$1 = Object.defineProperty;
1704
- var __defProps = Object.defineProperties;
1705
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1706
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1707
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1708
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1709
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1710
- var __spreadValues$1 = (a, b) => {
1711
- for (var prop in b || (b = {}))
1712
- if (__hasOwnProp$1.call(b, prop))
1713
- __defNormalProp$1(a, prop, b[prop]);
1714
- if (__getOwnPropSymbols$1)
1715
- for (var prop of __getOwnPropSymbols$1(b)) {
1716
- if (__propIsEnum$1.call(b, prop))
1717
- __defNormalProp$1(a, prop, b[prop]);
1718
- }
1719
- return a;
1720
- };
1721
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1722
1647
  const isAsyncFunction = (fn) => typeof fn === "function" && fn[Symbol.toStringTag] === "AsyncFunction";
1723
1648
  const getMatcherState = (assertion, expect) => {
1724
1649
  const obj = assertion._obj;
1725
1650
  const isNot = util.flag(assertion, "negate");
1726
1651
  const promise = util.flag(assertion, "promise") || "";
1727
- const jestUtils = __spreadProps(__spreadValues$1({}, matcherUtils), {
1652
+ const jestUtils = {
1653
+ ...matcherUtils,
1728
1654
  iterableEquality,
1729
1655
  subsetEquality
1730
- });
1731
- const matcherState = __spreadProps(__spreadValues$1({}, getState(expect)), {
1656
+ };
1657
+ const matcherState = {
1658
+ ...getState(expect),
1732
1659
  isNot,
1733
1660
  utils: jestUtils,
1734
1661
  promise,
1735
1662
  equals,
1736
1663
  suppressedErrors: [],
1737
1664
  snapshotState: getSnapshotClient().snapshotState
1738
- });
1665
+ };
1739
1666
  return {
1740
1667
  state: matcherState,
1741
1668
  isNot,
@@ -1957,7 +1884,8 @@ function formatTitle(template, items, idx) {
1957
1884
  }
1958
1885
  const describe = suite;
1959
1886
  const it = test;
1960
- const defaultSuite = suite("");
1887
+ const workerState = getWorkerState();
1888
+ const defaultSuite = workerState.config.sequence.shuffle ? suite.shuffle("") : suite("");
1961
1889
  function clearCollectorContext() {
1962
1890
  collectorContext.tasks.length = 0;
1963
1891
  defaultSuite.clear();
@@ -1975,7 +1903,7 @@ function createSuiteHooks() {
1975
1903
  };
1976
1904
  }
1977
1905
  function createSuiteCollector(name, factory = () => {
1978
- }, mode, concurrent) {
1906
+ }, mode, concurrent, shuffle) {
1979
1907
  const tasks = [];
1980
1908
  const factoryQueue = [];
1981
1909
  let suite2;
@@ -1992,6 +1920,8 @@ function createSuiteCollector(name, factory = () => {
1992
1920
  };
1993
1921
  if (this.concurrent || concurrent)
1994
1922
  test3.concurrent = true;
1923
+ if (shuffle)
1924
+ test3.shuffle = true;
1995
1925
  const context = createTestContext(test3);
1996
1926
  Object.defineProperty(test3, "context", {
1997
1927
  value: context,
@@ -2019,6 +1949,7 @@ function createSuiteCollector(name, factory = () => {
2019
1949
  type: "suite",
2020
1950
  name,
2021
1951
  mode,
1952
+ shuffle,
2022
1953
  tasks: []
2023
1954
  };
2024
1955
  setHooks(suite2, createSuiteHooks());
@@ -2048,9 +1979,9 @@ function createSuiteCollector(name, factory = () => {
2048
1979
  return collector;
2049
1980
  }
2050
1981
  function createSuite() {
2051
- const suite2 = createChainable(["concurrent", "skip", "only", "todo"], function(name, factory) {
1982
+ const suite2 = createChainable(["concurrent", "shuffle", "skip", "only", "todo"], function(name, factory) {
2052
1983
  const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
2053
- return createSuiteCollector(name, factory, mode, this.concurrent);
1984
+ return createSuiteCollector(name, factory, mode, this.concurrent, this.shuffle);
2054
1985
  });
2055
1986
  suite2.each = (cases) => {
2056
1987
  return (name, fn) => {
@@ -4621,71 +4552,6 @@ defaultImplementation.createClock;
4621
4552
  defaultImplementation.install;
4622
4553
  var withGlobal_1 = withGlobal;
4623
4554
 
4624
- const RealDate = Date;
4625
- let now = null;
4626
- class MockDate extends RealDate {
4627
- constructor(y, m, d, h, M, s, ms) {
4628
- super();
4629
- let date;
4630
- switch (arguments.length) {
4631
- case 0:
4632
- if (now !== null)
4633
- date = new RealDate(now.valueOf());
4634
- else
4635
- date = new RealDate();
4636
- break;
4637
- case 1:
4638
- date = new RealDate(y);
4639
- break;
4640
- default:
4641
- d = typeof d === "undefined" ? 1 : d;
4642
- h = h || 0;
4643
- M = M || 0;
4644
- s = s || 0;
4645
- ms = ms || 0;
4646
- date = new RealDate(y, m, d, h, M, s, ms);
4647
- break;
4648
- }
4649
- return date;
4650
- }
4651
- }
4652
- MockDate.UTC = RealDate.UTC;
4653
- MockDate.now = function() {
4654
- return new MockDate().valueOf();
4655
- };
4656
- MockDate.parse = function(dateString) {
4657
- return RealDate.parse(dateString);
4658
- };
4659
- MockDate.toString = function() {
4660
- return RealDate.toString();
4661
- };
4662
- function mockDate(date) {
4663
- const dateObj = new RealDate(date.valueOf());
4664
- if (isNaN(dateObj.getTime()))
4665
- throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
4666
- globalThis.Date = MockDate;
4667
- now = dateObj.valueOf();
4668
- }
4669
- function resetDate() {
4670
- globalThis.Date = RealDate;
4671
- }
4672
-
4673
- var __defProp = Object.defineProperty;
4674
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4675
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4676
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
4677
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4678
- var __spreadValues = (a, b) => {
4679
- for (var prop in b || (b = {}))
4680
- if (__hasOwnProp.call(b, prop))
4681
- __defNormalProp(a, prop, b[prop]);
4682
- if (__getOwnPropSymbols)
4683
- for (var prop of __getOwnPropSymbols(b)) {
4684
- if (__propIsEnum.call(b, prop))
4685
- __defNormalProp(a, prop, b[prop]);
4686
- }
4687
- return a;
4688
- };
4689
4555
  class FakeTimers {
4690
4556
  constructor({
4691
4557
  global,
@@ -4747,10 +4613,11 @@ class FakeTimers {
4747
4613
  }
4748
4614
  if (!this._fakingTime) {
4749
4615
  const toFake = Object.keys(this._fakeTimers.timers);
4750
- this._clock = this._fakeTimers.install(__spreadValues({
4616
+ this._clock = this._fakeTimers.install({
4751
4617
  now: Date.now(),
4752
- toFake
4753
- }, this._userConfig));
4618
+ toFake,
4619
+ ...this._userConfig
4620
+ });
4754
4621
  this._fakingTime = true;
4755
4622
  }
4756
4623
  }
@@ -4932,4 +4799,4 @@ function isWatchMode() {
4932
4799
  return getRunningMode() === "watch";
4933
4800
  }
4934
4801
 
4935
- export { getState as A, GLOBAL_EXPECT as G, RealDate as R, isFirstRun as a, beforeAll as b, afterAll as c, describe as d, beforeEach as e, afterEach as f, createExpect as g, globalExpect as h, it as i, vi as j, getRunningMode as k, isWatchMode as l, resetRunOnceCounter as m, clearCollectorContext as n, defaultSuite as o, setHooks as p, getHooks as q, runOnce as r, suite as s, test as t, collectorContext as u, vitest as v, withCallback as w, getSnapshotClient as x, setState as y, getFn as z };
4802
+ export { getState as A, GLOBAL_EXPECT as G, isFirstRun as a, beforeAll as b, afterAll as c, describe as d, beforeEach as e, afterEach as f, createExpect as g, globalExpect as h, it as i, vi as j, getRunningMode as k, isWatchMode as l, resetRunOnceCounter as m, clearCollectorContext as n, defaultSuite as o, setHooks as p, getHooks as q, runOnce as r, suite as s, test as t, collectorContext as u, vitest as v, withCallback as w, getSnapshotClient as x, setState as y, getFn as z };
@@ -1,43 +1,23 @@
1
- import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.7450fc0c.mjs';
1
+ import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.af8ead96.mjs';
2
2
  import { normalizePath } from 'vite';
3
- import { a as getWorkerState, J as isWindows, K as mergeSlashes, d as dirname, m as resolve, l as basename, L as getType, M as getAllProperties, s as slash } from './chunk-utils-global.79a8b1cc.mjs';
3
+ import { a as getWorkerState, M as isWindows, N as mergeSlashes, d as dirname, j as join, o as basename, q as resolve, O as getType, P as getAllProperties, s as slash } from './chunk-utils-global.1b22c4fd.mjs';
4
4
  import { existsSync, readdirSync } from 'fs';
5
- import { d as distDir } from './chunk-constants.7b9cfc82.mjs';
5
+ import { d as distDir } from './chunk-constants.8eb2ed35.mjs';
6
6
 
7
- var __defProp = Object.defineProperty;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
7
  const _VitestMocker = class {
24
8
  constructor(options, moduleCache, request) {
25
9
  this.options = options;
26
10
  this.moduleCache = moduleCache;
27
- this.callbacks = {};
28
- this.root = this.options.root;
29
11
  this.request = request;
30
12
  }
31
- get mockMap() {
32
- return this.options.mockMap;
13
+ get root() {
14
+ return this.options.root;
33
15
  }
34
- on(event, cb) {
35
- var _a;
36
- (_a = this.callbacks)[event] ?? (_a[event] = []);
37
- this.callbacks[event].push(cb);
16
+ get base() {
17
+ return this.options.base;
38
18
  }
39
- emit(event, ...args) {
40
- (this.callbacks[event] ?? []).forEach((fn) => fn(...args));
19
+ get mockMap() {
20
+ return this.options.mockMap;
41
21
  }
42
22
  getSuiteFilepath() {
43
23
  return getWorkerState().filepath || "global";
@@ -46,7 +26,10 @@ const _VitestMocker = class {
46
26
  const suite = this.getSuiteFilepath();
47
27
  const suiteMocks = this.mockMap.get(suite);
48
28
  const globalMocks = this.mockMap.get("global");
49
- return __spreadValues(__spreadValues({}, globalMocks), suiteMocks);
29
+ return {
30
+ ...globalMocks,
31
+ ...suiteMocks
32
+ };
50
33
  }
51
34
  async resolvePath(id, importer) {
52
35
  const path = await this.options.resolveId(id, importer);
@@ -73,17 +56,14 @@ const _VitestMocker = class {
73
56
  if (cached)
74
57
  return cached;
75
58
  const exports = await mock();
76
- this.emit("mocked", cacheName, { exports });
59
+ this.moduleCache.set(cacheName, { exports });
77
60
  return exports;
78
61
  }
79
62
  getDependencyMock(dep) {
80
- return this.getMocks()[this.resolveDependency(dep)];
81
- }
82
- resolveDependency(dep) {
83
- return normalizeRequestId(dep.replace(this.root, "")).replace(/^\/@fs\//, isWindows ? "" : "/");
63
+ return this.getMocks()[this.normalizePath(dep)];
84
64
  }
85
65
  normalizePath(path) {
86
- return normalizeRequestId(path.replace(this.root, "")).replace(/^\/@fs\//, isWindows ? "" : "/");
66
+ return normalizeRequestId(path.replace(this.root, ""), this.base).replace(/^\/@fs\//, isWindows ? "" : "/");
87
67
  }
88
68
  getFsPath(path, external) {
89
69
  if (external)
@@ -94,7 +74,7 @@ const _VitestMocker = class {
94
74
  const path = normalizeRequestId(external || mockPath);
95
75
  if (external || isNodeBuiltin(mockPath) || !existsSync(mockPath)) {
96
76
  const mockDirname = dirname(path);
97
- const mockFolder = resolve(this.root, "__mocks__", mockDirname);
77
+ const mockFolder = join(this.root, "__mocks__", mockDirname);
98
78
  if (!existsSync(mockFolder))
99
79
  return null;
100
80
  const files = readdirSync(mockFolder);
@@ -102,14 +82,14 @@ const _VitestMocker = class {
102
82
  for (const file of files) {
103
83
  const [basename2] = file.split(".");
104
84
  if (basename2 === baseFilename)
105
- return resolve(mockFolder, file).replace(this.root, "");
85
+ return resolve(mockFolder, file);
106
86
  }
107
87
  return null;
108
88
  }
109
89
  const dir = dirname(path);
110
90
  const baseId = basename(path);
111
91
  const fullPath = resolve(dir, "__mocks__", baseId);
112
- return existsSync(fullPath) ? fullPath.replace(this.root, "") : null;
92
+ return existsSync(fullPath) ? fullPath : null;
113
93
  }
114
94
  mockValue(value) {
115
95
  if (!_VitestMocker.spyModule) {
@@ -135,17 +115,17 @@ const _VitestMocker = class {
135
115
  }
136
116
  unmockPath(path) {
137
117
  const suitefile = this.getSuiteFilepath();
138
- const fsPath = this.normalizePath(path);
118
+ const id = this.normalizePath(path);
139
119
  const mock = this.mockMap.get(suitefile);
140
- if (mock == null ? void 0 : mock[fsPath])
141
- delete mock[fsPath];
120
+ if (mock == null ? void 0 : mock[id])
121
+ delete mock[id];
142
122
  }
143
123
  mockPath(path, external, factory) {
144
124
  const suitefile = this.getSuiteFilepath();
145
- const fsPath = this.normalizePath(path);
146
- if (!this.mockMap.has(suitefile))
147
- this.mockMap.set(suitefile, {});
148
- this.mockMap.get(suitefile)[fsPath] = factory || this.resolveMockPath(path, external);
125
+ const id = this.normalizePath(path);
126
+ const mocks = this.mockMap.get(suitefile) || {};
127
+ mocks[id] = factory || this.resolveMockPath(path, external);
128
+ this.mockMap.set(suitefile, mocks);
149
129
  }
150
130
  async importActual(id, importer) {
151
131
  const { path, external } = await this.resolvePath(id, importer);
@@ -155,17 +135,17 @@ const _VitestMocker = class {
155
135
  }
156
136
  async importMock(id, importer) {
157
137
  const { path, external } = await this.resolvePath(id, importer);
158
- let mock = this.getDependencyMock(path);
138
+ const fsPath = this.getFsPath(path, external);
139
+ let mock = this.getDependencyMock(fsPath);
159
140
  if (mock === void 0)
160
- mock = this.resolveMockPath(path, external);
141
+ mock = this.resolveMockPath(fsPath, external);
161
142
  if (mock === null) {
162
143
  await this.ensureSpy();
163
- const fsPath = this.getFsPath(path, external);
164
144
  const mod = await this.request(fsPath);
165
145
  return this.mockValue(mod);
166
146
  }
167
147
  if (typeof mock === "function")
168
- return this.callFunctionMock(path, mock);
148
+ return this.callFunctionMock(fsPath, mock);
169
149
  return this.requestWithMock(mock);
170
150
  }
171
151
  async ensureSpy() {
@@ -175,8 +155,10 @@ const _VitestMocker = class {
175
155
  }
176
156
  async requestWithMock(dep) {
177
157
  var _a;
178
- await this.ensureSpy();
179
- await this.resolveMocks();
158
+ await Promise.all([
159
+ this.ensureSpy(),
160
+ this.resolveMocks()
161
+ ]);
180
162
  const mock = this.getDependencyMock(dep);
181
163
  const callstack = this.request.callstack;
182
164
  if (mock === null) {
@@ -187,7 +169,7 @@ const _VitestMocker = class {
187
169
  const cacheKey = toFilePath(dep, this.root);
188
170
  const mod = ((_a = this.moduleCache.get(cacheKey)) == null ? void 0 : _a.exports) || await this.request(dep);
189
171
  const exports = this.mockValue(mod);
190
- this.emit("mocked", cacheName, { exports });
172
+ this.moduleCache.set(cacheName, { exports });
191
173
  return exports;
192
174
  }
193
175
  if (typeof mock === "function" && !callstack.includes(`mock:${dep}`)) {
@@ -207,9 +189,6 @@ const _VitestMocker = class {
207
189
  queueUnmock(id, importer) {
208
190
  _VitestMocker.pendingIds.push({ type: "unmock", id, importer });
209
191
  }
210
- withRequest(request) {
211
- return new _VitestMocker(this.options, this.moduleCache, request);
212
- }
213
192
  };
214
193
  let VitestMocker = _VitestMocker;
215
194
  VitestMocker.pendingIds = [];
@@ -226,16 +205,11 @@ class VitestRunner extends ViteNodeRunner {
226
205
  constructor(options) {
227
206
  super(options);
228
207
  this.options = options;
229
- this.entries = /* @__PURE__ */ new Set();
230
- this.mocker = new VitestMocker(options, this.moduleCache);
231
208
  }
232
209
  prepareContext(context) {
233
210
  const request = context.__vite_ssr_import__;
234
211
  const resolveId = context.__vitest_resolve_id__;
235
- const mocker = this.mocker.withRequest(request);
236
- mocker.on("mocked", (dep, module) => {
237
- this.moduleCache.set(dep, module);
238
- });
212
+ const mocker = new VitestMocker(this.options, this.moduleCache, request);
239
213
  const workerState = getWorkerState();
240
214
  if (workerState.filepath && normalizePath(workerState.filepath) === normalizePath(context.__filename)) {
241
215
  Object.defineProperty(context.__vite_ssr_import_meta__, "vitest", { get: () => globalThis.__vitest_index__ });
@@ -1,4 +1,4 @@
1
- import { a as getWorkerState, w as withSafeTimers } from './chunk-utils-global.79a8b1cc.mjs';
1
+ import { a as getWorkerState, w as withSafeTimers } from './chunk-utils-global.1b22c4fd.mjs';
2
2
 
3
3
  const rpc = () => {
4
4
  const { rpc: rpc2 } = getWorkerState();