vitest 0.17.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/{chunk-api-setup.5282c6cb.mjs → chunk-api-setup.9d3f7670.mjs} +18 -9
  3. package/dist/{chunk-constants.511c6e9b.mjs → chunk-constants.d4406290.mjs} +1 -1
  4. package/dist/{chunk-env-node.dc514f41.mjs → chunk-env-node.bbba78e5.mjs} +9 -3
  5. package/dist/{chunk-install-pkg.3fa50769.mjs → chunk-install-pkg.2dcb2c04.mjs} +1 -1
  6. package/dist/chunk-integrations-globals.00b6e1ad.mjs +23 -0
  7. package/dist/{chunk-runtime-chain.68f305d0.mjs → chunk-runtime-chain.b60d57da.mjs} +39 -60
  8. package/dist/{chunk-runtime-mocker.1c207219.mjs → chunk-runtime-mocker.1d853e3a.mjs} +77 -29
  9. package/dist/{chunk-runtime-rpc.5e78af38.mjs → chunk-runtime-rpc.9d1f4c48.mjs} +1 -1
  10. package/dist/{chunk-utils-global.79a8b1cc.mjs → chunk-utils-global.0a7416cf.mjs} +70 -6
  11. package/dist/{chunk-utils-source-map.f52527bc.mjs → chunk-utils-source-map.c03f8bc4.mjs} +2 -2
  12. package/dist/{chunk-vite-node-externalize.1efbe319.mjs → chunk-vite-node-externalize.6956d2d9.mjs} +2666 -2552
  13. package/dist/chunk-vite-node-utils.8077cd3c.mjs +1422 -0
  14. package/dist/cli.mjs +13 -13
  15. package/dist/config.cjs +6 -1
  16. package/dist/config.d.ts +1 -1
  17. package/dist/config.mjs +6 -1
  18. package/dist/entry.mjs +638 -11
  19. package/dist/index.d.ts +125 -52
  20. package/dist/index.mjs +8 -8
  21. package/dist/node.d.ts +126 -54
  22. package/dist/node.mjs +13 -13
  23. package/dist/spy.mjs +102 -2
  24. package/dist/{vendor-index.e5dc6622.mjs → vendor-index.4bf9c627.mjs} +405 -405
  25. package/dist/{vendor-index.98e769c1.mjs → vendor-index.de788b6a.mjs} +7 -7
  26. package/dist/worker.mjs +9 -9
  27. package/package.json +12 -12
  28. package/dist/chunk-integrations-globals.6bb781c7.mjs +0 -26
  29. package/dist/chunk-integrations-spy.674b628e.mjs +0 -102
  30. package/dist/chunk-vite-node-utils.4b58ae05.mjs +0 -9192
  31. package/dist/vendor-entry.2edaf3e0.mjs +0 -653
package/LICENSE.md CHANGED
@@ -1245,7 +1245,7 @@ Repository: unjs/mlly
1245
1245
 
1246
1246
  > MIT License
1247
1247
  >
1248
- > Copyright (c) 2021
1248
+ > Copyright (c) 2022 UnJS
1249
1249
  >
1250
1250
  > Permission is hereby granted, free of charge, to any person obtaining a copy
1251
1251
  > of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
1
1
  import { promises } from 'fs';
2
- import { c as createBirpc } from './chunk-vite-node-utils.4b58ae05.mjs';
2
+ import { c as createBirpc } from './chunk-vite-node-utils.8077cd3c.mjs';
3
3
  import require$$0$1 from 'stream';
4
4
  import require$$0 from 'zlib';
5
5
  import require$$3 from 'net';
@@ -9,14 +9,14 @@ import require$$2 from 'events';
9
9
  import require$$1 from 'https';
10
10
  import require$$2$1 from 'http';
11
11
  import url from 'url';
12
- import { A as API_PATH } from './chunk-constants.511c6e9b.mjs';
13
- import { j as interpretSourcePos, b as parseStacktrace } from './chunk-utils-source-map.f52527bc.mjs';
12
+ import { A as API_PATH } from './chunk-constants.d4406290.mjs';
13
+ import { j as interpretSourcePos, b as parseStacktrace } from './chunk-utils-source-map.c03f8bc4.mjs';
14
14
  import 'module';
