vitest 0.19.1 → 0.20.2

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 (35) hide show
  1. package/dist/browser.d.ts +48 -3
  2. package/dist/browser.mjs +9 -7
  3. package/dist/{chunk-api-setup.0cf2c96a.mjs → chunk-api-setup.7c4c8879.mjs} +7 -6
  4. package/dist/{chunk-constants.38b43a44.mjs → chunk-constants.16825f0c.mjs} +3 -2
  5. package/dist/{chunk-defaults.ed196a9a.mjs → chunk-defaults.1c51d585.mjs} +6 -4
  6. package/dist/chunk-integrations-globals.56a11010.mjs +26 -0
  7. package/dist/{chunk-utils-global.2aa95025.mjs → chunk-mock-date.9160e13b.mjs} +6 -36
  8. package/dist/{chunk-node-git.9058b82a.mjs → chunk-node-git.43dbdd42.mjs} +1 -1
  9. package/dist/{chunk-runtime-chain.f2e00f4c.mjs → chunk-runtime-chain.b6c2cdbc.mjs} +5 -3
  10. package/dist/{chunk-runtime-error.606e0393.mjs → chunk-runtime-error.0aa0dc06.mjs} +17 -13
  11. package/dist/{chunk-runtime-hooks.d4cadf47.mjs → chunk-runtime-hooks.3ee34848.mjs} +7 -4
  12. package/dist/{chunk-runtime-mocker.dfdfd57b.mjs → chunk-runtime-mocker.0a8f7c5e.mjs} +23 -17
  13. package/dist/{chunk-runtime-rpc.45d8ee19.mjs → chunk-runtime-rpc.dbf0b31d.mjs} +3 -1
  14. package/dist/chunk-utils-global.fa20c2f6.mjs +5 -0
  15. package/dist/{chunk-utils-source-map.8b066ce2.mjs → chunk-utils-source-map.8198ebd9.mjs} +1 -1
  16. package/dist/chunk-utils-timers.b48455ed.mjs +27 -0
  17. package/dist/chunk-vite-node-client.a247c2c2.mjs +320 -0
  18. package/dist/chunk-vite-node-debug.c5887932.mjs +76 -0
  19. package/dist/{chunk-vite-node-externalize.e9af6472.mjs → chunk-vite-node-externalize.45323563.mjs} +76 -22
  20. package/dist/{chunk-vite-node-utils.ad73f2ab.mjs → chunk-vite-node-utils.9dfd1e3f.mjs} +4 -323
  21. package/dist/cli.mjs +9 -7
  22. package/dist/config.cjs +3 -2
  23. package/dist/config.d.ts +1 -0
  24. package/dist/config.mjs +3 -2
  25. package/dist/entry.mjs +10 -8
  26. package/dist/index.d.ts +49 -4
  27. package/dist/index.mjs +7 -5
  28. package/dist/loader.mjs +36 -0
  29. package/dist/node.d.ts +49 -3
  30. package/dist/node.mjs +10 -7
  31. package/dist/suite.mjs +6 -4
  32. package/dist/worker.mjs +9 -6
  33. package/package.json +6 -5
  34. package/suppress-warnings.cjs +20 -0
  35. package/dist/chunk-integrations-globals.1018e651.mjs +0 -24
package/dist/browser.d.ts CHANGED
@@ -266,7 +266,6 @@ declare class ViteNodeRunner {
266
266
  */
267
267
  interopedImport(path: string): Promise<any>;
268
268
  hasNestedDefault(target: any): any;
269
- private debugLog;
270
269
  }
271
270
  interface DepsHandlingOptions {
272
271
  external?: (string | RegExp)[];
@@ -337,6 +336,33 @@ interface ViteNodeServerOptions {
337
336
  ssr?: RegExp[];
338
337
  web?: RegExp[];
339
338
  };
339
+ debug?: DebuggerOptions;
340
+ }
341
+ interface DebuggerOptions {
342
+ /**
343
+ * Dump the transformed module to filesystem
344
+ * Passing a string will dump to the specified path
345
+ */
346
+ dumpModules?: boolean | string;
347
+ /**
348
+ * Read dumpped module from filesystem whenever exists.
349
+ * Useful for debugging by modifying the dump result from the filesystem.
350
+ */
351
+ loadDumppedModules?: boolean;
352
+ }
353
+
354
+ declare class Debugger {
355
+ options: DebuggerOptions;
356
+ dumpDir: string | undefined;
357
+ initPromise: Promise<void> | undefined;
358
+ externalizeMap: Map<string, string>;
359
+ constructor(root: string, options: DebuggerOptions);
360
+ clearDump(): Promise<void>;
361
+ encodeId(id: string): string;
362
+ recordExternalize(id: string, path: string): Promise<void>;
363
+ dumpFile(id: string, result: TransformResult | null): Promise<void>;
364
+ loadDump(id: string): Promise<TransformResult | null>;
365
+ writeInfo(): Promise<void>;
340
366
  }
