vitest 2.1.0-beta.6 → 2.1.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 (56) hide show
  1. package/LICENSE.md +52 -342
  2. package/dist/browser.d.ts +4 -2
  3. package/dist/browser.js +1 -1
  4. package/dist/chunks/{RandomSequencer.CjkAy_bL.js → RandomSequencer.Bh5-tlNJ.js} +10 -37
  5. package/dist/chunks/{base.BH-FAiX7.js → base.BlXpj3e_.js} +1 -29
  6. package/dist/chunks/{base.B-9RAXb6.js → base.CsQmmYBA.js} +2 -4
  7. package/dist/chunks/{cac.BZlOqtiQ.js → cac.Ce8UWvQp.js} +25 -16
  8. package/dist/chunks/{cli-api.B-2f6g4d.js → cli-api.KmLFBnKP.js} +2778 -3488
  9. package/dist/chunks/{creator.D0TxjnLa.js → creator.zfBZSJzo.js} +8 -11
  10. package/dist/chunks/{execute.DT9BA6zp.js → execute._eQQfgI8.js} +322 -232
  11. package/dist/chunks/{git.ZtkbKc8u.js → git.B5SDxu-n.js} +5 -5
  12. package/dist/chunks/{globals.Br36EZIp.js → globals.C03P0O1a.js} +3 -3
  13. package/dist/chunks/{index.CM5UI-4O.js → index.Bn75ITYg.js} +3 -3
  14. package/dist/chunks/index.CPD77dLA.js +133 -0
  15. package/dist/chunks/{index.dWDhoZDV.js → index.DkN6V87F.js} +1 -1
  16. package/dist/chunks/{index.m3Xip5Zz.js → index.iyKRMe3s.js} +1 -1
  17. package/dist/chunks/{index.C4LZENmc.js → index.zPibhCkV.js} +43 -45
  18. package/dist/chunks/mocker.cRtM890J.d.ts +17 -0
  19. package/dist/chunks/{reporters.B0Ao6Zu1.d.ts → reporters.WnPwkmgA.d.ts} +30 -22
  20. package/dist/chunks/{resolveConfig.C0vpvVRF.js → resolveConfig.-K5hHm0S.js} +19 -6
  21. package/dist/chunks/{runBaseTests.Cf8lGnUq.js → runBaseTests.9YDrdSI4.js} +6 -6
  22. package/dist/chunks/{setup-common.B7uEQsGB.js → setup-common.DV1PI68g.js} +1 -1
  23. package/dist/chunks/{utils.C3_cBsyn.js → utils.Cn0zI1t3.js} +16 -3
  24. package/dist/chunks/{utils.DO38lwfj.js → utils.Dbnmsfq1.js} +1 -1
  25. package/dist/chunks/{vi.DBepMgvg.js → vi.D6IHiKAI.js} +40 -46
  26. package/dist/chunks/{vite.Bvz2vSw0.d.ts → vite.D2yAwzwa.d.ts} +1 -1
  27. package/dist/chunks/{vm.kl9T_5ai.js → vm.CPXwWp4C.js} +1 -2
  28. package/dist/chunks/{worker.DTM-0OlZ.d.ts → worker.Bws9Zuxu.d.ts} +1 -1
  29. package/dist/chunks/{worker.CTdJUeeB.d.ts → worker.CmPmTxgH.d.ts} +1 -14
  30. package/dist/cli.js +2 -2
  31. package/dist/config.d.ts +2 -2
  32. package/dist/coverage.d.ts +1 -1
  33. package/dist/coverage.js +4 -4
  34. package/dist/execute.d.ts +12 -13
  35. package/dist/execute.js +3 -2
  36. package/dist/index.d.ts +17 -15
  37. package/dist/index.js +4 -4
  38. package/dist/mocker.d.ts +1 -0
  39. package/dist/mocker.js +1 -0
  40. package/dist/node.d.ts +15 -7
  41. package/dist/node.js +18 -16
  42. package/dist/reporters.d.ts +1 -1
  43. package/dist/reporters.js +5 -5
  44. package/dist/runners.js +2 -2
  45. package/dist/utils.d.ts +1 -0
  46. package/dist/worker.js +3 -2
  47. package/dist/workers/forks.js +5 -4
  48. package/dist/workers/runVmTests.js +5 -5
  49. package/dist/workers/threads.js +5 -4
  50. package/dist/workers/vmForks.js +4 -4
  51. package/dist/workers/vmThreads.js +4 -4
  52. package/dist/workers.d.ts +2 -2
  53. package/dist/workers.js +6 -5
  54. package/mocker.d.ts +1 -0
  55. package/package.json +22 -17
  56. package/dist/chunks/index.CWhwfxXK.js +0 -835
@@ -5,16 +5,16 @@ import '@vitest/runner/utils';
5
5
  import { getSafeTimers } from '@vitest/utils';
6
6
  import { g as getWorkerState } from './utils.Ck2hJTRs.js';
7
7
  import './env.CmHVDJnw.js';
8
- import { a as globalExpect, r as resetModules, v as vi } from './vi.DBepMgvg.js';
8
+ import { a as globalExpect, r as resetModules, v as vi } from './vi.D6IHiKAI.js';
9
9
  import { a as startCoverageInsideWorker, s as stopCoverageInsideWorker } from './coverage.zlNdAMHK.js';
10
- import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.dWDhoZDV.js';
10
+ import { a as resolveSnapshotEnvironment, s as setupChaiConfig, r as resolveTestRunner } from './index.DkN6V87F.js';
11
11
  import { createRequire } from 'node:module';
