vitest 3.0.7 → 3.0.9

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 (66) hide show
  1. package/dist/browser.d.ts +14 -43
  2. package/dist/browser.js +4 -4
  3. package/dist/chunks/{base.BgUWWWYp.js → base.DV59CbtV.js} +2 -2
  4. package/dist/chunks/{benchmark.Cdu9hjj4.js → benchmark.DL72EVN-.js} +1 -1
  5. package/dist/chunks/{benchmark.CFFwLv-O.d.ts → benchmark.d.BwvBVTda.d.ts} +11 -11
  6. package/dist/chunks/{cac.87F_onld.js → cac.CeVHgzve.js} +30 -6
  7. package/dist/chunks/{cli-api.BZbq1zTX.js → cli-api.Ckwz_xSb.js} +21 -23
  8. package/dist/chunks/config.d.DevWltVl.d.ts +218 -0
  9. package/dist/chunks/{constants.fzPh7AOq.js → constants.DTYd6dNH.js} +1 -1
  10. package/dist/chunks/{coverage.DnNIv-kJ.js → coverage.A3sS5-Wm.js} +1 -29
  11. package/dist/chunks/coverage.d.S9RMNXIe.d.ts +35 -0
  12. package/dist/chunks/{resolveConfig.BbcK25zb.js → coverage.gV8doR2Y.js} +500 -131
  13. package/dist/chunks/{creator.2CFRE1Yx.js → creator.BsBnpTzI.js} +1 -1
  14. package/dist/chunks/defaults.C2Ndd9wx.js +119 -0
  15. package/dist/chunks/env.D4Lgay0q.js +8 -0
  16. package/dist/chunks/environment.d.C8UItCbf.d.ts +170 -0
  17. package/dist/chunks/{execute.Bhwls1-Z.js → execute.eDH0aFFd.js} +4 -4
  18. package/dist/chunks/global.d.Cg2sEPIm.d.ts +127 -0
  19. package/dist/chunks/{globals.BCtI_nQG.js → globals.BEpDe-k3.js} +5 -5
  20. package/dist/chunks/{index.C1f-_gvH.js → index.B8tIoLPT.js} +8 -3
  21. package/dist/chunks/{index.B8haHJlQ.js → index.D7Ny8f_s.js} +2 -2
  22. package/dist/chunks/{index.BmFFzXX_.js → index.uXkkC4xl.js} +1 -2
  23. package/dist/chunks/{mocker.cRtM890J.d.ts → mocker.d.BE_2ls6u.d.ts} +6 -6
  24. package/dist/chunks/reporters.d.CqBhtcTq.d.ts +3006 -0
  25. package/dist/chunks/{runBaseTests.9XCQcSZC.js → runBaseTests.BVrL_ow3.js} +9 -9
  26. package/dist/chunks/{setup-common.wObu9a36.js → setup-common.CPvtqi8q.js} +25 -2
  27. package/dist/chunks/{suite.qtkXWc6R.d.ts → suite.d.FvehnV49.d.ts} +1 -1
  28. package/dist/chunks/{typechecker.cZ0LjdSi.js → typechecker.BlF3eHsb.js} +2 -7
  29. package/dist/chunks/{vi.DT3m61kS.js → vi.nSCvwQ7l.js} +4 -4
  30. package/dist/chunks/vite.d.BUZTGxQ3.d.ts +11 -0
  31. package/dist/chunks/{vm.6kNys9FN.js → vm.jEFQDlX_.js} +1 -1
  32. package/dist/chunks/{worker.DaAIyCKm.d.ts → worker.d.C58isfFm.d.ts} +62 -62
  33. package/dist/chunks/{worker.B2JXutr8.d.ts → worker.d.CSFlSYJg.d.ts} +2 -2
  34. package/dist/cli.js +2 -2
  35. package/dist/config.d.ts +48 -45
  36. package/dist/config.js +6 -123
  37. package/dist/coverage.d.ts +82 -79
  38. package/dist/coverage.js +19 -469
  39. package/dist/environments.d.ts +11 -11
  40. package/dist/execute.d.ts +109 -109
  41. package/dist/execute.js +1 -1
  42. package/dist/index.d.ts +414 -412
  43. package/dist/index.js +4 -4
  44. package/dist/node.d.ts +51 -48
  45. package/dist/node.js +13 -10
  46. package/dist/reporters.d.ts +7 -4
  47. package/dist/reporters.js +3 -2
  48. package/dist/runners.d.ts +28 -28
  49. package/dist/runners.js +3 -4
  50. package/dist/snapshot.d.ts +2 -2
  51. package/dist/suite.d.ts +2 -2
  52. package/dist/suite.js +1 -1
  53. package/dist/workers/forks.js +2 -2
  54. package/dist/workers/runVmTests.js +9 -9
  55. package/dist/workers/threads.js +2 -2
  56. package/dist/workers/vmForks.js +2 -2
  57. package/dist/workers/vmThreads.js +2 -2
  58. package/dist/workers.d.ts +13 -13
  59. package/dist/workers.js +3 -3
  60. package/package.json +12 -12
  61. package/dist/chunks/config.BRtC-JeT.d.ts +0 -215
  62. package/dist/chunks/environment.d8YfPkTm.d.ts +0 -173
  63. package/dist/chunks/global.CnI8_G5V.d.ts +0 -133
  64. package/dist/chunks/reporters.QZ837uWx.d.ts +0 -3051
  65. package/dist/chunks/spy.Cf_4R5Oe.js +0 -22
  66. package/dist/chunks/vite.vM3UZq1q.d.ts +0 -11
package/dist/index.d.ts CHANGED
@@ -1,22 +1,22 @@
1
1
  import { File as File$1, TaskResultPack as TaskResultPack$1, TaskEventPack, TaskPopulated, Suite as Suite$1, Test as Test$1, Custom as Custom$1, Task as Task$1, TaskBase as TaskBase$1, TaskResult as TaskResult$1, DoneCallback as DoneCallback$1, RuntimeContext as RuntimeContext$1, SuiteHooks as SuiteHooks$1, SequenceHooks as SequenceHooks$1, SequenceSetupFiles as SequenceSetupFiles$1 } from '@vitest/runner';