341
367
 
342
368
  declare class ViteNodeServer {
@@ -348,6 +374,8 @@ declare class ViteNodeServer {
348
374
  timestamp: number;
349
375
  result: FetchResult;
350
376
  }>;
377
+ externalizeCache: Map<string, Promise<string | false>>;
378
+ debugger?: Debugger;
351
379
  constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
352
380
  shouldExternalize(id: string): Promise<string | false>;
353
381
  resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
@@ -374,16 +402,23 @@ interface WorkerPool {
374
402
  close: () => Promise<void>;
375
403
  }
376
404
 
405
+ interface CollectingPromise {
406
+ promise: Promise<void>;
407
+ resolve: () => void;
408
+ }
377
409
  declare class StateManager {
378
410
  filesMap: Map<string, File>;
379
411
  pathsSet: Set<string>;
412
+ collectingPromise: CollectingPromise | undefined;
380
413
  idMap: Map<string, Task>;
381
414
  taskFileMap: WeakMap<Task, File>;
382
415
  errorsSet: Set<unknown>;
383
416
  catchError(err: unknown, type: string): void;
384
417
  clearErrors(): void;
385
418
  getUnhandledErrors(): unknown[];
386
- getPaths(): string[];
419
+ startCollectingPaths(): void;
420
+ finishCollectingPaths(): void;
421
+ getPaths(): Promise<string[]>;
387
422
  getFiles(keys?: string[]): File[];
388
423
  getFilepaths(): string[];
389
424
  getFailedFilepaths(): string[];
@@ -892,6 +927,7 @@ interface Suite extends TaskBase {
892
927
  interface File extends Suite {
893
928
  filepath: string;
894
929
  collectDuration?: number;
930
+ setupDuration?: number;
895
931
  }
896
932
  interface Test<ExtraContext = {}> extends TaskBase {
897
933
  type: 'test';
@@ -1100,6 +1136,11 @@ interface InlineConfig {
1100
1136
  * @default false
1101
1137
  */
1102
1138
  fallbackCJS?: boolean;
1139
+ /**
1140
+ * Use experimental Node loader to resolve imports inside node_modules using Vite resolve algorithm.
1141
+ * @default true
1142
+ */
1143
+ registerNodeLoader?: boolean;
1103
1144
  };
1104
1145
  /**
1105
1146
  * Base directory to scan for the test files
@@ -1387,6 +1428,10 @@ interface InlineConfig {
1387
1428
  * Will be merged with the default aliases inside `resolve.alias`.
1388
1429
  */
1389
1430
  alias?: AliasOptions;
1431
+ /**
1432
+ * Ignore any unhandled errors that occur
1433
+ */
1434
+ dangerouslyIgnoreUnhandledErrors?: boolean;
1390
1435
  }
1391
1436
  interface UserConfig extends InlineConfig {
1392
1437
  /**
@@ -1820,7 +1865,7 @@ declare type MockedObject<T> = MaybeMockedConstructor<T> & {
1820
1865
  interface Constructable {
1821
1866
  new (...args: any[]): any;
1822
1867
  }
1823
- declare type MockedClass<T extends Constructable> = MockInstance<InstanceType<T>, T extends new (...args: infer P) => any ? P : never> & {
1868
+ declare type MockedClass<T extends Constructable> = MockInstance<T extends new (...args: infer P) => any ? P : never, InstanceType<T>> & {
1824
1869
  prototype: T extends {
1825
1870
  prototype: any;
1826
1871
  } ? Mocked<T['prototype']> : never;
package/dist/browser.mjs CHANGED
@@ -1,20 +1,22 @@
1
- export { c as createExpect, d as describe, b as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.f2e00f4c.mjs';
2
- export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach } from './chunk-runtime-hooks.d4cadf47.mjs';
3
- export { a as setupGlobalEnv, s as startTests } from './chunk-runtime-error.606e0393.mjs';
1
+ export { c as createExpect, d as describe, b as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.b6c2cdbc.mjs';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach } from './chunk-runtime-hooks.3ee34848.mjs';
3
+ export { a as setupGlobalEnv, s as startTests } from './chunk-runtime-error.0aa0dc06.mjs';
4
4
  import * as chai from 'chai';
5
5
  export { chai };
6
6
  export { assert, should } from 'chai';
7
7
  import 'util';
8
- import './chunk-utils-global.2aa95025.mjs';
8
+ import './chunk-mock-date.9160e13b.mjs';
9
9
  import 'path';
10
10
  import 'tty';
11
11
  import 'local-pkg';
12
12
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
13
- import './chunk-runtime-rpc.45d8ee19.mjs';
13
+ import './chunk-runtime-rpc.dbf0b31d.mjs';
14
+ import './chunk-utils-global.fa20c2f6.mjs';
15
+ import './chunk-utils-timers.b48455ed.mjs';
14
16
  import 'fs';
15
- import './chunk-utils-source-map.8b066ce2.mjs';
17
+ import './chunk-utils-source-map.8198ebd9.mjs';
16
18
  import './spy.mjs';
17
19
  import 'tinyspy';
18
- import './chunk-defaults.ed196a9a.mjs';
20
+ import './chunk-defaults.1c51d585.mjs';
19
21
  import 'module';
20
22
  import 'url';
@@ -1,5 +1,5 @@
1
1
  import { promises } from 'fs';
2
- import { c as createBirpc } from './chunk-vite-node-utils.ad73f2ab.mjs';
2
+ import { c as createBirpc } from './chunk-vite-node-client.a247c2c2.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,15 @@ 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.38b43a44.mjs';
13
- import { j as interpretSourcePos, p as parseStacktrace } from './chunk-utils-source-map.8b066ce2.mjs';
12
+ import { A as API_PATH } from './chunk-constants.16825f0c.mjs';
13
+ import { j as interpretSourcePos, p as parseStacktrace } from './chunk-utils-source-map.8198ebd9.mjs';
14
14
  import 'module';
15
15
  import 'vm';
16
- import './chunk-utils-global.2aa95025.mjs';
16
+ import './chunk-mock-date.9160e13b.mjs';
17
17
  import 'path';
18
18
  import 'tty';
19
19
  import 'local-pkg';
20
+ import './chunk-vite-node-utils.9dfd1e3f.mjs';
20
21
  import 'assert';
21
22
  import 'util';
22
23
  import 'debug';
@@ -4434,8 +4435,8 @@ function setup(ctx) {
4434
4435
  getFiles() {
4435
4436
  return ctx.state.getFiles();
4436
4437
  },
4437
- getPaths() {
4438
- return ctx.state.getPaths();
4438
+ async getPaths() {
4439
+ return await ctx.state.getPaths();
4439
4440
  },
4440
4441
  readFile(id) {
4441
4442
  return promises.readFile(id, "utf-8");
@@ -1,6 +1,7 @@
1
1
  import _url from 'url';
2
- import { C as resolve } from './chunk-utils-global.2aa95025.mjs';
2
+ import { y as resolve } from './chunk-mock-date.9160e13b.mjs';
3
3
 
4
+ const rootDir = resolve(_url.fileURLToPath(import.meta.url), "../../");
4
5
  const distDir = resolve(_url.fileURLToPath(import.meta.url), "../../dist");
5
6
  const defaultPort = 51204;
6
7
  const API_PATH = "/__vitest_api__";
@@ -34,4 +35,4 @@ const globalApis = [
34
35
  "afterEach"
35
36
  ];
36
37
 
37
- export { API_PATH as A, defaultPort as a, configFiles as c, distDir as d, globalApis as g };
38
+ export { API_PATH as A, defaultPort as a, configFiles as c, distDir as d, globalApis as g, rootDir as r };
@@ -1,7 +1,7 @@
1
1
  import { existsSync, promises } from 'fs';
2
2
  import { createRequire } from 'module';
3
3
  import _url from 'url';
4
- import { u as toArray, C as resolve } from './chunk-utils-global.2aa95025.mjs';
4
+ import { t as toArray, y as resolve } from './chunk-mock-date.9160e13b.mjs';
5
5
  import { importModule } from 'local-pkg';
6
6
 
7
7
  /*
@@ -162,7 +162,7 @@ const coverageConfigDefaults = {
162
162
  reportsDirectory: "./coverage",
163
163
  excludeNodeModules: true,
164
164
  exclude: defaultCoverageExcludes,
165
- reporter: ["text", "html"],
165
+ reporter: ["text", "html", "clover"],
166
166
  allowExternal: false,
167
167
  extension: [".js", ".cjs", ".mjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte"]
168
168
  };
@@ -212,7 +212,8 @@ const config = {
212
212
  },
213
213
  coverage: coverageConfigDefaults,
214
214
  fakeTimers: fakeTimersDefaults,
215
- maxConcurrency: 5
215
+ maxConcurrency: 5,
216
+ dangerouslyIgnoreUnhandledErrors: false
216
217
  };
217
218
  const configDefaults = Object.freeze(config);
218
219
 
@@ -525,7 +526,8 @@ const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
525
526
  const allowRewrite = [
526
527
  "Event",
527
528
  "EventTarget",
528
- "MessageEvent"
529
+ "MessageEvent",
530
+ "ArrayBuffer"
529
531
  ];
530
532
  const skipKeys = [
531
533
  "window",
@@ -0,0 +1,26 @@
1
+ import { g as globalApis } from './chunk-constants.16825f0c.mjs';
2
+ import { i as index } from './chunk-runtime-hooks.3ee34848.mjs';
3
+ import 'url';
4
+ import './chunk-mock-date.9160e13b.mjs';
5
+ import 'path';
6
+ import 'tty';
7
+ import 'local-pkg';
8
+ import './chunk-runtime-chain.b6c2cdbc.mjs';
9
+ import 'util';
10
+ import 'chai';
11
+ import './vendor-_commonjsHelpers.4da45ef5.mjs';
12
+ import './chunk-runtime-rpc.dbf0b31d.mjs';
13
+ import './chunk-utils-global.fa20c2f6.mjs';
14
+ import './chunk-utils-timers.b48455ed.mjs';
15
+ import 'fs';
16
+ import './chunk-utils-source-map.8198ebd9.mjs';
17
+ import './spy.mjs';
18
+ import 'tinyspy';
19
+
20
+ function registerApiGlobally() {
21
+ globalApis.forEach((api) => {
22
+ globalThis[api] = index[api];
23
+ });
24
+ }
25
+
26
+ export { registerApiGlobally };
@@ -246,10 +246,6 @@ const _path = /*#__PURE__*/Object.freeze({
246
246
  ..._path
247
247
  });
248
248
 
249
- function getWorkerState() {
250
- return globalThis.__vitest_worker__;
251
- }
252
-
253
249
  const RealDate = Date;
254
250
  let now = null;
255
251
  class MockDate extends RealDate {
@@ -456,32 +452,6 @@ function getNames(task) {
456
452
  return names;
457
453
  }
458
454
 
459
- const {
460
- setTimeout: safeSetTimeout,
461
- setInterval: safeSetInterval,
462
- clearInterval: safeClearInterval,
463
- clearTimeout: safeClearTimeout
464
- } = globalThis;
465
- function withSafeTimers(fn) {
466
- const currentSetTimeout = globalThis.setTimeout;
467
- const currentSetInterval = globalThis.setInterval;
468
- const currentClearInterval = globalThis.clearInterval;
469
- const currentClearTimeout = globalThis.clearTimeout;
470
- try {
471
- globalThis.setTimeout = safeSetTimeout;
472
- globalThis.setInterval = safeSetInterval;
473
- globalThis.clearInterval = safeClearInterval;
474
- globalThis.clearTimeout = safeClearTimeout;
475
- const result = fn();
476
- return result;
477
- } finally {
478
- globalThis.setTimeout = currentSetTimeout;
479
- globalThis.setInterval = currentSetInterval;
480
- globalThis.clearInterval = currentClearInterval;
481
- globalThis.clearTimeout = currentClearTimeout;
482
- }
483
- }
484
-
485
455
  var _a;
486
456
  const isNode = typeof process < "u" && typeof process.stdout < "u" && !((_a = process.versions) == null ? void 0 : _a.deno) && !globalThis.window;
487
457
  const isBrowser = typeof window !== "undefined";
@@ -502,15 +472,15 @@ function partitionSuiteChildren(suite) {
502
472
  tasksGroups.push(tasksGroup);
503
473
  return tasksGroups;
504
474
  }
505
- function resetModules() {
506
- const modules = getWorkerState().moduleCache;
507
- const vitestPaths = [
475
+ function resetModules(modules, resetMocks = false) {
476
+ const skipPaths = [
508
477
  /\/vitest\/dist\//,
509
478
  /vitest-virtual-\w+\/dist/,
510
- /@vitest\/dist/
479
+ /@vitest\/dist/,
480
+ ...!resetMocks ? [/^mock:/] : []
511
481
  ];
512
482
  modules.forEach((_, path) => {
513
- if (vitestPaths.some((re) => re.test(path)))
483
+ if (skipPaths.some((re) => re.test(path)))
514
484
  return;
515
485
  modules.delete(path);
516
486
  });
@@ -579,4 +549,4 @@ class AggregateErrorPonyfill extends Error {
579
549
  }
580
550
  }
581
551
 
582
- export { hasTests as A, hasFailed as B, resolve as C, basename as D, AggregateErrorPonyfill as E, isAbsolute as F, relative as G, getTests as H, hasFailedSnapshot as I, safeSetInterval as J, safeClearInterval as K, getSuites as L, normalize as M, deepMerge as N, toNamespacedPath as O, ensurePackageInstalled as P, stdout as Q, RealDate as R, extname as S, isWindows as T, mergeSlashes as U, getAllProperties as V, resetModules as a, getCallLastIndex as b, slash as c, dirname as d, getNames as e, assertTypes as f, getWorkerState as g, getFullName as h, isObject as i, join as j, safeClearTimeout as k, notNullish as l, mockDate as m, noop as n, deepClone as o, picocolors as p, getType as q, resetDate as r, safeSetTimeout as s, isNode as t, toArray as u, relativePath as v, withSafeTimers as w, isBrowser as x, partitionSuiteChildren as y, shuffle as z };
552
+ export { AggregateErrorPonyfill as A, isAbsolute as B, relative as C, getTests as D, hasFailedSnapshot as E, getSuites 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, getAllProperties as O, RealDate as R, resetModules as a, getNames as b, assertTypes as c, dirname as d, getFullName as e, notNullish as f, getCallLastIndex as g, deepClone as h, isObject as i, join as j, getType as k, isNode as l, mockDate as m, noop as n, relativePath as o, picocolors as p, isBrowser as q, resetDate as r, slash as s, toArray as t, partitionSuiteChildren as u, shuffle as v, hasTests as w, hasFailed as x, resolve as y, basename as z };
@@ -1,4 +1,4 @@
1
- import { C as resolve } from './chunk-utils-global.2aa95025.mjs';
1
+ import { y as resolve } from './chunk-mock-date.9160e13b.mjs';
2
2
  import { Buffer } from 'buffer';
3
3
  import path from 'path';
4
4
  import childProcess from 'child_process';
@@ -1,12 +1,14 @@
1
1
  import util$1 from 'util';
2
- import { i as isObject, j as join, d as dirname, b as getCallLastIndex, c as slash, g as getWorkerState, e as getNames, f as assertTypes, p as picocolors, h as getFullName, s as safeSetTimeout, k as safeClearTimeout, n as noop } from './chunk-utils-global.2aa95025.mjs';
2
+ import { i as isObject, j as join, d as dirname, g as getCallLastIndex, s as slash, b as getNames, c as assertTypes, p as picocolors, e as getFullName, n as noop } from './chunk-mock-date.9160e13b.mjs';
3
3
  import * as chai$2 from 'chai';
4
4
  import { expect, AssertionError, util } from 'chai';
5
5
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
6
- import { r as rpc } from './chunk-runtime-rpc.45d8ee19.mjs';
6
+ import { r as rpc } from './chunk-runtime-rpc.dbf0b31d.mjs';
7
7
  import fs, { promises } from 'fs';
8
- import { a as plugins_1, f as format_1, g as getOriginalPos, b as posToNumber, n as numberToPos, l as lineSplitRE, p as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils } from './chunk-utils-source-map.8b066ce2.mjs';
8
+ import { a as plugins_1, f as format_1, g as getOriginalPos, b as posToNumber, n as numberToPos, l as lineSplitRE, p as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils } from './chunk-utils-source-map.8198ebd9.mjs';
9
+ import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
9
10
  import { isMockFunction } from './spy.mjs';
11
+ import { s as safeSetTimeout, a as safeClearTimeout } from './chunk-utils-timers.b48455ed.mjs';
10
12
 
11
13
  function createChainable(keys, fn) {
12
14
  function create(obj) {
@@ -1,11 +1,13 @@
1
- import { e as environments, t as takeCoverage, p as pLimit } from './chunk-defaults.ed196a9a.mjs';
2
- import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.d4cadf47.mjs';
3
- import { o as deepClone, q as getType, t as isNode, g as getWorkerState, R as RealDate, k as safeClearTimeout, s as safeSetTimeout, u as toArray, v as relativePath, x as isBrowser, y as partitionSuiteChildren, z as shuffle, A as hasTests, B as hasFailed, h as getFullName } from './chunk-utils-global.2aa95025.mjs';
4
- import { e as clearCollectorContext, f as defaultSuite, h as setHooks, j as getHooks, k as collectorContext, l as setState, G as GLOBAL_EXPECT, m as getFn, n as getState } from './chunk-runtime-chain.f2e00f4c.mjs';
5
- import { r as rpc } from './chunk-runtime-rpc.45d8ee19.mjs';
1
+ import { e as environments, t as takeCoverage, p as pLimit } from './chunk-defaults.1c51d585.mjs';
2
+ import { r as resetRunOnceCounter, i as index, v as vi } from './chunk-runtime-hooks.3ee34848.mjs';
3
+ import { h as deepClone, k as getType, l as isNode, R as RealDate, t as toArray, o as relativePath, q as isBrowser, u as partitionSuiteChildren, v as shuffle, w as hasTests, x as hasFailed, e as getFullName } from './chunk-mock-date.9160e13b.mjs';
4
+ import { e as clearCollectorContext, f as defaultSuite, h as setHooks, j as getHooks, k as collectorContext, l as setState, G as GLOBAL_EXPECT, m as getFn, n as getState } from './chunk-runtime-chain.b6c2cdbc.mjs';
5
+ import { r as rpc } from './chunk-runtime-rpc.dbf0b31d.mjs';
6
6
  import util$1 from 'util';
7
7
  import { util } from 'chai';
8
- import { s as stringify } from './chunk-utils-source-map.8b066ce2.mjs';
8
+ import { s as stringify } from './chunk-utils-source-map.8198ebd9.mjs';
9
+ import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
10
+ import { a as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.b48455ed.mjs';
9
11
 
10
12
  const OBJECT_PROTO = Object.getPrototypeOf({});
11
13
  function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
@@ -128,7 +130,7 @@ async function setupGlobalEnv(config) {
128
130
  if (isNode)
129
131
  await setupConsoleLogSpy();
130
132
  if (config.globals)
131
- (await import('./chunk-integrations-globals.1018e651.mjs')).registerApiGlobally();
133
+ (await import('./chunk-integrations-globals.56a11010.mjs')).registerApiGlobally();
132
134
  }
133
135
  function setupDefines(defines) {
134
136
  for (const key in defines)
@@ -291,7 +293,10 @@ async function collectTests(paths, config) {
291
293
  };
292
294
  clearCollectorContext();
293
295
  try {
296
+ const setupStart = now$1();
294
297
  await runSetupFiles(config);
298
+ const collectStart = now$1();
299
+ file.setupDuration = collectStart - setupStart;
295
300
  if (config.browser && isBrowser)
296
301
  await importFromBrowser(filepath);
297
302
  else
@@ -304,13 +309,12 @@ async function collectTests(paths, config) {
304
309
  } else if (c.type === "suite") {
305
310
  file.tasks.push(c);
306
311
  } else {
307
- const start = now$1();
308
312
  const suite = await c.collect(file);
309
- file.collectDuration = now$1() - start;
310
313
  if (suite.name || suite.tasks.length)
311
314
  file.tasks.push(suite);
312
315
  }
313
316
  }
317
+ file.collectDuration = now$1() - collectStart;
314
318
  } catch (e) {
315
319
  file.result = {
316
320
  state: "fail",
@@ -437,7 +441,7 @@ async function sendTasksUpdate() {
437
441
  async function runTest(test) {
438
442
  var _a, _b;
439
443
  if (test.mode !== "run") {
440
- const { getSnapshotClient } = await import('./chunk-runtime-chain.f2e00f4c.mjs').then(function (n) { return n.p; });
444
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.b6c2cdbc.mjs').then(function (n) { return n.p; });
441
445
  getSnapshotClient().skipTestSnapshots(test);
442
446
  return;
443
447
  }
@@ -453,7 +457,7 @@ async function runTest(test) {
453
457
  updateTask(test);
454
458
  clearModuleMocks();
455
459
  if (isNode) {
456
- const { getSnapshotClient } = await import('./chunk-runtime-chain.f2e00f4c.mjs').then(function (n) { return n.p; });
460
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.b6c2cdbc.mjs').then(function (n) { return n.p; });
457
461
  await getSnapshotClient().setTest(test);
458
462
  }
459
463
  const workerState = getWorkerState();
@@ -506,7 +510,7 @@ async function runTest(test) {
506
510
  if (isBrowser && test.result.error)
507
511
  console.error(test.result.error.message, test.result.error.stackStr);
508
512
  if (isNode) {
509
- const { getSnapshotClient } = await import('./chunk-runtime-chain.f2e00f4c.mjs').then(function (n) { return n.p; });
513
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.b6c2cdbc.mjs').then(function (n) { return n.p; });
510
514
  getSnapshotClient().clearTest();
511
515
  }
512
516
  test.result.duration = now() - start;
@@ -618,7 +622,7 @@ async function startTestsBrowser(paths, config) {
618
622
  async function startTestsNode(paths, config) {
619
623
  const files = await collectTests(paths, config);
620
624
  rpc().onCollected(files);
621
- const { getSnapshotClient } = await import('./chunk-runtime-chain.f2e00f4c.mjs').then(function (n) { return n.p; });
625
+ const { getSnapshotClient } = await import('./chunk-runtime-chain.b6c2cdbc.mjs').then(function (n) { return n.p; });
622
626
  getSnapshotClient().clear();
623
627
  await runFiles(files, config);
624
628
  takeCoverage();
@@ -1,9 +1,11 @@
1
- import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, c as createExpect, b as globalExpect } from './chunk-runtime-chain.f2e00f4c.mjs';
2
- import { g as getWorkerState, R as RealDate, r as resetDate, m as mockDate, a as resetModules, s as safeSetTimeout } from './chunk-utils-global.2aa95025.mjs';
3
- import { p as parseStacktrace } from './chunk-utils-source-map.8b066ce2.mjs';
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, c as createExpect, b as globalExpect } from './chunk-runtime-chain.b6c2cdbc.mjs';
2
+ import { R as RealDate, r as resetDate, m as mockDate, a as resetModules } from './chunk-mock-date.9160e13b.mjs';
3
+ import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
4
+ import { p as parseStacktrace } from './chunk-utils-source-map.8198ebd9.mjs';
4
5
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
5
6
  import util from 'util';
6
7
  import { spyOn, fn, isMockFunction, spies } from './spy.mjs';
8
+ import { s as safeSetTimeout } from './chunk-utils-timers.b48455ed.mjs';
7
9
  import * as chai from 'chai';
8
10
  import { assert, should } from 'chai';
9
11
 
@@ -2772,7 +2774,8 @@ class VitestUtils {
2772
2774
  return this;
2773
2775
  }
2774
2776
  resetModules() {
2775
- resetModules();
2777
+ const state = getWorkerState();
2778
+ resetModules(state.moduleCache);
2776
2779
  return this;
2777
2780
  }
2778
2781
  async dynamicImportSettled() {
@@ -1,8 +1,10 @@
1
- import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.ad73f2ab.mjs';
1
+ import { V as ViteNodeRunner } from './chunk-vite-node-client.a247c2c2.mjs';
2
2
  import { normalizePath } from 'vite';
3
- import { g as getWorkerState, T as isWindows, U as mergeSlashes, d as dirname, j as join, D as basename, C as resolve, c as slash, q as getType, V as getAllProperties } from './chunk-utils-global.2aa95025.mjs';
3
+ import { M as isWindows, N as mergeSlashes, d as dirname, j as join, z as basename, y as resolve, s as slash, k as getType, O as getAllProperties } from './chunk-mock-date.9160e13b.mjs';
4
4
  import { existsSync, readdirSync } from 'fs';
5
- import { d as distDir } from './chunk-constants.38b43a44.mjs';
5
+ import { n as normalizeRequestId, i as isNodeBuiltin, b as toFilePath } from './chunk-vite-node-utils.9dfd1e3f.mjs';
6
+ import { d as distDir } from './chunk-constants.16825f0c.mjs';
7
+ import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
6
8
 
7
9
  class RefTracker {
8
10
  constructor() {
@@ -72,16 +74,18 @@ const _VitestMocker = class {
72
74
  }
73
75
  async callFunctionMock(dep, mock) {
74
76
  var _a;
75
- const cacheName = `${dep}__mock`;
76
- const cached = (_a = this.moduleCache.get(cacheName)) == null ? void 0 : _a.exports;
77
+ const cached = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
77
78
  if (cached)
78
79
  return cached;
79
80
  const exports = await mock();
80
- this.moduleCache.set(cacheName, { exports });
81
+ this.moduleCache.set(dep, { exports });
81
82
  return exports;
82
83
  }
83
- getDependencyMock(dep) {
84
- return this.getMocks()[this.normalizePath(dep)];
84
+ getMockPath(dep) {
85
+ return `mock:${dep}`;
86
+ }
87
+ getDependencyMock(id) {
88
+ return this.getMocks()[id];
85
89
  }
86
90
  normalizePath(path) {
87
91
  return normalizeRequestId(path.replace(this.root, ""), this.base).replace(/^\/@fs\//, isWindows ? "" : "/");
@@ -184,7 +188,8 @@ const _VitestMocker = class {
184
188
  async importMock(id, importer) {
185
189
  const { path, external } = await this.resolvePath(id, importer);
186
190
  const fsPath = this.getFsPath(path, external);
187
- let mock = this.getDependencyMock(fsPath);
191
+ const normalizedId = this.normalizePath(fsPath);
192
+ let mock = this.getDependencyMock(normalizedId);
188
193
  if (mock === void 0)
189
194
  mock = this.resolveMockPath(fsPath, external);
190
195
  if (mock === null) {
@@ -207,23 +212,24 @@ const _VitestMocker = class {
207
212
  this.ensureSpy(),
208
213
  this.resolveMocks()
209
214
  ]);
210
- const mock = this.getDependencyMock(dep);
215
+ const id = this.normalizePath(dep);
216
+ const mock = this.getDependencyMock(id);
211
217
  const callstack = this.request.callstack;
218
+ const mockPath = this.getMockPath(id);
212
219
  if (mock === null) {
213
- const cacheName = `${dep}__mock`;
214
- const cache = this.moduleCache.get(cacheName);
220
+ const cache = this.moduleCache.get(mockPath);
215
221
  if (cache == null ? void 0 : cache.exports)
216
222
  return cache.exports;
217
223
  const cacheKey = toFilePath(dep, this.root);
218
224
  const mod = ((_a = this.moduleCache.get(cacheKey)) == null ? void 0 : _a.exports) || await this.request(dep);
219
225
  const exports = this.mockObject(mod);
220
- this.moduleCache.set(cacheName, { exports });
226
+ this.moduleCache.set(mockPath, { exports });
221
227
  return exports;
222
228
  }
223
- if (typeof mock === "function" && !callstack.includes(`mock:${dep}`)) {
224
- callstack.push(`mock:${dep}`);
225
- const result = await this.callFunctionMock(dep, mock);
226
- const indexMock = callstack.indexOf(`mock:${dep}`);
229
+ if (typeof mock === "function" && !callstack.includes(mockPath)) {
230
+ callstack.push(mockPath);
231
+ const result = await this.callFunctionMock(mockPath, mock);
232
+ const indexMock = callstack.indexOf(mockPath);
227
233
  callstack.splice(indexMock, 1);
228
234
  return result;
229
235
  }
@@ -1,4 +1,6 @@
1
- import { g as getWorkerState, w as withSafeTimers } from './chunk-utils-global.2aa95025.mjs';
1
+ import './chunk-mock-date.9160e13b.mjs';
2
+ import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
3
+ import { w as withSafeTimers } from './chunk-utils-timers.b48455ed.mjs';
2
4
 
3
5
  const rpc = () => {
4
6
  const { rpc: rpc2 } = getWorkerState();
@@ -0,0 +1,5 @@
1
+ function getWorkerState() {
2
+ return globalThis.__vitest_worker__;
3
+ }
4
+
5
+ export { getWorkerState as g };
@@ -1,4 +1,4 @@
1
- import { c as slash, l as notNullish, p as picocolors } from './chunk-utils-global.2aa95025.mjs';
1
+ import { s as slash, f as notNullish, p as picocolors } from './chunk-mock-date.9160e13b.mjs';
2
2
 
3
3
  var build = {};
4
4
 
@@ -0,0 +1,27 @@
1
+ const {
2
+ setTimeout: safeSetTimeout,
3
+ setInterval: safeSetInterval,
4
+ clearInterval: safeClearInterval,
5
+ clearTimeout: safeClearTimeout
6
+ } = globalThis;
7
+ function withSafeTimers(fn) {
8
+ const currentSetTimeout = globalThis.setTimeout;
9
+ const currentSetInterval = globalThis.setInterval;
10
+ const currentClearInterval = globalThis.clearInterval;
11
+ const currentClearTimeout = globalThis.clearTimeout;
12
+ try {
13
+ globalThis.setTimeout = safeSetTimeout;
14
+ globalThis.setInterval = safeSetInterval;
15
+ globalThis.clearInterval = safeClearInterval;
16
+ globalThis.clearTimeout = safeClearTimeout;
17
+ const result = fn();
18
+ return result;
19
+ } finally {
20
+ globalThis.setTimeout = currentSetTimeout;
21
+ globalThis.setInterval = currentSetInterval;
22
+ globalThis.clearInterval = currentClearInterval;
23
+ globalThis.clearTimeout = currentClearTimeout;
24
+ }
25
+ }
26
+
27
+ export { safeClearTimeout as a, safeSetInterval as b, safeClearInterval as c, safeSetTimeout as s, withSafeTimers as w };