12
12
  import util from 'node:util';
13
13
  import timers from 'node:timers';
14
14
  import { installSourcemapsSupport } from 'vite-node/source-map';
15
15
  import { KNOWN_ASSET_TYPES } from 'vite-node/constants';
16
- import { V as VitestIndex } from './index.m3Xip5Zz.js';
17
- import { s as setupCommonEnv } from './setup-common.B7uEQsGB.js';
16
+ import { V as VitestIndex } from './index.iyKRMe3s.js';
17
+ import { s as setupCommonEnv } from './setup-common.DV1PI68g.js';
18
18
  import { c as closeInspector } from './inspector.70d6emsh.js';
19
19
  import 'std-env';
20
20
  import 'chai';
@@ -24,7 +24,7 @@ import '@vitest/snapshot';
24
24
  import '@vitest/utils/error';
25
25
  import './tasks.BZnCS9aT.js';
26
26
  import '@vitest/utils/source-map';
27
- import './base.BH-FAiX7.js';
27
+ import './base.BlXpj3e_.js';
28
28
  import './date.W2xKR2qe.js';
29
29
  import '@vitest/spy';
30
30
  import '../path.js';
@@ -122,7 +122,7 @@ async function run(method, files, config, environment, executor) {
122
122
  const isIsolatedThreads = config.pool === "threads" && (config.poolOptions?.threads?.isolate ?? true);
123
123
  const isIsolatedForks = config.pool === "forks" && (config.poolOptions?.forks?.isolate ?? true);
124
124
  if (isIsolatedThreads || isIsolatedForks) {
125
- workerState.mockMap.clear();
125
+ executor.mocker.reset();
126
126
  resetModules(workerState.moduleCache, true);
127
127
  }
128
128
  workerState.filepath = file;
@@ -13,7 +13,7 @@ async function setupCommonEnv(config) {
13
13
  globalSetup = true;
14
14
  setSafeTimers();
15
15
  if (config.globals) {
16
- (await import('./globals.Br36EZIp.js')).registerApiGlobally();
16
+ (await import('./globals.C03P0O1a.js')).registerApiGlobally();
17
17
  }
18
18
  }
19
19
  function setupDefines(defines) {
@@ -3,6 +3,8 @@ import { parseRegexp } from '@vitest/utils';
3
3
  const REGEXP_WRAP_PREFIX = "$$vitest:";
4
4
  const processSend = process.send?.bind(process);
5
5
  const processOn = process.on?.bind(process);
6
+ const processOff = process.off?.bind(process);
7
+ const dispose = [];
6
8
  function createThreadsRpcOptions({
7
9
  port
8
10
  }) {
@@ -15,6 +17,15 @@ function createThreadsRpcOptions({
15
17
  }
16
18
  };
17
19
  }
20
+ function disposeInternalListeners() {
21
+ for (const fn of dispose) {
22
+ try {
23
+ fn();
24
+ } catch {
25
+ }
26
+ }
27
+ dispose.length = 0;
28
+ }
18
29
  function createForksRpcOptions(nodeV8) {
19
30
  return {
20
31
  serialize: nodeV8.serialize,
@@ -23,12 +34,14 @@ function createForksRpcOptions(nodeV8) {
23
34
  processSend(v);
24
35
  },
25
36
  on(fn) {
26
- processOn("message", (message, ...extras) => {
37
+ const handler = (message, ...extras) => {
27
38
  if (message?.__tinypool_worker_message__) {
28
39
  return;
29
40
  }
30
41
  return fn(message, ...extras);
31
- });
42
+ };
43
+ processOn("message", handler);
44
+ dispose.push(() => processOff("message", handler));
32
45
  }
33
46
  };
34
47
  }
@@ -52,4 +65,4 @@ function unwrapSerializableConfig(config) {
52
65
  return config;
53
66
  }
54
67
 
55
- export { createThreadsRpcOptions as a, createForksRpcOptions as c, unwrapSerializableConfig as u };
68
+ export { createThreadsRpcOptions as a, createForksRpcOptions as c, disposeInternalListeners as d, unwrapSerializableConfig as u };
@@ -1,6 +1,6 @@
1
1
  import { isAbsolute, relative, dirname, basename } from 'pathe';
2
2
  import c from 'tinyrainbow';
3
- import { a as slash } from './base.BH-FAiX7.js';
3
+ import { a as slash } from './base.BlXpj3e_.js';
4
4
 
5
5
  const F_RIGHT = "\u2192";
6
6
  const F_DOWN = "\u2193";
@@ -11,7 +11,7 @@ import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/util
11
11
  import 'pathe';
12
12
  import './env.CmHVDJnw.js';
13
13
  import { parseSingleStack } from '@vitest/utils/source-map';
14
- import { i as isChildProcess } from './base.BH-FAiX7.js';
14
+ import { i as isChildProcess } from './base.BlXpj3e_.js';
15
15
  import { R as RealDate, r as resetDate, m as mockDate } from './date.W2xKR2qe.js';
16
16
  import { spyOn, fn, isMockFunction, mocks } from '@vitest/spy';
17
17
 
@@ -191,16 +191,16 @@ function getError(expected, promise) {
191
191
  }
192
192
  throw new Error("snapshot function didn't throw");
193
193
  }
194
- const SnapshotPlugin = (chai, utils) => {
195
- const getTestNames = (test) => {
196
- if (!test) {
197
- return {};
198
- }
199
- return {
200
- filepath: test.file.filepath,
201
- name: getNames(test).slice(1).join(" > ")
202
- };
194
+ function getTestNames(test) {
195
+ if (!test) {
196
+ return {};
197
+ }
198
+ return {
199
+ filepath: test.file.filepath,
200
+ name: getNames(test).slice(1).join(" > ")
203
201
  };
202
+ }
203
+ const SnapshotPlugin = (chai, utils) => {
204
204
  for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
205
205
  utils.addMethod(
206
206
  chai.Assertion.prototype,
@@ -463,7 +463,6 @@ function createExpect(test) {
463
463
  expect.getState = () => getState(expect);
464
464
  expect.setState = (state) => setState(state, expect);
465
465
  const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
466
- const testPath = getTestFile(test);
467
466
  setState(
468
467
  {
469
468
  // this should also add "snapshotState" that is added conditionally
@@ -474,7 +473,9 @@ function createExpect(test) {
474
473
  expectedAssertionsNumber: null,
475
474
  expectedAssertionsNumberErrorGen: null,
476
475
  environment: getCurrentEnvironment(),
477
- testPath,
476
+ get testPath() {
477
+ return getWorkerState().filepath;
478
+ },
478
479
  currentTestName: test ? getTestName(test) : globalState.currentTestName
479
480
  },
480
481
  expect
@@ -516,13 +517,6 @@ function createExpect(test) {
516
517
  chai$1.util.addMethod(expect, "hasAssertions", hasAssertions);
517
518
  return expect;
518
519
  }
519
- function getTestFile(test) {
520
- if (test) {
521
- return test.file.filepath;
522
- }
523
- const state = getWorkerState();
524
- return state.filepath;
525
- }
526
520
  const globalExpect = createExpect();
527
521
  Object.defineProperty(globalThis, GLOBAL_EXPECT, {
528
522
  value: globalExpect,
@@ -3469,18 +3463,6 @@ function waitUntil(callback, options = {}) {
3469
3463
  function createVitest() {
3470
3464
  let _mockedDate = null;
3471
3465
  let _config = null;
3472
- function _mocker() {
3473
- return typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy(
3474
- {},
3475
- {
3476
- get(_, name) {
3477
- throw new Error(
3478
- `Vitest mocker was not initialized in this environment. vi.${String(name)}() is forbidden.`
3479
- );
3480
- }
3481
- }
3482
- );
3483
- }
3484
3466
  const workerState = getWorkerState();
3485
3467
  let _timers;
3486
3468
  const timers = () => _timers ||= new FakeTimers({
@@ -3490,15 +3472,6 @@ function createVitest() {
3490
3472
  const _stubsGlobal = /* @__PURE__ */ new Map();
3491
3473
  const _stubsEnv = /* @__PURE__ */ new Map();
3492
3474
  const _envBooleans = ["PROD", "DEV", "SSR"];
3493
- const getImporter = (name) => {
3494
- const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 });
3495
- const stackArray = stackTrace.split("\n");
3496
- const importerStackIndex = stackArray.findIndex((stack2) => {
3497
- return stack2.includes(` at Object.${name}`) || stack2.includes(`${name}@`);
3498
- });
3499
- const stack = parseSingleStack(stackArray[importerStackIndex + 1]);
3500
- return stack?.file || "";
3501
- };
3502
3475
  const utils = {
3503
3476
  useFakeTimers(config) {
3504
3477
  if (isChildProcess()) {
@@ -3602,14 +3575,13 @@ function createVitest() {
3602
3575
  _mocker().queueMock(
3603
3576
  path,
3604
3577
  importer,
3605
- factory ? () => factory(
3578
+ typeof factory === "function" ? () => factory(
3606
3579
  () => _mocker().importActual(
3607
3580
  path,
3608
3581
  importer,
3609
3582
  _mocker().getMockContext().callstack
3610
3583
  )
3611
- ) : void 0,
3612
- true
3584
+ ) : factory
3613
3585
  );
3614
3586
  },
3615
3587
  unmock(path) {
@@ -3630,14 +3602,13 @@ function createVitest() {
3630
3602
  _mocker().queueMock(
3631
3603
  path,
3632
3604
  importer,
3633
- factory ? () => factory(
3605
+ typeof factory === "function" ? () => factory(
3634
3606
  () => _mocker().importActual(
3635
3607
  path,
3636
3608
  importer,
3637
3609
  _mocker().getMockContext().callstack
3638
3610
  )
3639
- ) : void 0,
3640
- false
3611
+ ) : factory
3641
3612
  );
3642
3613
  },
3643
3614
  doUnmock(path) {
@@ -3698,6 +3669,8 @@ function createVitest() {
3698
3669
  }
3699
3670
  if (_envBooleans.includes(name)) {
3700
3671
  process.env[name] = value ? "1" : "";
3672
+ } else if (value === void 0) {
3673
+ delete process.env[name];
3701
3674
  } else {
3702
3675
  process.env[name] = String(value);
3703
3676
  }
@@ -3748,5 +3721,26 @@ function createVitest() {
3748
3721
  }
3749
3722
  const vitest = createVitest();
3750
3723
  const vi = vitest;
3724
+ function _mocker() {
3725
+ return typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy(
3726
+ {},
3727
+ {
3728
+ get(_, name) {
3729
+ throw new Error(
3730
+ `Vitest mocker was not initialized in this environment. vi.${String(name)}() is forbidden.`
3731
+ );
3732
+ }
3733
+ }
3734
+ );
3735
+ }
3736
+ function getImporter(name) {
3737
+ const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 });
3738
+ const stackArray = stackTrace.split("\n");
3739
+ const importerStackIndex = stackArray.findIndex((stack2) => {
3740
+ return stack2.includes(` at Object.${name}`) || stack2.includes(`${name}@`);
3741
+ });
3742
+ const stack = parseSingleStack(stackArray[importerStackIndex + 1]);
3743
+ return stack?.file || "";
3744
+ }
3751
3745
 
3752
3746
  export { globalExpect as a, vitest as b, createExpect as c, getSnapshotClient as g, resetModules as r, vi as v };
@@ -1,4 +1,4 @@
1
- import { I as InlineConfig } from './reporters.B0Ao6Zu1.js';
1
+ import { I as InlineConfig } from './reporters.WnPwkmgA.js';
2
2
 
3
3
  type VitestInlineConfig = InlineConfig;
4
4
  declare module 'vite' {
@@ -2,7 +2,7 @@ import vm, { isContext } from 'node:vm';
2
2
  import { fileURLToPath, pathToFileURL } from 'node:url';
3
3
  import { dirname, basename, extname, normalize, join, resolve } from 'pathe';
4
4
  import { createCustomConsole } from './console.DI3gHgtH.js';
5
- import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.DT9BA6zp.js';
5
+ import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute._eQQfgI8.js';
6
6
  import { distDir } from '../path.js';
7
7
  import { dirname as dirname$1 } from 'node:path';
8
8
  import fs from 'node:fs';
@@ -822,7 +822,6 @@ async function runVmTests(method, state) {
822
822
  const executor = await startVitestExecutor({
823
823
  context,
824
824
  moduleCache: state.moduleCache,
825
- mockMap: state.mockMap,
826
825
  state,
827
826
  externalModulesExecutor,
828
827
  requestStubs: stubs
@@ -1,5 +1,5 @@
1
1
  import { MessagePort } from 'node:worker_threads';
2
- import { C as ContextRPC } from './worker.CTdJUeeB.js';
2
+ import { C as ContextRPC } from './worker.CmPmTxgH.js';
3
3
 
4
4
  interface WorkerContext extends ContextRPC {
5
5
  port: MessagePort;
@@ -4,18 +4,6 @@ import { S as SerializedConfig } from './config.CHuotKvS.js';
4
4
  import { SnapshotResult } from '@vitest/snapshot';
5
5
  import { T as TransformMode, U as UserConsoleLog, A as AfterSuiteRunMeta, E as Environment } from './environment.C5eAp3K6.js';
6
6
 
7
- type Promisable<T> = T | Promise<T>;
8
- type MockFactoryWithHelper<M = unknown> = (importOriginal: <T extends M = M>() => Promise<T>) => Promisable<Partial<M>>;
9
- type MockFactory = () => any;
10
- type MockMap = Map<string, Record<string, string | null | MockFactory>>;
11
- interface PendingSuiteMock {
12
- id: string;
13
- importer: string;
14
- type: 'mock' | 'unmock';
15
- throwIfCached: boolean;
16
- factory?: MockFactory;
17
- }
18
-
19
7
  interface RuntimeRPC {
20
8
  fetch: (id: string, transformMode: TransformMode) => Promise<{
21
9
  externalize?: string;
@@ -134,7 +122,6 @@ interface WorkerGlobalState {
134
122
  environmentTeardownRun?: boolean;
135
123
  onCancel: Promise<CancelReason>;
136
124
  moduleCache: ModuleCacheMap;
137
- mockMap: MockMap;
138
125
  providedContext: Record<string, any>;
139
126
  durations: {
140
127
  environment: number;
@@ -142,4 +129,4 @@ interface WorkerGlobalState {
142
129
  };
143
130
  }
144
131
 
145
- export type { BirpcOptions as B, ContextRPC as C, MockFactoryWithHelper as M, PendingSuiteMock as P, RuntimeRPC as R, WorkerGlobalState as W, BirpcReturn as a, RunnerRPC as b, ResolveIdFunction as c, WorkerRPC as d, ContextTestEnvironment as e, MockFactory as f, MockMap as g };
132
+ export type { BirpcOptions as B, ContextRPC as C, RuntimeRPC as R, WorkerGlobalState as W, BirpcReturn as a, RunnerRPC as b, ResolveIdFunction as c, WorkerRPC as d, ContextTestEnvironment as e };
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
- import { c as createCLI } from './chunks/cac.BZlOqtiQ.js';
1
+ import { c as createCLI } from './chunks/cac.Ce8UWvQp.js';
2
2
  import 'pathe';
3
3
  import 'events';
4
4
  import 'tinyrainbow';
5
- import './chunks/base.BH-FAiX7.js';
5
+ import './chunks/base.BlXpj3e_.js';
6
6
  import '@vitest/utils';
7
7
  import './chunks/constants.fzPh7AOq.js';
8
8
 
package/dist/config.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import './chunks/vite.Bvz2vSw0.js';
1
+ import './chunks/vite.D2yAwzwa.js';
2
2
  import { ConfigEnv, UserConfig } from 'vite';
3
3
  export { ConfigEnv, Plugin, UserConfig, mergeConfig } from 'vite';
4
- import { R as ResolvedCoverageOptions, b as CoverageV8Options, U as UserWorkspaceConfig, c as UserProjectConfigFn, d as UserProjectConfigExport, W as WorkspaceProjectConfiguration } from './chunks/reporters.B0Ao6Zu1.js';
4
+ import { R as ResolvedCoverageOptions, b as CoverageV8Options, U as UserWorkspaceConfig, c as UserProjectConfigFn, d as UserProjectConfigExport, W as WorkspaceProjectConfiguration } from './chunks/reporters.WnPwkmgA.js';
5
5
  import '@vitest/runner';
6
6
  import '@vitest/pretty-format';
7
7
  import './chunks/config.CHuotKvS.js';
@@ -1,5 +1,5 @@
1
1
  import * as vite from 'vite';
2
- import { B as BaseCoverageOptions, R as ResolvedCoverageOptions, V as Vitest } from './chunks/reporters.B0Ao6Zu1.js';
2
+ import { B as BaseCoverageOptions, R as ResolvedCoverageOptions, V as Vitest } from './chunks/reporters.WnPwkmgA.js';
3
3
  import '@vitest/runner';
4
4
  import '@vitest/pretty-format';
5
5
  import './chunks/config.CHuotKvS.js';
package/dist/coverage.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { relative } from 'pathe';
2
- import { m as mm, r as resolveCoverageReporters } from './chunks/resolveConfig.C0vpvVRF.js';
2
+ import { m as mm, r as resolveCoverageReporters } from './chunks/resolveConfig.-K5hHm0S.js';
3
3
  import 'node:path';
4
4
  import 'node:fs';
5
5
  import 'node:fs/promises';
@@ -15,13 +15,13 @@ import 'node:os';
15
15
  import './chunks/env.CmHVDJnw.js';
16
16
  import 'std-env';
17
17
  import '@vitest/runner/utils';
18
- import './chunks/base.BH-FAiX7.js';
18
+ import './chunks/base.BlXpj3e_.js';
19
19
  import '@vitest/utils';
20
20
  import 'node:crypto';
21
- import './chunks/RandomSequencer.CjkAy_bL.js';
21
+ import './chunks/RandomSequencer.Bh5-tlNJ.js';
22
22
  import 'node:perf_hooks';
23
- import 'execa';
24
23
  import '@vitest/utils/source-map';
24
+ import 'tinyexec';
25
25
  import 'path';
26
26
  import 'fs';
27
27
  import 'module';
package/dist/execute.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import vm from 'node:vm';
2
2
  import { ViteNodeRunner } from 'vite-node/client';
3
3
  import { ViteNodeRunnerOptions } from 'vite-node';
4
- import { P as PendingSuiteMock, f as MockFactory, R as RuntimeRPC, W as WorkerGlobalState, g as MockMap } from './chunks/worker.CTdJUeeB.js';
4
+ import { R as RuntimeRPC, W as WorkerGlobalState } from './chunks/worker.CmPmTxgH.js';
5
+ import * as _vitest_mocker from '@vitest/mocker';
6
+ import { MockedModuleType } from '@vitest/mocker';
7
+ import { P as PendingSuiteMock, b as MockFactory, a as MockOptions } from './chunks/mocker.cRtM890J.js';
5
8
  import '@vitest/runner';
6
9
  import './chunks/config.CHuotKvS.js';
7
10
  import '@vitest/pretty-format';
@@ -9,7 +12,6 @@ import '@vitest/snapshot';
9
12
  import '@vitest/snapshot/environment';
10
13
  import './chunks/environment.C5eAp3K6.js';
11
14
 
12
- type Key = string | symbol;
13
15
  interface MockContext {
14
16
  /**
15
17
  * When mocking with a factory, this refers to the module that imported the mock.
@@ -20,39 +22,37 @@ declare class VitestMocker {
20
22
  executor: VitestExecutor;
21
23
  static pendingIds: PendingSuiteMock[];
22
24
  private spyModule?;
23
- private resolveCache;
24
25
  private primitives;
25
26
  private filterPublicKeys;
27
+ private registries;
26
28
  private mockContext;
27
29
  constructor(executor: VitestExecutor);
28
30
  private get root();
29
- private get mockMap();
30
31
  private get moduleCache();
31
32
  private get moduleDirectories();
32
33
  initializeSpyModule(): Promise<void>;
34
+ private getMockerRegistry;
35
+ reset(): void;
33
36
  private deleteCachedItem;
34
37
  private isModuleDirectory;
35
38
  getSuiteFilepath(): string;
36
39
  private createError;
37
- getMocks(): {
38
- [x: string]: string | MockFactory | null;
39
- };
40
40
  private resolvePath;
41
41
  resolveMocks(): Promise<void>;
42
42
  private callFunctionMock;
43
43
  getMockContext(): MockContext;
44
44
  getMockPath(dep: string): string;
45
- getDependencyMock(id: string): string | MockFactory | null;
45
+ getDependencyMock(id: string): _vitest_mocker.MockedModule | undefined;
46
46
  normalizePath(path: string): string;
47
47
  resolveMockPath(mockPath: string, external: string | null): string | null;
48
- mockObject(object: Record<Key, any>, mockExports?: Record<Key, any>): Record<Key, any>;
48
+ mockObject(object: Record<string | symbol, any>, mockExports?: Record<string | symbol, any>, behavior?: MockedModuleType): Record<string | symbol, any>;
49
49
  unmockPath(path: string): void;
50
- mockPath(originalId: string, path: string, external: string | null, factory: MockFactory | undefined): void;
50
+ mockPath(originalId: string, path: string, external: string | null, mockType: MockedModuleType | undefined, factory: MockFactory | undefined): void;
51
51
  importActual<T>(rawId: string, importer: string, callstack?: string[] | null): Promise<T>;
52
52
  importMock(rawId: string, importee: string): Promise<any>;
53
53
  requestWithMock(url: string, callstack: string[]): Promise<any>;
54
- queueMock(id: string, importer: string, factory?: MockFactory, throwIfCached?: boolean): void;
55
- queueUnmock(id: string, importer: string, throwIfCached?: boolean): void;
54
+ queueMock(id: string, importer: string, factoryOrOptions?: MockFactory | MockOptions): void;
55
+ queueUnmock(id: string, importer: string): void;
56
56
  }
57
57
 
58
58
  interface ModuleEvaluateOptions {
@@ -115,7 +115,6 @@ declare class ExternalModulesExecutor {
115
115
  }
116
116
 
117
117
  interface ExecuteOptions extends ViteNodeRunnerOptions {
118
- mockMap: MockMap;
119
118
  moduleDirectories?: string[];
120
119
  state: WorkerGlobalState;
121
120
  context?: vm.Context;
package/dist/execute.js CHANGED
@@ -1,4 +1,4 @@
1
- export { V as VitestExecutor } from './chunks/execute.DT9BA6zp.js';
1
+ export { V as VitestExecutor } from './chunks/execute._eQQfgI8.js';
2
2
  import 'node:vm';
3
3
  import 'node:url';
4
4
  import 'node:fs';
@@ -8,4 +8,5 @@ import 'pathe';
8
8
  import '@vitest/utils/error';
9
9
  import './path.js';
10
10
  import '@vitest/utils';
11
- import './chunks/base.BH-FAiX7.js';
11
+ import '@vitest/mocker';
12
+ import 'node:module';
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import './chunks/vite.Bvz2vSw0.js';
1
+ import './chunks/vite.D2yAwzwa.js';
2
2
  import { Plugin } from '@vitest/pretty-format';
3
3
  import { SnapshotState } from '@vitest/snapshot';
4
4
  export { SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotSerializer, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, UncheckedSnapshot } from '@vitest/snapshot';
5
5
  import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
6
6
  export { Assertion, AsymmetricMatchersContaining, ExpectPollOptions, ExpectStatic, JestAssertion } from '@vitest/expect';
7
- import { e as VitestEnvironment$1, S as SerializedSpec, f as RawErrsMap$1, T as TscErrorInfo$1, g as CollectLineNumbers$1, h as CollectLines$1, i as RootAndTarget$1, j as Context$1, C as CoverageProvider$1, k as ReportContext$1, a as CoverageProviderModule$1, l as CoverageReporter$1, m as CoverageProviderName, n as CoverageOptions$1, R as ResolvedCoverageOptions$1, B as BaseCoverageOptions$1, o as CoverageIstanbulOptions$1, b as CoverageV8Options$1, p as CustomProviderOptions$1, q as Reporter$1, V as Vitest$1, r as BrowserScript$1, s as BrowserConfigOptions$1, t as BuiltinEnvironment$1, P as Pool$1, u as PoolOptions$1, v as CSSModuleScopeStrategy$1, A as ApiConfig$1, w as VitestRunMode$1, D as DepsOptimizationOptions$1, x as TransformModePatterns$1, I as InlineConfig$1, y as TypecheckConfig$1, z as UserConfig$1, E as ResolvedConfig$1, F as ProjectConfig$1, U as UserWorkspaceConfig$1, G as BenchmarkUserOptions$1 } from './chunks/reporters.B0Ao6Zu1.js';
7
+ import { e as VitestEnvironment$1, S as SerializedTestSpecification, f as RawErrsMap$1, T as TscErrorInfo$1, g as CollectLineNumbers$1, h as CollectLines$1, i as RootAndTarget$1, j as Context$1, C as CoverageProvider$1, k as ReportContext$1, a as CoverageProviderModule$1, l as CoverageReporter$1, m as CoverageProviderName, n as CoverageOptions$1, R as ResolvedCoverageOptions$1, B as BaseCoverageOptions$1, o as CoverageIstanbulOptions$1, b as CoverageV8Options$1, p as CustomProviderOptions$1, q as Reporter$1, V as Vitest$1, r as BrowserScript$1, s as BrowserConfigOptions$1, t as BuiltinEnvironment$1, P as Pool$1, u as PoolOptions$1, v as CSSModuleScopeStrategy$1, A as ApiConfig$1, w as VitestRunMode$1, D as DepsOptimizationOptions$1, x as TransformModePatterns$1, I as InlineConfig$1, y as TypecheckConfig$1, z as UserConfig$1, E as ResolvedConfig$1, F as ProjectConfig$1, U as UserWorkspaceConfig$1, G as BenchmarkUserOptions$1 } from './chunks/reporters.WnPwkmgA.js';
8
8
  import { B as BenchmarkResult } from './chunks/benchmark.puBFxyfE.js';
9
9
  export { b as BenchFunction, a as Benchmark, c as BenchmarkAPI } from './chunks/benchmark.puBFxyfE.js';
10
10
  import { U as UserConsoleLog, P as ProvidedContext, M as ModuleGraphData, b as Awaitable$1, N as Nullable$1, c as Arrayable$1, d as ArgumentsType$1, e as MutableArray$1, C as Constructable$1, O as OnServerRestartHandler$1, a as EnvironmentReturn$1, V as VmEnvironmentReturn$1, E as Environment$1, R as ResolvedTestEnvironment$1, J as JSDOMOptions$1, H as HappyDOMOptions$1, f as EnvironmentOptions$1 } from './chunks/environment.C5eAp3K6.js';
@@ -14,11 +14,12 @@ export { CancelReason, DoneCallback, ExtendedContext, HookCleanupCallback, HookL
14
14
  export { b as bench } from './chunks/suite.CcK46U-P.js';
15
15
  import { F as FakeTimerInstallOpts, R as RuntimeOptions, S as SerializedConfig } from './chunks/config.CHuotKvS.js';
16
16
  export { b as RuntimeConfig, a as SerializedCoverageConfig } from './chunks/config.CHuotKvS.js';
17
- import { M as MockFactoryWithHelper, a as BirpcReturn } from './chunks/worker.CTdJUeeB.js';
18
- export { C as ContextRPC, e as ContextTestEnvironment, c as ResolveIdFunction, b as RunnerRPC, R as RuntimeRPC, W as WorkerGlobalState, d as WorkerRPC } from './chunks/worker.CTdJUeeB.js';
17
+ import { M as MockFactoryWithHelper, a as MockOptions } from './chunks/mocker.cRtM890J.js';
19
18
  import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, MockInstance } from '@vitest/spy';
20
19
  export { Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject } from '@vitest/spy';
21
- export { W as WorkerContext } from './chunks/worker.DTM-0OlZ.js';
20
+ import { a as BirpcReturn } from './chunks/worker.CmPmTxgH.js';
21
+ export { C as ContextRPC, e as ContextTestEnvironment, c as ResolveIdFunction, b as RunnerRPC, R as RuntimeRPC, W as WorkerGlobalState, d as WorkerRPC } from './chunks/worker.CmPmTxgH.js';
22
+ export { W as WorkerContext } from './chunks/worker.Bws9Zuxu.js';
22
23
  export { ErrorWithDiff, ParsedStack, SerializedError, TestError } from '@vitest/utils';
23
24
  export { DiffOptions } from '@vitest/utils/diff';
24
25
  import * as chai from 'chai';
@@ -35,6 +36,7 @@ import '@vitest/utils/source-map';
35
36
  import 'node:fs';
36
37
  import '@vitest/runner/utils';
37
38
  import '@vitest/snapshot/environment';
39
+ import '@vitest/mocker';
38
40
  import 'node:worker_threads';
39
41
 
40
42
  declare global {
@@ -1353,8 +1355,8 @@ interface VitestUtils {
1353
1355
  * @param path Path to the module. Can be aliased, if your Vitest config supports it
1354
1356
  * @param factory Mocked module factory. The result of this function will be an exports object
1355
1357
  */
1356
- mock(path: string, factory?: MockFactoryWithHelper): void;
1357
- mock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T>): void;
1358
+ mock(path: string, factory?: MockFactoryWithHelper | MockOptions): void;
1359
+ mock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T> | MockOptions): void;
1358
1360
  /**
1359
1361
  * Removes module from mocked registry. All calls to import will return the original module even if it was mocked before.
1360
1362
  *
@@ -1372,8 +1374,8 @@ interface VitestUtils {
1372
1374
  * @param path Path to the module. Can be aliased, if your Vitest config supports it
1373
1375
  * @param factory Mocked module factory. The result of this function will be an exports object
1374
1376
  */
1375
- doMock(path: string, factory?: MockFactoryWithHelper): void;
1376
- doMock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T>): void;
1377
+ doMock(path: string, factory?: MockFactoryWithHelper | MockOptions): void;
1378
+ doMock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T> | MockOptions): void;
1377
1379
  /**
1378
1380
  * Removes module from mocked registry. All subsequent calls to import will return original module.
1379
1381
  *
@@ -1472,7 +1474,7 @@ interface VitestUtils {
1472
1474
  * Changes the value of `import.meta.env` and `process.env`.
1473
1475
  * You can return it back to original value with `vi.unstubAllEnvs`, or by enabling `unstubEnvs` config option.
1474
1476
  */
1475
- stubEnv: <T extends string>(name: T, value: T extends 'PROD' | 'DEV' | 'SSR' ? boolean : string) => VitestUtils;
1477
+ stubEnv: <T extends string>(name: T, value: T extends 'PROD' | 'DEV' | 'SSR' ? boolean : string | undefined) => VitestUtils;
1476
1478
  /**
1477
1479
  * Reset the value to original value that was available before first `vi.stubGlobal` was called.
1478
1480
  */
@@ -1543,7 +1545,7 @@ interface TransformResultWithSource {
1543
1545
  interface WebSocketHandlers {
1544
1546
  onTaskUpdate: (packs: TaskResultPack[]) => void;
1545
1547
  getFiles: () => File$1[];
1546
- getTestFiles: () => Promise<SerializedSpec[]>;
1548
+ getTestFiles: () => Promise<SerializedTestSpecification[]>;
1547
1549
  getPaths: () => string[];
1548
1550
  getConfig: () => SerializedConfig;
1549
1551
  getModuleGraph: (projectName: string, id: string, browser?: boolean) => Promise<ModuleGraphData>;
@@ -1560,7 +1562,7 @@ interface WebSocketEvents {
1560
1562
  onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable$1<void>;
1561
1563
  onUserConsoleLog?: (log: UserConsoleLog) => Awaitable$1<void>;
1562
1564
  onPathsCollected?: (paths?: string[]) => Awaitable$1<void>;
1563
- onSpecsCollected?: (specs?: SerializedSpec[]) => Awaitable$1<void>;
1565
+ onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable$1<void>;
1564
1566
  onFinishedReportCoverage: () => void;
1565
1567
  }
1566
1568
  type WebSocketRPC = BirpcReturn<WebSocketEvents, WebSocketHandlers>;
@@ -1682,10 +1684,10 @@ type ProjectConfig = ProjectConfig$1;
1682
1684
  /** @deprecated import from `vitest/node` instead */
1683
1685
  type UserWorkspaceConfig = UserWorkspaceConfig$1;
1684
1686
 
1685
- /** @deprecated use `SerializedSpec` instead */
1686
- type SerializableSpec = SerializedSpec;
1687
+ /** @deprecated use `SerializedTestSpecification` instead */
1688
+ type SerializableSpec = SerializedTestSpecification;
1687
1689
 
1688
1690
  /** @deprecated import from `vitest/node` instead */
1689
1691
  type BenchmarkUserOptions = BenchmarkUserOptions$1;
1690
1692
 
1691
- export { type ApiConfig, type ArgumentsType, type Arrayable, type AssertType, type Awaitable, type BaseCoverageOptions, BenchmarkResult, type BenchmarkUserOptions, type BrowserConfigOptions, type BrowserScript, type BrowserUI, type BuiltinEnvironment, type CSSModuleScopeStrategy, type CollectLineNumbers, type CollectLines, type Constructable, type Context, type CoverageIstanbulOptions, type CoverageOptions, type CoverageProvider, type CoverageProviderModule, type CoverageReporter, type CoverageV8Options, type Custom, type CustomProviderOptions, type DepsOptimizationOptions, type Environment, type EnvironmentOptions, type EnvironmentReturn, type ExpectTypeOf, type File, type HappyDOMOptions, type InlineConfig, type JSDOMOptions, ModuleGraphData, type MutableArray, type Nullable, type OnServerRestartHandler, type Pool, type PoolOptions, type ProjectConfig, ProvidedContext, type RawErrsMap, type ReportContext, type Reporter, type ResolvedConfig, type ResolvedCoverageOptions, type ResolvedTestEnvironment, type RootAndTarget, type SequenceHooks, type SequenceSetupFiles, type SerializableSpec, SerializedConfig, SerializedSpec, type Suite, type Task, type Test, type TransformModePatterns, type TransformResultWithSource, type TscErrorInfo, type TypecheckConfig, type UserConfig, UserConsoleLog, type UserWorkspaceConfig, type Vitest, type VitestEnvironment, type VitestRunMode, type VitestUtils, type VmEnvironmentReturn, type WebSocketEvents, type WebSocketHandlers, type WebSocketRPC, assertType, createExpect, globalExpect as expect, expectTypeOf, getRunningMode, inject, isFirstRun, isWatchMode, runOnce, vi, vitest };
1693
+ export { type ApiConfig, type ArgumentsType, type Arrayable, type AssertType, type Awaitable, type BaseCoverageOptions, BenchmarkResult, type BenchmarkUserOptions, type BrowserConfigOptions, type BrowserScript, type BrowserUI, type BuiltinEnvironment, type CSSModuleScopeStrategy, type CollectLineNumbers, type CollectLines, type Constructable, type Context, type CoverageIstanbulOptions, type CoverageOptions, type CoverageProvider, type CoverageProviderModule, type CoverageReporter, type CoverageV8Options, type Custom, type CustomProviderOptions, type DepsOptimizationOptions, type Environment, type EnvironmentOptions, type EnvironmentReturn, type ExpectTypeOf, type File, type HappyDOMOptions, type InlineConfig, type JSDOMOptions, ModuleGraphData, type MutableArray, type Nullable, type OnServerRestartHandler, type Pool, type PoolOptions, type ProjectConfig, ProvidedContext, type RawErrsMap, type ReportContext, type Reporter, type ResolvedConfig, type ResolvedCoverageOptions, type ResolvedTestEnvironment, type RootAndTarget, type SequenceHooks, type SequenceSetupFiles, type SerializableSpec, SerializedConfig, SerializedTestSpecification, type Suite, type Task, type Test, type TransformModePatterns, type TransformResultWithSource, type TscErrorInfo, type TypecheckConfig, type UserConfig, UserConsoleLog, type UserWorkspaceConfig, type Vitest, type VitestEnvironment, type VitestRunMode, type VitestUtils, type VmEnvironmentReturn, type WebSocketEvents, type WebSocketHandlers, type WebSocketRPC, assertType, createExpect, globalExpect as expect, expectTypeOf, getRunningMode, inject, isFirstRun, isWatchMode, runOnce, vi, vitest };
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  export { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
2
2
  export { b as bench } from './chunks/benchmark.C8CRJYG4.js';
3
- import { d as dist } from './chunks/index.m3Xip5Zz.js';
4
- export { a as assertType, g as getRunningMode, b as inject, i as isWatchMode } from './chunks/index.m3Xip5Zz.js';
3
+ import { d as dist } from './chunks/index.iyKRMe3s.js';
4
+ export { a as assertType, g as getRunningMode, b as inject, i as isWatchMode } from './chunks/index.iyKRMe3s.js';
5
5
  export { i as isFirstRun, a as runOnce } from './chunks/run-once.Sxe67Wng.js';
6
- export { c as createExpect, a as expect, v as vi, b as vitest } from './chunks/vi.DBepMgvg.js';
6
+ export { c as createExpect, a as expect, v as vi, b as vitest } from './chunks/vi.D6IHiKAI.js';
7
7
  import * as chai from 'chai';
8
8
  export { chai };
9
9
  export { assert, should } from 'chai';
@@ -20,7 +20,7 @@ import '@vitest/snapshot';
20
20
  import '@vitest/utils/error';
21
21
  import './chunks/tasks.BZnCS9aT.js';
22
22
  import '@vitest/utils/source-map';
23
- import './chunks/base.BH-FAiX7.js';
23
+ import './chunks/base.BlXpj3e_.js';
24
24
  import './chunks/date.W2xKR2qe.js';
25
25
  import '@vitest/spy';
26
26
 
@@ -0,0 +1 @@
1
+ export * from '@vitest/mocker';
package/dist/mocker.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@vitest/mocker';