2
2
  export { CancelReason, ExtendedContext, HookCleanupCallback, HookListener, OnTestFailedHandler, OnTestFinishedHandler, RunMode, Custom as RunnerCustomCase, Task as RunnerTask, TaskBase as RunnerTaskBase, TaskResult as RunnerTaskResult, TaskResultPack as RunnerTaskResultPack, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, SuiteAPI, SuiteCollector, SuiteFactory, TaskContext, TaskCustomOptions, TaskMeta, TaskState, TestAPI, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
3
- import { S as SerializedTestSpecification, c as CoverageProvider$1, a as ReportContext$1, g as CoverageProviderModule$1, h as CoverageReporter$1, i as CoverageProviderName, j as CoverageOptions$1, R as ResolvedCoverageOptions$1, B as BaseCoverageOptions$1, k as CoverageIstanbulOptions$1, d as CoverageV8Options$1, l as CustomProviderOptions$1, m as Reporter$1, V as Vitest$1, n as BrowserScript$1, o as BrowserConfigOptions$1, p as BuiltinEnvironment$1, q as VitestEnvironment$1, P as Pool$1, r as PoolOptions$1, s as CSSModuleScopeStrategy$1, A as ApiConfig$1, t as VitestRunMode$1, D as DepsOptimizationOptions$1, u as TransformModePatterns$1, I as InlineConfig$1, v as TypecheckConfig$1, w as UserConfig$1, x as ResolvedConfig$1, y as ProjectConfig$1, U as UserWorkspaceConfig$1, z as BenchmarkUserOptions$1 } from './chunks/reporters.QZ837uWx.js';
4
- import { W as WorkerContext$1 } from './chunks/worker.B2JXutr8.js';
5
- import { R as RawErrsMap$1, T as TscErrorInfo$1, C as CollectLineNumbers$1, a as CollectLines$1, b as RootAndTarget$1, c as Context$1 } from './chunks/global.CnI8_G5V.js';
6
- import { b as Awaitable$1, U as UserConsoleLog, M as ModuleGraphData, P as ProvidedContext, N as Nullable$1, c as Arrayable$1, d as ArgumentsType$1, e as MutableArray$1, C as Constructable$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.d8YfPkTm.js';
7
- export { A as AfterSuiteRunMeta, g as ModuleCache } from './chunks/environment.d8YfPkTm.js';
8
- import { a as BirpcReturn, b as WorkerRPC$1 } from './chunks/worker.DaAIyCKm.js';
9
- export { C as ContextRPC, d as ContextTestEnvironment, e as ResolveIdFunction, c as RunnerRPC, R as RuntimeRPC, W as WorkerGlobalState } from './chunks/worker.DaAIyCKm.js';
10
- import './chunks/vite.vM3UZq1q.js';
11
- import { S as SerializedConfig, F as FakeTimerInstallOpts, R as RuntimeOptions } from './chunks/config.BRtC-JeT.js';
12
- export { b as RuntimeConfig, a as SerializedCoverageConfig } from './chunks/config.BRtC-JeT.js';
3
+ import { S as SerializedTestSpecification, e as CoverageProvider$1, a as ReportContext$1, f as CoverageProviderModule$1, g as CoverageReporter$1, h as CoverageProviderName, i as CoverageOptions$1, R as ResolvedCoverageOptions$1, B as BaseCoverageOptions$1, j as CoverageIstanbulOptions$1, b as CoverageV8Options$1, k as CustomProviderOptions$1, l as Reporter$1, V as Vitest$1, m as BrowserScript$1, n as BrowserConfigOptions$1, o as BuiltinEnvironment$1, p as VitestEnvironment$1, P as Pool$1, q as PoolOptions$1, r as CSSModuleScopeStrategy$1, A as ApiConfig$1, s as VitestRunMode$1, D as DepsOptimizationOptions$1, t as TransformModePatterns$1, I as InlineConfig$1, u as TypecheckConfig$1, v as UserConfig$1, w as ResolvedConfig$1, x as ProjectConfig$1, U as UserWorkspaceConfig$1, y as BenchmarkUserOptions$1 } from './chunks/reporters.d.CqBhtcTq.js';
4
+ import { W as WorkerContext$1 } from './chunks/worker.d.CSFlSYJg.js';
5
+ import { R as RawErrsMap$1, T as TscErrorInfo$1, C as CollectLineNumbers$1, a as CollectLines$1, b as RootAndTarget$1, c as Context$1 } from './chunks/global.d.Cg2sEPIm.js';
6
+ import { b as Awaitable$1, U as UserConsoleLog, M as ModuleGraphData, P as ProvidedContext, N as Nullable$1, c as Arrayable$1, d as ArgumentsType$1, e as MutableArray$1, C as Constructable$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.d.C8UItCbf.js';
7
+ export { A as AfterSuiteRunMeta, g as ModuleCache } from './chunks/environment.d.C8UItCbf.js';
8
+ import { a as BirpcReturn, b as WorkerRPC$1 } from './chunks/worker.d.C58isfFm.js';
9
+ export { C as ContextRPC, d as ContextTestEnvironment, e as ResolveIdFunction, c as RunnerRPC, R as RuntimeRPC, W as WorkerGlobalState } from './chunks/worker.d.C58isfFm.js';
10
+ import './chunks/vite.d.BUZTGxQ3.js';
11
+ import { a as SerializedConfig, F as FakeTimerInstallOpts, R as RuntimeOptions } from './chunks/config.d.DevWltVl.js';
12
+ export { b as RuntimeConfig, S as SerializedCoverageConfig } from './chunks/config.d.DevWltVl.js';
13
13
  import { ExpectStatic } from '@vitest/expect';
14
14
  export { Assertion, AsymmetricMatchersContaining, ExpectPollOptions, ExpectStatic, JestAssertion } from '@vitest/expect';
15
15
  import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, MockInstance } from '@vitest/spy';
16
16
  export { Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject } from '@vitest/spy';
17
- import { M as MockFactoryWithHelper, a as MockOptions } from './chunks/mocker.cRtM890J.js';
18
- export { b as bench } from './chunks/suite.qtkXWc6R.js';
19
- export { a as BenchFunction, b as Benchmark, c as BenchmarkAPI, B as BenchmarkResult } from './chunks/benchmark.CFFwLv-O.js';
17
+ import { M as MockFactoryWithHelper, a as MockOptions } from './chunks/mocker.d.BE_2ls6u.js';
18
+ export { b as bench } from './chunks/suite.d.FvehnV49.js';
19
+ export { a as BenchFunction, b as Benchmark, c as BenchmarkAPI, B as BenchmarkResult } from './chunks/benchmark.d.BwvBVTda.js';
20
20
  export { ExpectTypeOf, expectTypeOf } from 'expect-type';
21
21
  export { SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotSerializer, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, UncheckedSnapshot } from '@vitest/snapshot';
22
22
  export { ErrorWithDiff, ParsedStack, SerializedError, TestError } from '@vitest/utils';
@@ -27,9 +27,12 @@ export { assert, should } from 'chai';
27
27
  export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench';
28
28
  import 'node:stream';
29
29
  import 'vite';
30
+ import 'node:console';
30
31
  import '@vitest/utils/source-map';
31
32
  import '@vitest/pretty-format';
32
33
  import 'vite-node';
34
+ import './chunks/coverage.d.S9RMNXIe.js';
35
+ import 'vite-node/client';
33
36
  import '@vitest/snapshot/manager';
34
37
  import 'node:fs';
35
38
  import 'node:worker_threads';
@@ -38,49 +41,49 @@ import '@vitest/mocker';
38
41
  import '@vitest/runner/utils';
39
42
 
40
43
  interface SourceMap {
41
- file: string;
42
- mappings: string;
43
- names: string[];
44
- sources: string[];
45
- sourcesContent?: string[];
46
- version: number;
47
- toString: () => string;
48
- toUrl: () => string;
44
+ file: string;
45
+ mappings: string;
46
+ names: string[];
47
+ sources: string[];
48
+ sourcesContent?: string[];
49
+ version: number;
50
+ toString: () => string;
51
+ toUrl: () => string;
49
52
  }
50
53
  interface TransformResultWithSource {
51
- code: string;
52
- map: SourceMap | {
53
- mappings: '';
54
- } | null;
55
- etag?: string;
56
- deps?: string[];
57
- dynamicDeps?: string[];
58
- source?: string;
54
+ code: string;
55
+ map: SourceMap | {
56
+ mappings: ""
57
+ } | null;
58
+ etag?: string;
59
+ deps?: string[];
60
+ dynamicDeps?: string[];
61
+ source?: string;
59
62
  }
60
63
  interface WebSocketHandlers {
61
- onTaskUpdate: (packs: TaskResultPack$1[], events: TaskEventPack[]) => void;
62
- getFiles: () => File$1[];
63
- getTestFiles: () => Promise<SerializedTestSpecification[]>;
64
- getPaths: () => string[];
65
- getConfig: () => SerializedConfig;
66
- getResolvedProjectNames: () => string[];
67
- getModuleGraph: (projectName: string, id: string, browser?: boolean) => Promise<ModuleGraphData>;
68
- getTransformResult: (projectName: string, id: string, browser?: boolean) => Promise<TransformResultWithSource | undefined>;
69
- readTestFile: (id: string) => Promise<string | null>;
70
- saveTestFile: (id: string, content: string) => Promise<void>;
71
- rerun: (files: string[], resetTestNamePattern?: boolean) => Promise<void>;
72
- rerunTask: (id: string) => Promise<void>;
73
- updateSnapshot: (file?: File$1) => Promise<void>;
74
- getUnhandledErrors: () => unknown[];
64
+ onTaskUpdate: (packs: TaskResultPack$1[], events: TaskEventPack[]) => void;
65
+ getFiles: () => File$1[];
66
+ getTestFiles: () => Promise<SerializedTestSpecification[]>;
67
+ getPaths: () => string[];
68
+ getConfig: () => SerializedConfig;
69
+ getResolvedProjectNames: () => string[];
70
+ getModuleGraph: (projectName: string, id: string, browser?: boolean) => Promise<ModuleGraphData>;
71
+ getTransformResult: (projectName: string, id: string, browser?: boolean) => Promise<TransformResultWithSource | undefined>;
72
+ readTestFile: (id: string) => Promise<string | null>;
73
+ saveTestFile: (id: string, content: string) => Promise<void>;
74
+ rerun: (files: string[], resetTestNamePattern?: boolean) => Promise<void>;
75
+ rerunTask: (id: string) => Promise<void>;
76
+ updateSnapshot: (file?: File$1) => Promise<void>;
77
+ getUnhandledErrors: () => unknown[];
75
78
  }
76
79
  interface WebSocketEvents {
77
- onCollected?: (files?: File$1[]) => Awaitable$1<void>;
78
- onFinished?: (files: File$1[], errors: unknown[], coverage?: unknown) => Awaitable$1<void>;
79
- onTaskUpdate?: (packs: TaskResultPack$1[]) => Awaitable$1<void>;
80
- onUserConsoleLog?: (log: UserConsoleLog) => Awaitable$1<void>;
81
- onPathsCollected?: (paths?: string[]) => Awaitable$1<void>;
82
- onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable$1<void>;
83
- onFinishedReportCoverage: () => void;
80
+ onCollected?: (files?: File$1[]) => Awaitable$1<void>;
81
+ onFinished?: (files: File$1[], errors: unknown[], coverage?: unknown) => Awaitable$1<void>;
82
+ onTaskUpdate?: (packs: TaskResultPack$1[]) => Awaitable$1<void>;
83
+ onUserConsoleLog?: (log: UserConsoleLog) => Awaitable$1<void>;
84
+ onPathsCollected?: (paths?: string[]) => Awaitable$1<void>;
85
+ onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable$1<void>;
86
+ onFinishedReportCoverage: () => void;
84
87
  }
85
88
  type WebSocketRPC = BirpcReturn<WebSocketEvents, WebSocketHandlers>;
86
89
 
@@ -88,395 +91,394 @@ declare function createExpect(test?: TaskPopulated): ExpectStatic;
88
91
  declare const globalExpect: ExpectStatic;
89
92
 
90
93
  /**
91
- * Gives access to injected context provided from the main thread.
92
- * This usually returns a value provided by `globalSetup` or an external library.
93
- */
94
+ * Gives access to injected context provided from the main thread.
95
+ * This usually returns a value provided by `globalSetup` or an external library.
96
+ */
94
97
  declare function inject<T extends keyof ProvidedContext & string>(key: T): ProvidedContext[T];
95
98
 
96
99
  /**
97
- * This utils allows computational intensive tasks to only be ran once
98
- * across test reruns to improve the watch mode performance.
99
- *
100
- * Currently only works with `poolOptions.<pool>.isolate: false`
101
- *
102
- * @experimental
103
- */
100
+ * This utils allows computational intensive tasks to only be ran once
101
+ * across test reruns to improve the watch mode performance.
102
+ *
103
+ * Currently only works with `poolOptions.<pool>.isolate: false`
104
+ *
105
+ * @experimental
106
+ */
104
107
  declare function runOnce<T>(fn: () => T, key?: string): T;
105
108
  /**
106
- * Get a boolean indicates whether the task is running in the first time.
107
- * Could only be `false` in watch mode.
108
- *
109
- * Currently only works with `isolate: false`
110
- *
111
- * @experimental
112
- */
109
+ * Get a boolean indicates whether the task is running in the first time.
110
+ * Could only be `false` in watch mode.
111
+ *
112
+ * Currently only works with `isolate: false`
113
+ *
114
+ * @experimental
115
+ */
113
116
  declare function isFirstRun(): boolean;
114
117
 
115
- declare function getRunningMode(): 'watch' | 'run';
118
+ declare function getRunningMode(): "watch" | "run";
116
119
  declare function isWatchMode(): boolean;
117
120
 
118
121
  type WaitForCallback<T> = () => T | Promise<T>;
119
122
  interface WaitForOptions {
120
- /**
121
- * @description Time in ms between each check callback
122
- * @default 50ms
123
- */
124
- interval?: number;
125
- /**
126
- * @description Time in ms after which the throw a timeout error
127
- * @default 1000ms
128
- */
129
- timeout?: number;
123
+ /**
124
+ * @description Time in ms between each check callback
125
+ * @default 50ms
126
+ */
127
+ interval?: number;
128
+ /**
129
+ * @description Time in ms after which the throw a timeout error
130
+ * @default 1000ms
131
+ */
132
+ timeout?: number;
130
133
  }
131
134
  declare function waitFor<T>(callback: WaitForCallback<T>, options?: number | WaitForOptions): Promise<T>;
132
135
  type WaitUntilCallback<T> = () => T | Promise<T>;
133
- interface WaitUntilOptions extends Pick<WaitForOptions, 'interval' | 'timeout'> {
134
- }
135
- type Truthy<T> = T extends false | '' | 0 | null | undefined ? never : T;
136
+ interface WaitUntilOptions extends Pick<WaitForOptions, "interval" | "timeout"> {}
137
+ type Truthy<T> = T extends false | "" | 0 | null | undefined ? never : T;
136
138
  declare function waitUntil<T>(callback: WaitUntilCallback<T>, options?: number | WaitUntilOptions): Promise<Truthy<T>>;
137
139
 
138
140
  type ESModuleExports = Record<string, unknown>;
139
141
  interface VitestUtils {
140
- /**
141
- * Checks if fake timers are enabled.
142
- */
143
- isFakeTimers: () => boolean;
144
- /**
145
- * This method wraps all further calls to timers until [`vi.useRealTimers()`](https://vitest.dev/api/vi#vi-userealtimers) is called.
146
- */
147
- useFakeTimers: (config?: FakeTimerInstallOpts) => VitestUtils;
148
- /**
149
- * Restores mocked timers to their original implementations. All timers that were scheduled before will be discarded.
150
- */
151
- useRealTimers: () => VitestUtils;
152
- /**
153
- * This method will call every timer that was initiated after [`vi.useFakeTimers`](https://vitest.dev/api/vi#vi-usefaketimers) call.
154
- * It will not fire any timer that was initiated during its call.
155
- */
156
- runOnlyPendingTimers: () => VitestUtils;
157
- /**
158
- * This method will asynchronously call every timer that was initiated after [`vi.useFakeTimers`](https://vitest.dev/api/vi#vi-usefaketimers) call, even asynchronous ones.
159
- * It will not fire any timer that was initiated during its call.
160
- */
161
- runOnlyPendingTimersAsync: () => Promise<VitestUtils>;
162
- /**
163
- * This method will invoke every initiated timer until the timer queue is empty. It means that every timer called during `runAllTimers` will be fired.
164
- * If you have an infinite interval, it will throw after 10,000 tries (can be configured with [`fakeTimers.loopLimit`](https://vitest.dev/config/#faketimers-looplimit)).
165
- */
166
- runAllTimers: () => VitestUtils;
167
- /**
168
- * This method will asynchronously invoke every initiated timer until the timer queue is empty. It means that every timer called during `runAllTimersAsync` will be fired even asynchronous timers.
169
- * If you have an infinite interval, it will throw after 10 000 tries (can be configured with [`fakeTimers.loopLimit`](https://vitest.dev/config/#faketimers-looplimit)).
170
- */
171
- runAllTimersAsync: () => Promise<VitestUtils>;
172
- /**
173
- * Calls every microtask that was queued by `process.nextTick`. This will also run all microtasks scheduled by themselves.
174
- */
175
- runAllTicks: () => VitestUtils;
176
- /**
177
- * This method will invoke every initiated timer until the specified number of milliseconds is passed or the queue is empty - whatever comes first.
178
- */
179
- advanceTimersByTime: (ms: number) => VitestUtils;
180
- /**
181
- * This method will invoke every initiated timer until the specified number of milliseconds is passed or the queue is empty - whatever comes first. This will include and await asynchronously set timers.
182
- */
183
- advanceTimersByTimeAsync: (ms: number) => Promise<VitestUtils>;
184
- /**
185
- * Will call next available timer. Useful to make assertions between each timer call. You can chain call it to manage timers by yourself.
186
- */
187
- advanceTimersToNextTimer: () => VitestUtils;
188
- /**
189
- * Will call next available timer and wait until it's resolved if it was set asynchronously. Useful to make assertions between each timer call.
190
- */
191
- advanceTimersToNextTimerAsync: () => Promise<VitestUtils>;
192
- /**
193
- * Similar to [`vi.advanceTimersByTime`](https://vitest.dev/api/vi#vi-advancetimersbytime), but will advance timers by the milliseconds needed to execute callbacks currently scheduled with `requestAnimationFrame`.
194
- */
195
- advanceTimersToNextFrame: () => VitestUtils;
196
- /**
197
- * Get the number of waiting timers.
198
- */
199
- getTimerCount: () => number;
200
- /**
201
- * If fake timers are enabled, this method simulates a user changing the system clock (will affect date related API like `hrtime`, `performance.now` or `new Date()`) - however, it will not fire any timers.
202
- * If fake timers are not enabled, this method will only mock `Date.*` and `new Date()` calls.
203
- */
204
- setSystemTime: (time: number | string | Date) => VitestUtils;
205
- /**
206
- * Returns mocked current date. If date is not mocked the method will return `null`.
207
- */
208
- getMockedSystemTime: () => Date | null;
209
- /**
210
- * When using `vi.useFakeTimers`, `Date.now` calls are mocked. If you need to get real time in milliseconds, you can call this function.
211
- */
212
- getRealSystemTime: () => number;
213
- /**
214
- * Removes all timers that are scheduled to run. These timers will never run in the future.
215
- */
216
- clearAllTimers: () => VitestUtils;
217
- /**
218
- * Creates a spy on a method or getter/setter of an object similar to [`vi.fn()`](https://vitest.dev/api/vi#vi-fn). It returns a [mock function](https://vitest.dev/api/mock).
219
- * @example
220
- * ```ts
221
- * const cart = {
222
- * getApples: () => 42
223
- * }
224
- *
225
- * const spy = vi.spyOn(cart, 'getApples').mockReturnValue(10)
226
- *
227
- * expect(cart.getApples()).toBe(10)
228
- * expect(spy).toHaveBeenCalled()
229
- * expect(spy).toHaveReturnedWith(10)
230
- * ```
231
- */
232
- spyOn: typeof spyOn;
233
- /**
234
- * Creates a spy on a function, though can be initiated without one. Every time a function is invoked, it stores its call arguments, returns, and instances. Also, you can manipulate its behavior with [methods](https://vitest.dev/api/mock).
235
- *
236
- * If no function is given, mock will return `undefined`, when invoked.
237
- * @example
238
- * ```ts
239
- * const getApples = vi.fn(() => 0)
240
- *
241
- * getApples()
242
- *
243
- * expect(getApples).toHaveBeenCalled()
244
- * expect(getApples).toHaveReturnedWith(0)
245
- *
246
- * getApples.mockReturnValueOnce(5)
247
- *
248
- * expect(getApples()).toBe(5)
249
- * expect(getApples).toHaveNthReturnedWith(2, 5)
250
- * ```
251
- */
252
- fn: typeof fn;
253
- /**
254
- * Wait for the callback to execute successfully. If the callback throws an error or returns a rejected promise it will continue to wait until it succeeds or times out.
255
- *
256
- * This is very useful when you need to wait for some asynchronous action to complete, for example, when you start a server and need to wait for it to start.
257
- * @example
258
- * ```ts
259
- * const server = createServer()
260
- *
261
- * await vi.waitFor(
262
- * () => {
263
- * if (!server.isReady)
264
- * throw new Error('Server not started')
265
- *
266
- * console.log('Server started')
267
- * }, {
268
- * timeout: 500, // default is 1000
269
- * interval: 20, // default is 50
270
- * }
271
- * )
272
- * ```
273
- */
274
- waitFor: typeof waitFor;
275
- /**
276
- * This is similar to [`vi.waitFor`](https://vitest.dev/api/vi#vi-waitfor), but if the callback throws any errors, execution is immediately interrupted and an error message is received.
277
- *
278
- * If the callback returns a falsy value, the next check will continue until a truthy value is returned. This is useful when you need to wait for something to exist before taking the next step.
279
- * @example
280
- * ```ts
281
- * const element = await vi.waitUntil(
282
- * () => document.querySelector('.element'),
283
- * {
284
- * timeout: 500, // default is 1000
285
- * interval: 20, // default is 50
286
- * }
287
- * )
288
- *
289
- * // do something with the element
290
- * expect(element.querySelector('.element-child')).toBeTruthy()
291
- * ```
292
- */
293
- waitUntil: typeof waitUntil;
294
- /**
295
- * Run the factory before imports are evaluated. You can return a value from the factory
296
- * to reuse it inside your [`vi.mock`](https://vitest.dev/api/vi#vi-mock) factory and tests.
297
- *
298
- * If used with [`vi.mock`](https://vitest.dev/api/vi#vi-mock), both will be hoisted in the order they are defined in.
299
- */
300
- hoisted: <T>(factory: () => T) => T;
301
- /**
302
- * Mocks every import call to the module even if it was already statically imported.
303
- *
304
- * The call to `vi.mock` is hoisted to the top of the file, so you don't have access to variables declared in the global file scope
305
- * unless they are defined with [`vi.hoisted`](https://vitest.dev/api/vi#vi-hoisted) before this call.
306
- *
307
- * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules).
308
- * @param path Path to the module. Can be aliased, if your Vitest config supports it
309
- * @param factory Mocked module factory. The result of this function will be an exports object
310
- */
311
- mock(path: string, factory?: MockFactoryWithHelper | MockOptions): void;
312
- mock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T> | MockOptions): void;
313
- /**
314
- * Removes module from mocked registry. All calls to import will return the original module even if it was mocked before.
315
- *
316
- * This call is hoisted to the top of the file, so it will only unmock modules that were defined in `setupFiles`, for example.
317
- * @param path Path to the module. Can be aliased, if your Vitest config supports it
318
- */
319
- unmock(path: string): void;
320
- unmock(module: Promise<unknown>): void;
321
- /**
322
- * Mocks every subsequent [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) call.
323
- *
324
- * Unlike [`vi.mock`](https://vitest.dev/api/vi#vi-mock), this method will not mock statically imported modules because it is not hoisted to the top of the file.
325
- *
326
- * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules).
327
- * @param path Path to the module. Can be aliased, if your Vitest config supports it
328
- * @param factory Mocked module factory. The result of this function will be an exports object
329
- */
330
- doMock(path: string, factory?: MockFactoryWithHelper | MockOptions): void;
331
- doMock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T> | MockOptions): void;
332
- /**
333
- * Removes module from mocked registry. All subsequent calls to import will return original module.
334
- *
335
- * Unlike [`vi.unmock`](https://vitest.dev/api/vi#vi-unmock), this method is not hoisted to the top of the file.
336
- * @param path Path to the module. Can be aliased, if your Vitest config supports it
337
- */
338
- doUnmock(path: string): void;
339
- doUnmock(module: Promise<unknown>): void;
340
- /**
341
- * Imports module, bypassing all checks if it should be mocked.
342
- * Can be useful if you want to mock module partially.
343
- * @example
344
- * ```ts
345
- * vi.mock('./example.js', async () => {
346
- * const axios = await vi.importActual<typeof import('./example.js')>('./example.js')
347
- *
348
- * return { ...axios, get: vi.fn() }
349
- * })
350
- * ```
351
- * @param path Path to the module. Can be aliased, if your config supports it
352
- */
353
- importActual: <T = ESModuleExports>(path: string) => Promise<T>;
354
- /**
355
- * Imports a module with all of its properties and nested properties mocked.
356
- *
357
- * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules).
358
- * @example
359
- * ```ts
360
- * const example = await vi.importMock<typeof import('./example.js')>('./example.js')
361
- * example.calc.mockReturnValue(10)
362
- * expect(example.calc()).toBe(10)
363
- * ```
364
- * @param path Path to the module. Can be aliased, if your config supports it
365
- * @returns Fully mocked module
366
- */
367
- importMock: <T = ESModuleExports>(path: string) => Promise<MaybeMockedDeep<T>>;
368
- /**
369
- * Type helper for TypeScript. Just returns the object that was passed.
370
- *
371
- * When `partial` is `true` it will expect a `Partial<T>` as a return value. By default, this will only make TypeScript believe that
372
- * the first level values are mocked. You can pass down `{ deep: true }` as a second argument to tell TypeScript that the whole object is mocked, if it actually is.
373
- * @example
374
- * ```ts
375
- * import example from './example.js'
376
- * vi.mock('./example.js')
377
- *
378
- * test('1 + 1 equals 10' async () => {
379
- * vi.mocked(example.calc).mockReturnValue(10)
380
- * expect(example.calc(1, '+', 1)).toBe(10)
381
- * })
382
- * ```
383
- * @param item Anything that can be mocked
384
- * @param deep If the object is deeply mocked
385
- * @param options If the object is partially or deeply mocked
386
- */
387
- mocked: (<T>(item: T, deep?: false) => MaybeMocked<T>) & (<T>(item: T, deep: true) => MaybeMockedDeep<T>) & (<T>(item: T, options: {
388
- partial?: false;
389
- deep?: false;
390
- }) => MaybeMocked<T>) & (<T>(item: T, options: {
391
- partial?: false;
392
- deep: true;
393
- }) => MaybeMockedDeep<T>) & (<T>(item: T, options: {
394
- partial: true;
395
- deep?: false;
396
- }) => MaybePartiallyMocked<T>) & (<T>(item: T, options: {
397
- partial: true;
398
- deep: true;
399
- }) => MaybePartiallyMockedDeep<T>) & (<T>(item: T) => MaybeMocked<T>);
400
- /**
401
- * Checks that a given parameter is a mock function. If you are using TypeScript, it will also narrow down its type.
402
- */
403
- isMockFunction: (fn: any) => fn is MockInstance;
404
- /**
405
- * Calls [`.mockClear()`](https://vitest.dev/api/mock#mockclear) on every mocked function.
406
- *
407
- * This will only empty `.mock` state, it will not affect mock implementations.
408
- *
409
- * This is useful if you need to clean up mocks between different assertions within a test.
410
- */
411
- clearAllMocks: () => VitestUtils;
412
- /**
413
- * Calls [`.mockReset()`](https://vitest.dev/api/mock#mockreset) on every mocked function.
414
- *
415
- * This will empty `.mock` state, reset "once" implementations, and reset each mock's base implementation to its original.
416
- *
417
- * This is useful when you want to reset all mocks to their original states.
418
- */
419
- resetAllMocks: () => VitestUtils;
420
- /**
421
- * Calls [`.mockRestore()`](https://vitest.dev/api/mock#mockrestore) on every mocked function.
422
- *
423
- * This will empty `.mock` state, restore all original mock implementations, and restore original descriptors of spied-on objects.
424
- *
425
- * This is useful for inter-test cleanup and/or removing mocks created by [`vi.spyOn(...)`](https://vitest.dev/api/vi#vi-spyon).
426
- */
427
- restoreAllMocks: () => VitestUtils;
428
- /**
429
- * Makes value available on global namespace.
430
- * Useful, if you want to have global variables available, like `IntersectionObserver`.
431
- * You can return it back to original value with `vi.unstubAllGlobals`, or by enabling `unstubGlobals` config option.
432
- */
433
- stubGlobal: (name: string | symbol | number, value: unknown) => VitestUtils;
434
- /**
435
- * Changes the value of `import.meta.env` and `process.env`.
436
- * You can return it back to original value with `vi.unstubAllEnvs`, or by enabling `unstubEnvs` config option.
437
- */
438
- stubEnv: <T extends string>(name: T, value: T extends 'PROD' | 'DEV' | 'SSR' ? boolean : string | undefined) => VitestUtils;
439
- /**
440
- * Reset the value to original value that was available before first `vi.stubGlobal` was called.
441
- */
442
- unstubAllGlobals: () => VitestUtils;
443
- /**
444
- * Reset environmental variables to the ones that were available before first `vi.stubEnv` was called.
445
- */
446
- unstubAllEnvs: () => VitestUtils;
447
- /**
448
- * Resets modules registry by clearing the cache of all modules. This allows modules to be reevaluated when reimported.
449
- * Top-level imports cannot be re-evaluated. Might be useful to isolate modules where local state conflicts between tests.
450
- *
451
- * This method does not reset mocks registry. To clear mocks registry, use [`vi.unmock`](https://vitest.dev/api/vi#vi-unmock) or [`vi.doUnmock`](https://vitest.dev/api/vi#vi-dounmock).
452
- */
453
- resetModules: () => VitestUtils;
454
- /**
455
- * Wait for all imports to load. Useful, if you have a synchronous call that starts
456
- * importing a module that you cannot await otherwise.
457
- * Will also wait for new imports, started during the wait.
458
- */
459
- dynamicImportSettled: () => Promise<void>;
460
- /**
461
- * Updates runtime config. You can only change values that are used when executing tests.
462
- */
463
- setConfig: (config: RuntimeOptions) => void;
464
- /**
465
- * If config was changed with `vi.setConfig`, this will reset it to the original state.
466
- */
467
- resetConfig: () => void;
142
+ /**
143
+ * Checks if fake timers are enabled.
144
+ */
145
+ isFakeTimers: () => boolean;
146
+ /**
147
+ * This method wraps all further calls to timers until [`vi.useRealTimers()`](https://vitest.dev/api/vi#vi-userealtimers) is called.
148
+ */
149
+ useFakeTimers: (config?: FakeTimerInstallOpts) => VitestUtils;
150
+ /**
151
+ * Restores mocked timers to their original implementations. All timers that were scheduled before will be discarded.
152
+ */
153
+ useRealTimers: () => VitestUtils;
154
+ /**
155
+ * This method will call every timer that was initiated after [`vi.useFakeTimers`](https://vitest.dev/api/vi#vi-usefaketimers) call.
156
+ * It will not fire any timer that was initiated during its call.
157
+ */
158
+ runOnlyPendingTimers: () => VitestUtils;
159
+ /**
160
+ * This method will asynchronously call every timer that was initiated after [`vi.useFakeTimers`](https://vitest.dev/api/vi#vi-usefaketimers) call, even asynchronous ones.
161
+ * It will not fire any timer that was initiated during its call.
162
+ */
163
+ runOnlyPendingTimersAsync: () => Promise<VitestUtils>;
164
+ /**
165
+ * This method will invoke every initiated timer until the timer queue is empty. It means that every timer called during `runAllTimers` will be fired.
166
+ * If you have an infinite interval, it will throw after 10,000 tries (can be configured with [`fakeTimers.loopLimit`](https://vitest.dev/config/#faketimers-looplimit)).
167
+ */
168
+ runAllTimers: () => VitestUtils;
169
+ /**
170
+ * This method will asynchronously invoke every initiated timer until the timer queue is empty. It means that every timer called during `runAllTimersAsync` will be fired even asynchronous timers.
171
+ * If you have an infinite interval, it will throw after 10 000 tries (can be configured with [`fakeTimers.loopLimit`](https://vitest.dev/config/#faketimers-looplimit)).
172
+ */
173
+ runAllTimersAsync: () => Promise<VitestUtils>;
174
+ /**
175
+ * Calls every microtask that was queued by `process.nextTick`. This will also run all microtasks scheduled by themselves.
176
+ */
177
+ runAllTicks: () => VitestUtils;
178
+ /**
179
+ * This method will invoke every initiated timer until the specified number of milliseconds is passed or the queue is empty - whatever comes first.
180
+ */
181
+ advanceTimersByTime: (ms: number) => VitestUtils;
182
+ /**
183
+ * This method will invoke every initiated timer until the specified number of milliseconds is passed or the queue is empty - whatever comes first. This will include and await asynchronously set timers.
184
+ */
185
+ advanceTimersByTimeAsync: (ms: number) => Promise<VitestUtils>;
186
+ /**
187
+ * Will call next available timer. Useful to make assertions between each timer call. You can chain call it to manage timers by yourself.
188
+ */
189
+ advanceTimersToNextTimer: () => VitestUtils;
190
+ /**
191
+ * Will call next available timer and wait until it's resolved if it was set asynchronously. Useful to make assertions between each timer call.
192
+ */
193
+ advanceTimersToNextTimerAsync: () => Promise<VitestUtils>;
194
+ /**
195
+ * Similar to [`vi.advanceTimersByTime`](https://vitest.dev/api/vi#vi-advancetimersbytime), but will advance timers by the milliseconds needed to execute callbacks currently scheduled with `requestAnimationFrame`.
196
+ */
197
+ advanceTimersToNextFrame: () => VitestUtils;
198
+ /**
199
+ * Get the number of waiting timers.
200
+ */
201
+ getTimerCount: () => number;
202
+ /**
203
+ * If fake timers are enabled, this method simulates a user changing the system clock (will affect date related API like `hrtime`, `performance.now` or `new Date()`) - however, it will not fire any timers.
204
+ * If fake timers are not enabled, this method will only mock `Date.*` and `new Date()` calls.
205
+ */
206
+ setSystemTime: (time: number | string | Date) => VitestUtils;
207
+ /**
208
+ * Returns mocked current date. If date is not mocked the method will return `null`.
209
+ */
210
+ getMockedSystemTime: () => Date | null;
211
+ /**
212
+ * When using `vi.useFakeTimers`, `Date.now` calls are mocked. If you need to get real time in milliseconds, you can call this function.
213
+ */
214
+ getRealSystemTime: () => number;
215
+ /**
216
+ * Removes all timers that are scheduled to run. These timers will never run in the future.
217
+ */
218
+ clearAllTimers: () => VitestUtils;
219
+ /**
220
+ * Creates a spy on a method or getter/setter of an object similar to [`vi.fn()`](https://vitest.dev/api/vi#vi-fn). It returns a [mock function](https://vitest.dev/api/mock).
221
+ * @example
222
+ * ```ts
223
+ * const cart = {
224
+ * getApples: () => 42
225
+ * }
226
+ *
227
+ * const spy = vi.spyOn(cart, 'getApples').mockReturnValue(10)
228
+ *
229
+ * expect(cart.getApples()).toBe(10)
230
+ * expect(spy).toHaveBeenCalled()
231
+ * expect(spy).toHaveReturnedWith(10)
232
+ * ```
233
+ */
234
+ spyOn: typeof spyOn;
235
+ /**
236
+ * Creates a spy on a function, though can be initiated without one. Every time a function is invoked, it stores its call arguments, returns, and instances. Also, you can manipulate its behavior with [methods](https://vitest.dev/api/mock).
237
+ *
238
+ * If no function is given, mock will return `undefined`, when invoked.
239
+ * @example
240
+ * ```ts
241
+ * const getApples = vi.fn(() => 0)
242
+ *
243
+ * getApples()
244
+ *
245
+ * expect(getApples).toHaveBeenCalled()
246
+ * expect(getApples).toHaveReturnedWith(0)
247
+ *
248
+ * getApples.mockReturnValueOnce(5)
249
+ *
250
+ * expect(getApples()).toBe(5)
251
+ * expect(getApples).toHaveNthReturnedWith(2, 5)
252
+ * ```
253
+ */
254
+ fn: typeof fn;
255
+ /**
256
+ * Wait for the callback to execute successfully. If the callback throws an error or returns a rejected promise it will continue to wait until it succeeds or times out.
257
+ *
258
+ * This is very useful when you need to wait for some asynchronous action to complete, for example, when you start a server and need to wait for it to start.
259
+ * @example
260
+ * ```ts
261
+ * const server = createServer()
262
+ *
263
+ * await vi.waitFor(
264
+ * () => {
265
+ * if (!server.isReady)
266
+ * throw new Error('Server not started')
267
+ *
268
+ * console.log('Server started')
269
+ * }, {
270
+ * timeout: 500, // default is 1000
271
+ * interval: 20, // default is 50
272
+ * }
273
+ * )
274
+ * ```
275
+ */
276
+ waitFor: typeof waitFor;
277
+ /**
278
+ * This is similar to [`vi.waitFor`](https://vitest.dev/api/vi#vi-waitfor), but if the callback throws any errors, execution is immediately interrupted and an error message is received.
279
+ *
280
+ * If the callback returns a falsy value, the next check will continue until a truthy value is returned. This is useful when you need to wait for something to exist before taking the next step.
281
+ * @example
282
+ * ```ts
283
+ * const element = await vi.waitUntil(
284
+ * () => document.querySelector('.element'),
285
+ * {
286
+ * timeout: 500, // default is 1000
287
+ * interval: 20, // default is 50
288
+ * }
289
+ * )
290
+ *
291
+ * // do something with the element
292
+ * expect(element.querySelector('.element-child')).toBeTruthy()
293
+ * ```
294
+ */
295
+ waitUntil: typeof waitUntil;
296
+ /**
297
+ * Run the factory before imports are evaluated. You can return a value from the factory
298
+ * to reuse it inside your [`vi.mock`](https://vitest.dev/api/vi#vi-mock) factory and tests.
299
+ *
300
+ * If used with [`vi.mock`](https://vitest.dev/api/vi#vi-mock), both will be hoisted in the order they are defined in.
301
+ */
302
+ hoisted: <T>(factory: () => T) => T;
303
+ /**
304
+ * Mocks every import call to the module even if it was already statically imported.
305
+ *
306
+ * The call to `vi.mock` is hoisted to the top of the file, so you don't have access to variables declared in the global file scope
307
+ * unless they are defined with [`vi.hoisted`](https://vitest.dev/api/vi#vi-hoisted) before this call.
308
+ *
309
+ * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules).
310
+ * @param path Path to the module. Can be aliased, if your Vitest config supports it
311
+ * @param factory Mocked module factory. The result of this function will be an exports object
312
+ */
313
+ mock(path: string, factory?: MockFactoryWithHelper | MockOptions): void;
314
+ mock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T> | MockOptions): void;
315
+ /**
316
+ * Removes module from mocked registry. All calls to import will return the original module even if it was mocked before.
317
+ *
318
+ * This call is hoisted to the top of the file, so it will only unmock modules that were defined in `setupFiles`, for example.
319
+ * @param path Path to the module. Can be aliased, if your Vitest config supports it
320
+ */
321
+ unmock(path: string): void;
322
+ unmock(module: Promise<unknown>): void;
323
+ /**
324
+ * Mocks every subsequent [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) call.
325
+ *
326
+ * Unlike [`vi.mock`](https://vitest.dev/api/vi#vi-mock), this method will not mock statically imported modules because it is not hoisted to the top of the file.
327
+ *
328
+ * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules).
329
+ * @param path Path to the module. Can be aliased, if your Vitest config supports it
330
+ * @param factory Mocked module factory. The result of this function will be an exports object
331
+ */
332
+ doMock(path: string, factory?: MockFactoryWithHelper | MockOptions): void;
333
+ doMock<T>(module: Promise<T>, factory?: MockFactoryWithHelper<T> | MockOptions): void;
334
+ /**
335
+ * Removes module from mocked registry. All subsequent calls to import will return original module.
336
+ *
337
+ * Unlike [`vi.unmock`](https://vitest.dev/api/vi#vi-unmock), this method is not hoisted to the top of the file.
338
+ * @param path Path to the module. Can be aliased, if your Vitest config supports it
339
+ */
340
+ doUnmock(path: string): void;
341
+ doUnmock(module: Promise<unknown>): void;
342
+ /**
343
+ * Imports module, bypassing all checks if it should be mocked.
344
+ * Can be useful if you want to mock module partially.
345
+ * @example
346
+ * ```ts
347
+ * vi.mock('./example.js', async () => {
348
+ * const axios = await vi.importActual<typeof import('./example.js')>('./example.js')
349
+ *
350
+ * return { ...axios, get: vi.fn() }
351
+ * })
352
+ * ```
353
+ * @param path Path to the module. Can be aliased, if your config supports it
354
+ */
355
+ importActual: <T = ESModuleExports>(path: string) => Promise<T>;
356
+ /**
357
+ * Imports a module with all of its properties and nested properties mocked.
358
+ *
359
+ * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules).
360
+ * @example
361
+ * ```ts
362
+ * const example = await vi.importMock<typeof import('./example.js')>('./example.js')
363
+ * example.calc.mockReturnValue(10)
364
+ * expect(example.calc()).toBe(10)
365
+ * ```
366
+ * @param path Path to the module. Can be aliased, if your config supports it
367
+ * @returns Fully mocked module
368
+ */
369
+ importMock: <T = ESModuleExports>(path: string) => Promise<MaybeMockedDeep<T>>;
370
+ /**
371
+ * Type helper for TypeScript. Just returns the object that was passed.
372
+ *
373
+ * When `partial` is `true` it will expect a `Partial<T>` as a return value. By default, this will only make TypeScript believe that
374
+ * the first level values are mocked. You can pass down `{ deep: true }` as a second argument to tell TypeScript that the whole object is mocked, if it actually is.
375
+ * @example
376
+ * ```ts
377
+ * import example from './example.js'
378
+ * vi.mock('./example.js')
379
+ *
380
+ * test('1 + 1 equals 10' async () => {
381
+ * vi.mocked(example.calc).mockReturnValue(10)
382
+ * expect(example.calc(1, '+', 1)).toBe(10)
383
+ * })
384
+ * ```
385
+ * @param item Anything that can be mocked
386
+ * @param deep If the object is deeply mocked
387
+ * @param options If the object is partially or deeply mocked
388
+ */
389
+ mocked: (<T>(item: T, deep?: false) => MaybeMocked<T>) & (<T>(item: T, deep: true) => MaybeMockedDeep<T>) & (<T>(item: T, options: {
390
+ partial?: false
391
+ deep?: false
392
+ }) => MaybeMocked<T>) & (<T>(item: T, options: {
393
+ partial?: false
394
+ deep: true
395
+ }) => MaybeMockedDeep<T>) & (<T>(item: T, options: {
396
+ partial: true
397
+ deep?: false
398
+ }) => MaybePartiallyMocked<T>) & (<T>(item: T, options: {
399
+ partial: true
400
+ deep: true
401
+ }) => MaybePartiallyMockedDeep<T>) & (<T>(item: T) => MaybeMocked<T>);
402
+ /**
403
+ * Checks that a given parameter is a mock function. If you are using TypeScript, it will also narrow down its type.
404
+ */
405
+ isMockFunction: (fn: any) => fn is MockInstance;
406
+ /**
407
+ * Calls [`.mockClear()`](https://vitest.dev/api/mock#mockclear) on every mocked function.
408
+ *
409
+ * This will only empty `.mock` state, it will not affect mock implementations.
410
+ *
411
+ * This is useful if you need to clean up mocks between different assertions within a test.
412
+ */
413
+ clearAllMocks: () => VitestUtils;
414
+ /**
415
+ * Calls [`.mockReset()`](https://vitest.dev/api/mock#mockreset) on every mocked function.
416
+ *
417
+ * This will empty `.mock` state, reset "once" implementations, and reset each mock's base implementation to its original.
418
+ *
419
+ * This is useful when you want to reset all mocks to their original states.
420
+ */
421
+ resetAllMocks: () => VitestUtils;
422
+ /**
423
+ * Calls [`.mockRestore()`](https://vitest.dev/api/mock#mockrestore) on every mocked function.
424
+ *
425
+ * This will empty `.mock` state, restore all original mock implementations, and restore original descriptors of spied-on objects.
426
+ *
427
+ * This is useful for inter-test cleanup and/or removing mocks created by [`vi.spyOn(...)`](https://vitest.dev/api/vi#vi-spyon).
428
+ */
429
+ restoreAllMocks: () => VitestUtils;
430
+ /**
431
+ * Makes value available on global namespace.
432
+ * Useful, if you want to have global variables available, like `IntersectionObserver`.
433
+ * You can return it back to original value with `vi.unstubAllGlobals`, or by enabling `unstubGlobals` config option.
434
+ */
435
+ stubGlobal: (name: string | symbol | number, value: unknown) => VitestUtils;
436
+ /**
437
+ * Changes the value of `import.meta.env` and `process.env`.
438
+ * You can return it back to original value with `vi.unstubAllEnvs`, or by enabling `unstubEnvs` config option.
439
+ */
440
+ stubEnv: <T extends string>(name: T, value: T extends "PROD" | "DEV" | "SSR" ? boolean : string | undefined) => VitestUtils;
441
+ /**
442
+ * Reset the value to original value that was available before first `vi.stubGlobal` was called.
443
+ */
444
+ unstubAllGlobals: () => VitestUtils;
445
+ /**
446
+ * Reset environmental variables to the ones that were available before first `vi.stubEnv` was called.
447
+ */
448
+ unstubAllEnvs: () => VitestUtils;
449
+ /**
450
+ * Resets modules registry by clearing the cache of all modules. This allows modules to be reevaluated when reimported.
451
+ * Top-level imports cannot be re-evaluated. Might be useful to isolate modules where local state conflicts between tests.
452
+ *
453
+ * This method does not reset mocks registry. To clear mocks registry, use [`vi.unmock`](https://vitest.dev/api/vi#vi-unmock) or [`vi.doUnmock`](https://vitest.dev/api/vi#vi-dounmock).
454
+ */
455
+ resetModules: () => VitestUtils;
456
+ /**
457
+ * Wait for all imports to load. Useful, if you have a synchronous call that starts
458
+ * importing a module that you cannot await otherwise.
459
+ * Will also wait for new imports, started during the wait.
460
+ */
461
+ dynamicImportSettled: () => Promise<void>;
462
+ /**
463
+ * Updates runtime config. You can only change values that are used when executing tests.
464
+ */
465
+ setConfig: (config: RuntimeOptions) => void;
466
+ /**
467
+ * If config was changed with `vi.setConfig`, this will reset it to the original state.
468
+ */
469
+ resetConfig: () => void;
468
470
  }
469
471
  declare const vitest: VitestUtils;
470
472
  declare const vi: VitestUtils;
471
473
 
472
474
  interface AssertType {
473
- <T>(value: T): void;
475
+ <T>(value: T): void;
474
476
  }
475
477
  declare const assertType: AssertType;
476
478
 
477
479
  interface BrowserUI {
478
- setCurrentFileId: (fileId: string) => void;
479
- setIframeViewport: (width: number, height: number) => Promise<void>;
480
+ setCurrentFileId: (fileId: string) => void;
481
+ setIframeViewport: (width: number, height: number) => Promise<void>;
480
482
  }
481
483
 
482
484
  /** @deprecated import `TypeCheckRawErrorsMap` from `vitest/node` instead */