15
15
  import 'vm';
16
- import './chunk-utils-global.79a8b1cc.mjs';
16
+ import './chunk-utils-global.0a7416cf.mjs';
17
+ import 'path';
17
18
  import 'tty';
18
19
  import 'local-pkg';
19
- import 'path';
20
20
  import 'assert';
21
21
  import 'util';
22
22
  import 'debug';
@@ -3217,11 +3217,11 @@ function initAsClient(websocket, address, protocols, options) {
3217
3217
  ? parsedUrl.hostname.slice(1, -1)
3218
3218
  : parsedUrl.hostname;
3219
3219
  opts.headers = {
3220
+ ...opts.headers,
3220
3221
  'Sec-WebSocket-Version': opts.protocolVersion,
3221
3222
  'Sec-WebSocket-Key': key,
3222
3223
  Connection: 'Upgrade',
3223
- Upgrade: 'websocket',
3224
- ...opts.headers
3224
+ Upgrade: 'websocket'
3225
3225
  };
3226
3226
  opts.path = parsedUrl.pathname + parsedUrl.search;
3227
3227
  opts.timeout = opts.handshakeTimeout;
@@ -3275,8 +3275,11 @@ function initAsClient(websocket, address, protocols, options) {
3275
3275
 
3276
3276
  if (opts.followRedirects) {
3277
3277
  if (websocket._redirects === 0) {
3278
+ websocket._originalUnixSocket = isUnixSocket;
3278
3279
  websocket._originalSecure = isSecure;
3279
- websocket._originalHost = parsedUrl.host;
3280
+ websocket._originalHostOrSocketPath = isUnixSocket
3281
+ ? opts.socketPath
3282
+ : parsedUrl.host;
3280
3283
 
3281
3284
  const headers = options && options.headers;
3282
3285
 
@@ -3292,7 +3295,13 @@ function initAsClient(websocket, address, protocols, options) {
3292
3295
  }
3293
3296
  }
3294
3297
  } else if (websocket.listenerCount('redirect') === 0) {
3295
- const isSameHost = parsedUrl.host === websocket._originalHost;
3298
+ const isSameHost = isUnixSocket
3299
+ ? websocket._originalUnixSocket
3300
+ ? opts.socketPath === websocket._originalHostOrSocketPath
3301
+ : false
3302
+ : websocket._originalUnixSocket
3303
+ ? false
3304
+ : parsedUrl.host === websocket._originalHostOrSocketPath;
3296
3305
 
3297
3306
  if (!isSameHost || (websocket._originalSecure && !isSecure)) {
3298
3307
  //
@@ -1,5 +1,5 @@
1
1
  import { fileURLToPath } from 'url';
2
- import { m as resolve } from './chunk-utils-global.79a8b1cc.mjs';
2
+ import { q as resolve } from './chunk-utils-global.0a7416cf.mjs';
3
3
 
4
4
  const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
5
5
  const defaultPort = 51204;
@@ -2,7 +2,7 @@ import { importModule } from 'local-pkg';
2
2
  import { existsSync, promises } from 'fs';
3
3
  import { createRequire } from 'module';
4
4
  import { pathToFileURL } from 'url';
5
- import { C as toArray, m as resolve } from './chunk-utils-global.79a8b1cc.mjs';
5
+ import { F as toArray, q as resolve } from './chunk-utils-global.0a7416cf.mjs';
6
6
 
7
7
  var node = {
8
8
  name: "node",
@@ -237,7 +237,8 @@ const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
237
237
 
238
238
  const allowRewrite = [
239
239
  "Event",
240
- "EventTarget"
240
+ "EventTarget",
241
+ "MessageEvent"
241
242
  ];
242
243
  const skipKeys = [
243
244
  "window",
@@ -532,6 +533,7 @@ const defaultCoverageExcludes = [
532
533
  "test{,s}/**",
533
534
  "test{,-*}.{js,cjs,mjs,ts,tsx,jsx}",
534
535
  "**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}",
536
+ "**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}",
535
537
  "**/__tests__/**",
536
538
  "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc}.config.{js,cjs,mjs,ts}",
537
539
  "**/.{eslint,mocha,prettier}rc.{js,cjs,yml}"
@@ -575,7 +577,11 @@ const config = {
575
577
  hookTimeout: 1e4,
576
578
  isolate: true,
577
579
  watchExclude: ["**/node_modules/**", "**/dist/**"],
578
- forceRerunTriggers: [],
580
+ forceRerunTriggers: [
581
+ "**/package.json/**",
582
+ "**/vitest.config.*/**",
583
+ "**/vite.config.*/**"
584
+ ],
579
585
  update: false,
580
586
  reporters: [],
581
587
  silent: false,
@@ -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';
@@ -0,0 +1,23 @@
1
+ import { g as globalApis } from './chunk-constants.d4406290.mjs';
2
+ import { i as index } from './chunk-runtime-chain.b60d57da.mjs';
3
+ import 'url';
4
+ import './chunk-utils-global.0a7416cf.mjs';
5
+ import 'path';
6
+ import 'tty';
7
+ import 'local-pkg';
8
+ import 'util';
9
+ import 'chai';
10
+ import './vendor-_commonjsHelpers.4da45ef5.mjs';
11
+ import './chunk-runtime-rpc.9d1f4c48.mjs';
12
+ import 'fs';
13
+ import './chunk-utils-source-map.c03f8bc4.mjs';
14
+ import './spy.mjs';
15
+ import 'tinyspy';
16
+
17
+ function registerApiGlobally() {
18
+ globalApis.forEach((api) => {
19
+ globalThis[api] = index[api];
20
+ });
21
+ }
22
+
23
+ export { registerApiGlobally };
@@ -1,11 +1,11 @@
1
- import chai$1, { expect, AssertionError, util } from 'chai';
1
+ import require$$0, { format } from 'util';
2
+ 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.0a7416cf.mjs';
3
+ import chai$1, { expect, AssertionError, util, assert, should } from 'chai';
2
4
  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';
5
+ import { r as rpc } from './chunk-runtime-rpc.9d1f4c48.mjs';
5
6
  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.f52527bc.mjs';
7
- import { i as isMockFunction, s as spyOn, f as fn, a as spies } from './chunk-integrations-spy.674b628e.mjs';
8
- import require$$0, { format } from 'util';
7
+ 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.c03f8bc4.mjs';
8
+ import { isMockFunction, spyOn, fn, spies } from './spy.mjs';
9
9
 
10
10
  function createChainable(keys, fn) {
11
11
  function create(obj) {
@@ -1884,7 +1884,8 @@ function formatTitle(template, items, idx) {
1884
1884
  }
1885
1885
  const describe = suite;
1886
1886
  const it = test;
1887
- const defaultSuite = suite("");
1887
+ const workerState = getWorkerState();
1888
+ const defaultSuite = workerState.config.sequence.shuffle ? suite.shuffle("") : suite("");
1888
1889
  function clearCollectorContext() {
1889
1890
  collectorContext.tasks.length = 0;
1890
1891
  defaultSuite.clear();
@@ -1902,7 +1903,7 @@ function createSuiteHooks() {
1902
1903
  };
1903
1904
  }
1904
1905
  function createSuiteCollector(name, factory = () => {
1905
- }, mode, concurrent) {
1906
+ }, mode, concurrent, shuffle) {
1906
1907
  const tasks = [];
1907
1908
  const factoryQueue = [];
1908
1909
  let suite2;
@@ -1919,6 +1920,8 @@ function createSuiteCollector(name, factory = () => {
1919
1920
  };
1920
1921
  if (this.concurrent || concurrent)
1921
1922
  test3.concurrent = true;
1923
+ if (shuffle)
1924
+ test3.shuffle = true;
1922
1925
  const context = createTestContext(test3);
1923
1926
  Object.defineProperty(test3, "context", {
1924
1927
  value: context,
@@ -1946,6 +1949,7 @@ function createSuiteCollector(name, factory = () => {
1946
1949
  type: "suite",
1947
1950
  name,
1948
1951
  mode,
1952
+ shuffle,
1949
1953
  tasks: []
1950
1954
  };
1951
1955
  setHooks(suite2, createSuiteHooks());
@@ -1975,9 +1979,9 @@ function createSuiteCollector(name, factory = () => {
1975
1979
  return collector;
1976
1980
  }
1977
1981
  function createSuite() {
1978
- const suite2 = createChainable(["concurrent", "skip", "only", "todo"], function(name, factory) {
1982
+ const suite2 = createChainable(["concurrent", "shuffle", "skip", "only", "todo"], function(name, factory) {
1979
1983
  const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
1980
- return createSuiteCollector(name, factory, mode, this.concurrent);
1984
+ return createSuiteCollector(name, factory, mode, this.concurrent, this.shuffle);
1981
1985
  });
1982
1986
  suite2.each = (cases) => {
1983
1987
  return (name, fn) => {
@@ -4548,55 +4552,6 @@ defaultImplementation.createClock;
4548
4552
  defaultImplementation.install;
4549
4553
  var withGlobal_1 = withGlobal;
4550
4554
 
4551
- const RealDate = Date;
4552
- let now = null;
4553
- class MockDate extends RealDate {
4554
- constructor(y, m, d, h, M, s, ms) {
4555
- super();
4556
- let date;
4557
- switch (arguments.length) {
4558
- case 0:
4559
- if (now !== null)
4560
- date = new RealDate(now.valueOf());
4561
- else
4562
- date = new RealDate();
4563
- break;
4564
- case 1:
4565
- date = new RealDate(y);
4566
- break;
4567
- default:
4568
- d = typeof d === "undefined" ? 1 : d;
4569
- h = h || 0;
4570
- M = M || 0;
4571
- s = s || 0;
4572
- ms = ms || 0;
4573
- date = new RealDate(y, m, d, h, M, s, ms);
4574
- break;
4575
- }
4576
- return date;
4577
- }
4578
- }
4579
- MockDate.UTC = RealDate.UTC;
4580
- MockDate.now = function() {
4581
- return new MockDate().valueOf();
4582
- };
4583
- MockDate.parse = function(dateString) {
4584
- return RealDate.parse(dateString);
4585
- };
4586
- MockDate.toString = function() {
4587
- return RealDate.toString();
4588
- };
4589
- function mockDate(date) {
4590
- const dateObj = new RealDate(date.valueOf());
4591
- if (isNaN(dateObj.getTime()))
4592
- throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
4593
- globalThis.Date = MockDate;
4594
- now = dateObj.valueOf();
4595
- }
4596
- function resetDate() {
4597
- globalThis.Date = RealDate;
4598
- }
4599
-
4600
4555
  class FakeTimers {
4601
4556
  constructor({
4602
4557
  global,
@@ -4844,4 +4799,28 @@ function isWatchMode() {
4844
4799
  return getRunningMode() === "watch";
4845
4800
  }
4846
4801
 
4847
- 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
+ var index = /*#__PURE__*/Object.freeze({
4803
+ __proto__: null,
4804
+ suite: suite,
4805
+ test: test,
4806
+ describe: describe,
4807
+ it: it,
4808
+ runOnce: runOnce,
4809
+ isFirstRun: isFirstRun,
4810
+ beforeAll: beforeAll,
4811
+ afterAll: afterAll,
4812
+ beforeEach: beforeEach,
4813
+ afterEach: afterEach,
4814
+ withCallback: withCallback,
4815
+ assert: assert,
4816
+ should: should,
4817
+ createExpect: createExpect,
4818
+ chai: chai$1,
4819
+ expect: globalExpect,
4820
+ vitest: vitest,
4821
+ vi: vi,
4822
+ getRunningMode: getRunningMode,
4823
+ isWatchMode: isWatchMode
4824
+ });
4825
+
4826
+ export { getRunningMode as A, isWatchMode as B, GLOBAL_EXPECT as G, collectorContext as a, getSnapshotClient as b, clearCollectorContext as c, defaultSuite as d, setState as e, getFn as f, getHooks as g, getState as h, index as i, suite as j, describe as k, it as l, runOnce as m, isFirstRun as n, beforeAll as o, afterAll as p, beforeEach as q, resetRunOnceCounter as r, setHooks as s, test as t, afterEach as u, vi as v, withCallback as w, createExpect as x, globalExpect as y, vitest as z };
@@ -1,9 +1,30 @@
1
- import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.4b58ae05.mjs';
1
+ import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.8077cd3c.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, s as slash, O as getType, P as getAllProperties } from './chunk-utils-global.0a7416cf.mjs';
4
4
  import { existsSync, readdirSync } from 'fs';
5
- import { d as distDir } from './chunk-constants.511c6e9b.mjs';
5
+ import { d as distDir } from './chunk-constants.d4406290.mjs';
6
6
 
7
+ class RefTracker {
8
+ constructor() {
9
+ this.idMap = /* @__PURE__ */ new Map();
10
+ this.mockedValueMap = /* @__PURE__ */ new Map();
11
+ }
12
+ getId(value) {
13
+ return this.idMap.get(value);
14
+ }
15
+ getMockedValue(id) {
16
+ return this.mockedValueMap.get(id);
17
+ }
18
+ track(originalValue, mockedValue) {
19
+ const newId = this.idMap.size;
20
+ this.idMap.set(originalValue, newId);
21
+ this.mockedValueMap.set(newId, mockedValue);
22
+ return newId;
23
+ }
24
+ }
25
+ function isSpecialProp(prop, parentType) {
26
+ return parentType.includes("Function") && typeof prop === "string" && ["arguments", "callee", "caller", "length", "name"].includes(prop);
27
+ }
7
28
  const _VitestMocker = class {
8
29
  constructor(options, moduleCache, request) {
9
30
  this.options = options;
@@ -74,7 +95,7 @@ const _VitestMocker = class {
74
95
  const path = normalizeRequestId(external || mockPath);
75
96
  if (external || isNodeBuiltin(mockPath) || !existsSync(mockPath)) {
76
97
  const mockDirname = dirname(path);
77
- const mockFolder = resolve(this.root, "__mocks__", mockDirname);
98
+ const mockFolder = join(this.root, "__mocks__", mockDirname);
78
99
  if (!existsSync(mockFolder))
79
100
  return null;
80
101
  const files = readdirSync(mockFolder);
@@ -82,36 +103,63 @@ const _VitestMocker = class {
82
103
  for (const file of files) {
83
104
  const [basename2] = file.split(".");
84
105
  if (basename2 === baseFilename)
85
- return resolve(mockFolder, file).replace(this.root, "");
106
+ return resolve(mockFolder, file);
86
107
  }
87
108
  return null;
88
109
  }
89
110
  const dir = dirname(path);
90
111
  const baseId = basename(path);
91
112
  const fullPath = resolve(dir, "__mocks__", baseId);
92
- return existsSync(fullPath) ? fullPath.replace(this.root, "") : null;
113
+ return existsSync(fullPath) ? fullPath : null;
93
114
  }
94
- mockValue(value) {
115
+ mockObject(object) {
95
116
  if (!_VitestMocker.spyModule) {
96
117
  throw new Error("Error: Spy module is not defined. This is likely an internal bug in Vitest. Please report it to https://github.com/vitest-dev/vitest/issues");
97
118
  }
98
- const type = getType(value);
99
- if (Array.isArray(value))
100
- return [];
101
- else if (type !== "Object" && type !== "Module")
102
- return value;
103
- const newObj = {};
104
- const properties = getAllProperties(value);
105
- for (const k of properties) {
106
- newObj[k] = this.mockValue(value[k]);
107
- const type2 = getType(value[k]);
108
- if (type2.includes("Function") && !value[k]._isMockFunction) {
109
- _VitestMocker.spyModule.spyOn(newObj, k).mockImplementation(() => void 0);
110
- Object.defineProperty(newObj[k], "length", { value: 0 });
119
+ const spyModule = _VitestMocker.spyModule;
120
+ const finalizers = new Array();
121
+ const refs = new RefTracker();
122
+ const mockPropertiesOf = (container, newContainer) => {
123
+ const containerType = getType(container);
124
+ const isModule = containerType === "Module" || !!container.__esModule;
125
+ for (const property of getAllProperties(container)) {
126
+ if (!isModule) {
127
+ const descriptor = Object.getOwnPropertyDescriptor(container, property);
128
+ if ((descriptor == null ? void 0 : descriptor.get) || (descriptor == null ? void 0 : descriptor.set))
129
+ continue;
130
+ }
131
+ if (isSpecialProp(property, containerType))
132
+ continue;
133
+ const value = container[property];
134
+ const refId = refs.getId(value);
135
+ if (refId) {
136
+ finalizers.push(() => newContainer[property] = refs.getMockedValue(refId));
137
+ continue;
138
+ }
139
+ const type = getType(value);
140
+ if (Array.isArray(value)) {
141
+ newContainer[property] = [];
142
+ continue;
143
+ }
144
+ const isFunction = type.includes("Function") && typeof value === "function";
145
+ if ((!isFunction || value.__isMockFunction) && type !== "Object" && type !== "Module") {
146
+ newContainer[property] = value;
147
+ continue;
148
+ }
149
+ newContainer[property] = isFunction ? value : {};
150
+ if (isFunction) {
151
+ spyModule.spyOn(newContainer, property).mockImplementation(() => void 0);
152
+ Object.defineProperty(newContainer[property], "length", { value: 0 });
153
+ }
154
+ refs.track(value, newContainer[property]);
155
+ mockPropertiesOf(value, newContainer[property]);
111
156
  }
112
- }
113
- Object.setPrototypeOf(newObj, Object.getPrototypeOf(value));
114
- return newObj;
157
+ };
158
+ const mockedObject = {};
159
+ mockPropertiesOf(object, mockedObject);
160
+ for (const finalizer of finalizers)
161
+ finalizer();
162
+ return mockedObject;
115
163
  }
116
164
  unmockPath(path) {
117
165
  const suitefile = this.getSuiteFilepath();
@@ -135,17 +183,17 @@ const _VitestMocker = class {
135
183
  }
136
184
  async importMock(id, importer) {
137
185
  const { path, external } = await this.resolvePath(id, importer);
138
- let mock = this.getDependencyMock(path);
186
+ const fsPath = this.getFsPath(path, external);
187
+ let mock = this.getDependencyMock(fsPath);
139
188
  if (mock === void 0)
140
- mock = this.resolveMockPath(path, external);
189
+ mock = this.resolveMockPath(fsPath, external);
141
190
  if (mock === null) {
142
191
  await this.ensureSpy();
143
- const fsPath = this.getFsPath(path, external);
144
192
  const mod = await this.request(fsPath);
145
- return this.mockValue(mod);
193
+ return this.mockObject(mod);
146
194
  }
147
195
  if (typeof mock === "function")
148
- return this.callFunctionMock(path, mock);
196
+ return this.callFunctionMock(fsPath, mock);
149
197
  return this.requestWithMock(mock);
150
198
  }
151
199
  async ensureSpy() {
@@ -168,7 +216,7 @@ const _VitestMocker = class {
168
216
  return cache.exports;
169
217
  const cacheKey = toFilePath(dep, this.root);
170
218
  const mod = ((_a = this.moduleCache.get(cacheKey)) == null ? void 0 : _a.exports) || await this.request(dep);
171
- const exports = this.mockValue(mod);
219
+ const exports = this.mockObject(mod);
172
220
  this.moduleCache.set(cacheName, { exports });
173
221
  return exports;
174
222
  }
@@ -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.0a7416cf.mjs';
2
2
 
3
3
  const rpc = () => {
4
4
  const { rpc: rpc2 } = getWorkerState();
@@ -1,6 +1,6 @@
1
+ import path from 'path';
1
2
  import require$$0 from 'tty';
2
3
  import { isPackageExists } from 'local-pkg';
3
- import path from 'path';
4
4
 
5
5
  var picocolors = {exports: {}};
6
6
 
@@ -250,14 +250,63 @@ function getWorkerState() {
250
250
  return globalThis.__vitest_worker__;
251
251
  }
252
252
 
253
+ const RealDate = Date;
254
+ let now = null;
255
+ class MockDate extends RealDate {
256
+ constructor(y, m, d, h, M, s, ms) {
257
+ super();
258
+ let date;
259
+ switch (arguments.length) {
260
+ case 0:
261
+ if (now !== null)
262
+ date = new RealDate(now.valueOf());
263
+ else
264
+ date = new RealDate();
265
+ break;
266
+ case 1:
267
+ date = new RealDate(y);
268
+ break;
269
+ default:
270
+ d = typeof d === "undefined" ? 1 : d;
271
+ h = h || 0;
272
+ M = M || 0;
273
+ s = s || 0;
274
+ ms = ms || 0;
275
+ date = new RealDate(y, m, d, h, M, s, ms);
276
+ break;
277
+ }
278
+ return date;
279
+ }
280
+ }
281
+ MockDate.UTC = RealDate.UTC;
282
+ MockDate.now = function() {
283
+ return new MockDate().valueOf();
284
+ };
285
+ MockDate.parse = function(dateString) {
286
+ return RealDate.parse(dateString);
287
+ };
288
+ MockDate.toString = function() {
289
+ return RealDate.toString();
290
+ };
291
+ function mockDate(date) {
292
+ const dateObj = new RealDate(date.valueOf());
293
+ if (isNaN(dateObj.getTime()))
294
+ throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
295
+ globalThis.Date = MockDate;
296
+ now = dateObj.valueOf();
297
+ }
298
+ function resetDate() {
299
+ globalThis.Date = RealDate;
300
+ }
301
+
253
302
  function isFinalObj(obj) {
254
303
  return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
255
304
  }
256
305
  function collectOwnProperties(obj, collector) {
257
306
  const props = Object.getOwnPropertyNames(obj);
258
- const symbs = Object.getOwnPropertySymbols(obj);
307
+ const symbols = Object.getOwnPropertySymbols(obj);
259
308
  props.forEach((prop) => collector.add(prop));
260
- symbs.forEach((symb) => collector.add(symb));
309
+ symbols.forEach((symbol) => collector.add(symbol));
261
310
  }
262
311
  function getAllProperties(obj) {
263
312
  const allProps = /* @__PURE__ */ new Set();
@@ -358,6 +407,21 @@ function assertTypes(value, name, types) {
358
407
  function stdout() {
359
408
  return console._stdout || process.stdout;
360
409
  }
410
+ function random(seed) {
411
+ const x = Math.sin(seed++) * 1e4;
412
+ return x - Math.floor(x);
413
+ }
414
+ function shuffle(array, seed = RealDate.now()) {
415
+ let length = array.length;
416
+ while (length) {
417
+ const index = Math.floor(random(seed) * length--);
418
+ const previous = array[length];
419
+ array[length] = array[index];
420
+ array[index] = previous;
421
+ ++seed;
422
+ }
423
+ return array;
424
+ }
361
425
 
362
426
  function getTests(suite) {
363
427
  return toArray(suite).flatMap((s) => s.type === "test" ? [s] : s.tasks.flatMap((c) => c.type === "test" ? [c] : getTests(c)));
@@ -459,14 +523,14 @@ async function ensurePackageInstalled(dependency, promptInstall = !process.env.C
459
523
  `));
460
524
  if (!promptInstall)
461
525
  return false;
462
- const prompts = await import('./vendor-index.98e769c1.mjs').then(function (n) { return n.i; });
526
+ const prompts = await import('./vendor-index.de788b6a.mjs').then(function (n) { return n.i; });
463
527
  const { install } = await prompts.prompt({
464
528
  type: "confirm",
465
529
  name: "install",
466
530
  message: picocolors.exports.reset(`Do you want to install ${picocolors.exports.green(dependency)}?`)
467
531
  });
468
532
  if (install) {
469
- await (await import('./chunk-install-pkg.3fa50769.mjs')).installPackage(dependency, { dev: true });
533
+ await (await import('./chunk-install-pkg.2dcb2c04.mjs')).installPackage(dependency, { dev: true });
470
534
  process.stderr.write(picocolors.exports.yellow(`
471
535
  Package ${dependency} installed, re-run the command to start.
472
536
  `));
@@ -510,4 +574,4 @@ class AggregateErrorPonyfill extends Error {
510
574
  }
511
575
  }
512
576
 
513
- export { AggregateErrorPonyfill as A, safeClearInterval as B, toArray as C, normalize as D, deepMerge as E, toNamespacedPath as F, ensurePackageInstalled as G, stdout as H, extname as I, isWindows as J, mergeSlashes as K, getType as L, getAllProperties as M, deepClone as N, partitionSuiteChildren as O, hasTests as P, getWorkerState as a, getNames as b, assertTypes as c, dirname as d, getFullName as e, safeSetTimeout as f, getCallLastIndex as g, safeClearTimeout as h, isObject as i, join as j, notNullish as k, basename as l, resolve as m, noop as n, isAbsolute as o, picocolors as p, relative as q, resetModules as r, slash as s, isNode as t, getTests as u, hasFailed as v, withSafeTimers as w, hasFailedSnapshot as x, getSuites as y, safeSetInterval as z };
577
+ export { AggregateErrorPonyfill as A, safeSetInterval as B, safeClearInterval as C, getSuites as D, shuffle as E, toArray as F, normalize as G, deepMerge as H, toNamespacedPath as I, ensurePackageInstalled as J, stdout as K, extname as L, isWindows as M, mergeSlashes as N, getType as O, getAllProperties as P, deepClone as Q, RealDate as R, partitionSuiteChildren as S, hasTests as T, getWorkerState as a, getNames as b, assertTypes as c, dirname as d, getFullName as e, safeSetTimeout as f, getCallLastIndex as g, safeClearTimeout as h, isObject as i, join as j, resetModules as k, notNullish as l, mockDate as m, noop as n, basename as o, picocolors as p, resolve as q, resetDate as r, slash as s, isAbsolute as t, relative as u, isNode as v, withSafeTimers as w, getTests as x, hasFailed as y, hasFailedSnapshot as z };
@@ -1,4 +1,4 @@
1
- import { s as slash, k as notNullish, p as picocolors } from './chunk-utils-global.79a8b1cc.mjs';
1
+ import { s as slash, l as notNullish, p as picocolors } from './chunk-utils-global.0a7416cf.mjs';
2
2
 
3
3
  var build = {};
4
4
 
@@ -7435,4 +7435,4 @@ var matcherUtils = /*#__PURE__*/Object.freeze({
7435
7435
  diff: diff
7436
7436
  });
7437
7437
 
7438
- export { posToNumber as a, parseStacktrace as b, stripAnsi as c, stringWidth as d, ansiStyles as e, format_1 as f, getOriginalPos as g, sliceAnsi as h, cliTruncate as i, interpretSourcePos as j, lineSplitRE as l, matcherUtils as m, numberToPos as n, plugins_1 as p, stringify as s, unifiedDiff as u };
7438
+ export { posToNumber as a, parseStacktrace as b, stripAnsi as c, cliTruncate as d, stringWidth as e, format_1 as f, getOriginalPos as g, ansiStyles as h, sliceAnsi as i, interpretSourcePos as j, lineSplitRE as l, matcherUtils as m, numberToPos as n, plugins_1 as p, stringify as s, unifiedDiff as u };