vitest 3.2.4 → 4.0.0-beta.10

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 (88) hide show
  1. package/LICENSE.md +2 -2
  2. package/dist/browser.d.ts +13 -16
  3. package/dist/browser.js +6 -5
  4. package/dist/chunks/base.Cjha6usc.js +129 -0
  5. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.CJUa-Hsa.js} +6 -8
  6. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  7. package/dist/chunks/browser.d.yFAklsD1.d.ts +18 -0
  8. package/dist/chunks/{cac.Cb-PYCCB.js → cac.DCxo_nSu.js} +72 -163
  9. package/dist/chunks/{cli-api.BkDphVBG.js → cli-api.BJJXh9BV.js} +1331 -1678
  10. package/dist/chunks/{config.d.D2ROskhv.d.ts → config.d.B_LthbQq.d.ts} +59 -65
  11. package/dist/chunks/{console.CtFJOzRO.js → console.7h5kHUIf.js} +34 -70
  12. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  13. package/dist/chunks/{coverage.DL5VHqXY.js → coverage.BCU-r2QL.js} +538 -765
  14. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  15. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  16. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  17. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  18. package/dist/chunks/{defaults.B7q_naMc.js → defaults.CXFFjsi8.js} +2 -42
  19. package/dist/chunks/environment.d.BsToaxti.d.ts +65 -0
  20. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  21. package/dist/chunks/{global.d.MAmajcmJ.d.ts → global.d.BK3X7FW1.d.ts} +7 -32
  22. package/dist/chunks/{globals.DEHgCU4V.js → globals.DG-S3xFe.js} +8 -8
  23. package/dist/chunks/{index.VByaPkjc.js → index.BIP7prJq.js} +472 -803
  24. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  25. package/dist/chunks/{index.BCWujgDG.js → index.BjKEiSn0.js} +14 -24
  26. package/dist/chunks/{index.CdQS2e2Q.js → index.CMfqw92x.js} +7 -8
  27. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  28. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  29. package/dist/chunks/moduleRunner.d.D9nBoC4p.d.ts +201 -0
  30. package/dist/chunks/moduleTransport.I-bgQy0S.js +19 -0
  31. package/dist/chunks/{node.fjCdwEIl.js → node.CyipiPvJ.js} +1 -1
  32. package/dist/chunks/plugin.d.BMVSnsGV.d.ts +9 -0
  33. package/dist/chunks/{reporters.d.BFLkQcL6.d.ts → reporters.d.BUWjmRYq.d.ts} +2086 -2146
  34. package/dist/chunks/resolveSnapshotEnvironment.Bkht6Yor.js +81 -0
  35. package/dist/chunks/resolver.Bx6lE0iq.js +119 -0
  36. package/dist/chunks/rpc.BKr6mtxz.js +65 -0
  37. package/dist/chunks/{setup-common.Dd054P77.js → setup-common.uiMcU3cv.js} +17 -29
  38. package/dist/chunks/startModuleRunner.p67gbNo9.js +665 -0
  39. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  40. package/dist/chunks/test.BiqSKISg.js +214 -0
  41. package/dist/chunks/{typechecker.DRKU1-1g.js → typechecker.DB-fIMaH.js} +165 -234
  42. package/dist/chunks/{utils.CAioKnHs.js → utils.C2YI6McM.js} +5 -14
  43. package/dist/chunks/{utils.XdZDrNZV.js → utils.D2R2NiOH.js} +8 -27
  44. package/dist/chunks/{vi.bdSIJ99Y.js → vi.ZPgvtBao.js} +156 -305
  45. package/dist/chunks/{vm.BThCzidc.js → vm.Ca0Y0W5f.js} +116 -226
  46. package/dist/chunks/{worker.d.1GmBbd7G.d.ts → worker.d.BDsXGkwh.d.ts} +31 -32
  47. package/dist/chunks/{worker.d.CKwWzBSj.d.ts → worker.d.BNcX_2mH.d.ts} +1 -1
  48. package/dist/cli.js +10 -10
  49. package/dist/config.cjs +5 -58
  50. package/dist/config.d.ts +72 -71
  51. package/dist/config.js +3 -9
  52. package/dist/coverage.d.ts +31 -24
  53. package/dist/coverage.js +9 -9
  54. package/dist/environments.d.ts +9 -14
  55. package/dist/environments.js +1 -1
  56. package/dist/index.d.ts +52 -213
  57. package/dist/index.js +7 -9
  58. package/dist/module-evaluator.d.ts +13 -0
  59. package/dist/module-evaluator.js +276 -0
  60. package/dist/module-runner.js +15 -0
  61. package/dist/node.d.ts +62 -51
  62. package/dist/node.js +26 -42
  63. package/dist/reporters.d.ts +11 -12
  64. package/dist/reporters.js +12 -12
  65. package/dist/runners.d.ts +3 -4
  66. package/dist/runners.js +13 -231
  67. package/dist/snapshot.js +2 -2
  68. package/dist/suite.d.ts +2 -2
  69. package/dist/suite.js +2 -2
  70. package/dist/worker.js +90 -47
  71. package/dist/workers/forks.js +34 -10
  72. package/dist/workers/runVmTests.js +36 -56
  73. package/dist/workers/threads.js +34 -10
  74. package/dist/workers/vmForks.js +11 -10
  75. package/dist/workers/vmThreads.js +11 -10
  76. package/dist/workers.d.ts +5 -7
  77. package/dist/workers.js +35 -17
  78. package/globals.d.ts +17 -17
  79. package/package.json +32 -31
  80. package/dist/chunks/base.DfmxU-tU.js +0 -38
  81. package/dist/chunks/environment.d.cL3nLXbE.d.ts +0 -119
  82. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  83. package/dist/chunks/index.CwejwG0H.js +0 -105
  84. package/dist/chunks/rpc.-pEldfrD.js +0 -83
  85. package/dist/chunks/runBaseTests.9Ij9_de-.js +0 -129
  86. package/dist/chunks/vite.d.CMLlLIFP.d.ts +0 -25
  87. package/dist/execute.d.ts +0 -150
  88. package/dist/execute.js +0 -13
@@ -1,387 +1,398 @@
1
- import { Task, TaskMeta, Suite, File, TestAnnotation, ImportDuration, TaskResultPack, TaskEventPack, SequenceSetupFiles, SequenceHooks, CancelReason } from '@vitest/runner';
2
- import { b as Awaitable, U as UserConsoleLog, c as Arrayable$1, A as AfterSuiteRunMeta, L as LabelColor, f as EnvironmentOptions, P as ProvidedContext } from './environment.d.cL3nLXbE.js';
3
- import { ParsedStack, TestError, SerializedError, ErrorWithDiff, Arrayable, Awaitable as Awaitable$1 } from '@vitest/utils';
1
+ import { CancelReason, TaskMeta, Suite, File, TestAnnotation, ImportDuration, Test, Task, TaskResultPack, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
2
+ import { Awaitable, ParsedStack, TestError, SerializedError, Arrayable as Arrayable$1 } from '@vitest/utils';
3
+ import { P as ProvidedContext, c as Arrayable, A as AfterSuiteRunMeta, U as UserConsoleLog, b as Awaitable$1, L as LabelColor } from './environment.d.BsToaxti.js';
4
4
  import { Writable } from 'node:stream';
5
- import { TransformResult as TransformResult$1, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions, ViteDevServer, ModuleNode } from 'vite';
6
- import { Console } from 'node:console';
5
+ import { ViteDevServer, TransformResult as TransformResult$1, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
7
6
  import { MockedModule } from '@vitest/mocker';
8
7
  import { StackTraceParserOptions } from '@vitest/utils/source-map';
9
- import { T as TestExecutionMethod } from './worker.d.1GmBbd7G.js';
10
- import { a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.D2ROskhv.js';
8
+ import { B as BrowserTesterOptions, S as SerializedTestSpecification } from './browser.d.yFAklsD1.js';
9
+ import { a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.B_LthbQq.js';
11
10
  import { PrettyFormatOptions } from '@vitest/pretty-format';
12
11
  import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
13
12
  import { SerializedDiffOptions } from '@vitest/utils/diff';
14
- import { ViteNodeServerOptions } from 'vite-node';
15
- import * as chai from 'chai';
16
- import { B as BenchmarkResult } from './benchmark.d.BwvBVTda.js';
17
- import { a as RuntimeCoverageProviderModule } from './coverage.d.S9RMNXIe.js';
13
+ import { chai } from '@vitest/expect';
14
+ import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
15
+ import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
16
+ import { a as RuntimeCoverageProviderModule } from './coverage.d.BZtK59WP.js';
18
17
  import { SnapshotManager } from '@vitest/snapshot/manager';
19
18
  import { Stats } from 'node:fs';
19
+ import { Console } from 'node:console';
20
20
 
21
- declare class TypeCheckError extends Error {
22
- message: string;
23
- stacks: ParsedStack[];
24
- name: string;
25
- constructor(message: string, stacks: ParsedStack[]);
26
- }
27
-
28
- interface ErrorOptions {
29
- type?: string;
30
- fullStack?: boolean;
31
- project?: TestProject;
32
- verbose?: boolean;
33
- screenshotPaths?: string[];
34
- task?: Task;
35
- showCodeFrame?: boolean;
36
- }
37
- type Listener = () => void;
38
- declare class Logger {
39
- ctx: Vitest;
40
- outputStream: NodeJS.WriteStream | Writable;
41
- errorStream: NodeJS.WriteStream | Writable;
42
- private _clearScreenPending;
43
- private _highlights;
44
- private cleanupListeners;
45
- console: Console;
46
- constructor(ctx: Vitest, outputStream?: NodeJS.WriteStream | Writable, errorStream?: NodeJS.WriteStream | Writable);
47
- log(...args: any[]): void;
48
- error(...args: any[]): void;
49
- warn(...args: any[]): void;
50
- clearFullScreen(message?: string): void;
51
- clearScreen(message: string, force?: boolean): void;
52
- private _clearScreen;
53
- printError(err: unknown, options?: ErrorOptions): void;
54
- deprecate(message: string): void;
55
- clearHighlightCache(filename?: string): void;
56
- highlight(filename: string, source: string): string;
57
- printNoTestFound(filters?: string[]): void;
58
- printBanner(): void;
59
- printBrowserBanner(project: TestProject): void;
60
- printUnhandledErrors(errors: unknown[]): void;
61
- printSourceTypeErrors(errors: TypeCheckError[]): void;
62
- getColumns(): number;
63
- onTerminalCleanup(listener: Listener): void;
64
- private addCleanupListeners;
65
- private registerUnhandledRejection;
66
- }
21
+ type ChaiConfig = Omit<Partial<typeof chai.config>, "useProxy" | "proxyExcludedKeys">;
67
22
 
68
- type SerializedTestSpecification = [project: {
69
- name: string | undefined
70
- root: string
71
- }, file: string, options: {
72
- pool: string
73
- testLines?: number[] | undefined
74
- }];
23
+ type HappyDOMOptions = Omit<NonNullable<ConstructorParameters<typeof happyDomTypes.Window>[0]>, "console">;
75
24
 
76
- declare class ReportedTaskImplementation {
77
- /**
78
- * The project associated with the test or suite.
79
- */
80
- readonly project: TestProject;
81
- /**
82
- * Unique identifier.
83
- * This ID is deterministic and will be the same for the same test across multiple runs.
84
- * The ID is based on the project name, module url and test order.
85
- */
86
- readonly id: string;
87
- /**
88
- * Location in the module where the test or suite is defined.
89
- */
90
- readonly location: {
91
- line: number
92
- column: number
93
- } | undefined;
25
+ type JSDOMOptions = ConstructorOptionsOverride & Omit<jsdomTypes.ConstructorOptions, keyof ConstructorOptionsOverride>;
26
+ interface ConstructorOptionsOverride {
94
27
  /**
95
- * Checks if the test did not fail the suite.
96
- * If the test is not finished yet or was skipped, it will return `true`.
97
- */
98
- ok(): boolean;
99
- /**
100
- * Custom metadata that was attached to the test during its execution.
101
- */
102
- meta(): TaskMeta;
103
- }
104
- declare class TestCase extends ReportedTaskImplementation {
105
- #private;
106
- readonly type = "test";
107
- /**
108
- * Direct reference to the test module where the test or suite is defined.
28
+ * The html content for the test.
29
+ *
30
+ * @default '<!DOCTYPE html>'
109
31
  */
110
- readonly module: TestModule;
32
+ html?: string | ArrayBufferLike;
111
33
  /**
112
- * Name of the test.
34
+ * userAgent affects the value read from navigator.userAgent, as well as the User-Agent header sent while fetching subresources.
35
+ *
36
+ * @default `Mozilla/5.0 (${process.platform}) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/${jsdomVersion}`
113
37
  */
114
- readonly name: string;
38
+ userAgent?: string;
115
39
  /**
116
- * Options that the test was initiated with.
40
+ * url sets the value returned by window.location, document.URL, and document.documentURI,
41
+ * and affects things like resolution of relative URLs within the document
42
+ * and the same-origin restrictions and referrer used while fetching subresources.
43
+ *
44
+ * @default 'http://localhost:3000'.
117
45
  */
118
- readonly options: TaskOptions;
46
+ url?: string;
119
47
  /**
120
- * Parent suite. If the test was called directly inside the module, the parent will be the module itself.
48
+ * Enable console?
49
+ *
50
+ * @default false
121
51
  */
122
- readonly parent: TestSuite | TestModule;
52
+ console?: boolean;
123
53
  /**
124
- * Full name of the test including all parent suites separated with `>`.
54
+ * jsdom does not have the capability to render visual content, and will act like a headless browser by default.
55
+ * It provides hints to web pages through APIs such as document.hidden that their content is not visible.
56
+ *
57
+ * When the `pretendToBeVisual` option is set to `true`, jsdom will pretend that it is rendering and displaying
58
+ * content.
59
+ *
60
+ * @default true
125
61
  */
126
- get fullName(): string;
62
+ pretendToBeVisual?: boolean;
127
63
  /**
128
- * Test results.
129
- * - **pending**: Test was collected, but didn't finish running yet.
130
- * - **passed**: Test passed successfully
131
- * - **failed**: Test failed to execute
132
- * - **skipped**: Test was skipped during collection or dynamically with `ctx.skip()`.
64
+ * Enable CookieJar
65
+ *
66
+ * @default false
133
67
  */
134
- result(): TestResult;
68
+ cookieJar?: boolean;
69
+ resources?: "usable";
70
+ }
71
+
72
+ interface CDPSession {
73
+ send: (method: string, params?: Record<string, unknown>) => Promise<unknown>;
74
+ on: (event: string, listener: (...args: unknown[]) => void) => void;
75
+ once: (event: string, listener: (...args: unknown[]) => void) => void;
76
+ off: (event: string, listener: (...args: unknown[]) => void) => void;
77
+ }
78
+ interface BrowserModuleMocker {
79
+ register: (sessionId: string, module: MockedModule) => Promise<void>;
80
+ delete: (sessionId: string, url: string) => Promise<void>;
81
+ clear: (sessionId: string) => Promise<void>;
82
+ }
83
+ interface BrowserProviderOption {
84
+ name: string;
85
+ supportedBrowser?: ReadonlyArray<string>;
86
+ factory: (project: TestProject) => BrowserProvider;
87
+ }
88
+ interface BrowserProvider {
89
+ name: string;
90
+ mocker?: BrowserModuleMocker;
135
91
  /**
136
- * Test annotations added via the `task.annotate` API during the test execution.
92
+ * @experimental opt-in into file parallelisation
137
93
  */
138
- annotations(): ReadonlyArray<TestAnnotation>;
94
+ supportsParallelism: boolean;
95
+ getCommandsContext: (sessionId: string) => Record<string, unknown>;
96
+ openPage: (sessionId: string, url: string) => Promise<void>;
97
+ getCDPSession?: (sessionId: string) => Promise<CDPSession>;
98
+ close: () => Awaitable<void>;
99
+ }
100
+ type BrowserBuiltinProvider = "webdriverio" | "playwright" | "preview";
101
+ type UnsupportedProperties = "browser" | "typecheck" | "alias" | "sequence" | "root" | "pool" | "poolOptions" | "runner" | "api" | "deps" | "environment" | "environmentOptions" | "server" | "benchmark" | "name";
102
+ interface BrowserInstanceOption extends Omit<ProjectConfig, UnsupportedProperties>, Pick<BrowserConfigOptions, "headless" | "locators" | "viewport" | "testerHtmlPath" | "screenshotDirectory" | "screenshotFailures" | "provider"> {
139
103
  /**
140
- * Useful information about the test like duration, memory usage, etc.
141
- * Diagnostic is only available after the test has finished.
104
+ * Name of the browser
142
105
  */
143
- diagnostic(): TestDiagnostic | undefined;
106
+ browser: string;
107
+ name?: string;
144
108
  }
145
- declare class TestCollection {
146
- #private;
147
- constructor(task: Suite | File, project: TestProject);
109
+ interface BrowserConfigOptions {
148
110
  /**
149
- * Returns the test or suite at a specific index.
111
+ * if running tests in the browser should be the default
112
+ *
113
+ * @default false
150
114
  */
151
- at(index: number): TestCase | TestSuite | undefined;
115
+ enabled?: boolean;
152
116
  /**
153
- * The number of tests and suites in the collection.
117
+ * Configurations for different browser setups
154
118
  */
155
- get size(): number;
119
+ instances: BrowserInstanceOption[];
156
120
  /**
157
- * Returns the collection in array form for easier manipulation.
121
+ * Browser provider
158
122
  */
159
- array(): (TestCase | TestSuite)[];
123
+ provider?: BrowserProviderOption;
160
124
  /**
161
- * Filters all tests that are part of this collection and its children.
125
+ * enable headless mode
126
+ *
127
+ * @default process.env.CI
162
128
  */
163
- allTests(state?: TestState): Generator<TestCase, undefined, void>;
129
+ headless?: boolean;
164
130
  /**
165
- * Filters only the tests that are part of this collection.
131
+ * Serve API options.
132
+ *
133
+ * The default port is 63315.
166
134
  */
167
- tests(state?: TestState): Generator<TestCase, undefined, void>;
135
+ api?: ApiConfig | number;
168
136
  /**
169
- * Filters only the suites that are part of this collection.
137
+ * Isolate test environment after each test
138
+ *
139
+ * @default true
170
140
  */
171
- suites(): Generator<TestSuite, undefined, void>;
141
+ isolate?: boolean;
172
142
  /**
173
- * Filters all suites that are part of this collection and its children.
143
+ * Run test files in parallel if provider supports this option
144
+ * This option only has effect in headless mode (enabled in CI by default)
145
+ *
146
+ * @default // Same as "test.fileParallelism"
174
147
  */
175
- allSuites(): Generator<TestSuite, undefined, void>;
176
- [Symbol.iterator](): Generator<TestSuite | TestCase, undefined, void>;
177
- }
178
-
179
- type ReportedHookContext = {
180
- readonly name: "beforeAll" | "afterAll"
181
- readonly entity: TestSuite | TestModule
182
- } | {
183
- readonly name: "beforeEach" | "afterEach"
184
- readonly entity: TestCase
185
- };
186
- declare abstract class SuiteImplementation extends ReportedTaskImplementation {
148
+ fileParallelism?: boolean;
187
149
  /**
188
- * Collection of suites and tests that are part of this suite.
150
+ * Show Vitest UI
151
+ *
152
+ * @default !process.env.CI
189
153
  */
190
- readonly children: TestCollection;
154
+ ui?: boolean;
191
155
  /**
192
- * Errors that happened outside of the test run during collection, like syntax errors.
156
+ * Default viewport size
193
157
  */
194
- errors(): SerializedError[];
195
- }
196
- declare class TestSuite extends SuiteImplementation {
197
- #private;
198
- readonly type = "suite";
158
+ viewport?: {
159
+ /**
160
+ * Width of the viewport
161
+ * @default 414
162
+ */
163
+ width: number;
164
+ /**
165
+ * Height of the viewport
166
+ * @default 896
167
+ */
168
+ height: number;
169
+ };
199
170
  /**
200
- * Name of the test or the suite.
171
+ * Locator options
201
172
  */
202
- readonly name: string;
173
+ locators?: {
174
+ /**
175
+ * Attribute used to locate elements by test id
176
+ * @default 'data-testid'
177
+ */
178
+ testIdAttribute?: string;
179
+ };
203
180
  /**
204
- * Direct reference to the test module where the test or suite is defined.
181
+ * Directory where screenshots will be saved when page.screenshot() is called
182
+ * If not set, all screenshots are saved to __screenshots__ directory in the same folder as the test file.
183
+ * If this is set, it will be resolved relative to the project root.
184
+ * @default __screenshots__
205
185
  */
206
- readonly module: TestModule;
186
+ screenshotDirectory?: string;
207
187
  /**
208
- * Parent suite. If suite was called directly inside the module, the parent will be the module itself.
188
+ * Should Vitest take screenshots if the test fails
189
+ * @default !browser.ui
209
190
  */
210
- readonly parent: TestSuite | TestModule;
191
+ screenshotFailures?: boolean;
211
192
  /**
212
- * Options that suite was initiated with.
193
+ * Path to the index.html file that will be used to run tests.
213
194
  */
214
- readonly options: TaskOptions;
195
+ testerHtmlPath?: string;
215
196
  /**
216
- * Checks if the suite has any failed tests.
217
- * This will also return `false` if suite failed during collection.
197
+ * Scripts injected into the main window.
218
198
  */
219
- ok: () => boolean;
199
+ orchestratorScripts?: BrowserScript[];
220
200
  /**
221
- * The meta information attached to the suite during its collection or execution.
201
+ * Commands that will be executed on the server
202
+ * via the browser `import("@vitest/browser/context").commands` API.
203
+ * @see {@link https://vitest.dev/guide/browser/commands}
222
204
  */
223
- meta: () => TaskMeta;
205
+ commands?: Record<string, BrowserCommand<any>>;
224
206
  /**
225
- * Checks the running state of the suite.
207
+ * Timeout for connecting to the browser
208
+ * @default 30000
226
209
  */
227
- state(): TestSuiteState;
210
+ connectTimeout?: number;
211
+ expect?: {
212
+ toMatchScreenshot?: { [ComparatorName in keyof ToMatchScreenshotComparators] : {
213
+ /**
214
+ * The name of the comparator to use for visual diffing.
215
+ *
216
+ * @defaultValue `'pixelmatch'`
217
+ */
218
+ comparatorName?: ComparatorName;
219
+ comparatorOptions?: ToMatchScreenshotComparators[ComparatorName];
220
+ } }[keyof ToMatchScreenshotComparators] & ToMatchScreenshotOptions;
221
+ };
228
222
  /**
229
- * Full name of the suite including all parent suites separated with `>`.
223
+ * Enables tracking uncaught errors and exceptions so they can be reported by Vitest.
224
+ *
225
+ * If you need to hide certain errors, it is recommended to use [`onUnhandledError`](https://vitest.dev/config/#onunhandlederror) option instead.
226
+ *
227
+ * Disabling this will completely remove all Vitest error handlers, which can help debugging with the "Pause on exceptions" checkbox turned on.
228
+ * @default true
230
229
  */
231
- get fullName(): string;
230
+ trackUnhandledErrors?: boolean;
232
231
  }
233
- declare class TestModule extends SuiteImplementation {
234
- readonly location: undefined;
235
- readonly type = "module";
236
- /**
237
- * This is usually an absolute UNIX file path.
238
- * It can be a virtual ID if the file is not on the disk.
239
- * This value corresponds to the ID in the Vite's module graph.
240
- */
241
- readonly moduleId: string;
242
- /**
243
- * Checks the running state of the test file.
244
- */
245
- state(): TestModuleState;
246
- /**
247
- * Checks if the module has any failed tests.
248
- * This will also return `false` if module failed during collection.
249
- */
250
- ok: () => boolean;
251
- /**
252
- * The meta information attached to the module during its collection or execution.
253
- */
254
- meta: () => TaskMeta;
255
- /**
256
- * Useful information about the module like duration, memory usage, etc.
257
- * If the module was not executed yet, all diagnostic values will return `0`.
258
- */
259
- diagnostic(): ModuleDiagnostic;
232
+ interface BrowserCommandContext {
233
+ testPath: string | undefined;
234
+ provider: BrowserProvider;
235
+ project: TestProject;
236
+ sessionId: string;
260
237
  }
261
- interface TaskOptions {
262
- readonly each: boolean | undefined;
263
- readonly fails: boolean | undefined;
264
- readonly concurrent: boolean | undefined;
265
- readonly shuffle: boolean | undefined;
266
- readonly retry: number | undefined;
267
- readonly repeats: number | undefined;
268
- readonly mode: "run" | "only" | "skip" | "todo";
238
+ interface BrowserServerStateSession {
239
+ project: TestProject;
240
+ connected: () => void;
241
+ fail: (v: Error) => void;
269
242
  }
270
- type TestSuiteState = "skipped" | "pending" | "failed" | "passed";
271
- type TestModuleState = TestSuiteState | "queued";
272
- type TestState = TestResult["state"];
273
- type TestResult = TestResultPassed | TestResultFailed | TestResultSkipped | TestResultPending;
274
- interface TestResultPending {
275
- /**
276
- * The test was collected, but didn't finish running yet.
277
- */
278
- readonly state: "pending";
279
- /**
280
- * Pending tests have no errors.
281
- */
282
- readonly errors: undefined;
243
+ interface BrowserOrchestrator {
244
+ cleanupTesters: () => Promise<void>;
245
+ createTesters: (options: BrowserTesterOptions) => Promise<void>;
246
+ onCancel: (reason: CancelReason) => Promise<void>;
247
+ $close: () => void;
283
248
  }
284
- interface TestResultPassed {
285
- /**
286
- * The test passed successfully.
287
- */
288
- readonly state: "passed";
289
- /**
290
- * Errors that were thrown during the test execution.
291
- *
292
- * **Note**: If test was retried successfully, errors will still be reported.
293
- */
294
- readonly errors: ReadonlyArray<TestError> | undefined;
249
+ interface BrowserServerState {
250
+ orchestrators: Map<string, BrowserOrchestrator>;
295
251
  }
296
- interface TestResultFailed {
297
- /**
298
- * The test failed to execute.
299
- */
300
- readonly state: "failed";
301
- /**
302
- * Errors that were thrown during the test execution.
303
- */
304
- readonly errors: ReadonlyArray<TestError>;
252
+ interface ParentProjectBrowser {
253
+ spawn: (project: TestProject) => ProjectBrowser;
305
254
  }
306
- interface TestResultSkipped {
255
+ interface ProjectBrowser {
256
+ vite: ViteDevServer;
257
+ state: BrowserServerState;
258
+ provider: BrowserProvider;
259
+ close: () => Promise<void>;
260
+ initBrowserProvider: (project: TestProject) => Promise<void>;
261
+ parseStacktrace: (stack: string) => ParsedStack[];
262
+ parseErrorStacktrace: (error: TestError, options?: StackTraceParserOptions) => ParsedStack[];
263
+ }
264
+ interface BrowserCommand<Payload extends unknown[]> {
265
+ (context: BrowserCommandContext, ...payload: Payload): Awaitable<any>;
266
+ }
267
+ interface BrowserScript {
307
268
  /**
308
- * The test was skipped with `only` (on another test), `skip` or `todo` flag.
309
- * You can see which one was used in the `options.mode` option.
269
+ * If "content" is provided and type is "module", this will be its identifier.
270
+ *
271
+ * If you are using TypeScript, you can add `.ts` extension here for example.
272
+ * @default `injected-${index}.js`
310
273
  */
311
- readonly state: "skipped";
274
+ id?: string;
312
275
  /**
313
- * Skipped tests have no errors.
276
+ * JavaScript content to be injected. This string is processed by Vite plugins if type is "module".
277
+ *
278
+ * You can use `id` to give Vite a hint about the file extension.
314
279
  */
315
- readonly errors: undefined;
280
+ content?: string;
316
281
  /**
317
- * A custom note passed down to `ctx.skip(note)`.
282
+ * Path to the script. This value is resolved by Vite so it can be a node module or a file path.
318
283
  */
319
- readonly note: string | undefined;
320
- }
321
- interface TestDiagnostic {
284
+ src?: string;
322
285
  /**
323
- * If the duration of the test is above `slowTestThreshold`.
286
+ * If the script should be loaded asynchronously.
324
287
  */
325
- readonly slow: boolean;
288
+ async?: boolean;
326
289
  /**
327
- * The amount of memory used by the test in bytes.
328
- * This value is only available if the test was executed with `logHeapUsage` flag.
290
+ * Script type.
291
+ * @default 'module'
329
292
  */
330
- readonly heap: number | undefined;
293
+ type?: string;
294
+ }
295
+ interface ResolvedBrowserOptions extends BrowserConfigOptions {
296
+ name: string;
297
+ enabled: boolean;
298
+ headless: boolean;
299
+ isolate: boolean;
300
+ fileParallelism: boolean;
301
+ api: ApiConfig;
302
+ ui: boolean;
303
+ viewport: {
304
+ width: number;
305
+ height: number;
306
+ };
307
+ screenshotFailures: boolean;
308
+ locators: {
309
+ testIdAttribute: string;
310
+ };
311
+ }
312
+ type ToMatchScreenshotResolvePath = (data: {
331
313
  /**
332
- * The time it takes to execute the test in ms.
314
+ * Path **without** extension, sanitized and relative to the test file.
315
+ *
316
+ * This comes from the arguments passed to `toMatchScreenshot`; if called
317
+ * without arguments this will be the auto-generated name.
318
+ *
319
+ * @example
320
+ * test('calls `onClick`', () => {
321
+ * expect(locator).toMatchScreenshot()
322
+ * // arg = "calls-onclick-1"
323
+ * })
324
+ *
325
+ * @example
326
+ * expect(locator).toMatchScreenshot('foo/bar/baz.png')
327
+ * // arg = "foo/bar/baz"
328
+ *
329
+ * @example
330
+ * expect(locator).toMatchScreenshot('../foo/bar/baz.png')
331
+ * // arg = "foo/bar/baz"
333
332
  */
334
- readonly duration: number;
333
+ arg: string;
335
334
  /**
336
- * The time in ms when the test started.
335
+ * Screenshot extension, with leading dot.
336
+ *
337
+ * This can be set through the arguments passed to `toMatchScreenshot`, but
338
+ * the value will fall back to `'.png'` if an unsupported extension is used.
337
339
  */
338
- readonly startTime: number;
340
+ ext: string;
339
341
  /**
340
- * The amount of times the test was retried.
342
+ * The instance's browser name.
341
343
  */
342
- readonly retryCount: number;
344
+ browserName: string;
343
345
  /**
344
- * The amount of times the test was repeated as configured by `repeats` option.
345
- * This value can be lower if the test failed during the repeat and no `retry` is configured.
346
+ * The value of {@linkcode process.platform}.
346
347
  */
347
- readonly repeatCount: number;
348
+ platform: NodeJS.Platform;
348
349
  /**
349
- * If test passed on a second retry.
350
+ * The value provided to
351
+ * {@linkcode https://vitest.dev/guide/browser/config#browser-screenshotdirectory|browser.screenshotDirectory},
352
+ * if none is provided, its default value.
350
353
  */
351
- readonly flaky: boolean;
352
- }
353
- interface ModuleDiagnostic {
354
+ screenshotDirectory: string;
354
355
  /**
355
- * The time it takes to import and initiate an environment.
356
+ * Absolute path to the project's
357
+ * {@linkcode https://vitest.dev/config/#root|root}.
356
358
  */
357
- readonly environmentSetupDuration: number;
359
+ root: string;
358
360
  /**
359
- * The time it takes Vitest to setup test harness (runner, mocks, etc.).
361
+ * Path to the test file, relative to the project's
362
+ * {@linkcode https://vitest.dev/config/#root|root}.
360
363
  */
361
- readonly prepareDuration: number;
364
+ testFileDirectory: string;
362
365
  /**
363
- * The time it takes to import the test module.
364
- * This includes importing everything in the module and executing suite callbacks.
366
+ * The test's filename.
365
367
  */
366
- readonly collectDuration: number;
368
+ testFileName: string;
367
369
  /**
368
- * The time it takes to import the setup module.
370
+ * The {@linkcode https://vitest.dev/api/#test|test}'s name, including
371
+ * parent {@linkcode https://vitest.dev/api/#describe|describe}, sanitized.
369
372
  */
370
- readonly setupDuration: number;
373
+ testName: string;
371
374
  /**
372
- * Accumulated duration of all tests and hooks in the module.
375
+ * The value provided to
376
+ * {@linkcode https://vitest.dev/config/#attachmentsdir|attachmentsDir},
377
+ * if none is provided, its default value.
373
378
  */
374
- readonly duration: number;
379
+ attachmentsDir: string;
380
+ }) => string;
381
+ interface ToMatchScreenshotOptions {
375
382
  /**
376
- * The amount of memory used by the test module in bytes.
377
- * This value is only available if the test was executed with `logHeapUsage` flag.
383
+ * Overrides default reference screenshot path.
384
+ *
385
+ * @default `${root}/${testFileDirectory}/${screenshotDirectory}/${testFileName}/${arg}-${browserName}-${platform}${ext}`
378
386
  */
379
- readonly heap: number | undefined;
387
+ resolveScreenshotPath?: ToMatchScreenshotResolvePath;
380
388
  /**
381
- * The time spent importing every non-externalized dependency that Vitest has processed.
389
+ * Overrides default screenshot path used for diffs.
390
+ *
391
+ * @default `${root}/${attachmentsDir}/${testFileDirectory}/${testFileName}/${arg}-${browserName}-${platform}${ext}`
382
392
  */
383
- readonly importDurations: Record<string, ImportDuration>;
393
+ resolveDiffPath?: ToMatchScreenshotResolvePath;
384
394
  }
395
+ interface ToMatchScreenshotComparators {}
385
396
 
386
397
  type BuiltinPool = "browser" | "threads" | "forks" | "vmThreads" | "vmForks" | "typescript";
387
398
  type Pool = BuiltinPool | (string & {});
@@ -423,8 +434,6 @@ interface ResolvedPoolOptions extends PoolOptions {
423
434
  vmForks?: ResolvedForksOptions & VmOptions;
424
435
  }
425
436
  interface ThreadsOptions {
426
- /** Minimum amount of threads to use */
427
- minThreads?: number | string;
428
437
  /** Maximum amount of threads to use */
429
438
  maxThreads?: number | string;
430
439
  /**
@@ -443,12 +452,9 @@ interface ThreadsOptions {
443
452
  useAtomics?: boolean;
444
453
  }
445
454
  interface ResolvedThreadsOptions extends ThreadsOptions {
446
- minThreads?: number;
447
455
  maxThreads?: number;
448
456
  }
449
457
  interface ForksOptions {
450
- /** Minimum amount of child processes to use */
451
- minForks?: number | string;
452
458
  /** Maximum amount of child processes to use */
453
459
  maxForks?: number | string;
454
460
  /**
@@ -459,7 +465,6 @@ interface ForksOptions {
459
465
  singleFork?: boolean;
460
466
  }
461
467
  interface ResolvedForksOptions extends ForksOptions {
462
- minForks?: number;
463
468
  maxForks?: number;
464
469
  }
465
470
  interface WorkerContextOptions {
@@ -505,20 +510,6 @@ interface VmOptions {
505
510
  }
506
511
 
507
512
  declare class TestSpecification {
508
- /**
509
- * @deprecated use `project` instead
510
- */
511
- readonly 0: TestProject;
512
- /**
513
- * @deprecated use `moduleId` instead
514
- */
515
- readonly 1: string;
516
- /**
517
- * @deprecated use `pool` instead
518
- */
519
- readonly 2: {
520
- pool: Pool
521
- };
522
513
  /**
523
514
  * The task ID associated with the test module.
524
515
  */
@@ -546,195 +537,444 @@ declare class TestSpecification {
546
537
  */
547
538
  get testModule(): TestModule | undefined;
548
539
  toJSON(): SerializedTestSpecification;
549
- /**
550
- * for backwards compatibility
551
- * @deprecated
552
- */
553
- [Symbol.iterator](): Generator<string | TestProject, void, unknown>;
554
540
  }
555
541
 
556
- type TestRunEndReason = "passed" | "interrupted" | "failed";
557
- interface Reporter {
558
- onInit?: (vitest: Vitest) => void;
559
- /**
560
- * Called when the project initiated the browser instance.
561
- * project.browser will always be defined.
562
- * @experimental
563
- */
564
- onBrowserInit?: (project: TestProject) => Awaitable<void>;
542
+ declare class TestProject {
543
+ options?: InitializeProjectOptions | undefined;
565
544
  /**
566
- * @deprecated use `onTestRunStart` instead
545
+ * The global Vitest instance.
546
+ * @experimental The public Vitest API is experimental and does not follow semver.
567
547
  */
568
- onPathsCollected?: (paths?: string[]) => Awaitable<void>;
548
+ readonly vitest: Vitest;
569
549
  /**
570
- * @deprecated use `onTestRunStart` instead
550
+ * Resolved global configuration. If there are no workspace projects, this will be the same as `config`.
571
551
  */
572
- onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable<void>;
552
+ readonly globalConfig: ResolvedConfig;
573
553
  /**
574
- * @deprecated use `onTestModuleCollected` instead
554
+ * Browser instance if the browser is enabled. This is initialized when the tests run for the first time.
575
555
  */
576
- onCollected?: (files: File[]) => Awaitable<void>;
556
+ browser?: ProjectBrowser;
577
557
  /**
578
- * @deprecated use `onTestRunEnd` instead
558
+ * Temporary directory for the project. This is unique for each project. Vitest stores transformed content here.
579
559
  */
580
- onFinished?: (files: File[], errors: unknown[], coverage?: unknown) => Awaitable<void>;
560
+ readonly tmpDir: string;
561
+ /** @inetrnal */ testFilesList: string[] | null;
562
+ private runner;
563
+ private closingPromise;
564
+ private typecheckFilesList;
565
+ private _globalSetups?;
566
+ private _provided;
567
+ constructor(vitest: Vitest, options?: InitializeProjectOptions | undefined);
581
568
  /**
582
- * @deprecated use `onTestModuleQueued`, `onTestModuleStart`, `onTestModuleEnd`, `onTestCaseReady`, `onTestCaseResult` instead
569
+ * The unique hash of this project. This value is consistent between the reruns.
570
+ *
571
+ * It is based on the root of the project (not consistent between OS) and its name.
583
572
  */
584
- onTaskUpdate?: (packs: TaskResultPack[], events: TaskEventPack[]) => Awaitable<void>;
585
- onTestRemoved?: (trigger?: string) => Awaitable<void>;
586
- onWatcherStart?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
587
- onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
588
- onServerRestart?: (reason?: string) => Awaitable<void>;
589
- onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
590
- onProcessTimeout?: () => Awaitable<void>;
573
+ get hash(): string;
591
574
  /**
592
- * Called when the new test run starts.
575
+ * Provide a value to the test context. This value will be available to all tests with `inject`.
593
576
  */
594
- onTestRunStart?: (specifications: ReadonlyArray<TestSpecification>) => Awaitable<void>;
577
+ provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
595
578
  /**
596
- * Called when the test run is finished.
579
+ * Get the provided context. The project context is merged with the global context.
597
580
  */
598
- onTestRunEnd?: (testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason) => Awaitable<void>;
581
+ getProvidedContext(): ProvidedContext;
599
582
  /**
600
- * Called when the module is enqueued for testing. The file itself is not loaded yet.
583
+ * Creates a new test specification. Specifications describe how to run tests.
584
+ * @param moduleId The file path
601
585
  */
602
- onTestModuleQueued?: (testModule: TestModule) => Awaitable<void>;
586
+ createSpecification(moduleId: string, locations?: number[] | undefined, pool?: string): TestSpecification;
587
+ toJSON(): SerializedTestProject;
603
588
  /**
604
- * Called when the test file is loaded and the module is ready to run tests.
589
+ * Vite's dev server instance. Every workspace project has its own server.
605
590
  */
606
- onTestModuleCollected?: (testModule: TestModule) => Awaitable<void>;
591
+ get vite(): ViteDevServer;
607
592
  /**
608
- * Called when starting to run tests of the test file
593
+ * Resolved project configuration.
609
594
  */
610
- onTestModuleStart?: (testModule: TestModule) => Awaitable<void>;
595
+ get config(): ResolvedConfig;
611
596
  /**
612
- * Called when all tests of the test file have finished running.
597
+ * The name of the project or an empty string if not set.
613
598
  */
614
- onTestModuleEnd?: (testModule: TestModule) => Awaitable<void>;
599
+ get name(): string;
615
600
  /**
616
- * Called when test case is ready to run.
617
- * Called before the `beforeEach` hooks for the test are run.
601
+ * The color used when reporting tasks of this project.
618
602
  */
619
- onTestCaseReady?: (testCase: TestCase) => Awaitable<void>;
603
+ get color(): ProjectName["color"];
620
604
  /**
621
- * Called after the test and its hooks are finished running.
622
- * The `result()` cannot be `pending`.
605
+ * Serialized project configuration. This is the config that tests receive.
623
606
  */
624
- onTestCaseResult?: (testCase: TestCase) => Awaitable<void>;
607
+ get serializedConfig(): SerializedConfig;
625
608
  /**
626
- * Called when annotation is added via the `task.annotate` API.
609
+ * Check if this is the root project. The root project is the one that has the root config.
627
610
  */
628
- onTestCaseAnnotate?: (testCase: TestCase, annotation: TestAnnotation) => Awaitable<void>;
611
+ isRootProject(): boolean;
612
+ onTestsRerun(cb: OnTestsRerunHandler): void;
629
613
  /**
630
- * Called when test suite is ready to run.
631
- * Called before the `beforeAll` hooks for the test are run.
614
+ * Get all files in the project that match the globs in the config and the filters.
615
+ * @param filters String filters to match the test files.
632
616
  */
633
- onTestSuiteReady?: (testSuite: TestSuite) => Awaitable<void>;
617
+ globTestFiles(filters?: string[]): Promise<{
618
+ /**
619
+ * Test files that match the filters.
620
+ */
621
+ testFiles: string[];
622
+ /**
623
+ * Typecheck test files that match the filters. This will be empty unless `typecheck.enabled` is `true`.
624
+ */
625
+ typecheckTestFiles: string[];
626
+ }>;
627
+ private globAllTestFiles;
628
+ isBrowserEnabled(): boolean;
629
+ private markTestFile;
634
630
  /**
635
- * Called after the test suite and its hooks are finished running.
636
- * The `state` cannot be `pending`.
631
+ * Test if a file matches the test globs. This does the actual glob matching if the test is not cached, unlike `isCachedTestFile`.
637
632
  */
638
- onTestSuiteResult?: (testSuite: TestSuite) => Awaitable<void>;
633
+ matchesTestGlob(moduleId: string, source?: () => string): boolean;
634
+ private isInSourceTestCode;
635
+ private filterFiles;
636
+ private _parentBrowser?;
639
637
  /**
640
- * Called before the hook starts to run.
638
+ * Closes the project and all associated resources. This can only be called once; the closing promise is cached until the server restarts.
639
+ * If the resources are needed again, create a new project.
641
640
  */
642
- onHookStart?: (hook: ReportedHookContext) => Awaitable<void>;
641
+ close(): Promise<void>;
643
642
  /**
644
- * Called after the hook finished running.
643
+ * Import a file using Vite module runner.
644
+ * @param moduleId The ID of the module in Vite module graph
645
645
  */
646
- onHookEnd?: (hook: ReportedHookContext) => Awaitable<void>;
647
- onCoverage?: (coverage: unknown) => Awaitable<void>;
646
+ import<T>(moduleId: string): Promise<T>;
647
+ private _setHash;
648
+ private _serializeOverriddenConfig;
649
+ private clearTmpDir;
648
650
  }
649
-
650
- interface BaseOptions {
651
- isTTY?: boolean;
651
+ interface SerializedTestProject {
652
+ name: string;
653
+ serializedConfig: SerializedConfig;
654
+ context: ProvidedContext;
652
655
  }
653
- declare abstract class BaseReporter implements Reporter {
654
- start: number;
655
- end: number;
656
- watchFilters?: string[];
657
- failedUnwatchedFiles: TestModule[];
658
- isTTY: boolean;
659
- ctx: Vitest;
660
- renderSucceed: boolean;
661
- protected verbose: boolean;
662
- private _filesInWatchMode;
663
- private _timeStart;
664
- constructor(options?: BaseOptions);
665
- onInit(ctx: Vitest): void;
666
- log(...messages: any): void;
667
- error(...messages: any): void;
668
- relative(path: string): string;
669
- onFinished(files?: File[], errors?: unknown[]): void;
670
- onTestCaseResult(testCase: TestCase): void;
671
- onTestSuiteResult(testSuite: TestSuite): void;
672
- onTestModuleEnd(testModule: TestModule): void;
673
- private logFailedTask;
674
- protected printTestModule(testModule: TestModule): void;
675
- protected printTestCase(moduleState: TestModuleState, test: TestCase): void;
676
- private getModuleLog;
677
- protected printTestSuite(_suite: TestSuite): void;
678
- protected getTestName(test: Task, separator?: string): string;
679
- protected getFullName(test: Task, separator?: string): string;
680
- protected formatShortError(error: ErrorWithDiff): string;
681
- protected getTestIndentation(_test: Task): string;
682
- protected printAnnotations(test: TestCase, console: "log" | "error", padding?: number): void;
683
- protected getDurationPrefix(task: Task): string;
684
- onWatcherStart(files?: File[], errors?: unknown[]): void;
685
- onWatcherRerun(files: string[], trigger?: string): void;
686
- onUserConsoleLog(log: UserConsoleLog, taskState?: TestResult["state"]): void;
687
- onTestRemoved(trigger?: string): void;
688
- shouldLog(log: UserConsoleLog, taskState?: TestResult["state"]): boolean;
689
- onServerRestart(reason?: string): void;
690
- reportSummary(files: File[], errors: unknown[]): void;
691
- reportTestSummary(files: File[], errors: unknown[]): void;
692
- private printErrorsSummary;
693
- reportBenchmarkSummary(files: File[]): void;
694
- private printTaskErrors;
656
+ interface InitializeProjectOptions extends TestProjectInlineConfiguration {
657
+ configFile: string | false;
695
658
  }
696
659
 
697
- interface BlobOptions {
698
- outputFile?: string;
660
+ declare class ReportedTaskImplementation {
661
+ /**
662
+ * The project associated with the test or suite.
663
+ */
664
+ readonly project: TestProject;
665
+ /**
666
+ * Unique identifier.
667
+ * This ID is deterministic and will be the same for the same test across multiple runs.
668
+ * The ID is based on the project name, module url and test order.
669
+ */
670
+ readonly id: string;
671
+ /**
672
+ * Location in the module where the test or suite is defined.
673
+ */
674
+ readonly location: {
675
+ line: number;
676
+ column: number;
677
+ } | undefined;
678
+ /**
679
+ * Checks if the test did not fail the suite.
680
+ * If the test is not finished yet or was skipped, it will return `true`.
681
+ */
682
+ ok(): boolean;
683
+ /**
684
+ * Custom metadata that was attached to the test during its execution.
685
+ */
686
+ meta(): TaskMeta;
699
687
  }
700
- declare class BlobReporter implements Reporter {
701
- start: number;
702
- ctx: Vitest;
703
- options: BlobOptions;
704
- constructor(options: BlobOptions);
705
- onInit(ctx: Vitest): void;
706
- onFinished(files: File[] | undefined, errors: unknown[] | undefined, coverage: unknown): Promise<void>;
688
+ declare class TestCase extends ReportedTaskImplementation {
689
+ #private;
690
+ readonly type = "test";
691
+ /**
692
+ * Direct reference to the test module where the test or suite is defined.
693
+ */
694
+ readonly module: TestModule;
695
+ /**
696
+ * Name of the test.
697
+ */
698
+ readonly name: string;
699
+ /**
700
+ * Options that the test was initiated with.
701
+ */
702
+ readonly options: TaskOptions;
703
+ /**
704
+ * Parent suite. If the test was called directly inside the module, the parent will be the module itself.
705
+ */
706
+ readonly parent: TestSuite | TestModule;
707
+ /**
708
+ * Full name of the test including all parent suites separated with `>`.
709
+ */
710
+ get fullName(): string;
711
+ /**
712
+ * Test results.
713
+ * - **pending**: Test was collected, but didn't finish running yet.
714
+ * - **passed**: Test passed successfully
715
+ * - **failed**: Test failed to execute
716
+ * - **skipped**: Test was skipped during collection or dynamically with `ctx.skip()`.
717
+ */
718
+ result(): TestResult;
719
+ /**
720
+ * Test annotations added via the `task.annotate` API during the test execution.
721
+ */
722
+ annotations(): ReadonlyArray<TestAnnotation>;
723
+ /**
724
+ * Useful information about the test like duration, memory usage, etc.
725
+ * Diagnostic is only available after the test has finished.
726
+ */
727
+ diagnostic(): TestDiagnostic | undefined;
707
728
  }
708
- interface MergedBlobs {
709
- files: File[];
710
- errors: unknown[];
711
- coverages: unknown[];
712
- executionTimes: number[];
729
+ declare class TestCollection {
730
+ #private;
731
+ constructor(task: Suite | File, project: TestProject);
732
+ /**
733
+ * Returns the test or suite at a specific index.
734
+ */
735
+ at(index: number): TestCase | TestSuite | undefined;
736
+ /**
737
+ * The number of tests and suites in the collection.
738
+ */
739
+ get size(): number;
740
+ /**
741
+ * Returns the collection in array form for easier manipulation.
742
+ */
743
+ array(): (TestCase | TestSuite)[];
744
+ /**
745
+ * Filters all tests that are part of this collection and its children.
746
+ */
747
+ allTests(state?: TestState): Generator<TestCase, undefined, void>;
748
+ /**
749
+ * Filters only the tests that are part of this collection.
750
+ */
751
+ tests(state?: TestState): Generator<TestCase, undefined, void>;
752
+ /**
753
+ * Filters only the suites that are part of this collection.
754
+ */
755
+ suites(): Generator<TestSuite, undefined, void>;
756
+ /**
757
+ * Filters all suites that are part of this collection and its children.
758
+ */
759
+ allSuites(): Generator<TestSuite, undefined, void>;
760
+ [Symbol.iterator](): Generator<TestSuite | TestCase, undefined, void>;
713
761
  }
714
762
 
715
- interface DefaultReporterOptions extends BaseOptions {
716
- summary?: boolean;
717
- }
718
- declare class DefaultReporter extends BaseReporter {
719
- private options;
720
- private summary?;
721
- constructor(options?: DefaultReporterOptions);
722
- onTestRunStart(specifications: ReadonlyArray<TestSpecification>): void;
723
- onTestModuleQueued(file: TestModule): void;
724
- onTestModuleCollected(module: TestModule): void;
725
- onTestModuleEnd(module: TestModule): void;
726
- onTestCaseReady(test: TestCase): void;
727
- onTestCaseResult(test: TestCase): void;
728
- onHookStart(hook: ReportedHookContext): void;
729
- onHookEnd(hook: ReportedHookContext): void;
730
- onInit(ctx: Vitest): void;
731
- onTestRunEnd(): void;
763
+ type ReportedHookContext = {
764
+ readonly name: "beforeAll" | "afterAll";
765
+ readonly entity: TestSuite | TestModule;
766
+ } | {
767
+ readonly name: "beforeEach" | "afterEach";
768
+ readonly entity: TestCase;
769
+ };
770
+ declare abstract class SuiteImplementation extends ReportedTaskImplementation {
771
+ /**
772
+ * Collection of suites and tests that are part of this suite.
773
+ */
774
+ readonly children: TestCollection;
775
+ /**
776
+ * Errors that happened outside of the test run during collection, like syntax errors.
777
+ */
778
+ errors(): SerializedError[];
732
779
  }
733
-
734
- interface HTMLOptions {
735
- outputFile?: string;
780
+ declare class TestSuite extends SuiteImplementation {
781
+ #private;
782
+ readonly type = "suite";
783
+ /**
784
+ * Name of the test or the suite.
785
+ */
786
+ readonly name: string;
787
+ /**
788
+ * Direct reference to the test module where the test or suite is defined.
789
+ */
790
+ readonly module: TestModule;
791
+ /**
792
+ * Parent suite. If suite was called directly inside the module, the parent will be the module itself.
793
+ */
794
+ readonly parent: TestSuite | TestModule;
795
+ /**
796
+ * Options that suite was initiated with.
797
+ */
798
+ readonly options: TaskOptions;
799
+ /**
800
+ * Checks if the suite has any failed tests.
801
+ * This will also return `false` if suite failed during collection.
802
+ */
803
+ ok: () => boolean;
804
+ /**
805
+ * The meta information attached to the suite during its collection or execution.
806
+ */
807
+ meta: () => TaskMeta;
808
+ /**
809
+ * Checks the running state of the suite.
810
+ */
811
+ state(): TestSuiteState;
812
+ /**
813
+ * Full name of the suite including all parent suites separated with `>`.
814
+ */
815
+ get fullName(): string;
736
816
  }
737
-
817
+ declare class TestModule extends SuiteImplementation {
818
+ readonly location: undefined;
819
+ readonly type = "module";
820
+ /**
821
+ * This is usually an absolute UNIX file path.
822
+ * It can be a virtual ID if the file is not on the disk.
823
+ * This value corresponds to the ID in the Vite's module graph.
824
+ */
825
+ readonly moduleId: string;
826
+ /**
827
+ * Module id relative to the project. This is the same as `task.name`.
828
+ */
829
+ readonly relativeModuleId: string;
830
+ /**
831
+ * Checks the running state of the test file.
832
+ */
833
+ state(): TestModuleState;
834
+ /**
835
+ * Checks if the module has any failed tests.
836
+ * This will also return `false` if module failed during collection.
837
+ */
838
+ ok: () => boolean;
839
+ /**
840
+ * The meta information attached to the module during its collection or execution.
841
+ */
842
+ meta: () => TaskMeta;
843
+ /**
844
+ * Useful information about the module like duration, memory usage, etc.
845
+ * If the module was not executed yet, all diagnostic values will return `0`.
846
+ */
847
+ diagnostic(): ModuleDiagnostic;
848
+ }
849
+ interface TaskOptions {
850
+ readonly each: boolean | undefined;
851
+ readonly fails: boolean | undefined;
852
+ readonly concurrent: boolean | undefined;
853
+ readonly shuffle: boolean | undefined;
854
+ readonly retry: number | undefined;
855
+ readonly repeats: number | undefined;
856
+ readonly mode: "run" | "only" | "skip" | "todo";
857
+ }
858
+ type TestSuiteState = "skipped" | "pending" | "failed" | "passed";
859
+ type TestModuleState = TestSuiteState | "queued";
860
+ type TestState = TestResult["state"];
861
+ type TestResult = TestResultPassed | TestResultFailed | TestResultSkipped | TestResultPending;
862
+ interface TestResultPending {
863
+ /**
864
+ * The test was collected, but didn't finish running yet.
865
+ */
866
+ readonly state: "pending";
867
+ /**
868
+ * Pending tests have no errors.
869
+ */
870
+ readonly errors: undefined;
871
+ }
872
+ interface TestResultPassed {
873
+ /**
874
+ * The test passed successfully.
875
+ */
876
+ readonly state: "passed";
877
+ /**
878
+ * Errors that were thrown during the test execution.
879
+ *
880
+ * **Note**: If test was retried successfully, errors will still be reported.
881
+ */
882
+ readonly errors: ReadonlyArray<TestError> | undefined;
883
+ }
884
+ interface TestResultFailed {
885
+ /**
886
+ * The test failed to execute.
887
+ */
888
+ readonly state: "failed";
889
+ /**
890
+ * Errors that were thrown during the test execution.
891
+ */
892
+ readonly errors: ReadonlyArray<TestError>;
893
+ }
894
+ interface TestResultSkipped {
895
+ /**
896
+ * The test was skipped with `only` (on another test), `skip` or `todo` flag.
897
+ * You can see which one was used in the `options.mode` option.
898
+ */
899
+ readonly state: "skipped";
900
+ /**
901
+ * Skipped tests have no errors.
902
+ */
903
+ readonly errors: undefined;
904
+ /**
905
+ * A custom note passed down to `ctx.skip(note)`.
906
+ */
907
+ readonly note: string | undefined;
908
+ }
909
+ interface TestDiagnostic {
910
+ /**
911
+ * If the duration of the test is above `slowTestThreshold`.
912
+ */
913
+ readonly slow: boolean;
914
+ /**
915
+ * The amount of memory used by the test in bytes.
916
+ * This value is only available if the test was executed with `logHeapUsage` flag.
917
+ */
918
+ readonly heap: number | undefined;
919
+ /**
920
+ * The time it takes to execute the test in ms.
921
+ */
922
+ readonly duration: number;
923
+ /**
924
+ * The time in ms when the test started.
925
+ */
926
+ readonly startTime: number;
927
+ /**
928
+ * The amount of times the test was retried.
929
+ */
930
+ readonly retryCount: number;
931
+ /**
932
+ * The amount of times the test was repeated as configured by `repeats` option.
933
+ * This value can be lower if the test failed during the repeat and no `retry` is configured.
934
+ */
935
+ readonly repeatCount: number;
936
+ /**
937
+ * If test passed on a second retry.
938
+ */
939
+ readonly flaky: boolean;
940
+ }
941
+ interface ModuleDiagnostic {
942
+ /**
943
+ * The time it takes to import and initiate an environment.
944
+ */
945
+ readonly environmentSetupDuration: number;
946
+ /**
947
+ * The time it takes Vitest to setup test harness (runner, mocks, etc.).
948
+ */
949
+ readonly prepareDuration: number;
950
+ /**
951
+ * The time it takes to import the test module.
952
+ * This includes importing everything in the module and executing suite callbacks.
953
+ */
954
+ readonly collectDuration: number;
955
+ /**
956
+ * The time it takes to import the setup module.
957
+ */
958
+ readonly setupDuration: number;
959
+ /**
960
+ * Accumulated duration of all tests and hooks in the module.
961
+ */
962
+ readonly duration: number;
963
+ /**
964
+ * The amount of memory used by the test module in bytes.
965
+ * This value is only available if the test was executed with `logHeapUsage` flag.
966
+ */
967
+ readonly heap: number | undefined;
968
+ /**
969
+ * The time spent importing every non-externalized dependency that Vitest has processed.
970
+ */
971
+ readonly importDurations: Record<string, ImportDuration>;
972
+ }
973
+ declare function experimental_getRunnerTask(entity: TestCase): Test;
974
+ declare function experimental_getRunnerTask(entity: TestSuite): Suite;
975
+ declare function experimental_getRunnerTask(entity: TestModule): File;
976
+ declare function experimental_getRunnerTask(entity: TestCase | TestSuite | TestModule): Suite | File | Test;
977
+
738
978
  interface CoverageSummaryData {
739
979
  lines: Totals;
740
980
  statements: Totals;
@@ -839,366 +1079,65 @@ declare class FileCoverage implements FileCoverageData {
839
1079
  b: { [key: string]: number[] };
840
1080
  }
841
1081
 
842
- // for compatibility reasons, the reporter produces a JSON similar to the one produced by the Jest JSON reporter
843
- // the following types are extracted from the Jest repository (and simplified)
844
- // the commented-out fields are the missing ones
845
- type Status = "passed" | "failed" | "skipped" | "pending" | "todo" | "disabled";
846
- type Milliseconds = number;
847
- interface Callsite {
848
- line: number;
849
- column: number;
1082
+ interface Node {
1083
+ isRoot(): boolean;
1084
+ visit(visitor: Visitor, state: any): void;
850
1085
  }
851
- interface JsonAssertionResult {
852
- ancestorTitles: Array<string>;
853
- fullName: string;
854
- status: Status;
855
- title: string;
856
- meta: TaskMeta;
857
- duration?: Milliseconds | null;
858
- failureMessages: Array<string> | null;
859
- location?: Callsite | null;
1086
+
1087
+ interface Visitor<N extends Node = Node> {
1088
+ onStart(root: N, state: any): void;
1089
+ onSummary(root: N, state: any): void;
1090
+ onDetail(root: N, state: any): void;
1091
+ onSummaryEnd(root: N, state: any): void;
1092
+ onEnd(root: N, state: any): void;
860
1093
  }
861
- interface JsonTestResult {
862
- message: string;
863
- name: string;
864
- status: "failed" | "passed";
865
- startTime: number;
866
- endTime: number;
867
- assertionResults: Array<JsonAssertionResult>;
1094
+
1095
+ interface FileOptions {
1096
+ file: string;
868
1097
  }
869
- interface JsonTestResults {
870
- numFailedTests: number;
871
- numFailedTestSuites: number;
872
- numPassedTests: number;
873
- numPassedTestSuites: number;
874
- numPendingTests: number;
875
- numPendingTestSuites: number;
876
- numTodoTests: number;
877
- numTotalTests: number;
878
- numTotalTestSuites: number;
879
- startTime: number;
880
- success: boolean;
881
- testResults: Array<JsonTestResult>;
882
- snapshot: SnapshotSummary;
883
- coverageMap?: CoverageMap | null | undefined;
1098
+
1099
+ interface ProjectOptions {
1100
+ projectRoot: string;
884
1101
  }
885
- interface JsonOptions$1 {
886
- outputFile?: string;
1102
+
1103
+ interface ReportOptions {
1104
+ clover: CloverOptions;
1105
+ cobertura: CoberturaOptions;
1106
+ "html-spa": HtmlSpaOptions;
1107
+ html: HtmlOptions;
1108
+ json: JsonOptions$1;
1109
+ "json-summary": JsonSummaryOptions;
1110
+ lcov: LcovOptions;
1111
+ lcovonly: LcovOnlyOptions;
1112
+ none: never;
1113
+ teamcity: TeamcityOptions;
1114
+ text: TextOptions;
1115
+ "text-lcov": TextLcovOptions;
1116
+ "text-summary": TextSummaryOptions;
887
1117
  }
888
- declare class JsonReporter implements Reporter {
889
- start: number;
890
- ctx: Vitest;
891
- options: JsonOptions$1;
892
- constructor(options: JsonOptions$1);
893
- onInit(ctx: Vitest): void;
894
- protected logTasks(files: File[], coverageMap?: CoverageMap | null): Promise<void>;
895
- onFinished(files?: File[], _errors?: unknown[], coverageMap?: unknown): Promise<void>;
896
- /**
897
- * Writes the report to an output file if specified in the config,
898
- * or logs it to the console otherwise.
899
- * @param report
900
- */
901
- writeReport(report: string): Promise<void>;
1118
+
1119
+ interface CloverOptions extends FileOptions, ProjectOptions {}
1120
+
1121
+ interface CoberturaOptions extends FileOptions, ProjectOptions {}
1122
+
1123
+ interface HtmlSpaOptions extends HtmlOptions {
1124
+ metricsToShow: Array<"lines" | "branches" | "functions" | "statements">;
1125
+ }
1126
+ interface HtmlOptions {
1127
+ verbose: boolean;
1128
+ skipEmpty: boolean;
1129
+ subdir: string;
1130
+ linkMapper: LinkMapper;
902
1131
  }
903
1132
 
904
- interface ClassnameTemplateVariables {
905
- filename: string;
906
- filepath: string;
907
- }
908
- interface JUnitOptions {
909
- outputFile?: string;
910
- /** @deprecated Use `classnameTemplate` instead. */
911
- classname?: string;
912
- /**
913
- * Template for the classname attribute. Can be either a string or a function. The string can contain placeholders {filename} and {filepath}.
914
- */
915
- classnameTemplate?: string | ((classnameVariables: ClassnameTemplateVariables) => string);
916
- suiteName?: string;
917
- /**
918
- * Write <system-out> and <system-err> for console output
919
- * @default true
920
- */
921
- includeConsoleOutput?: boolean;
922
- /**
923
- * Add <testcase file="..."> attribute (validated on CIRCLE CI and GitLab CI)
924
- * @default false
925
- */
926
- addFileAttribute?: boolean;
927
- }
928
- declare class JUnitReporter implements Reporter {
929
- private ctx;
930
- private reportFile?;
931
- private baseLog;
932
- private logger;
933
- private _timeStart;
934
- private fileFd?;
935
- private options;
936
- constructor(options: JUnitOptions);
937
- onInit(ctx: Vitest): Promise<void>;
938
- writeElement(name: string, attrs: Record<string, any>, children: () => Promise<void>): Promise<void>;
939
- writeLogs(task: Task, type: "err" | "out"): Promise<void>;
940
- writeTasks(tasks: Task[], filename: string): Promise<void>;
941
- onFinished(files?: File[]): Promise<void>;
942
- }
943
-
944
- declare class BasicReporter extends BaseReporter {
945
- constructor();
946
- onInit(ctx: Vitest): void;
947
- reportSummary(files: File[], errors: unknown[]): void;
948
- }
949
-
950
- declare class DotReporter extends BaseReporter {
951
- private renderer?;
952
- private tests;
953
- private finishedTests;
954
- onInit(ctx: Vitest): void;
955
- // Ignore default logging of base reporter
956
- printTestModule(): void;
957
- onWatcherRerun(files: string[], trigger?: string): void;
958
- onFinished(files?: File[], errors?: unknown[]): void;
959
- onTestModuleCollected(module: TestModule): void;
960
- onTestCaseReady(test: TestCase): void;
961
- onTestCaseResult(test: TestCase): void;
962
- onTestModuleEnd(testModule: TestModule): void;
963
- private createSummary;
964
- }
965
-
966
- interface GithubActionsReporterOptions {
967
- onWritePath?: (path: string) => string;
968
- }
969
- declare class GithubActionsReporter implements Reporter {
970
- ctx: Vitest;
971
- options: GithubActionsReporterOptions;
972
- constructor(options?: GithubActionsReporterOptions);
973
- onInit(ctx: Vitest): void;
974
- onTestCaseAnnotate(testCase: TestCase, annotation: TestAnnotation): void;
975
- onFinished(files?: File[], errors?: unknown[]): void;
976
- }
977
-
978
- declare class HangingProcessReporter implements Reporter {
979
- whyRunning: (() => void) | undefined;
980
- onInit(): void;
981
- onProcessTimeout(): void;
982
- }
983
-
984
- declare class TapReporter implements Reporter {
985
- protected ctx: Vitest;
986
- private logger;
987
- onInit(ctx: Vitest): void;
988
- static getComment(task: Task): string;
989
- private logErrorDetails;
990
- protected logTasks(tasks: Task[]): void;
991
- onFinished(files?: File[]): void;
992
- }
993
-
994
- declare class TapFlatReporter extends TapReporter {
995
- onInit(ctx: Vitest): void;
996
- onFinished(files?: File[]): void;
997
- }
998
-
999
- declare class VerboseReporter extends DefaultReporter {
1000
- protected verbose: boolean;
1001
- renderSucceed: boolean;
1002
- printTestModule(module: TestModule): void;
1003
- onTestCaseResult(test: TestCase): void;
1004
- protected printTestSuite(testSuite: TestSuite): void;
1005
- protected getTestName(test: Task): string;
1006
- protected getTestIndentation(test: Task): string;
1007
- protected formatShortError(): string;
1008
- }
1009
-
1010
- type FormattedBenchmarkResult = BenchmarkResult & {
1011
- id: string
1012
- };
1013
-
1014
- declare function renderTable(options: {
1015
- tasks: Task[]
1016
- level: number
1017
- shallow?: boolean
1018
- showHeap: boolean
1019
- columns: number
1020
- slowTestThreshold: number
1021
- compare?: Record<Task["id"], FormattedBenchmarkResult>
1022
- }): string;
1023
-
1024
- declare class BenchmarkReporter extends DefaultReporter {
1025
- compare?: Parameters<typeof renderTable>[0]["compare"];
1026
- onInit(ctx: Vitest): Promise<void>;
1027
- onTaskUpdate(packs: TaskResultPack[]): void;
1028
- onTestSuiteResult(testSuite: TestSuite): void;
1029
- protected printTestModule(testModule: TestModule): void;
1030
- private printSuiteTable;
1031
- onFinished(files?: File[], errors?: unknown[]): Promise<void>;
1032
- }
1033
-
1034
- declare class VerboseBenchmarkReporter extends BenchmarkReporter {
1035
- protected verbose: boolean;
1036
- }
1037
-
1038
- declare const BenchmarkReportsMap: {
1039
- default: typeof BenchmarkReporter
1040
- verbose: typeof VerboseBenchmarkReporter
1041
- };
1042
- type BenchmarkBuiltinReporters = keyof typeof BenchmarkReportsMap;
1043
-
1044
- declare const ReportersMap: {
1045
- default: typeof DefaultReporter
1046
- basic: typeof BasicReporter
1047
- blob: typeof BlobReporter
1048
- verbose: typeof VerboseReporter
1049
- dot: typeof DotReporter
1050
- json: typeof JsonReporter
1051
- tap: typeof TapReporter
1052
- "tap-flat": typeof TapFlatReporter
1053
- junit: typeof JUnitReporter
1054
- "hanging-process": typeof HangingProcessReporter
1055
- "github-actions": typeof GithubActionsReporter
1056
- };
1057
- type BuiltinReporters = keyof typeof ReportersMap;
1058
- interface BuiltinReporterOptions {
1059
- "default": DefaultReporterOptions;
1060
- "basic": BaseOptions;
1061
- "verbose": DefaultReporterOptions;
1062
- "dot": BaseOptions;
1063
- "json": JsonOptions$1;
1064
- "blob": BlobOptions;
1065
- "tap": never;
1066
- "tap-flat": never;
1067
- "junit": JUnitOptions;
1068
- "hanging-process": never;
1069
- "html": HTMLOptions;
1070
- }
1071
-
1072
- interface BrowserTesterOptions {
1073
- method: TestExecutionMethod;
1074
- files: string[];
1075
- providedContext: string;
1076
- startTime: number;
1077
- }
1078
-
1079
- type ChaiConfig = Omit<Partial<typeof chai.config>, "useProxy" | "proxyExcludedKeys">;
1080
-
1081
- interface TestSequencer {
1082
- /**
1083
- * Slicing tests into shards. Will be run before `sort`.
1084
- * Only run, if `shard` is defined.
1085
- */
1086
- shard: (files: TestSpecification[]) => Awaitable<TestSpecification[]>;
1087
- sort: (files: TestSpecification[]) => Awaitable<TestSpecification[]>;
1088
- }
1089
- interface TestSequencerConstructor {
1090
- new (ctx: Vitest): TestSequencer;
1091
- }
1092
-
1093
- interface WatcherTriggerPattern {
1094
- pattern: RegExp;
1095
- testsToRun: (file: string, match: RegExpMatchArray) => string[] | string | null | undefined | void;
1096
- }
1097
-
1098
- interface BenchmarkUserOptions {
1099
- /**
1100
- * Include globs for benchmark test files
1101
- *
1102
- * @default ['**\/*.{bench,benchmark}.?(c|m)[jt]s?(x)']
1103
- */
1104
- include?: string[];
1105
- /**
1106
- * Exclude globs for benchmark test files
1107
- * @default ['**\/node_modules/**', '**\/dist/**', '**\/cypress/**', '**\/.{idea,git,cache,output,temp}/**', '**\/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*']
1108
- */
1109
- exclude?: string[];
1110
- /**
1111
- * Include globs for in-source benchmark test files
1112
- *
1113
- * @default []
1114
- */
1115
- includeSource?: string[];
1116
- /**
1117
- * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
1118
- * and/or paths to custom reporters
1119
- *
1120
- * @default ['default']
1121
- */
1122
- reporters?: Arrayable<BenchmarkBuiltinReporters | Reporter>;
1123
- /**
1124
- * @deprecated Use `benchmark.outputJson` instead
1125
- */
1126
- outputFile?: string | (Partial<Record<BenchmarkBuiltinReporters, string>> & Record<string, string>);
1127
- /**
1128
- * benchmark output file to compare against
1129
- */
1130
- compare?: string;
1131
- /**
1132
- * benchmark output file
1133
- */
1134
- outputJson?: string;
1135
- /**
1136
- * Include `samples` array of benchmark results for API or custom reporter usages.
1137
- * This is disabled by default to reduce memory usage.
1138
- * @default false
1139
- */
1140
- includeSamples?: boolean;
1141
- }
1142
-
1143
- interface Node {
1144
- isRoot(): boolean;
1145
- visit(visitor: Visitor, state: any): void;
1146
- }
1147
-
1148
- interface Visitor<N extends Node = Node> {
1149
- onStart(root: N, state: any): void;
1150
- onSummary(root: N, state: any): void;
1151
- onDetail(root: N, state: any): void;
1152
- onSummaryEnd(root: N, state: any): void;
1153
- onEnd(root: N, state: any): void;
1154
- }
1155
-
1156
- interface FileOptions {
1157
- file: string;
1158
- }
1159
-
1160
- interface ProjectOptions {
1161
- projectRoot: string;
1162
- }
1163
-
1164
- interface ReportOptions {
1165
- clover: CloverOptions;
1166
- cobertura: CoberturaOptions;
1167
- "html-spa": HtmlSpaOptions;
1168
- html: HtmlOptions;
1169
- json: JsonOptions;
1170
- "json-summary": JsonSummaryOptions;
1171
- lcov: LcovOptions;
1172
- lcovonly: LcovOnlyOptions;
1173
- none: never;
1174
- teamcity: TeamcityOptions;
1175
- text: TextOptions;
1176
- "text-lcov": TextLcovOptions;
1177
- "text-summary": TextSummaryOptions;
1178
- }
1179
-
1180
- interface CloverOptions extends FileOptions, ProjectOptions {}
1181
-
1182
- interface CoberturaOptions extends FileOptions, ProjectOptions {}
1183
-
1184
- interface HtmlSpaOptions extends HtmlOptions {
1185
- metricsToShow: Array<"lines" | "branches" | "functions" | "statements">;
1186
- }
1187
- interface HtmlOptions {
1188
- verbose: boolean;
1189
- skipEmpty: boolean;
1190
- subdir: string;
1191
- linkMapper: LinkMapper;
1192
- }
1193
-
1194
- type JsonOptions = FileOptions;
1195
- type JsonSummaryOptions = FileOptions;
1196
-
1197
- interface LcovOptions extends FileOptions, ProjectOptions {}
1198
- interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
1199
-
1200
- interface TeamcityOptions extends FileOptions {
1201
- blockName: string;
1133
+ type JsonOptions$1 = FileOptions;
1134
+ type JsonSummaryOptions = FileOptions;
1135
+
1136
+ interface LcovOptions extends FileOptions, ProjectOptions {}
1137
+ interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
1138
+
1139
+ interface TeamcityOptions extends FileOptions {
1140
+ blockName: string;
1202
1141
  }
1203
1142
 
1204
1143
  interface TextOptions extends FileOptions {
@@ -1237,6 +1176,8 @@ interface CoverageProvider {
1237
1176
  mergeReports?: (coverages: CoverageResults[]) => void | Promise<void>;
1238
1177
  /** Callback called for instrumenting files with coverage counters. */
1239
1178
  onFileTransform?: (sourceCode: string, id: string, pluginCtx: any) => TransformResult | Promise<TransformResult>;
1179
+ /** Callback that's called when the coverage is enabled via a programmatic `enableCoverage` API. */
1180
+ onEnabled?: () => void | Promise<void>;
1240
1181
  }
1241
1182
  interface ReportContext {
1242
1183
  /** Indicates whether all tests were run. False when only specific tests were run. */
@@ -1252,23 +1193,23 @@ type CoverageReporter = keyof ReportOptions | (string & {});
1252
1193
  type CoverageReporterWithOptions<ReporterName extends CoverageReporter = CoverageReporter> = ReporterName extends keyof ReportOptions ? ReportOptions[ReporterName] extends never ? [ReporterName, object] : [ReporterName, Partial<ReportOptions[ReporterName]>] : [ReporterName, Record<string, unknown>];
1253
1194
  type CoverageProviderName = "v8" | "istanbul" | "custom" | undefined;
1254
1195
  type CoverageOptions<T extends CoverageProviderName = CoverageProviderName> = T extends "istanbul" ? {
1255
- provider: T
1196
+ provider: T;
1256
1197
  } & CoverageIstanbulOptions : T extends "v8" ? {
1257
1198
  /**
1258
1199
  * Provider to use for coverage collection.
1259
1200
  *
1260
1201
  * @default 'v8'
1261
1202
  */
1262
- provider: T
1203
+ provider: T;
1263
1204
  } & CoverageV8Options : T extends "custom" ? {
1264
- provider: T
1205
+ provider: T;
1265
1206
  } & CustomProviderOptions : {
1266
- provider?: T
1207
+ provider?: T;
1267
1208
  } & CoverageV8Options;
1268
1209
  /** Fields that have default values. Internally these will always be defined. */
1269
- type FieldsWithDefaultValues = "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "exclude" | "extension" | "reportOnFailure" | "allowExternal" | "processingConcurrency";
1210
+ type FieldsWithDefaultValues = "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "exclude" | "reportOnFailure" | "allowExternal" | "processingConcurrency";
1270
1211
  type ResolvedCoverageOptions<T extends CoverageProviderName = CoverageProviderName> = CoverageOptions<T> & Required<Pick<CoverageOptions<T>, FieldsWithDefaultValues>> & {
1271
- reporter: CoverageReporterWithOptions[]
1212
+ reporter: CoverageReporterWithOptions[];
1272
1213
  };
1273
1214
  interface BaseCoverageOptions {
1274
1215
  /**
@@ -1278,35 +1219,25 @@ interface BaseCoverageOptions {
1278
1219
  */
1279
1220
  enabled?: boolean;
1280
1221
  /**
1281
- * List of files included in coverage as glob patterns
1222
+ * List of files included in coverage as glob patterns.
1223
+ * By default only files covered by tests are included.
1282
1224
  *
1283
- * @default ['**']
1225
+ * See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
1284
1226
  */
1285
1227
  include?: string[];
1286
1228
  /**
1287
- * Extensions for files to be included in coverage
1288
- *
1289
- * @default ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.vue', '.svelte', '.marko']
1290
- */
1291
- extension?: string | string[];
1292
- /**
1293
- * List of files excluded from coverage as glob patterns
1229
+ * List of files excluded from coverage as glob patterns.
1230
+ * Files are first checked against `coverage.include`.
1294
1231
  *
1295
- * @default ['coverage/**', 'dist/**', '**\/[.]**', 'packages/*\/test?(s)/**', '**\/*.d.ts', '**\/virtual:*', '**\/__x00__*', '**\/\x00*', 'cypress/**', 'test?(s)/**', 'test?(-*).?(c|m)[jt]s?(x)', '**\/*{.,-}{test,spec}?(-d).?(c|m)[jt]s?(x)', '**\/__tests__/**', '**\/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*', '**\/vitest.{workspace,projects}.[jt]s?(on)', '**\/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}']
1232
+ * See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
1296
1233
  */
1297
1234
  exclude?: string[];
1298
1235
  /**
1299
- * Whether to include all files, including the untested ones into report
1236
+ * Clean coverage results before running tests
1300
1237
  *
1301
1238
  * @default true
1302
1239
  */
1303
- all?: boolean;
1304
- /**
1305
- * Clean coverage results before running tests
1306
- *
1307
- * @default true
1308
- */
1309
- clean?: boolean;
1240
+ clean?: boolean;
1310
1241
  /**
1311
1242
  * Clean coverage report on watch rerun
1312
1243
  *
@@ -1325,7 +1256,7 @@ interface BaseCoverageOptions {
1325
1256
  *
1326
1257
  * @default ['text', 'html', 'clover', 'json']
1327
1258
  */
1328
- reporter?: Arrayable$1<CoverageReporter> | (CoverageReporter | [CoverageReporter] | CoverageReporterWithOptions)[];
1259
+ reporter?: Arrayable<CoverageReporter> | (CoverageReporter | [CoverageReporter] | CoverageReporterWithOptions)[];
1329
1260
  /**
1330
1261
  * Do not show files with 100% statement, branch, and function coverage
1331
1262
  *
@@ -1354,7 +1285,7 @@ interface BaseCoverageOptions {
1354
1285
  * ```
1355
1286
  */
1356
1287
  thresholds?: Thresholds | ({
1357
- [glob: string]: Pick<Thresholds, 100 | "statements" | "functions" | "branches" | "lines">
1288
+ [glob: string]: Pick<Thresholds, 100 | "statements" | "functions" | "branches" | "lines">;
1358
1289
  } & Thresholds);
1359
1290
  /**
1360
1291
  * Watermarks for statements, lines, branches and functions.
@@ -1362,10 +1293,10 @@ interface BaseCoverageOptions {
1362
1293
  * Default value is `[50,80]` for each property.
1363
1294
  */
1364
1295
  watermarks?: {
1365
- statements?: [number, number]
1366
- functions?: [number, number]
1367
- branches?: [number, number]
1368
- lines?: [number, number]
1296
+ statements?: [number, number];
1297
+ functions?: [number, number];
1298
+ branches?: [number, number];
1299
+ lines?: [number, number];
1369
1300
  };
1370
1301
  /**
1371
1302
  * Generate coverage report even when tests fail.
@@ -1395,8 +1326,6 @@ interface BaseCoverageOptions {
1395
1326
  * Defaults to `Math.min(20, os.availableParallelism?.() ?? os.cpus().length)`
1396
1327
  */
1397
1328
  processingConcurrency?: number;
1398
- }
1399
- interface CoverageIstanbulOptions extends BaseCoverageOptions {
1400
1329
  /**
1401
1330
  * Set to array of class method names to ignore for coverage
1402
1331
  *
@@ -1404,25 +1333,8 @@ interface CoverageIstanbulOptions extends BaseCoverageOptions {
1404
1333
  */
1405
1334
  ignoreClassMethods?: string[];
1406
1335
  }
1407
- interface CoverageV8Options extends BaseCoverageOptions {
1408
- /**
1409
- * Ignore empty lines, comments and other non-runtime code, e.g. Typescript types
1410
- * - Requires `experimentalAstAwareRemapping: false`
1411
- */
1412
- ignoreEmptyLines?: boolean;
1413
- /**
1414
- * Remap coverage with experimental AST based analysis
1415
- * - Provides more accurate results compared to default mode
1416
- */
1417
- experimentalAstAwareRemapping?: boolean;
1418
- /**
1419
- * Set to array of class method names to ignore for coverage.
1420
- * - Requires `experimentalAstAwareRemapping: true`
1421
- *
1422
- * @default []
1423
- */
1424
- ignoreClassMethods?: string[];
1425
- }
1336
+ interface CoverageIstanbulOptions extends BaseCoverageOptions {}
1337
+ interface CoverageV8Options extends BaseCoverageOptions {}
1426
1338
  interface CustomProviderOptions extends Pick<BaseCoverageOptions, FieldsWithDefaultValues> {
1427
1339
  /** Name of the module or path to a file to load the custom provider from */
1428
1340
  customProviderModule: string;
@@ -1434,10 +1346,11 @@ interface Thresholds {
1434
1346
  perFile?: boolean;
1435
1347
  /**
1436
1348
  * Update threshold values automatically when current coverage is higher than earlier thresholds
1349
+ * Also can accept a function to format the new threshold values
1437
1350
  *
1438
1351
  * @default false
1439
1352
  */
1440
- autoUpdate?: boolean;
1353
+ autoUpdate?: boolean | ((newThreshold: number) => number);
1441
1354
  /** Thresholds for statements */
1442
1355
  statements?: number;
1443
1356
  /** Thresholds for functions */
@@ -1448,1708 +1361,1735 @@ interface Thresholds {
1448
1361
  lines?: number;
1449
1362
  }
1450
1363
 
1451
- type BuiltinEnvironment = "node" | "jsdom" | "happy-dom" | "edge-runtime";
1452
- // Record is used, so user can get intellisense for builtin environments, but still allow custom environments
1453
- type VitestEnvironment = BuiltinEnvironment | (string & Record<never, never>);
1364
+ interface TestRunResult {
1365
+ testModules: TestModule[];
1366
+ unhandledErrors: unknown[];
1367
+ }
1454
1368
 
1455
- type CSSModuleScopeStrategy = "stable" | "scoped" | "non-scoped";
1456
- type ApiConfig = Pick<ServerOptions, "port" | "strictPort" | "host" | "middlewareMode">;
1369
+ interface SuiteResultCache {
1370
+ failed: boolean;
1371
+ duration: number;
1372
+ }
1373
+ declare class ResultsCache {
1374
+ private cache;
1375
+ private workspacesKeyMap;
1376
+ private cachePath;
1377
+ private version;
1378
+ private root;
1379
+ constructor(version: string);
1380
+ getCachePath(): string | null;
1381
+ setConfig(root: string, config: ResolvedConfig["cache"]): void;
1382
+ getResults(key: string): SuiteResultCache | undefined;
1383
+ readFromCache(): Promise<void>;
1384
+ updateResults(files: File[]): void;
1385
+ removeFromCache(filepath: string): void;
1386
+ writeToCache(): Promise<void>;
1387
+ }
1457
1388
 
1458
- type VitestRunMode = "test" | "benchmark";
1459
- interface ProjectName {
1460
- label: string;
1461
- color?: LabelColor;
1389
+ type FileStatsCache = Pick<Stats, "size">;
1390
+ declare class FilesStatsCache {
1391
+ cache: Map<string, FileStatsCache>;
1392
+ getStats(key: string): FileStatsCache | undefined;
1393
+ populateStats(root: string, specs: TestSpecification[]): Promise<void>;
1394
+ updateStats(fsPath: string, key: string): Promise<void>;
1395
+ removeStats(fsPath: string): void;
1462
1396
  }
1463
- interface SequenceOptions {
1397
+
1398
+ declare class VitestCache {
1399
+ results: ResultsCache;
1400
+ stats: FilesStatsCache;
1401
+ constructor(version: string);
1402
+ getFileTestResults(key: string): SuiteResultCache | undefined;
1403
+ getFileStats(key: string): {
1404
+ size: number;
1405
+ } | undefined;
1406
+ static resolveCacheDir(root: string, dir?: string, projectName?: string): string;
1407
+ }
1408
+
1409
+ declare class TypeCheckError extends Error {
1410
+ message: string;
1411
+ stacks: ParsedStack[];
1412
+ name: string;
1413
+ constructor(message: string, stacks: ParsedStack[]);
1414
+ }
1415
+
1416
+ interface ErrorOptions {
1417
+ type?: string;
1418
+ fullStack?: boolean;
1419
+ project?: TestProject;
1420
+ verbose?: boolean;
1421
+ screenshotPaths?: string[];
1422
+ task?: Task;
1423
+ showCodeFrame?: boolean;
1424
+ }
1425
+ type Listener = () => void;
1426
+ declare class Logger {
1427
+ ctx: Vitest;
1428
+ outputStream: NodeJS.WriteStream | Writable;
1429
+ errorStream: NodeJS.WriteStream | Writable;
1430
+ private _clearScreenPending;
1431
+ private _highlights;
1432
+ private cleanupListeners;
1433
+ console: Console;
1434
+ constructor(ctx: Vitest, outputStream?: NodeJS.WriteStream | Writable, errorStream?: NodeJS.WriteStream | Writable);
1435
+ log(...args: any[]): void;
1436
+ error(...args: any[]): void;
1437
+ warn(...args: any[]): void;
1438
+ clearFullScreen(message?: string): void;
1439
+ clearScreen(message: string, force?: boolean): void;
1440
+ private _clearScreen;
1441
+ printError(err: unknown, options?: ErrorOptions): void;
1442
+ deprecate(message: string): void;
1443
+ clearHighlightCache(filename?: string): void;
1444
+ highlight(filename: string, source: string): string;
1445
+ printNoTestFound(filters?: string[]): void;
1446
+ printBanner(): void;
1447
+ printBrowserBanner(project: TestProject): void;
1448
+ printUnhandledErrors(errors: ReadonlyArray<unknown>): void;
1449
+ printSourceTypeErrors(errors: TypeCheckError[]): void;
1450
+ getColumns(): number;
1451
+ onTerminalCleanup(listener: Listener): void;
1452
+ private addCleanupListeners;
1453
+ private registerUnhandledRejection;
1454
+ }
1455
+
1456
+ declare class VitestPackageInstaller {
1457
+ isPackageExists(name: string, options?: {
1458
+ paths?: string[];
1459
+ }): boolean;
1460
+ ensureInstalled(dependency: string, root: string, version?: string): Promise<boolean>;
1461
+ }
1462
+
1463
+ interface BlobOptions {
1464
+ outputFile?: string;
1465
+ }
1466
+ declare class BlobReporter implements Reporter {
1467
+ start: number;
1468
+ ctx: Vitest;
1469
+ options: BlobOptions;
1470
+ coverage: unknown | undefined;
1471
+ constructor(options: BlobOptions);
1472
+ onInit(ctx: Vitest): void;
1473
+ onCoverage(coverage: unknown): void;
1474
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): Promise<void>;
1475
+ }
1476
+ interface MergedBlobs {
1477
+ files: File[];
1478
+ errors: unknown[];
1479
+ coverages: unknown[];
1480
+ executionTimes: number[];
1481
+ }
1482
+
1483
+ declare class StateManager {
1484
+ filesMap: Map<string, File[]>;
1485
+ pathsSet: Set<string>;
1486
+ idMap: Map<string, Task>;
1487
+ taskFileMap: WeakMap<Task, File>;
1488
+ errorsSet: Set<unknown>;
1489
+ processTimeoutCauses: Set<string>;
1490
+ reportedTasksMap: WeakMap<Task, TestModule | TestCase | TestSuite>;
1491
+ blobs?: MergedBlobs;
1492
+ transformTime: number;
1493
+ onUnhandledError?: OnUnhandledErrorCallback;
1494
+ constructor(options: {
1495
+ onUnhandledError?: OnUnhandledErrorCallback;
1496
+ });
1497
+ catchError(error: unknown, type: string): void;
1498
+ clearErrors(): void;
1499
+ getUnhandledErrors(): unknown[];
1500
+ addProcessTimeoutCause(cause: string): void;
1501
+ getProcessTimeoutCauses(): string[];
1502
+ getPaths(): string[];
1464
1503
  /**
1465
- * Class that handles sorting and sharding algorithm.
1466
- * If you only need to change sorting, you can extend
1467
- * your custom sequencer from `BaseSequencer` from `vitest/node`.
1468
- * @default BaseSequencer
1504
+ * Return files that were running or collected.
1469
1505
  */
1470
- sequencer?: TestSequencerConstructor;
1506
+ getFiles(keys?: string[]): File[];
1507
+ getTestModules(keys?: string[]): TestModule[];
1508
+ getFilepaths(): string[];
1509
+ getFailedFilepaths(): string[];
1510
+ collectPaths(paths?: string[]): void;
1511
+ collectFiles(project: TestProject, files?: File[]): void;
1512
+ clearFiles(project: TestProject, paths?: string[]): void;
1513
+ updateId(task: Task, project: TestProject): void;
1514
+ getReportedEntity(task: Task): TestModule | TestCase | TestSuite | undefined;
1515
+ updateTasks(packs: TaskResultPack[]): void;
1516
+ updateUserLog(log: UserConsoleLog): void;
1517
+ getCountOfFailedTests(): number;
1518
+ cancelFiles(files: string[], project: TestProject): void;
1519
+ }
1520
+
1521
+ declare class VitestWatcher {
1522
+ private vitest;
1471
1523
  /**
1472
- * Controls the order in which this project runs its tests when using multiple [projects](/guide/projects).
1473
- *
1474
- * - Projects with the same group order number will run together, and groups are run from lowest to highest.
1475
- * - If you don’t set this option, all projects run in parallel.
1476
- * - If several projects use the same group order, they will run at the same time.
1477
- * @default 0
1524
+ * Modules that will be invalidated on the next run.
1478
1525
  */
1479
- groupOrder?: number;
1526
+ readonly invalidates: Set<string>;
1480
1527
  /**
1481
- * Should files and tests run in random order.
1482
- * @default false
1528
+ * Test files that have changed and need to be rerun.
1483
1529
  */
1484
- shuffle?: boolean | {
1485
- /**
1486
- * Should files run in random order. Long running tests will not start
1487
- * earlier if you enable this option.
1488
- * @default false
1489
- */
1490
- files?: boolean
1491
- /**
1492
- * Should tests run in random order.
1493
- * @default false
1494
- */
1495
- tests?: boolean
1496
- };
1530
+ readonly changedTests: Set<string>;
1531
+ private readonly _onRerun;
1532
+ constructor(vitest: Vitest);
1533
+ unregisterWatcher: () => void;
1534
+ registerWatcher(): this;
1535
+ private scheduleRerun;
1536
+ private getTestFilesFromWatcherTrigger;
1537
+ onFileChange: (id: string) => void;
1538
+ onFileDelete: (id: string) => void;
1539
+ onFileCreate: (id: string) => void;
1540
+ private handleSetupFile;
1497
1541
  /**
1498
- * Should tests run in parallel.
1499
- * @default false
1542
+ * @returns A value indicating whether rerun is needed (changedTests was mutated)
1500
1543
  */
1501
- concurrent?: boolean;
1544
+ private handleFileChanged;
1545
+ }
1546
+ interface WatcherTriggerPattern {
1547
+ pattern: RegExp;
1548
+ testsToRun: (file: string, match: RegExpMatchArray) => string[] | string | null | undefined | void;
1549
+ }
1550
+
1551
+ interface VitestOptions {
1552
+ packageInstaller?: VitestPackageInstaller;
1553
+ stdin?: NodeJS.ReadStream;
1554
+ stdout?: NodeJS.WriteStream | Writable;
1555
+ stderr?: NodeJS.WriteStream | Writable;
1556
+ }
1557
+ declare class Vitest {
1558
+ readonly mode: VitestRunMode;
1502
1559
  /**
1503
- * Defines how setup files should be ordered
1504
- * - 'parallel' will run all setup files in parallel
1505
- * - 'list' will run all setup files in the order they are defined in the config file
1506
- * @default 'parallel'
1560
+ * Current Vitest version.
1561
+ * @example '2.0.0'
1507
1562
  */
1508
- setupFiles?: SequenceSetupFiles;
1563
+ readonly version: string;
1564
+ static readonly version: string;
1509
1565
  /**
1510
- * Seed for the random number generator.
1511
- * @default Date.now()
1566
+ * The logger instance used to log messages. It's recommended to use this logger instead of `console`.
1567
+ * It's possible to override stdout and stderr streams when initiating Vitest.
1568
+ * @example
1569
+ * new Vitest('test', {
1570
+ * stdout: new Writable(),
1571
+ * })
1512
1572
  */
1513
- seed?: number;
1573
+ readonly logger: Logger;
1514
1574
  /**
1515
- * Defines how hooks should be ordered
1516
- * - `stack` will order "after" hooks in reverse order, "before" hooks will run sequentially
1517
- * - `list` will order hooks in the order they are defined
1518
- * - `parallel` will run hooks in a single group in parallel
1519
- * @default 'stack'
1575
+ * The package installer instance used to install Vitest packages.
1576
+ * @example
1577
+ * await vitest.packageInstaller.ensureInstalled('@vitest/browser', process.cwd())
1520
1578
  */
1521
- hooks?: SequenceHooks;
1522
- }
1523
- type DepsOptimizationOptions = Omit<DepOptimizationConfig, "disabled" | "noDiscovery"> & {
1524
- enabled?: boolean
1525
- };
1526
- interface TransformModePatterns {
1579
+ readonly packageInstaller: VitestPackageInstaller;
1527
1580
  /**
1528
- * Use SSR transform pipeline for all modules inside specified tests.
1529
- * Vite plugins will receive `ssr: true` flag when processing those files.
1530
- *
1531
- * @default tests with node or edge environment
1581
+ * A path to the built Vitest directory. This is usually a folder in `node_modules`.
1532
1582
  */
1533
- ssr?: string[];
1583
+ readonly distPath: string;
1534
1584
  /**
1535
- * First do a normal transform pipeline (targeting browser),
1536
- * then then do a SSR rewrite to run the code in Node.
1537
- * Vite plugins will receive `ssr: false` flag when processing those files.
1538
- *
1539
- * @default tests with jsdom or happy-dom environment
1585
+ * A list of projects that are currently running.
1586
+ * If projects were filtered with `--project` flag, they won't appear here.
1540
1587
  */
1541
- web?: string[];
1542
- }
1543
- interface DepsOptions {
1588
+ projects: TestProject[];
1544
1589
  /**
1545
- * Enable dependency optimization. This can improve the performance of your tests.
1590
+ * A watcher handler. This is not the file system watcher. The handler only
1591
+ * exposes methods to handle changed files.
1592
+ *
1593
+ * If you have your own watcher, you can use these methods to replicate
1594
+ * Vitest behaviour.
1546
1595
  */
1547
- optimizer?: {
1548
- web?: DepsOptimizationOptions
1549
- ssr?: DepsOptimizationOptions
1550
- };
1551
- web?: {
1552
- /**
1553
- * Should Vitest process assets (.png, .svg, .jpg, etc) files and resolve them like Vite does in the browser.
1554
- *
1555
- * These module will have a default export equal to the path to the asset, if no query is specified.
1556
- *
1557
- * **At the moment, this option only works with `{ pool: 'vmThreads' }`.**
1558
- *
1559
- * @default true
1560
- */
1561
- transformAssets?: boolean
1562
- /**
1563
- * Should Vitest process CSS (.css, .scss, .sass, etc) files and resolve them like Vite does in the browser.
1564
- *
1565
- * If CSS files are disabled with `css` options, this option will just silence UNKNOWN_EXTENSION errors.
1566
- *
1567
- * **At the moment, this option only works with `{ pool: 'vmThreads' }`.**
1568
- *
1569
- * @default true
1570
- */
1571
- transformCss?: boolean
1572
- /**
1573
- * Regexp pattern to match external files that should be transformed.
1574
- *
1575
- * By default, files inside `node_modules` are externalized and not transformed.
1576
- *
1577
- * **At the moment, this option only works with `{ pool: 'vmThreads' }`.**
1578
- *
1579
- * @default []
1580
- */
1581
- transformGlobPattern?: RegExp | RegExp[]
1582
- };
1596
+ readonly watcher: VitestWatcher;
1597
+ private isFirstRun;
1598
+ private restartsCount;
1599
+ private readonly specifications;
1600
+ private pool;
1601
+ private _config?;
1602
+ private _vite?;
1603
+ private _state?;
1604
+ private _cache?;
1605
+ private _snapshot?;
1606
+ private _coverageProvider?;
1607
+ constructor(mode: VitestRunMode, cliOptions: UserConfig, options?: VitestOptions);
1608
+ private _onRestartListeners;
1609
+ private _onClose;
1610
+ private _onSetServer;
1611
+ private _onCancelListeners;
1612
+ private _onUserTestsRerun;
1613
+ private _onFilterWatchedSpecification;
1583
1614
  /**
1584
- * Externalize means that Vite will bypass the package to native Node.
1585
- *
1586
- * Externalized dependencies will not be applied Vite's transformers and resolvers.
1587
- * And does not support HMR on reload.
1588
- *
1589
- * Typically, packages under `node_modules` are externalized.
1590
- *
1591
- * @deprecated If you rely on vite-node directly, use `server.deps.external` instead. Otherwise, consider using `deps.optimizer.{web,ssr}.exclude`.
1615
+ * The global config.
1592
1616
  */
1593
- external?: (string | RegExp)[];
1617
+ get config(): ResolvedConfig;
1594
1618
  /**
1595
- * Vite will process inlined modules.
1596
- *
1597
- * This could be helpful to handle packages that ship `.js` in ESM format (that Node can't handle).
1598
- *
1599
- * If `true`, every dependency will be inlined
1600
- *
1601
- * @deprecated If you rely on vite-node directly, use `server.deps.inline` instead. Otherwise, consider using `deps.optimizer.{web,ssr}.include`.
1619
+ * Global Vite's dev server instance.
1602
1620
  */
1603
- inline?: (string | RegExp)[] | true;
1621
+ get vite(): ViteDevServer;
1604
1622
  /**
1605
- * Interpret CJS module's default as named exports
1606
- *
1607
- * @default true
1623
+ * The global test state manager.
1624
+ * @experimental The State API is experimental and not subject to semver.
1608
1625
  */
1609
- interopDefault?: boolean;
1626
+ get state(): StateManager;
1610
1627
  /**
1611
- * When a dependency is a valid ESM package, try to guess the cjs version based on the path.
1612
- * This will significantly improve the performance in huge repo, but might potentially
1613
- * cause some misalignment if a package have different logic in ESM and CJS mode.
1614
- *
1615
- * @default false
1616
- *
1617
- * @deprecated Use `server.deps.fallbackCJS` instead.
1628
+ * The global snapshot manager. You can access the current state on `snapshot.summary`.
1618
1629
  */
1619
- fallbackCJS?: boolean;
1630
+ get snapshot(): SnapshotManager;
1620
1631
  /**
1621
- * A list of directories relative to the config file that should be treated as module directories.
1622
- *
1623
- * @default ['node_modules']
1632
+ * Test results and test file stats cache. Primarily used by the sequencer to sort tests.
1624
1633
  */
1625
- moduleDirectories?: string[];
1626
- }
1627
- type InlineReporter = Reporter;
1628
- type ReporterName = BuiltinReporters | "html" | (string & {});
1629
- type ReporterWithOptions<Name extends ReporterName = ReporterName> = Name extends keyof BuiltinReporterOptions ? BuiltinReporterOptions[Name] extends never ? [Name, object] : [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
1630
- interface ResolveSnapshotPathHandlerContext {
1631
- config: SerializedConfig;
1632
- }
1633
- type ResolveSnapshotPathHandler = (testPath: string, snapExtension: string, context: ResolveSnapshotPathHandlerContext) => string;
1634
- interface InlineConfig {
1634
+ get cache(): VitestCache;
1635
+ enableCoverage(): Promise<void>;
1636
+ disableCoverage(): void;
1637
+ private _coverageOverrideCache;
1635
1638
  /**
1636
- * Name of the project. Will be used to display in the reporter.
1639
+ * Inject new test projects into the workspace.
1640
+ * @param config Glob, config path or a custom config options.
1641
+ * @returns An array of new test projects. Can be empty if the name was filtered out.
1637
1642
  */
1638
- name?: string | ProjectName;
1643
+ private injectTestProject;
1639
1644
  /**
1640
- * Benchmark options.
1641
- *
1642
- * @default {}
1645
+ * Provide a value to the test context. This value will be available to all tests with `inject`.
1643
1646
  */
1644
- benchmark?: BenchmarkUserOptions;
1647
+ provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
1645
1648
  /**
1646
- * Include globs for test files
1647
- *
1648
- * @default ['**\/*.{test,spec}.?(c|m)[jt]s?(x)']
1649
+ * Get global provided context.
1649
1650
  */
1650
- include?: string[];
1651
+ getProvidedContext(): ProvidedContext;
1651
1652
  /**
1652
- * Exclude globs for test files
1653
- * @default ['**\/node_modules/**', '**\/dist/**', '**\/cypress/**', '**\/.{idea,git,cache,output,temp}/**', '**\/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*']
1653
+ * Return project that has the root (or "global") config.
1654
1654
  */
1655
- exclude?: string[];
1655
+ getRootProject(): TestProject;
1656
+ getProjectByName(name: string): TestProject;
1656
1657
  /**
1657
- * Include globs for in-source test files
1658
- *
1659
- * @default []
1658
+ * Import a file using Vite module runner. The file will be transformed by Vite and executed in a separate context.
1659
+ * @param moduleId The ID of the module in Vite module graph
1660
1660
  */
1661
- includeSource?: string[];
1661
+ import<T>(moduleId: string): Promise<T>;
1662
1662
  /**
1663
- * Handling for dependencies inlining or externalizing
1664
- *
1663
+ * Creates a coverage provider if `coverage` is enabled in the config.
1665
1664
  */
1666
- deps?: DepsOptions;
1665
+ createCoverageProvider(): Promise<CoverageProvider | null>;
1666
+ private resolveProjects;
1667
1667
  /**
1668
- * Vite-node server options
1668
+ * Glob test files in every project and create a TestSpecification for each file and pool.
1669
+ * @param filters String filters to match the test files.
1669
1670
  */
1670
- server?: Omit<ViteNodeServerOptions, "transformMode">;
1671
+ globTestSpecifications(filters?: string[]): Promise<TestSpecification[]>;
1672
+ private initCoverageProvider;
1671
1673
  /**
1672
- * Base directory to scan for the test files
1673
- *
1674
- * @default `config.root`
1674
+ * Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified).
1675
1675
  */
1676
- dir?: string;
1676
+ mergeReports(directory?: string): Promise<TestRunResult>;
1677
+ collect(filters?: string[]): Promise<TestRunResult>;
1677
1678
  /**
1678
- * Register apis globally
1679
- *
1680
- * @default false
1679
+ * Returns the list of test files that match the config and filters.
1680
+ * @param filters String filters to match the test files
1681
1681
  */
1682
- globals?: boolean;
1682
+ getRelevantTestSpecifications(filters?: string[]): Promise<TestSpecification[]>;
1683
1683
  /**
1684
- * Running environment
1685
- *
1686
- * Supports 'node', 'jsdom', 'happy-dom', 'edge-runtime'
1687
- *
1688
- * If used unsupported string, will try to load the package `vitest-environment-${env}`
1689
- *
1690
- * @default 'node'
1684
+ * Initialize reporters, the coverage provider, and run tests.
1685
+ * This method can throw an error:
1686
+ * - `FilesNotFoundError` if no tests are found
1687
+ * - `GitNotFoundError` if `--related` flag is used, but git repository is not initialized
1688
+ * - `Error` from the user reporters
1689
+ * @param filters String filters to match the test files
1691
1690
  */
1692
- environment?: VitestEnvironment;
1691
+ start(filters?: string[]): Promise<TestRunResult>;
1693
1692
  /**
1694
- * Environment options.
1693
+ * Initialize reporters and the coverage provider. This method doesn't run any tests.
1694
+ * If the `--watch` flag is provided, Vitest will still run changed tests even if this method was not called.
1695
1695
  */
1696
- environmentOptions?: EnvironmentOptions;
1696
+ init(): Promise<void>;
1697
1697
  /**
1698
- * Automatically assign environment based on globs. The first match will be used.
1699
- * This has effect only when running tests inside Node.js.
1700
- *
1701
- * Format: [glob, environment-name]
1702
- *
1703
- * @deprecated use [`projects`](https://vitest.dev/config/#projects) instead
1704
- * @default []
1705
- * @example [
1706
- * // all tests in tests/dom will run in jsdom
1707
- * ['tests/dom/**', 'jsdom'],
1708
- * // all tests in tests/ with .edge.test.ts will run in edge-runtime
1709
- * ['**\/*.edge.test.ts', 'edge-runtime'],
1710
- * // ...
1711
- * ]
1698
+ * If there is a test run happening, returns a promise that will
1699
+ * resolve when the test run is finished.
1712
1700
  */
1713
- environmentMatchGlobs?: [string, VitestEnvironment][];
1701
+ waitForTestRunEnd(): Promise<void>;
1714
1702
  /**
1715
- * Run tests in an isolated environment. This option has no effect on vmThreads pool.
1716
- *
1717
- * Disabling this option might improve performance if your code doesn't rely on side effects.
1703
+ * Get test specifications associated with the given module. If module is not a test file, an empty array is returned.
1718
1704
  *
1719
- * @default true
1705
+ * **Note:** this method relies on a cache generated by `globTestSpecifications`. If the file was not processed yet, use `project.matchesGlobPattern` instead.
1706
+ * @param moduleId The module ID to get test specifications for.
1720
1707
  */
1721
- isolate?: boolean;
1708
+ getModuleSpecifications(moduleId: string): TestSpecification[];
1722
1709
  /**
1723
- * Pool used to run tests in.
1724
- *
1725
- * Supports 'threads', 'forks', 'vmThreads'
1726
- *
1727
- * @default 'forks'
1710
+ * Vitest automatically caches test specifications for each file. This method clears the cache for the given file or the whole cache altogether.
1728
1711
  */
1729
- pool?: Exclude<Pool, "browser">;
1712
+ clearSpecificationsCache(moduleId?: string): void;
1730
1713
  /**
1731
- * Pool options
1714
+ * Run tests for the given test specifications. This does not trigger `onWatcher*` events.
1715
+ * @param specifications A list of specifications to run.
1716
+ * @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
1732
1717
  */
1733
- poolOptions?: PoolOptions;
1718
+ runTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
1734
1719
  /**
1735
- * Maximum number or percentage of workers to run tests in. `poolOptions.{threads,vmThreads}.maxThreads`/`poolOptions.forks.maxForks` has higher priority.
1720
+ * Rerun files and trigger `onWatcherRerun`, `onWatcherStart` and `onTestsRerun` events.
1721
+ * @param specifications A list of specifications to run.
1722
+ * @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
1736
1723
  */
1737
- maxWorkers?: number | string;
1724
+ rerunTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
1725
+ private runFiles;
1726
+ experimental_parseSpecifications(specifications: TestSpecification[], options?: {
1727
+ /** @default os.availableParallelism() */
1728
+ concurrency?: number;
1729
+ }): Promise<TestModule[]>;
1730
+ experimental_parseSpecification(specification: TestSpecification): Promise<TestModule>;
1738
1731
  /**
1739
- * Minimum number or percentage of workers to run tests in. `poolOptions.{threads,vmThreads}.minThreads`/`poolOptions.forks.minForks` has higher priority.
1732
+ * Collect tests in specified modules. Vitest will run the files to collect tests.
1733
+ * @param specifications A list of specifications to run.
1740
1734
  */
1741
- minWorkers?: number | string;
1735
+ collectTests(specifications: TestSpecification[]): Promise<TestRunResult>;
1742
1736
  /**
1743
- * Should all test files run in parallel. Doesn't affect tests running in the same file.
1744
- * Setting this to `false` will override `maxWorkers` and `minWorkers` options to `1`.
1745
- *
1746
- * @default true
1737
+ * Gracefully cancel the current test run. Vitest will wait until all running tests are finished before cancelling.
1747
1738
  */
1748
- fileParallelism?: boolean;
1739
+ cancelCurrentRun(reason: CancelReason): Promise<void>;
1740
+ private initializeGlobalSetup;
1749
1741
  /**
1750
- * Automatically assign pool based on globs. The first match will be used.
1751
- *
1752
- * Format: [glob, pool-name]
1742
+ * Update snapshots in specified files. If no files are provided, it will update files with failed tests and obsolete snapshots.
1743
+ * @param files The list of files on the file system
1744
+ */
1745
+ updateSnapshot(files?: string[]): Promise<TestRunResult>;
1746
+ /**
1747
+ * Enable the mode that allows updating snapshots when running tests.
1748
+ * This method doesn't run any tests.
1753
1749
  *
1754
- * @deprecated use [`projects`](https://vitest.dev/config/#projects) instead
1755
- * @default []
1756
- * @example [
1757
- * // all tests in "forks" directory will run using "poolOptions.forks" API
1758
- * ['tests/forks/**', 'forks'],
1759
- * // all other tests will run based on "poolOptions.threads" option, if you didn't specify other globs
1760
- * // ...
1761
- * ]
1750
+ * Every test that runs after this method is called will update snapshots.
1751
+ * To disable the mode, call `resetSnapshotUpdate`.
1762
1752
  */
1763
- poolMatchGlobs?: [string, Exclude<Pool, "browser">][];
1753
+ enableSnapshotUpdate(): void;
1764
1754
  /**
1765
- * Options for projects
1755
+ * Disable the mode that allows updating snapshots when running tests.
1766
1756
  */
1767
- projects?: TestProjectConfiguration[];
1757
+ resetSnapshotUpdate(): void;
1768
1758
  /**
1769
- * Path to a workspace configuration file
1770
- * @deprecated use `projects` instead
1759
+ * Set the global test name pattern to a regexp.
1760
+ * This method doesn't run any tests.
1771
1761
  */
1772
- workspace?: string | TestProjectConfiguration[];
1762
+ setGlobalTestNamePattern(pattern: string | RegExp): void;
1773
1763
  /**
1774
- * Update snapshot
1775
- *
1776
- * @default false
1764
+ * Returns the regexp used for the global test name pattern.
1777
1765
  */
1778
- update?: boolean;
1766
+ getGlobalTestNamePattern(): RegExp | undefined;
1779
1767
  /**
1780
- * Watch mode
1781
- *
1782
- * @default !process.env.CI
1768
+ * Resets the global test name pattern. This method doesn't run any tests.
1783
1769
  */
1784
- watch?: boolean;
1770
+ resetGlobalTestNamePattern(): void;
1771
+ private _rerunTimer;
1772
+ private scheduleRerun;
1785
1773
  /**
1786
- * Project root
1787
- *
1788
- * @default process.cwd()
1774
+ * Invalidate a file in all projects.
1789
1775
  */
1790
- root?: string;
1776
+ invalidateFile(filepath: string): void;
1777
+ private reportCoverage;
1791
1778
  /**
1792
- * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
1793
- * and/or paths to custom reporters.
1794
- *
1795
- * @default []
1779
+ * Closes all projects and their associated resources.
1780
+ * This can only be called once; the closing promise is cached until the server restarts.
1796
1781
  */
1797
- reporters?: Arrayable$1<ReporterName | InlineReporter> | ((ReporterName | InlineReporter) | [ReporterName] | ReporterWithOptions)[];
1782
+ close(): Promise<void>;
1798
1783
  /**
1799
- * Write test results to a file when the --reporter=json` or `--reporter=junit` option is also specified.
1800
- * Also definable individually per reporter by using an object instead.
1784
+ * Closes all projects and exit the process
1785
+ * @param force If true, the process will exit immediately after closing the projects.
1801
1786
  */
1802
- outputFile?: string | (Partial<Record<BuiltinReporters, string>> & Record<string, string>);
1787
+ exit(force?: boolean): Promise<void>;
1803
1788
  /**
1804
- * Default timeout of a test in milliseconds
1805
- *
1806
- * @default 5000
1807
- */
1808
- testTimeout?: number;
1809
- /**
1810
- * Default timeout of a hook in milliseconds
1811
- *
1812
- * @default 10000
1813
- */
1814
- hookTimeout?: number;
1815
- /**
1816
- * Default timeout to wait for close when Vitest shuts down, in milliseconds
1817
- *
1818
- * @default 10000
1819
- */
1820
- teardownTimeout?: number;
1821
- /**
1822
- * Silent mode
1823
- *
1824
- * Use `'passed-only'` to see logs from failing tests only.
1825
- *
1826
- * @default false
1827
- */
1828
- silent?: boolean | "passed-only";
1829
- /**
1830
- * Hide logs for skipped tests
1831
- *
1832
- * @default false
1833
- */
1834
- hideSkippedTests?: boolean;
1835
- /**
1836
- * Path to setup files
1837
- */
1838
- setupFiles?: string | string[];
1839
- /**
1840
- * Path to global setup files
1841
- */
1842
- globalSetup?: string | string[];
1843
- /**
1844
- * Glob patter of file paths that will trigger the whole suite rerun
1845
- *
1846
- * Useful if you are testing calling CLI commands
1847
- *
1848
- * @default ['**\/package.json/**', '**\/{vitest,vite}.config.*\/**']
1849
- */
1850
- forceRerunTriggers?: string[];
1851
- /**
1852
- * Pattern configuration to rerun only the tests that are affected
1853
- * by the changes of specific files in the repository.
1854
- */
1855
- watchTriggerPatterns?: WatcherTriggerPattern[];
1856
- /**
1857
- * Coverage options
1858
- */
1859
- coverage?: CoverageOptions;
1860
- /**
1861
- * run test names with the specified pattern
1862
- */
1863
- testNamePattern?: string | RegExp;
1864
- /**
1865
- * Will call `.mockClear()` on all spies before each test
1866
- * @default false
1789
+ * Should the server be kept running after the tests are done.
1867
1790
  */
1868
- clearMocks?: boolean;
1791
+ shouldKeepServer(): boolean;
1869
1792
  /**
1870
- * Will call `.mockReset()` on all spies before each test
1871
- * @default false
1793
+ * Register a handler that will be called when the server is restarted due to a config change.
1872
1794
  */
1873
- mockReset?: boolean;
1795
+ onServerRestart(fn: OnServerRestartHandler): void;
1874
1796
  /**
1875
- * Will call `.mockRestore()` on all spies before each test
1876
- * @default false
1797
+ * Register a handler that will be called when the test run is cancelled with `vitest.cancelCurrentRun`.
1877
1798
  */
1878
- restoreMocks?: boolean;
1799
+ onCancel(fn: (reason: CancelReason) => Awaitable<void>): void;
1879
1800
  /**
1880
- * Will restore all global stubs to their original values before each test
1881
- * @default false
1801
+ * Register a handler that will be called when the server is closed.
1882
1802
  */
1883
- unstubGlobals?: boolean;
1803
+ onClose(fn: () => Awaitable<void>): void;
1884
1804
  /**
1885
- * Will restore all env stubs to their original values before each test
1886
- * @default false
1805
+ * Register a handler that will be called when the tests are rerunning.
1887
1806
  */
1888
- unstubEnvs?: boolean;
1807
+ onTestsRerun(fn: OnTestsRerunHandler): void;
1889
1808
  /**
1890
- * Serve API options.
1891
- *
1892
- * When set to true, the default port is 51204.
1893
- *
1894
- * @default false
1809
+ * Register a handler that will be called when a file is changed.
1810
+ * This callback should return `true` of `false` indicating whether the test file needs to be rerun.
1811
+ * @example
1812
+ * const testsToRun = [resolve('./test.spec.ts')]
1813
+ * vitest.onFilterWatchedSpecification(specification => testsToRun.includes(specification.moduleId))
1895
1814
  */
1896
- api?: boolean | number | ApiConfig;
1815
+ onFilterWatchedSpecification(fn: (specification: TestSpecification) => boolean): void;
1897
1816
  /**
1898
- * Enable Vitest UI
1899
- *
1900
- * @default false
1817
+ * Check if the project with a given name should be included.
1901
1818
  */
1902
- ui?: boolean;
1819
+ matchesProjectFilter(name: string): boolean;
1820
+ }
1821
+ type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
1822
+ type OnTestsRerunHandler = (testFiles: TestSpecification[]) => Promise<void> | void;
1823
+
1824
+ type TestRunEndReason = "passed" | "interrupted" | "failed";
1825
+ interface Reporter {
1826
+ onInit?: (vitest: Vitest) => void;
1903
1827
  /**
1904
- * options for test in a browser environment
1828
+ * Called when the project initiated the browser instance.
1829
+ * project.browser will always be defined.
1905
1830
  * @experimental
1906
- *
1907
- * @default false
1908
1831
  */
1909
- browser?: BrowserConfigOptions;
1910
- /**
1911
- * Open UI automatically.
1912
- *
1913
- * @default !process.env.CI
1914
- */
1915
- open?: boolean;
1832
+ onBrowserInit?: (project: TestProject) => Awaitable$1<void>;
1833
+ onTestRemoved?: (trigger?: string) => Awaitable$1<void>;
1834
+ onWatcherStart?: (files?: File[], errors?: unknown[]) => Awaitable$1<void>;
1835
+ onWatcherRerun?: (files: string[], trigger?: string) => Awaitable$1<void>;
1836
+ onServerRestart?: (reason?: string) => Awaitable$1<void>;
1837
+ onUserConsoleLog?: (log: UserConsoleLog) => Awaitable$1<void>;
1838
+ onProcessTimeout?: () => Awaitable$1<void>;
1916
1839
  /**
1917
- * Base url for the UI
1918
- *
1919
- * @default '/__vitest__/'
1920
- */
1921
- uiBase?: string;
1922
- /**
1923
- * Determine the transform method for all modules imported inside a test that matches the glob pattern.
1840
+ * Called when the new test run starts.
1924
1841
  */
1925
- testTransformMode?: TransformModePatterns;
1842
+ onTestRunStart?: (specifications: ReadonlyArray<TestSpecification>) => Awaitable$1<void>;
1926
1843
  /**
1927
- * Format options for snapshot testing.
1844
+ * Called when the test run is finished.
1928
1845
  */
1929
- snapshotFormat?: Omit<PrettyFormatOptions, "plugins">;
1846
+ onTestRunEnd?: (testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason) => Awaitable$1<void>;
1930
1847
  /**
1931
- * Path to a module which has a default export of diff config.
1848
+ * Called when the module is enqueued for testing. The file itself is not loaded yet.
1932
1849
  */
1933
- diff?: string | SerializedDiffOptions;
1850
+ onTestModuleQueued?: (testModule: TestModule) => Awaitable$1<void>;
1934
1851
  /**
1935
- * Paths to snapshot serializer modules.
1852
+ * Called when the test file is loaded and the module is ready to run tests.
1936
1853
  */
1937
- snapshotSerializers?: string[];
1854
+ onTestModuleCollected?: (testModule: TestModule) => Awaitable$1<void>;
1938
1855
  /**
1939
- * Resolve custom snapshot path
1856
+ * Called when starting to run tests of the test file
1940
1857
  */
1941
- resolveSnapshotPath?: ResolveSnapshotPathHandler;
1858
+ onTestModuleStart?: (testModule: TestModule) => Awaitable$1<void>;
1942
1859
  /**
1943
- * Path to a custom snapshot environment module that has a default export of `SnapshotEnvironment` object.
1860
+ * Called when all tests of the test file have finished running.
1944
1861
  */
1945
- snapshotEnvironment?: string;
1862
+ onTestModuleEnd?: (testModule: TestModule) => Awaitable$1<void>;
1946
1863
  /**
1947
- * Pass with no tests
1864
+ * Called when test case is ready to run.
1865
+ * Called before the `beforeEach` hooks for the test are run.
1948
1866
  */
1949
- passWithNoTests?: boolean;
1867
+ onTestCaseReady?: (testCase: TestCase) => Awaitable$1<void>;
1950
1868
  /**
1951
- * Allow tests and suites that are marked as only
1952
- *
1953
- * @default !process.env.CI
1869
+ * Called after the test and its hooks are finished running.
1870
+ * The `result()` cannot be `pending`.
1954
1871
  */
1955
- allowOnly?: boolean;
1872
+ onTestCaseResult?: (testCase: TestCase) => Awaitable$1<void>;
1956
1873
  /**
1957
- * Show heap usage after each test. Useful for debugging memory leaks.
1874
+ * Called when annotation is added via the `task.annotate` API.
1958
1875
  */
1959
- logHeapUsage?: boolean;
1876
+ onTestCaseAnnotate?: (testCase: TestCase, annotation: TestAnnotation) => Awaitable$1<void>;
1960
1877
  /**
1961
- * Custom environment variables assigned to `process.env` before running tests.
1878
+ * Called when test suite is ready to run.
1879
+ * Called before the `beforeAll` hooks for the test are run.
1962
1880
  */
1963
- env?: Partial<NodeJS.ProcessEnv>;
1881
+ onTestSuiteReady?: (testSuite: TestSuite) => Awaitable$1<void>;
1964
1882
  /**
1965
- * Options for @sinon/fake-timers
1883
+ * Called after the test suite and its hooks are finished running.
1884
+ * The `state` cannot be `pending`.
1966
1885
  */
1967
- fakeTimers?: FakeTimerInstallOpts;
1886
+ onTestSuiteResult?: (testSuite: TestSuite) => Awaitable$1<void>;
1968
1887
  /**
1969
- * Custom handler for console.log in tests.
1970
- *
1971
- * Return `false` to ignore the log.
1888
+ * Called before the hook starts to run.
1972
1889
  */
1973
- onConsoleLog?: (log: string, type: "stdout" | "stderr") => boolean | void;
1890
+ onHookStart?: (hook: ReportedHookContext) => Awaitable$1<void>;
1974
1891
  /**
1975
- * Enable stack trace filtering. If absent, all stack trace frames
1976
- * will be shown.
1977
- *
1978
- * Return `false` to omit the frame.
1892
+ * Called after the hook finished running.
1979
1893
  */
1980
- onStackTrace?: (error: ErrorWithDiff, frame: ParsedStack) => boolean | void;
1894
+ onHookEnd?: (hook: ReportedHookContext) => Awaitable$1<void>;
1895
+ onCoverage?: (coverage: unknown) => Awaitable$1<void>;
1896
+ }
1897
+
1898
+ interface BaseOptions {
1899
+ isTTY?: boolean;
1900
+ }
1901
+ declare abstract class BaseReporter implements Reporter {
1902
+ start: number;
1903
+ end: number;
1904
+ watchFilters?: string[];
1905
+ failedUnwatchedFiles: TestModule[];
1906
+ isTTY: boolean;
1907
+ ctx: Vitest;
1908
+ renderSucceed: boolean;
1909
+ protected verbose: boolean;
1910
+ private _filesInWatchMode;
1911
+ private _timeStart;
1912
+ constructor(options?: BaseOptions);
1913
+ onInit(ctx: Vitest): void;
1914
+ log(...messages: any): void;
1915
+ error(...messages: any): void;
1916
+ relative(path: string): string;
1917
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, _reason: TestRunEndReason): void;
1918
+ onTestCaseResult(testCase: TestCase): void;
1919
+ onTestSuiteResult(testSuite: TestSuite): void;
1920
+ onTestModuleEnd(testModule: TestModule): void;
1921
+ private logFailedTask;
1922
+ protected printTestModule(testModule: TestModule): void;
1923
+ protected printTestCase(moduleState: TestModuleState, test: TestCase): void;
1924
+ private getModuleLog;
1925
+ protected printTestSuite(_suite: TestSuite): void;
1926
+ protected getTestName(test: Task, separator?: string): string;
1927
+ protected getFullName(test: Task, separator?: string): string;
1928
+ protected formatShortError(error: TestError): string;
1929
+ protected getTestIndentation(_test: Task): string;
1930
+ protected printAnnotations(test: TestCase, console: "log" | "error", padding?: number): void;
1931
+ protected getDurationPrefix(task: Task): string;
1932
+ onWatcherStart(files?: File[], errors?: unknown[]): void;
1933
+ onWatcherRerun(files: string[], trigger?: string): void;
1934
+ onUserConsoleLog(log: UserConsoleLog, taskState?: TestResult["state"]): void;
1935
+ onTestRemoved(trigger?: string): void;
1936
+ shouldLog(log: UserConsoleLog, taskState?: TestResult["state"]): boolean;
1937
+ onServerRestart(reason?: string): void;
1938
+ reportSummary(files: File[], errors: unknown[]): void;
1939
+ reportTestSummary(files: File[], errors: unknown[]): void;
1940
+ private printErrorsSummary;
1941
+ reportBenchmarkSummary(files: File[]): void;
1942
+ private printTaskErrors;
1943
+ }
1944
+
1945
+ interface DefaultReporterOptions extends BaseOptions {
1946
+ summary?: boolean;
1947
+ }
1948
+ declare class DefaultReporter extends BaseReporter {
1949
+ private options;
1950
+ private summary?;
1951
+ constructor(options?: DefaultReporterOptions);
1952
+ onTestRunStart(specifications: ReadonlyArray<TestSpecification>): void;
1953
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): void;
1954
+ onTestModuleQueued(file: TestModule): void;
1955
+ onTestModuleCollected(module: TestModule): void;
1956
+ onTestModuleEnd(module: TestModule): void;
1957
+ onTestCaseReady(test: TestCase): void;
1958
+ onTestCaseResult(test: TestCase): void;
1959
+ onHookStart(hook: ReportedHookContext): void;
1960
+ onHookEnd(hook: ReportedHookContext): void;
1961
+ onInit(ctx: Vitest): void;
1962
+ }
1963
+
1964
+ interface HTMLOptions {
1965
+ outputFile?: string;
1966
+ }
1967
+
1968
+ type Status = "passed" | "failed" | "skipped" | "pending" | "todo" | "disabled";
1969
+ type Milliseconds = number;
1970
+ interface Callsite {
1971
+ line: number;
1972
+ column: number;
1973
+ }
1974
+ interface JsonAssertionResult {
1975
+ ancestorTitles: Array<string>;
1976
+ fullName: string;
1977
+ status: Status;
1978
+ title: string;
1979
+ meta: TaskMeta;
1980
+ duration?: Milliseconds | null;
1981
+ failureMessages: Array<string> | null;
1982
+ location?: Callsite | null;
1983
+ }
1984
+ interface JsonTestResult {
1985
+ message: string;
1986
+ name: string;
1987
+ status: "failed" | "passed";
1988
+ startTime: number;
1989
+ endTime: number;
1990
+ assertionResults: Array<JsonAssertionResult>;
1991
+ }
1992
+ interface JsonTestResults {
1993
+ numFailedTests: number;
1994
+ numFailedTestSuites: number;
1995
+ numPassedTests: number;
1996
+ numPassedTestSuites: number;
1997
+ numPendingTests: number;
1998
+ numPendingTestSuites: number;
1999
+ numTodoTests: number;
2000
+ numTotalTests: number;
2001
+ numTotalTestSuites: number;
2002
+ startTime: number;
2003
+ success: boolean;
2004
+ testResults: Array<JsonTestResult>;
2005
+ snapshot: SnapshotSummary;
2006
+ coverageMap?: CoverageMap | null | undefined;
2007
+ }
2008
+ interface JsonOptions {
2009
+ outputFile?: string;
2010
+ }
2011
+ declare class JsonReporter implements Reporter {
2012
+ start: number;
2013
+ ctx: Vitest;
2014
+ options: JsonOptions;
2015
+ coverageMap?: CoverageMap;
2016
+ constructor(options: JsonOptions);
2017
+ onInit(ctx: Vitest): void;
2018
+ onCoverage(coverageMap: unknown): void;
2019
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): Promise<void>;
1981
2020
  /**
1982
- * Indicates if CSS files should be processed.
1983
- *
1984
- * When excluded, the CSS files will be replaced with empty strings to bypass the subsequent processing.
1985
- *
1986
- * @default { include: [], modules: { classNameStrategy: false } }
2021
+ * Writes the report to an output file if specified in the config,
2022
+ * or logs it to the console otherwise.
2023
+ * @param report
1987
2024
  */
1988
- css?: boolean | {
1989
- include?: RegExp | RegExp[]
1990
- exclude?: RegExp | RegExp[]
1991
- modules?: {
1992
- classNameStrategy?: CSSModuleScopeStrategy
1993
- }
1994
- };
2025
+ writeReport(report: string): Promise<void>;
2026
+ }
2027
+
2028
+ interface ClassnameTemplateVariables {
2029
+ filename: string;
2030
+ filepath: string;
2031
+ }
2032
+ interface JUnitOptions {
2033
+ outputFile?: string;
1995
2034
  /**
1996
- * A number of tests that are allowed to run at the same time marked with `test.concurrent`.
1997
- * @default 5
2035
+ * Template for the classname attribute. Can be either a string or a function. The string can contain placeholders {filename} and {filepath}.
1998
2036
  */
1999
- maxConcurrency?: number;
2037
+ classnameTemplate?: string | ((classnameVariables: ClassnameTemplateVariables) => string);
2038
+ suiteName?: string;
2000
2039
  /**
2001
- * Options for configuring cache policy.
2002
- * @default { dir: 'node_modules/.vite/vitest/{project-hash}' }
2040
+ * Write <system-out> and <system-err> for console output
2041
+ * @default true
2003
2042
  */
2004
- cache?: false | {
2005
- /**
2006
- * @deprecated Use Vite's "cacheDir" instead if you want to change the cache director. Note caches will be written to "cacheDir\/vitest".
2007
- */
2008
- dir: string
2009
- };
2043
+ includeConsoleOutput?: boolean;
2010
2044
  /**
2011
- * Options for configuring the order of running tests.
2045
+ * Add <testcase file="..."> attribute (validated on CIRCLE CI and GitLab CI)
2046
+ * @default false
2012
2047
  */
2013
- sequence?: SequenceOptions;
2048
+ addFileAttribute?: boolean;
2049
+ }
2050
+ declare class JUnitReporter implements Reporter {
2051
+ private ctx;
2052
+ private reportFile?;
2053
+ private baseLog;
2054
+ private logger;
2055
+ private _timeStart;
2056
+ private fileFd?;
2057
+ private options;
2058
+ constructor(options: JUnitOptions);
2059
+ onInit(ctx: Vitest): Promise<void>;
2060
+ writeElement(name: string, attrs: Record<string, any>, children: () => Promise<void>): Promise<void>;
2061
+ writeLogs(task: Task, type: "err" | "out"): Promise<void>;
2062
+ writeTasks(tasks: Task[], filename: string): Promise<void>;
2063
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): Promise<void>;
2064
+ }
2065
+
2066
+ declare class DotReporter extends BaseReporter {
2067
+ private renderer?;
2068
+ private tests;
2069
+ private finishedTests;
2070
+ onInit(ctx: Vitest): void;
2071
+ printTestModule(): void;
2072
+ onWatcherRerun(files: string[], trigger?: string): void;
2073
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): void;
2074
+ onTestModuleCollected(module: TestModule): void;
2075
+ onTestCaseReady(test: TestCase): void;
2076
+ onTestCaseResult(test: TestCase): void;
2077
+ onTestModuleEnd(testModule: TestModule): void;
2078
+ private createSummary;
2079
+ }
2080
+
2081
+ interface GithubActionsReporterOptions {
2082
+ onWritePath?: (path: string) => string;
2083
+ }
2084
+ declare class GithubActionsReporter implements Reporter {
2085
+ ctx: Vitest;
2086
+ options: GithubActionsReporterOptions;
2087
+ constructor(options?: GithubActionsReporterOptions);
2088
+ onInit(ctx: Vitest): void;
2089
+ onTestCaseAnnotate(testCase: TestCase, annotation: TestAnnotation): void;
2090
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): void;
2091
+ }
2092
+
2093
+ declare class HangingProcessReporter implements Reporter {
2094
+ whyRunning: (() => void) | undefined;
2095
+ onInit(): void;
2096
+ onProcessTimeout(): void;
2097
+ }
2098
+
2099
+ declare class TapReporter implements Reporter {
2100
+ protected ctx: Vitest;
2101
+ private logger;
2102
+ onInit(ctx: Vitest): void;
2103
+ static getComment(task: Task): string;
2104
+ private logErrorDetails;
2105
+ protected logTasks(tasks: Task[]): void;
2106
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): void;
2107
+ }
2108
+
2109
+ declare class TapFlatReporter extends TapReporter {
2110
+ onInit(ctx: Vitest): void;
2111
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): void;
2112
+ }
2113
+
2114
+ declare class VerboseReporter extends DefaultReporter {
2115
+ protected verbose: boolean;
2116
+ renderSucceed: boolean;
2117
+ printTestModule(module: TestModule): void;
2118
+ onTestCaseResult(test: TestCase): void;
2119
+ protected printTestSuite(testSuite: TestSuite): void;
2120
+ protected getTestName(test: Task): string;
2121
+ protected getTestIndentation(test: Task): string;
2122
+ protected formatShortError(): string;
2123
+ }
2124
+
2125
+ type FormattedBenchmarkResult = BenchmarkResult & {
2126
+ id: string;
2127
+ };
2128
+
2129
+ declare function renderTable(options: {
2130
+ tasks: Task[];
2131
+ level: number;
2132
+ shallow?: boolean;
2133
+ showHeap: boolean;
2134
+ columns: number;
2135
+ slowTestThreshold: number;
2136
+ compare?: Record<Task["id"], FormattedBenchmarkResult>;
2137
+ }): string;
2138
+
2139
+ declare class BenchmarkReporter extends DefaultReporter {
2140
+ compare?: Parameters<typeof renderTable>[0]["compare"];
2141
+ onInit(ctx: Vitest): Promise<void>;
2142
+ onTaskUpdate(packs: TaskResultPack[]): void;
2143
+ onTestSuiteResult(testSuite: TestSuite): void;
2144
+ protected printTestModule(testModule: TestModule): void;
2145
+ private printSuiteTable;
2146
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): Promise<void>;
2147
+ }
2148
+
2149
+ declare class VerboseBenchmarkReporter extends BenchmarkReporter {
2150
+ protected verbose: boolean;
2151
+ }
2152
+
2153
+ declare const BenchmarkReportsMap: {
2154
+ default: typeof BenchmarkReporter;
2155
+ verbose: typeof VerboseBenchmarkReporter;
2156
+ };
2157
+ type BenchmarkBuiltinReporters = keyof typeof BenchmarkReportsMap;
2158
+
2159
+ declare const ReportersMap: {
2160
+ default: typeof DefaultReporter;
2161
+ blob: typeof BlobReporter;
2162
+ verbose: typeof VerboseReporter;
2163
+ dot: typeof DotReporter;
2164
+ json: typeof JsonReporter;
2165
+ tap: typeof TapReporter;
2166
+ "tap-flat": typeof TapFlatReporter;
2167
+ junit: typeof JUnitReporter;
2168
+ "hanging-process": typeof HangingProcessReporter;
2169
+ "github-actions": typeof GithubActionsReporter;
2170
+ };
2171
+ type BuiltinReporters = keyof typeof ReportersMap;
2172
+ interface BuiltinReporterOptions {
2173
+ "default": DefaultReporterOptions;
2174
+ "verbose": DefaultReporterOptions;
2175
+ "dot": BaseOptions;
2176
+ "json": JsonOptions;
2177
+ "blob": BlobOptions;
2178
+ "tap": never;
2179
+ "tap-flat": never;
2180
+ "junit": JUnitOptions;
2181
+ "hanging-process": never;
2182
+ "html": HTMLOptions;
2183
+ }
2184
+
2185
+ interface TestSequencer {
2014
2186
  /**
2015
- * Specifies an `Object`, or an `Array` of `Object`,
2016
- * which defines aliases used to replace values in `import` or `require` statements.
2017
- * Will be merged with the default aliases inside `resolve.alias`.
2187
+ * Slicing tests into shards. Will be run before `sort`.
2188
+ * Only run, if `shard` is defined.
2018
2189
  */
2019
- alias?: AliasOptions;
2190
+ shard: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
2191
+ sort: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
2192
+ }
2193
+ interface TestSequencerConstructor {
2194
+ new (ctx: Vitest): TestSequencer;
2195
+ }
2196
+
2197
+ interface BenchmarkUserOptions {
2020
2198
  /**
2021
- * Ignore any unhandled errors that occur
2199
+ * Include globs for benchmark test files
2022
2200
  *
2023
- * @default false
2201
+ * @default ['**\/*.{bench,benchmark}.?(c|m)[jt]s?(x)']
2024
2202
  */
2025
- dangerouslyIgnoreUnhandledErrors?: boolean;
2203
+ include?: string[];
2026
2204
  /**
2027
- * Options for configuring typechecking test environment.
2205
+ * Exclude globs for benchmark test files
2206
+ * @default ['**\/node_modules/**', '**\/dist/**', '**\/cypress/**', '**\/.{idea,git,cache,output,temp}/**', '**\/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*']
2028
2207
  */
2029
- typecheck?: Partial<TypecheckConfig>;
2208
+ exclude?: string[];
2030
2209
  /**
2031
- * The number of milliseconds after which a test is considered slow and reported as such in the results.
2210
+ * Include globs for in-source benchmark test files
2032
2211
  *
2033
- * @default 300
2034
- */
2035
- slowTestThreshold?: number;
2036
- /**
2037
- * Path to a custom test runner.
2212
+ * @default []
2038
2213
  */
2039
- runner?: string;
2214
+ includeSource?: string[];
2040
2215
  /**
2041
- * Debug tests by opening `node:inspector` in worker / child process.
2042
- * Provides similar experience as `--inspect` Node CLI argument.
2216
+ * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
2217
+ * and/or paths to custom reporters
2043
2218
  *
2044
- * Requires `poolOptions.threads.singleThread: true` OR `poolOptions.forks.singleFork: true`.
2219
+ * @default ['default']
2045
2220
  */
2046
- inspect?: boolean | string;
2221
+ reporters?: Arrayable$1<BenchmarkBuiltinReporters | Reporter>;
2047
2222
  /**
2048
- * Debug tests by opening `node:inspector` in worker / child process and wait for debugger to connect.
2049
- * Provides similar experience as `--inspect-brk` Node CLI argument.
2050
- *
2051
- * Requires `poolOptions.threads.singleThread: true` OR `poolOptions.forks.singleFork: true`.
2223
+ * @deprecated Use `benchmark.outputJson` instead
2052
2224
  */
2053
- inspectBrk?: boolean | string;
2225
+ outputFile?: string | (Partial<Record<BenchmarkBuiltinReporters, string>> & Record<string, string>);
2054
2226
  /**
2055
- * Inspector options. If `--inspect` or `--inspect-brk` is enabled, these options will be passed to the inspector.
2227
+ * benchmark output file to compare against
2056
2228
  */
2057
- inspector?: {
2058
- /**
2059
- * Enable inspector
2060
- */
2061
- enabled?: boolean
2062
- /**
2063
- * Port to run inspector on
2064
- */
2065
- port?: number
2066
- /**
2067
- * Host to run inspector on
2068
- */
2069
- host?: string
2070
- /**
2071
- * Wait for debugger to connect before running tests
2072
- */
2073
- waitForDebugger?: boolean
2074
- };
2229
+ compare?: string;
2075
2230
  /**
2076
- * Define variables that will be returned from `inject` in the test environment.
2077
- * @example
2078
- * ```ts
2079
- * // vitest.config.ts
2080
- * export default defineConfig({
2081
- * test: {
2082
- * provide: {
2083
- * someKey: 'someValue'
2084
- * }
2085
- * }
2086
- * })
2087
- * ```
2088
- * ```ts
2089
- * // test file
2090
- * import { inject } from 'vitest'
2091
- * const value = inject('someKey') // 'someValue'
2092
- * ```
2231
+ * benchmark output file
2093
2232
  */
2094
- provide?: Partial<ProvidedContext>;
2233
+ outputJson?: string;
2095
2234
  /**
2096
- * Configuration options for expect() matches.
2235
+ * Include `samples` array of benchmark results for API or custom reporter usages.
2236
+ * This is disabled by default to reduce memory usage.
2237
+ * @default false
2097
2238
  */
2098
- expect?: {
2099
- /**
2100
- * Throw an error if tests don't have any expect() assertions.
2101
- */
2102
- requireAssertions?: boolean
2103
- /**
2104
- * Default options for expect.poll()
2105
- */
2106
- poll?: {
2107
- /**
2108
- * Timeout in milliseconds
2109
- * @default 1000
2110
- */
2111
- timeout?: number
2112
- /**
2113
- * Polling interval in milliseconds
2114
- * @default 50
2115
- */
2116
- interval?: number
2117
- }
2118
- };
2239
+ includeSamples?: boolean;
2240
+ }
2241
+
2242
+ type BuiltinEnvironment = "node" | "jsdom" | "happy-dom" | "edge-runtime";
2243
+ type VitestEnvironment = BuiltinEnvironment | (string & Record<never, never>);
2244
+
2245
+ type CSSModuleScopeStrategy = "stable" | "scoped" | "non-scoped";
2246
+ type ApiConfig = Pick<ServerOptions, "port" | "strictPort" | "host" | "middlewareMode">;
2247
+ interface EnvironmentOptions {
2119
2248
  /**
2120
- * Modify default Chai config. Vitest uses Chai for `expect` and `assert` matches.
2121
- * https://github.com/chaijs/chai/blob/4.x.x/lib/chai/config.js
2249
+ * jsdom options.
2122
2250
  */
2123
- chaiConfig?: ChaiConfig;
2251
+ jsdom?: JSDOMOptions;
2252
+ happyDOM?: HappyDOMOptions;
2253
+ [x: string]: unknown;
2254
+ }
2255
+
2256
+ type VitestRunMode = "test" | "benchmark";
2257
+ interface ProjectName {
2258
+ label: string;
2259
+ color?: LabelColor;
2260
+ }
2261
+ interface SequenceOptions {
2124
2262
  /**
2125
- * Stop test execution when given number of tests have failed.
2263
+ * Class that handles sorting and sharding algorithm.
2264
+ * If you only need to change sorting, you can extend
2265
+ * your custom sequencer from `BaseSequencer` from `vitest/node`.
2266
+ * @default BaseSequencer
2126
2267
  */
2127
- bail?: number;
2268
+ sequencer?: TestSequencerConstructor;
2128
2269
  /**
2129
- * Retry the test specific number of times if it fails.
2270
+ * Controls the order in which this project runs its tests when using multiple [projects](/guide/projects).
2130
2271
  *
2272
+ * - Projects with the same group order number will run together, and groups are run from lowest to highest.
2273
+ * - If you don’t set this option, all projects run in parallel.
2274
+ * - If several projects use the same group order, they will run at the same time.
2131
2275
  * @default 0
2132
2276
  */
2133
- retry?: number;
2134
- /**
2135
- * Show full diff when snapshot fails instead of a patch.
2136
- */
2137
- expandSnapshotDiff?: boolean;
2277
+ groupOrder?: number;
2138
2278
  /**
2139
- * By default, Vitest automatically intercepts console logging during tests for extra formatting of test file, test title, etc...
2140
- * This is also required for console log preview on Vitest UI.
2141
- * However, disabling such interception might help when you want to debug a code with normal synchronous terminal console logging.
2142
- *
2143
- * This option has no effect on browser pool since Vitest preserves original logging on browser devtools.
2144
- *
2279
+ * Should files and tests run in random order.
2145
2280
  * @default false
2146
2281
  */
2147
- disableConsoleIntercept?: boolean;
2282
+ shuffle?: boolean | {
2283
+ /**
2284
+ * Should files run in random order. Long running tests will not start
2285
+ * earlier if you enable this option.
2286
+ * @default false
2287
+ */
2288
+ files?: boolean;
2289
+ /**
2290
+ * Should tests run in random order.
2291
+ * @default false
2292
+ */
2293
+ tests?: boolean;
2294
+ };
2148
2295
  /**
2149
- * Always print console stack traces.
2150
- *
2296
+ * Should tests run in parallel.
2151
2297
  * @default false
2152
2298
  */
2153
- printConsoleTrace?: boolean;
2299
+ concurrent?: boolean;
2154
2300
  /**
2155
- * Include "location" property inside the test definition
2156
- *
2157
- * @default false
2301
+ * Defines how setup files should be ordered
2302
+ * - 'parallel' will run all setup files in parallel
2303
+ * - 'list' will run all setup files in the order they are defined in the config file
2304
+ * @default 'parallel'
2158
2305
  */
2159
- includeTaskLocation?: boolean;
2306
+ setupFiles?: SequenceSetupFiles;
2160
2307
  /**
2161
- * Directory path for storing attachments created by `context.annotate`
2162
- *
2163
- * @default '.vitest-attachments'
2308
+ * Seed for the random number generator.
2309
+ * @default Date.now()
2164
2310
  */
2165
- attachmentsDir?: string;
2166
- }
2167
- interface TypecheckConfig {
2311
+ seed?: number;
2168
2312
  /**
2169
- * Run typechecking tests alongside regular tests.
2313
+ * Defines how hooks should be ordered
2314
+ * - `stack` will order "after" hooks in reverse order, "before" hooks will run sequentially
2315
+ * - `list` will order hooks in the order they are defined
2316
+ * - `parallel` will run hooks in a single group in parallel
2317
+ * @default 'stack'
2170
2318
  */
2319
+ hooks?: SequenceHooks;
2320
+ }
2321
+ type DepsOptimizationOptions = Omit<DepOptimizationConfig, "disabled" | "noDiscovery"> & {
2171
2322
  enabled?: boolean;
2323
+ };
2324
+ interface DepsOptions {
2172
2325
  /**
2173
- * When typechecking is enabled, only run typechecking tests.
2174
- */
2175
- only?: boolean;
2176
- /**
2177
- * What tools to use for type checking.
2178
- *
2179
- * @default 'tsc'
2326
+ * Enable dependency optimization. This can improve the performance of your tests.
2180
2327
  */
2181
- checker: "tsc" | "vue-tsc" | (string & Record<never, never>);
2328
+ optimizer?: Partial<Record<"client" | "ssr" | ({} & string), DepsOptimizationOptions>>;
2329
+ web?: {
2330
+ /**
2331
+ * Should Vitest process assets (.png, .svg, .jpg, etc) files and resolve them like Vite does in the browser.
2332
+ *
2333
+ * These module will have a default export equal to the path to the asset, if no query is specified.
2334
+ *
2335
+ * **At the moment, this option only works with `{ pool: 'vmThreads' }`.**
2336
+ *
2337
+ * @default true
2338
+ */
2339
+ transformAssets?: boolean;
2340
+ /**
2341
+ * Should Vitest process CSS (.css, .scss, .sass, etc) files and resolve them like Vite does in the browser.
2342
+ *
2343
+ * If CSS files are disabled with `css` options, this option will just silence UNKNOWN_EXTENSION errors.
2344
+ *
2345
+ * **At the moment, this option only works with `{ pool: 'vmThreads' }`.**
2346
+ *
2347
+ * @default true
2348
+ */
2349
+ transformCss?: boolean;
2350
+ /**
2351
+ * Regexp pattern to match external files that should be transformed.
2352
+ *
2353
+ * By default, files inside `node_modules` are externalized and not transformed.
2354
+ *
2355
+ * **At the moment, this option only works with `{ pool: 'vmThreads' }`.**
2356
+ *
2357
+ * @default []
2358
+ */
2359
+ transformGlobPattern?: RegExp | RegExp[];
2360
+ };
2182
2361
  /**
2183
- * Pattern for files that should be treated as test files
2362
+ * Interpret CJS module's default as named exports
2184
2363
  *
2185
- * @default ['**\/*.{test,spec}-d.?(c|m)[jt]s?(x)']
2364
+ * @default true
2186
2365
  */
2187
- include: string[];
2366
+ interopDefault?: boolean;
2188
2367
  /**
2189
- * Pattern for files that should not be treated as test files
2368
+ * A list of directories relative to the config file that should be treated as module directories.
2190
2369
  *
2191
- * @default ['**\/node_modules/**', '**\/dist/**', '**\/cypress/**', '**\/.{idea,git,cache,output,temp}/**', '**\/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*']
2192
- */
2193
- exclude: string[];
2194
- /**
2195
- * Check JS files that have `@ts-check` comment.
2196
- * If you have it enabled in tsconfig, this will not overwrite it.
2197
- */
2198
- allowJs?: boolean;
2199
- /**
2200
- * Do not fail, if Vitest found errors outside the test files.
2201
- */
2202
- ignoreSourceErrors?: boolean;
2203
- /**
2204
- * Path to tsconfig, relative to the project root.
2205
- */
2206
- tsconfig?: string;
2207
- /**
2208
- * Minimum time in milliseconds it takes to spawn the typechecker.
2209
- * @default 10_000
2370
+ * @default ['node_modules']
2210
2371
  */
2211
- spawnTimeout?: number;
2372
+ moduleDirectories?: string[];
2373
+ }
2374
+ type InlineReporter = Reporter;
2375
+ type ReporterName = BuiltinReporters | "html" | (string & {});
2376
+ type ReporterWithOptions<Name extends ReporterName = ReporterName> = Name extends keyof BuiltinReporterOptions ? BuiltinReporterOptions[Name] extends never ? [Name, object] : [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
2377
+ interface ResolveSnapshotPathHandlerContext {
2378
+ config: SerializedConfig;
2212
2379
  }
2213
- interface UserConfig extends InlineConfig {
2380
+ type ResolveSnapshotPathHandler = (testPath: string, snapExtension: string, context: ResolveSnapshotPathHandlerContext) => string;
2381
+ interface InlineConfig {
2214
2382
  /**
2215
- * Path to the config file.
2216
- *
2217
- * Default resolving to `vitest.config.*`, `vite.config.*`
2218
- *
2219
- * Setting to `false` will disable config resolving.
2383
+ * Name of the project. Will be used to display in the reporter.
2220
2384
  */
2221
- config?: string | false | undefined;
2385
+ name?: string | ProjectName;
2222
2386
  /**
2223
- * Do not run tests when Vitest starts.
2224
- *
2225
- * Vitest will only run tests if it's called programmatically or the test file changes.
2387
+ * Benchmark options.
2226
2388
  *
2227
- * CLI file filters will be ignored.
2389
+ * @default {}
2228
2390
  */
2229
- standalone?: boolean;
2391
+ benchmark?: BenchmarkUserOptions;
2230
2392
  /**
2231
- * Use happy-dom
2393
+ * Include globs for test files
2394
+ *
2395
+ * @default ['**\/*.{test,spec}.?(c|m)[jt]s?(x)']
2232
2396
  */
2233
- dom?: boolean;
2397
+ include?: string[];
2234
2398
  /**
2235
- * Run tests that cover a list of source files
2399
+ * Exclude globs for test files
2400
+ * @default ['**\/node_modules/**', '**\/.git/**']
2236
2401
  */
2237
- related?: string[] | string;
2402
+ exclude?: string[];
2238
2403
  /**
2239
- * Overrides Vite mode
2240
- * @default 'test'
2404
+ * Include globs for in-source test files
2405
+ *
2406
+ * @default []
2241
2407
  */
2242
- mode?: string;
2408
+ includeSource?: string[];
2243
2409
  /**
2244
- * Runs tests that are affected by the changes in the repository, or between specified branch or commit hash
2245
- * Requires initialized git repository
2246
- * @default false
2410
+ * Handling for dependencies inlining or externalizing
2411
+ *
2247
2412
  */
2248
- changed?: boolean | string;
2413
+ deps?: DepsOptions;
2414
+ server?: {
2415
+ deps?: ServerDepsOptions;
2416
+ };
2249
2417
  /**
2250
- * Test suite shard to execute in a format of <index>/<count>.
2251
- * Will divide tests into a `count` numbers, and run only the `indexed` part.
2252
- * Cannot be used with enabled watch.
2253
- * @example --shard=2/3
2418
+ * Base directory to scan for the test files
2419
+ *
2420
+ * @default `config.root`
2254
2421
  */
2255
- shard?: string;
2422
+ dir?: string;
2256
2423
  /**
2257
- * Name of the project or projects to run.
2424
+ * Register apis globally
2425
+ *
2426
+ * @default false
2258
2427
  */
2259
- project?: string | string[];
2428
+ globals?: boolean;
2260
2429
  /**
2261
- * Additional exclude patterns
2430
+ * Running environment
2431
+ *
2432
+ * Supports 'node', 'jsdom', 'happy-dom', 'edge-runtime'
2433
+ *
2434
+ * If used unsupported string, will try to load the package `vitest-environment-${env}`
2435
+ *
2436
+ * @default 'node'
2262
2437
  */
2263
- cliExclude?: string[];
2438
+ environment?: VitestEnvironment;
2264
2439
  /**
2265
- * Override vite config's clearScreen from cli
2440
+ * Environment options.
2266
2441
  */
2267
- clearScreen?: boolean;
2442
+ environmentOptions?: EnvironmentOptions;
2268
2443
  /**
2269
- * benchmark.compare option exposed at the top level for cli
2444
+ * Run tests in an isolated environment. This option has no effect on vmThreads pool.
2445
+ *
2446
+ * Disabling this option might improve performance if your code doesn't rely on side effects.
2447
+ *
2448
+ * @default true
2270
2449
  */
2271
- compare?: string;
2450
+ isolate?: boolean;
2272
2451
  /**
2273
- * benchmark.outputJson option exposed at the top level for cli
2452
+ * Pool used to run tests in.
2453
+ *
2454
+ * Supports 'threads', 'forks', 'vmThreads'
2455
+ *
2456
+ * @default 'forks'
2274
2457
  */
2275
- outputJson?: string;
2458
+ pool?: Exclude<Pool, "browser">;
2276
2459
  /**
2277
- * Directory of blob reports to merge
2278
- * @default '.vitest-reports'
2460
+ * Pool options
2279
2461
  */
2280
- mergeReports?: string;
2281
- }
2282
- interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config" | "filters" | "browser" | "coverage" | "testNamePattern" | "related" | "api" | "reporters" | "resolveSnapshotPath" | "benchmark" | "shard" | "cache" | "sequence" | "typecheck" | "runner" | "poolOptions" | "pool" | "cliExclude" | "diff" | "setupFiles" | "snapshotEnvironment" | "bail" | "name"> {
2283
- mode: VitestRunMode;
2284
- name: ProjectName["label"];
2285
- color?: ProjectName["color"];
2286
- base?: string;
2287
- diff?: string | SerializedDiffOptions;
2288
- bail?: number;
2289
- setupFiles: string[];
2290
- snapshotEnvironment?: string;
2291
- config?: string;
2292
- filters?: string[];
2293
- testNamePattern?: RegExp;
2294
- related?: string[];
2295
- coverage: ResolvedCoverageOptions;
2296
- snapshotOptions: SnapshotStateOptions;
2297
- browser: ResolvedBrowserOptions;
2298
- pool: Pool;
2299
- poolOptions?: ResolvedPoolOptions;
2300
- reporters: (InlineReporter | ReporterWithOptions)[];
2301
- defines: Record<string, any>;
2302
- api: ApiConfig & {
2303
- token: string
2304
- };
2305
- cliExclude?: string[];
2306
- project: string[];
2307
- benchmark?: Required<Omit<BenchmarkUserOptions, "outputFile" | "compare" | "outputJson">> & Pick<BenchmarkUserOptions, "outputFile" | "compare" | "outputJson">;
2308
- shard?: {
2309
- index: number
2310
- count: number
2311
- };
2312
- cache: {
2313
- /**
2314
- * @deprecated
2315
- */
2316
- dir: string
2317
- } | false;
2318
- sequence: {
2319
- sequencer: TestSequencerConstructor
2320
- hooks: SequenceHooks
2321
- setupFiles: SequenceSetupFiles
2322
- shuffle?: boolean
2323
- concurrent?: boolean
2324
- seed: number
2325
- groupOrder: number
2326
- };
2327
- typecheck: Omit<TypecheckConfig, "enabled"> & {
2328
- enabled: boolean
2329
- };
2330
- runner?: string;
2331
- maxWorkers: number;
2332
- minWorkers: number;
2333
- }
2334
- type NonProjectOptions = "shard" | "watch" | "run" | "cache" | "update" | "reporters" | "outputFile" | "teardownTimeout" | "silent" | "forceRerunTriggers" | "testNamePattern" | "ui" | "open" | "uiBase" | "snapshotFormat" | "resolveSnapshotPath" | "passWithNoTests" | "onConsoleLog" | "onStackTrace" | "dangerouslyIgnoreUnhandledErrors" | "slowTestThreshold" | "inspect" | "inspectBrk" | "coverage" | "maxWorkers" | "minWorkers" | "fileParallelism" | "workspace" | "watchTriggerPatterns";
2335
- type ProjectConfig = Omit<InlineConfig, NonProjectOptions | "sequencer" | "deps" | "poolOptions"> & {
2336
- mode?: string
2337
- sequencer?: Omit<SequenceOptions, "sequencer" | "seed">
2338
- deps?: Omit<DepsOptions, "moduleDirectories">
2339
- poolOptions?: {
2340
- threads?: Pick<NonNullable<PoolOptions["threads"]>, "singleThread" | "isolate">
2341
- vmThreads?: Pick<NonNullable<PoolOptions["vmThreads"]>, "singleThread">
2342
- forks?: Pick<NonNullable<PoolOptions["forks"]>, "singleFork" | "isolate">
2343
- }
2344
- };
2345
- type ResolvedProjectConfig = Omit<ResolvedConfig, Exclude<NonProjectOptions, "coverage" | "watch">>;
2346
- interface UserWorkspaceConfig extends UserConfig$1 {
2347
- test?: ProjectConfig;
2348
- }
2349
- type UserProjectConfigFn = (env: ConfigEnv) => UserWorkspaceConfig | Promise<UserWorkspaceConfig>;
2350
- type UserProjectConfigExport = UserWorkspaceConfig | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
2351
- type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
2462
+ poolOptions?: PoolOptions;
2352
2463
  /**
2353
- * Relative path to the extendable config. All other options will be merged with this config.
2354
- * If `true`, the project will inherit all options from the root config.
2355
- * @example '../vite.config.ts'
2464
+ * Maximum number or percentage of workers to run tests in. `poolOptions.{threads,vmThreads}.maxThreads`/`poolOptions.forks.maxForks` has higher priority.
2356
2465
  */
2357
- extends?: string | true
2358
- });
2359
- type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
2360
- /** @deprecated use `TestProjectConfiguration` instead */
2361
- type WorkspaceProjectConfiguration = TestProjectConfiguration;
2362
-
2363
- interface BrowserProviderInitializationOptions {
2364
- browser: string;
2365
- options?: BrowserProviderOptions;
2366
- }
2367
- interface CDPSession {
2368
- send: (method: string, params?: Record<string, unknown>) => Promise<unknown>;
2369
- on: (event: string, listener: (...args: unknown[]) => void) => void;
2370
- once: (event: string, listener: (...args: unknown[]) => void) => void;
2371
- off: (event: string, listener: (...args: unknown[]) => void) => void;
2372
- }
2373
- interface BrowserModuleMocker {
2374
- register: (sessionId: string, module: MockedModule) => Promise<void>;
2375
- delete: (sessionId: string, url: string) => Promise<void>;
2376
- clear: (sessionId: string) => Promise<void>;
2377
- }
2378
- interface BrowserProvider {
2379
- name: string;
2380
- mocker?: BrowserModuleMocker;
2466
+ maxWorkers?: number | string;
2381
2467
  /**
2382
- * @experimental opt-in into file parallelisation
2468
+ * Should all test files run in parallel. Doesn't affect tests running in the same file.
2469
+ * Setting this to `false` will override `maxWorkers` option to `1`.
2470
+ *
2471
+ * @default true
2383
2472
  */
2384
- supportsParallelism: boolean;
2385
- getSupportedBrowsers: () => readonly string[];
2386
- getCommandsContext: (sessionId: string) => Record<string, unknown>;
2387
- openPage: (sessionId: string, url: string, beforeNavigate?: () => Promise<void>) => Promise<void>;
2388
- getCDPSession?: (sessionId: string) => Promise<CDPSession>;
2389
- close: () => Awaitable$1<void>;
2390
- // eslint-disable-next-line ts/method-signature-style -- we want to allow extended options
2391
- initialize(ctx: TestProject, options: BrowserProviderInitializationOptions): Awaitable$1<void>;
2392
- }
2393
- interface BrowserProviderModule {
2394
- new (): BrowserProvider;
2395
- }
2396
- interface BrowserProviderOptions {}
2397
- type BrowserBuiltinProvider = "webdriverio" | "playwright" | "preview";
2398
- type UnsupportedProperties = "browser" | "typecheck" | "alias" | "sequence" | "root" | "pool" | "poolOptions" | "runner" | "api" | "deps" | "testTransformMode" | "poolMatchGlobs" | "environmentMatchGlobs" | "environment" | "environmentOptions" | "server" | "benchmark" | "name";
2399
- interface BrowserInstanceOption extends BrowserProviderOptions, Omit<ProjectConfig, UnsupportedProperties>, Pick<BrowserConfigOptions, "headless" | "locators" | "viewport" | "testerHtmlPath" | "screenshotDirectory" | "screenshotFailures"> {
2473
+ fileParallelism?: boolean;
2400
2474
  /**
2401
- * Name of the browser
2475
+ * Options for projects
2402
2476
  */
2403
- browser: string;
2404
- name?: string;
2405
- }
2406
- interface BrowserConfigOptions {
2477
+ projects?: TestProjectConfiguration[];
2407
2478
  /**
2408
- * if running tests in the browser should be the default
2479
+ * Update snapshot
2409
2480
  *
2410
2481
  * @default false
2411
2482
  */
2412
- enabled?: boolean;
2413
- /**
2414
- * Name of the browser
2415
- * @deprecated use `instances` instead. if both are defined, this will filter `instances` by name.
2416
- */
2417
- name?: string;
2483
+ update?: boolean;
2418
2484
  /**
2419
- * Configurations for different browser setups
2485
+ * Watch mode
2486
+ *
2487
+ * @default !process.env.CI
2420
2488
  */
2421
- instances?: BrowserInstanceOption[];
2489
+ watch?: boolean;
2422
2490
  /**
2423
- * Browser provider
2491
+ * Project root
2424
2492
  *
2425
- * @default 'preview'
2493
+ * @default process.cwd()
2426
2494
  */
2427
- provider?: BrowserBuiltinProvider | (string & {});
2495
+ root?: string;
2428
2496
  /**
2429
- * Options that are passed down to a browser provider.
2430
- * To support type hinting, add one of the types to your tsconfig.json "compilerOptions.types" field:
2431
- *
2432
- * - for webdriverio: `@vitest/browser/providers/webdriverio`
2433
- * - for playwright: `@vitest/browser/providers/playwright`
2497
+ * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
2498
+ * and/or paths to custom reporters.
2434
2499
  *
2435
- * @example
2436
- * { playwright: { launch: { devtools: true } }
2437
- * @deprecated use `instances` instead
2500
+ * @default []
2438
2501
  */
2439
- providerOptions?: BrowserProviderOptions;
2502
+ reporters?: Arrayable<ReporterName | InlineReporter> | ((ReporterName | InlineReporter) | [ReporterName] | ReporterWithOptions)[];
2440
2503
  /**
2441
- * enable headless mode
2442
- *
2443
- * @default process.env.CI
2504
+ * Write test results to a file when the --reporter=json` or `--reporter=junit` option is also specified.
2505
+ * Also definable individually per reporter by using an object instead.
2444
2506
  */
2445
- headless?: boolean;
2507
+ outputFile?: string | (Partial<Record<BuiltinReporters, string>> & Record<string, string>);
2446
2508
  /**
2447
- * Serve API options.
2509
+ * Default timeout of a test in milliseconds
2448
2510
  *
2449
- * The default port is 63315.
2511
+ * @default 5000
2450
2512
  */
2451
- api?: ApiConfig | number;
2513
+ testTimeout?: number;
2452
2514
  /**
2453
- * Isolate test environment after each test
2515
+ * Default timeout of a hook in milliseconds
2454
2516
  *
2455
- * @default true
2517
+ * @default 10000
2456
2518
  */
2457
- isolate?: boolean;
2519
+ hookTimeout?: number;
2458
2520
  /**
2459
- * Run test files in parallel if provider supports this option
2460
- * This option only has effect in headless mode (enabled in CI by default)
2521
+ * Default timeout to wait for close when Vitest shuts down, in milliseconds
2461
2522
  *
2462
- * @default // Same as "test.fileParallelism"
2523
+ * @default 10000
2463
2524
  */
2464
- fileParallelism?: boolean;
2525
+ teardownTimeout?: number;
2465
2526
  /**
2466
- * Show Vitest UI
2527
+ * Silent mode
2467
2528
  *
2468
- * @default !process.env.CI
2529
+ * Use `'passed-only'` to see logs from failing tests only.
2530
+ *
2531
+ * @default false
2469
2532
  */
2470
- ui?: boolean;
2533
+ silent?: boolean | "passed-only";
2471
2534
  /**
2472
- * Default viewport size
2473
- */
2474
- viewport?: {
2475
- /**
2476
- * Width of the viewport
2477
- * @default 414
2478
- */
2479
- width: number
2480
- /**
2481
- * Height of the viewport
2482
- * @default 896
2483
- */
2484
- height: number
2485
- };
2535
+ * Hide logs for skipped tests
2536
+ *
2537
+ * @default false
2538
+ */
2539
+ hideSkippedTests?: boolean;
2486
2540
  /**
2487
- * Locator options
2541
+ * Path to setup files
2488
2542
  */
2489
- locators?: {
2490
- /**
2491
- * Attribute used to locate elements by test id
2492
- * @default 'data-testid'
2493
- */
2494
- testIdAttribute?: string
2495
- };
2543
+ setupFiles?: string | string[];
2496
2544
  /**
2497
- * Directory where screenshots will be saved when page.screenshot() is called
2498
- * If not set, all screenshots are saved to __screenshots__ directory in the same folder as the test file.
2499
- * If this is set, it will be resolved relative to the project root.
2500
- * @default __screenshots__
2545
+ * Path to global setup files
2501
2546
  */
2502
- screenshotDirectory?: string;
2547
+ globalSetup?: string | string[];
2503
2548
  /**
2504
- * Should Vitest take screenshots if the test fails
2505
- * @default !browser.ui
2549
+ * Glob pattern of file paths that will trigger the whole suite rerun
2550
+ *
2551
+ * Useful if you are testing calling CLI commands
2552
+ *
2553
+ * @default ['**\/package.json/**', '**\/{vitest,vite}.config.*\/**']
2506
2554
  */
2507
- screenshotFailures?: boolean;
2555
+ forceRerunTriggers?: string[];
2508
2556
  /**
2509
- * Scripts injected into the tester iframe.
2510
- * @deprecated Will be removed in the future, use `testerHtmlPath` instead.
2557
+ * Pattern configuration to rerun only the tests that are affected
2558
+ * by the changes of specific files in the repository.
2511
2559
  */
2512
- testerScripts?: BrowserScript[];
2560
+ watchTriggerPatterns?: WatcherTriggerPattern[];
2513
2561
  /**
2514
- * Path to the index.html file that will be used to run tests.
2562
+ * Coverage options
2515
2563
  */
2516
- testerHtmlPath?: string;
2564
+ coverage?: CoverageOptions;
2517
2565
  /**
2518
- * Scripts injected into the main window.
2566
+ * run test names with the specified pattern
2519
2567
  */
2520
- orchestratorScripts?: BrowserScript[];
2568
+ testNamePattern?: string | RegExp;
2521
2569
  /**
2522
- * Commands that will be executed on the server
2523
- * via the browser `import("@vitest/browser/context").commands` API.
2524
- * @see {@link https://vitest.dev/guide/browser/commands}
2570
+ * Will call `.mockClear()` on all spies before each test
2571
+ * @default false
2525
2572
  */
2526
- commands?: Record<string, BrowserCommand<any>>;
2573
+ clearMocks?: boolean;
2527
2574
  /**
2528
- * Timeout for connecting to the browser
2529
- * @default 30000
2575
+ * Will call `.mockReset()` on all spies before each test
2576
+ * @default false
2530
2577
  */
2531
- connectTimeout?: number;
2532
- }
2533
- interface BrowserCommandContext {
2534
- testPath: string | undefined;
2535
- provider: BrowserProvider;
2536
- project: TestProject;
2537
- /** @deprecated use `sessionId` instead */
2538
- contextId: string;
2539
- sessionId: string;
2540
- }
2541
- interface BrowserServerStateSession {
2542
- project: TestProject;
2543
- connected: () => void;
2544
- fail: (v: Error) => void;
2545
- }
2546
- interface BrowserOrchestrator {
2547
- cleanupTesters: () => Promise<void>;
2548
- createTesters: (options: BrowserTesterOptions) => Promise<void>;
2549
- onCancel: (reason: CancelReason) => Promise<void>;
2550
- $close: () => void;
2551
- }
2552
- interface BrowserServerState {
2553
- orchestrators: Map<string, BrowserOrchestrator>;
2554
- }
2555
- interface ParentProjectBrowser {
2556
- spawn: (project: TestProject) => ProjectBrowser;
2557
- }
2558
- interface ProjectBrowser {
2559
- vite: ViteDevServer;
2560
- state: BrowserServerState;
2561
- provider: BrowserProvider;
2562
- close: () => Promise<void>;
2563
- initBrowserProvider: (project: TestProject) => Promise<void>;
2564
- parseStacktrace: (stack: string) => ParsedStack[];
2565
- parseErrorStacktrace: (error: ErrorWithDiff, options?: StackTraceParserOptions) => ParsedStack[];
2566
- }
2567
- interface BrowserCommand<Payload extends unknown[]> {
2568
- (context: BrowserCommandContext, ...payload: Payload): Awaitable$1<any>;
2569
- }
2570
- interface BrowserScript {
2578
+ mockReset?: boolean;
2571
2579
  /**
2572
- * If "content" is provided and type is "module", this will be its identifier.
2573
- *
2574
- * If you are using TypeScript, you can add `.ts` extension here for example.
2575
- * @default `injected-${index}.js`
2580
+ * Will call `.mockRestore()` on all spies before each test
2581
+ * @default false
2576
2582
  */
2577
- id?: string;
2583
+ restoreMocks?: boolean;
2578
2584
  /**
2579
- * JavaScript content to be injected. This string is processed by Vite plugins if type is "module".
2580
- *
2581
- * You can use `id` to give Vite a hint about the file extension.
2585
+ * Will restore all global stubs to their original values before each test
2586
+ * @default false
2582
2587
  */
2583
- content?: string;
2588
+ unstubGlobals?: boolean;
2584
2589
  /**
2585
- * Path to the script. This value is resolved by Vite so it can be a node module or a file path.
2590
+ * Will restore all env stubs to their original values before each test
2591
+ * @default false
2586
2592
  */
2587
- src?: string;
2593
+ unstubEnvs?: boolean;
2588
2594
  /**
2589
- * If the script should be loaded asynchronously.
2595
+ * Serve API options.
2596
+ *
2597
+ * When set to true, the default port is 51204.
2598
+ *
2599
+ * @default false
2590
2600
  */
2591
- async?: boolean;
2601
+ api?: boolean | number | ApiConfig;
2592
2602
  /**
2593
- * Script type.
2594
- * @default 'module'
2603
+ * Enable Vitest UI
2604
+ *
2605
+ * @default false
2595
2606
  */
2596
- type?: string;
2597
- }
2598
- interface ResolvedBrowserOptions extends BrowserConfigOptions {
2599
- name: string;
2600
- providerOptions?: BrowserProviderOptions;
2601
- enabled: boolean;
2602
- headless: boolean;
2603
- isolate: boolean;
2604
- fileParallelism: boolean;
2605
- api: ApiConfig;
2606
- ui: boolean;
2607
- viewport: {
2608
- width: number
2609
- height: number
2610
- };
2611
- screenshotFailures: boolean;
2612
- locators: {
2613
- testIdAttribute: string
2614
- };
2615
- }
2616
-
2617
- declare class TestProject {
2618
- /** @deprecated */
2619
- path: string | number;
2620
- options?: InitializeProjectOptions | undefined;
2607
+ ui?: boolean;
2621
2608
  /**
2622
- * The global Vitest instance.
2623
- * @experimental The public Vitest API is experimental and does not follow semver.
2609
+ * options for test in a browser environment
2610
+ * @experimental
2611
+ *
2612
+ * @default false
2624
2613
  */
2625
- readonly vitest: Vitest;
2614
+ browser?: BrowserConfigOptions;
2626
2615
  /**
2627
- * Resolved global configuration. If there are no workspace projects, this will be the same as `config`.
2616
+ * Open UI automatically.
2617
+ *
2618
+ * @default !process.env.CI
2628
2619
  */
2629
- readonly globalConfig: ResolvedConfig;
2620
+ open?: boolean;
2630
2621
  /**
2631
- * Browser instance if the browser is enabled. This is initialized when the tests run for the first time.
2622
+ * Base url for the UI
2623
+ *
2624
+ * @default '/__vitest__/'
2632
2625
  */
2633
- browser?: ProjectBrowser;
2634
- /** @deprecated use `vitest` instead */
2635
- ctx: Vitest;
2626
+ uiBase?: string;
2636
2627
  /**
2637
- * Temporary directory for the project. This is unique for each project. Vitest stores transformed content here.
2628
+ * Format options for snapshot testing.
2638
2629
  */
2639
- readonly tmpDir: string;
2640
- private runner;
2641
- private closingPromise;
2642
- private testFilesList;
2643
- private typecheckFilesList;
2644
- private _globalSetups?;
2645
- private _provided;
2646
- constructor(path: string | number, vitest: Vitest, options?: InitializeProjectOptions | undefined);
2630
+ snapshotFormat?: Omit<PrettyFormatOptions, "plugins" | "compareKeys"> & {
2631
+ compareKeys?: null | undefined;
2632
+ };
2647
2633
  /**
2648
- * The unique hash of this project. This value is consistent between the reruns.
2649
- *
2650
- * It is based on the root of the project (not consistent between OS) and its name.
2634
+ * Path to a module which has a default export of diff config.
2651
2635
  */
2652
- get hash(): string;
2653
- // "provide" is a property, not a method to keep the context when destructed in the global setup,
2654
- // making it a method would be a breaking change, and can be done in Vitest 3 at minimum
2636
+ diff?: string | SerializedDiffOptions;
2655
2637
  /**
2656
- * Provide a value to the test context. This value will be available to all tests with `inject`.
2638
+ * Paths to snapshot serializer modules.
2657
2639
  */
2658
- provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
2640
+ snapshotSerializers?: string[];
2659
2641
  /**
2660
- * Get the provided context. The project context is merged with the global context.
2642
+ * Resolve custom snapshot path
2661
2643
  */
2662
- getProvidedContext(): ProvidedContext;
2644
+ resolveSnapshotPath?: ResolveSnapshotPathHandler;
2663
2645
  /**
2664
- * Creates a new test specification. Specifications describe how to run tests.
2665
- * @param moduleId The file path
2646
+ * Path to a custom snapshot environment module that has a default export of `SnapshotEnvironment` object.
2666
2647
  */
2667
- createSpecification(moduleId: string, locations?: number[] | undefined, pool?: string): TestSpecification;
2668
- toJSON(): SerializedTestProject;
2648
+ snapshotEnvironment?: string;
2669
2649
  /**
2670
- * Vite's dev server instance. Every workspace project has its own server.
2650
+ * Pass with no tests
2671
2651
  */
2672
- get vite(): ViteDevServer;
2652
+ passWithNoTests?: boolean;
2673
2653
  /**
2674
- * Resolved project configuration.
2654
+ * Allow tests and suites that are marked as only
2655
+ *
2656
+ * @default !process.env.CI
2675
2657
  */
2676
- get config(): ResolvedConfig;
2658
+ allowOnly?: boolean;
2677
2659
  /**
2678
- * The name of the project or an empty string if not set.
2660
+ * Show heap usage after each test. Useful for debugging memory leaks.
2679
2661
  */
2680
- get name(): string;
2662
+ logHeapUsage?: boolean;
2681
2663
  /**
2682
- * The color used when reporting tasks of this project.
2664
+ * Custom environment variables assigned to `process.env` before running tests.
2683
2665
  */
2684
- get color(): ProjectName["color"];
2666
+ env?: Partial<NodeJS.ProcessEnv>;
2685
2667
  /**
2686
- * Serialized project configuration. This is the config that tests receive.
2668
+ * Options for @sinon/fake-timers
2687
2669
  */
2688
- get serializedConfig(): SerializedConfig;
2689
- /** @deprecated use `vite` instead */
2690
- get server(): ViteDevServer;
2670
+ fakeTimers?: FakeTimerInstallOpts;
2691
2671
  /**
2692
- * Check if this is the root project. The root project is the one that has the root config.
2672
+ * Custom handler for console.log in tests.
2673
+ *
2674
+ * Return `false` to ignore the log.
2693
2675
  */
2694
- isRootProject(): boolean;
2695
- /** @deprecated use `isRootProject` instead */
2696
- isCore(): boolean;
2697
- /** @deprecated use `createSpecification` instead */
2698
- createSpec(moduleId: string, pool: string): WorkspaceSpec;
2699
- /** @deprecated */
2700
- initializeGlobalSetup(): Promise<void>;
2701
- onTestsRerun(cb: OnTestsRerunHandler): void;
2702
- /** @deprecated */
2703
- teardownGlobalSetup(): Promise<void>;
2704
- /** @deprecated use `vitest.logger` instead */
2705
- get logger(): Logger;
2706
- // it's possible that file path was imported with different queries (?raw, ?url, etc)
2707
- /** @deprecated use `.vite` or `.browser.vite` directly */
2708
- getModulesByFilepath(file: string): Set<ModuleNode>;
2709
- /** @deprecated use `.vite` or `.browser.vite` directly */
2710
- getModuleById(id: string): ModuleNode | undefined;
2711
- /** @deprecated use `.vite` or `.browser.vite` directly */
2712
- getSourceMapModuleById(id: string): TransformResult$1["map"] | undefined;
2713
- /** @deprecated use `vitest.reporters` instead */
2714
- get reporters(): Reporter[];
2676
+ onConsoleLog?: (log: string, type: "stdout" | "stderr", entity: TestModule | TestCase | TestSuite | undefined) => boolean | void;
2715
2677
  /**
2716
- * Get all files in the project that match the globs in the config and the filters.
2717
- * @param filters String filters to match the test files.
2678
+ * Enable stack trace filtering. If absent, all stack trace frames
2679
+ * will be shown.
2680
+ *
2681
+ * Return `false` to omit the frame.
2718
2682
  */
2719
- globTestFiles(filters?: string[]): Promise<{
2720
- /**
2721
- * Test files that match the filters.
2722
- */
2723
- testFiles: string[]
2724
- /**
2725
- * Typecheck test files that match the filters. This will be empty unless `typecheck.enabled` is `true`.
2726
- */
2727
- typecheckTestFiles: string[]
2728
- }>;
2729
- private globAllTestFiles;
2730
- isBrowserEnabled(): boolean;
2731
- private markTestFile;
2732
- /** @deprecated use `serializedConfig` instead */
2733
- getSerializableConfig(): SerializedConfig;
2683
+ onStackTrace?: (error: TestError, frame: ParsedStack) => boolean | void;
2734
2684
  /**
2735
- * Test if a file matches the test globs. This does the actual glob matching if the test is not cached, unlike `isCachedTestFile`.
2685
+ * A callback that can return `false` to ignore an unhandled error
2736
2686
  */
2737
- matchesTestGlob(moduleId: string, source?: () => string): boolean;
2738
- /** @deprecated use `matchesTestGlob` instead */
2739
- isTargetFile(id: string, source?: string): Promise<boolean>;
2740
- private isInSourceTestCode;
2741
- private filterFiles;
2742
- private _parentBrowser?;
2687
+ onUnhandledError?: OnUnhandledErrorCallback;
2743
2688
  /**
2744
- * Closes the project and all associated resources. This can only be called once; the closing promise is cached until the server restarts.
2745
- * If the resources are needed again, create a new project.
2689
+ * Indicates if CSS files should be processed.
2690
+ *
2691
+ * When excluded, the CSS files will be replaced with empty strings to bypass the subsequent processing.
2692
+ *
2693
+ * @default { include: [], modules: { classNameStrategy: false } }
2746
2694
  */
2747
- close(): Promise<void>;
2695
+ css?: boolean | {
2696
+ include?: RegExp | RegExp[];
2697
+ exclude?: RegExp | RegExp[];
2698
+ modules?: {
2699
+ classNameStrategy?: CSSModuleScopeStrategy;
2700
+ };
2701
+ };
2748
2702
  /**
2749
- * Import a file using Vite module runner.
2750
- * @param moduleId The ID of the module in Vite module graph
2703
+ * A number of tests that are allowed to run at the same time marked with `test.concurrent`.
2704
+ * @default 5
2751
2705
  */
2752
- import<T>(moduleId: string): Promise<T>;
2753
- /** @deprecated use `name` instead */
2754
- getName(): string;
2755
- /** @deprecated internal */
2756
- setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
2757
- private _setHash;
2758
- private _serializeOverriddenConfig;
2759
- private clearTmpDir;
2760
- /** @deprecated */
2761
- initBrowserProvider(): Promise<void>;
2762
- }
2763
-
2764
- interface SerializedTestProject {
2765
- name: string;
2766
- serializedConfig: SerializedConfig;
2767
- context: ProvidedContext;
2768
- }
2769
- interface InitializeProjectOptions extends TestProjectInlineConfiguration {
2770
- configFile: string | false;
2771
- }
2772
-
2773
- /**
2774
- * @deprecated use TestSpecification instead
2775
- */
2776
- type WorkspaceSpec = TestSpecification & [project: TestProject, file: string, options: {
2777
- pool: Pool
2778
- }];
2779
- type RunWithFiles = (files: TestSpecification[], invalidates?: string[]) => Awaitable$1<void>;
2780
- interface ProcessPool {
2781
- name: string;
2782
- runTests: RunWithFiles;
2783
- collectTests: RunWithFiles;
2784
- close?: () => Awaitable$1<void>;
2785
- }
2786
- declare function getFilePoolName(project: TestProject, file: string): Pool;
2787
-
2788
- interface TestRunResult {
2789
- testModules: TestModule[];
2790
- unhandledErrors: unknown[];
2791
- }
2792
-
2793
- interface SuiteResultCache {
2794
- failed: boolean;
2795
- duration: number;
2796
- }
2797
- declare class ResultsCache {
2798
- private cache;
2799
- private workspacesKeyMap;
2800
- private cachePath;
2801
- private version;
2802
- private root;
2803
- constructor(version: string);
2804
- getCachePath(): string | null;
2805
- setConfig(root: string, config: ResolvedConfig["cache"]): void;
2806
- getResults(key: string): SuiteResultCache | undefined;
2807
- readFromCache(): Promise<void>;
2808
- updateResults(files: File[]): void;
2809
- removeFromCache(filepath: string): void;
2810
- writeToCache(): Promise<void>;
2811
- }
2812
-
2813
- type FileStatsCache = Pick<Stats, "size">;
2814
- declare class FilesStatsCache {
2815
- cache: Map<string, FileStatsCache>;
2816
- getStats(key: string): FileStatsCache | undefined;
2817
- populateStats(root: string, specs: TestSpecification[]): Promise<void>;
2818
- updateStats(fsPath: string, key: string): Promise<void>;
2819
- removeStats(fsPath: string): void;
2820
- }
2821
-
2822
- declare class VitestCache {
2823
- results: ResultsCache;
2824
- stats: FilesStatsCache;
2825
- constructor(version: string);
2826
- getFileTestResults(key: string): SuiteResultCache | undefined;
2827
- getFileStats(key: string): {
2828
- size: number
2829
- } | undefined;
2830
- static resolveCacheDir(root: string, dir?: string, projectName?: string): string;
2831
- }
2832
-
2833
- declare class VitestPackageInstaller {
2834
- isPackageExists(name: string, options?: {
2835
- paths?: string[]
2836
- }): boolean;
2837
- ensureInstalled(dependency: string, root: string, version?: string): Promise<boolean>;
2838
- }
2839
-
2840
- declare class StateManager {
2841
- filesMap: Map<string, File[]>;
2842
- pathsSet: Set<string>;
2843
- idMap: Map<string, Task>;
2844
- taskFileMap: WeakMap<Task, File>;
2845
- errorsSet: Set<unknown>;
2846
- processTimeoutCauses: Set<string>;
2847
- reportedTasksMap: WeakMap<Task, TestModule | TestCase | TestSuite>;
2848
- blobs?: MergedBlobs;
2849
- catchError(err: unknown, type: string): void;
2850
- clearErrors(): void;
2851
- getUnhandledErrors(): unknown[];
2852
- addProcessTimeoutCause(cause: string): void;
2853
- getProcessTimeoutCauses(): string[];
2854
- getPaths(): string[];
2706
+ maxConcurrency?: number;
2855
2707
  /**
2856
- * Return files that were running or collected.
2708
+ * Options for configuring cache policy.
2709
+ * @default { dir: 'node_modules/.vite/vitest/{project-hash}' }
2857
2710
  */
2858
- getFiles(keys?: string[]): File[];
2859
- getTestModules(keys?: string[]): TestModule[];
2860
- getFilepaths(): string[];
2861
- getFailedFilepaths(): string[];
2862
- collectPaths(paths?: string[]): void;
2863
- collectFiles(project: TestProject, files?: File[]): void;
2864
- clearFiles(project: TestProject, paths?: string[]): void;
2865
- updateId(task: Task, project: TestProject): void;
2866
- getReportedEntity(task: Task): TestModule | TestCase | TestSuite | undefined;
2867
- updateTasks(packs: TaskResultPack[]): void;
2868
- updateUserLog(log: UserConsoleLog): void;
2869
- getCountOfFailedTests(): number;
2870
- cancelFiles(files: string[], project: TestProject): void;
2871
- }
2872
-
2873
- interface VitestOptions {
2874
- packageInstaller?: VitestPackageInstaller;
2875
- stdin?: NodeJS.ReadStream;
2876
- stdout?: NodeJS.WriteStream | Writable;
2877
- stderr?: NodeJS.WriteStream | Writable;
2878
- }
2879
- declare class Vitest {
2880
- readonly mode: VitestRunMode;
2711
+ cache?: false | {
2712
+ /**
2713
+ * @deprecated Use Vite's "cacheDir" instead if you want to change the cache director. Note caches will be written to "cacheDir\/vitest".
2714
+ */
2715
+ dir: string;
2716
+ };
2881
2717
  /**
2882
- * Current Vitest version.
2883
- * @example '2.0.0'
2718
+ * Options for configuring the order of running tests.
2884
2719
  */
2885
- readonly version: string;
2886
- static readonly version: string;
2720
+ sequence?: SequenceOptions;
2887
2721
  /**
2888
- * The logger instance used to log messages. It's recommended to use this logger instead of `console`.
2889
- * It's possible to override stdout and stderr streams when initiating Vitest.
2890
- * @example
2891
- * new Vitest('test', {
2892
- * stdout: new Writable(),
2893
- * })
2722
+ * Specifies an `Object`, or an `Array` of `Object`,
2723
+ * which defines aliases used to replace values in `import` or `require` statements.
2724
+ * Will be merged with the default aliases inside `resolve.alias`.
2894
2725
  */
2895
- readonly logger: Logger;
2726
+ alias?: AliasOptions;
2896
2727
  /**
2897
- * The package installer instance used to install Vitest packages.
2898
- * @example
2899
- * await vitest.packageInstaller.ensureInstalled('@vitest/browser', process.cwd())
2728
+ * Ignore any unhandled errors that occur
2729
+ *
2730
+ * @default false
2900
2731
  */
2901
- readonly packageInstaller: VitestPackageInstaller;
2732
+ dangerouslyIgnoreUnhandledErrors?: boolean;
2902
2733
  /**
2903
- * A path to the built Vitest directory. This is usually a folder in `node_modules`.
2734
+ * Options for configuring typechecking test environment.
2904
2735
  */
2905
- readonly distPath: string;
2736
+ typecheck?: Partial<TypecheckConfig>;
2906
2737
  /**
2907
- * A list of projects that are currently running.
2908
- * If projects were filtered with `--project` flag, they won't appear here.
2738
+ * The number of milliseconds after which a test is considered slow and reported as such in the results.
2739
+ *
2740
+ * @default 300
2909
2741
  */
2910
- projects: TestProject[];
2911
- private isFirstRun;
2912
- private restartsCount;
2913
- private readonly specifications;
2914
- private readonly watcher;
2915
- private pool;
2916
- private _config?;
2917
- private _vite?;
2918
- private _state?;
2919
- private _cache?;
2920
- private _snapshot?;
2921
- private _workspaceConfigPath?;
2922
- constructor(mode: VitestRunMode, cliOptions: UserConfig, options?: VitestOptions);
2923
- private _onRestartListeners;
2924
- private _onClose;
2925
- private _onSetServer;
2926
- private _onCancelListeners;
2927
- private _onUserTestsRerun;
2928
- private _onFilterWatchedSpecification;
2929
- /** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
2930
- get invalidates(): Set<string>;
2931
- /** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
2932
- get changedTests(): Set<string>;
2742
+ slowTestThreshold?: number;
2933
2743
  /**
2934
- * The global config.
2744
+ * Path to a custom test runner.
2935
2745
  */
2936
- get config(): ResolvedConfig;
2937
- /** @deprecated use `vitest.vite` instead */
2938
- get server(): ViteDevServer;
2746
+ runner?: string;
2939
2747
  /**
2940
- * Global Vite's dev server instance.
2748
+ * Debug tests by opening `node:inspector` in worker / child process.
2749
+ * Provides similar experience as `--inspect` Node CLI argument.
2750
+ *
2751
+ * Requires `poolOptions.threads.singleThread: true` OR `poolOptions.forks.singleFork: true`.
2941
2752
  */
2942
- get vite(): ViteDevServer;
2753
+ inspect?: boolean | string;
2943
2754
  /**
2944
- * The global test state manager.
2945
- * @experimental The State API is experimental and not subject to semver.
2755
+ * Debug tests by opening `node:inspector` in worker / child process and wait for debugger to connect.
2756
+ * Provides similar experience as `--inspect-brk` Node CLI argument.
2757
+ *
2758
+ * Requires `poolOptions.threads.singleThread: true` OR `poolOptions.forks.singleFork: true`.
2946
2759
  */
2947
- get state(): StateManager;
2760
+ inspectBrk?: boolean | string;
2948
2761
  /**
2949
- * The global snapshot manager. You can access the current state on `snapshot.summary`.
2762
+ * Inspector options. If `--inspect` or `--inspect-brk` is enabled, these options will be passed to the inspector.
2950
2763
  */
2951
- get snapshot(): SnapshotManager;
2764
+ inspector?: {
2765
+ /**
2766
+ * Enable inspector
2767
+ */
2768
+ enabled?: boolean;
2769
+ /**
2770
+ * Port to run inspector on
2771
+ */
2772
+ port?: number;
2773
+ /**
2774
+ * Host to run inspector on
2775
+ */
2776
+ host?: string;
2777
+ /**
2778
+ * Wait for debugger to connect before running tests
2779
+ */
2780
+ waitForDebugger?: boolean;
2781
+ };
2952
2782
  /**
2953
- * Test results and test file stats cache. Primarily used by the sequencer to sort tests.
2783
+ * Define variables that will be returned from `inject` in the test environment.
2784
+ * @example
2785
+ * ```ts
2786
+ * // vitest.config.ts
2787
+ * export default defineConfig({
2788
+ * test: {
2789
+ * provide: {
2790
+ * someKey: 'someValue'
2791
+ * }
2792
+ * }
2793
+ * })
2794
+ * ```
2795
+ * ```ts
2796
+ * // test file
2797
+ * import { inject } from 'vitest'
2798
+ * const value = inject('someKey') // 'someValue'
2799
+ * ```
2954
2800
  */
2955
- get cache(): VitestCache;
2956
- /** @deprecated internal */
2957
- setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
2801
+ provide?: Partial<ProvidedContext>;
2958
2802
  /**
2959
- * Inject new test projects into the workspace.
2960
- * @param config Glob, config path or a custom config options.
2961
- * @returns An array of new test projects. Can be empty if the name was filtered out.
2803
+ * Configuration options for expect() matches.
2962
2804
  */
2963
- private injectTestProject;
2805
+ expect?: {
2806
+ /**
2807
+ * Throw an error if tests don't have any expect() assertions.
2808
+ */
2809
+ requireAssertions?: boolean;
2810
+ /**
2811
+ * Default options for expect.poll()
2812
+ */
2813
+ poll?: {
2814
+ /**
2815
+ * Timeout in milliseconds
2816
+ * @default 1000
2817
+ */
2818
+ timeout?: number;
2819
+ /**
2820
+ * Polling interval in milliseconds
2821
+ * @default 50
2822
+ */
2823
+ interval?: number;
2824
+ };
2825
+ };
2964
2826
  /**
2965
- * Provide a value to the test context. This value will be available to all tests with `inject`.
2827
+ * Modify default Chai config. Vitest uses Chai for `expect` and `assert` matches.
2828
+ * https://github.com/chaijs/chai/blob/4.x.x/lib/chai/config.js
2966
2829
  */
2967
- provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
2830
+ chaiConfig?: ChaiConfig;
2968
2831
  /**
2969
- * Get global provided context.
2832
+ * Stop test execution when given number of tests have failed.
2970
2833
  */
2971
- getProvidedContext(): ProvidedContext;
2972
- /** @deprecated use `getRootProject` instead */
2973
- getCoreWorkspaceProject(): TestProject;
2834
+ bail?: number;
2974
2835
  /**
2975
- * Return project that has the root (or "global") config.
2836
+ * Retry the test specific number of times if it fails.
2837
+ *
2838
+ * @default 0
2976
2839
  */
2977
- getRootProject(): TestProject;
2840
+ retry?: number;
2978
2841
  /**
2979
- * @deprecated use Reported Task API instead
2842
+ * Show full diff when snapshot fails instead of a patch.
2980
2843
  */
2981
- getProjectByTaskId(taskId: string): TestProject;
2982
- getProjectByName(name: string): TestProject;
2844
+ expandSnapshotDiff?: boolean;
2983
2845
  /**
2984
- * Import a file using Vite module runner. The file will be transformed by Vite and executed in a separate context.
2985
- * @param moduleId The ID of the module in Vite module graph
2846
+ * By default, Vitest automatically intercepts console logging during tests for extra formatting of test file, test title, etc...
2847
+ * This is also required for console log preview on Vitest UI.
2848
+ * However, disabling such interception might help when you want to debug a code with normal synchronous terminal console logging.
2849
+ *
2850
+ * This option has no effect on browser pool since Vitest preserves original logging on browser devtools.
2851
+ *
2852
+ * @default false
2986
2853
  */
2987
- import<T>(moduleId: string): Promise<T>;
2988
- private resolveWorkspaceConfigPath;
2989
- private resolveProjects;
2854
+ disableConsoleIntercept?: boolean;
2990
2855
  /**
2991
- * Glob test files in every project and create a TestSpecification for each file and pool.
2992
- * @param filters String filters to match the test files.
2856
+ * Always print console stack traces.
2857
+ *
2858
+ * @default false
2993
2859
  */
2994
- globTestSpecifications(filters?: string[]): Promise<TestSpecification[]>;
2995
- private initCoverageProvider;
2860
+ printConsoleTrace?: boolean;
2996
2861
  /**
2997
- * Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified).
2862
+ * Include "location" property inside the test definition
2863
+ *
2864
+ * @default false
2998
2865
  */
2999
- mergeReports(directory?: string): Promise<TestRunResult>;
3000
- collect(filters?: string[]): Promise<TestRunResult>;
3001
- /** @deprecated use `getRelevantTestSpecifications` instead */
3002
- listFiles(filters?: string[]): Promise<TestSpecification[]>;
2866
+ includeTaskLocation?: boolean;
3003
2867
  /**
3004
- * Returns the list of test files that match the config and filters.
3005
- * @param filters String filters to match the test files
2868
+ * Directory path for storing attachments created by `context.annotate`
2869
+ *
2870
+ * @default '.vitest-attachments'
3006
2871
  */
3007
- getRelevantTestSpecifications(filters?: string[]): Promise<TestSpecification[]>;
2872
+ attachmentsDir?: string;
2873
+ }
2874
+ interface TypecheckConfig {
3008
2875
  /**
3009
- * Initialize reporters, the coverage provider, and run tests.
3010
- * This method can throw an error:
3011
- * - `FilesNotFoundError` if no tests are found
3012
- * - `GitNotFoundError` if `--related` flag is used, but git repository is not initialized
3013
- * - `Error` from the user reporters
3014
- * @param filters String filters to match the test files
2876
+ * Run typechecking tests alongside regular tests.
3015
2877
  */
3016
- start(filters?: string[]): Promise<TestRunResult>;
2878
+ enabled?: boolean;
3017
2879
  /**
3018
- * Initialize reporters and the coverage provider. This method doesn't run any tests.
3019
- * If the `--watch` flag is provided, Vitest will still run changed tests even if this method was not called.
2880
+ * When typechecking is enabled, only run typechecking tests.
3020
2881
  */
3021
- init(): Promise<void>;
2882
+ only?: boolean;
3022
2883
  /**
3023
- * @deprecated remove when vscode extension supports "getModuleSpecifications"
2884
+ * What tools to use for type checking.
2885
+ *
2886
+ * @default 'tsc'
3024
2887
  */
3025
- getProjectsByTestFile(file: string): WorkspaceSpec[];
3026
- /** @deprecated */
3027
- getFileWorkspaceSpecs(file: string): WorkspaceSpec[];
2888
+ checker: "tsc" | "vue-tsc" | (string & Record<never, never>);
3028
2889
  /**
3029
- * Get test specifications associated with the given module. If module is not a test file, an empty array is returned.
2890
+ * Pattern for files that should be treated as test files
3030
2891
  *
3031
- * **Note:** this method relies on a cache generated by `globTestSpecifications`. If the file was not processed yet, use `project.matchesGlobPattern` instead.
3032
- * @param moduleId The module ID to get test specifications for.
2892
+ * @default ['**\/*.{test,spec}-d.?(c|m)[jt]s?(x)']
3033
2893
  */
3034
- getModuleSpecifications(moduleId: string): TestSpecification[];
2894
+ include: string[];
3035
2895
  /**
3036
- * Vitest automatically caches test specifications for each file. This method clears the cache for the given file or the whole cache altogether.
2896
+ * Pattern for files that should not be treated as test files
2897
+ *
2898
+ * @default ['**\/node_modules/**', '**\/dist/**', '**\/cypress/**', '**\/.{idea,git,cache,output,temp}/**', '**\/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*']
3037
2899
  */
3038
- clearSpecificationsCache(moduleId?: string): void;
2900
+ exclude: string[];
3039
2901
  /**
3040
- * Run tests for the given test specifications. This does not trigger `onWatcher*` events.
3041
- * @param specifications A list of specifications to run.
3042
- * @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
2902
+ * Check JS files that have `@ts-check` comment.
2903
+ * If you have it enabled in tsconfig, this will not overwrite it.
3043
2904
  */
3044
- runTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
2905
+ allowJs?: boolean;
3045
2906
  /**
3046
- * Rerun files and trigger `onWatcherRerun`, `onWatcherStart` and `onTestsRerun` events.
3047
- * @param specifications A list of specifications to run.
3048
- * @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
2907
+ * Do not fail, if Vitest found errors outside the test files.
3049
2908
  */
3050
- rerunTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
3051
- private runFiles;
2909
+ ignoreSourceErrors?: boolean;
3052
2910
  /**
3053
- * Collect tests in specified modules. Vitest will run the files to collect tests.
3054
- * @param specifications A list of specifications to run.
2911
+ * Path to tsconfig, relative to the project root.
3055
2912
  */
3056
- collectTests(specifications: TestSpecification[]): Promise<TestRunResult>;
2913
+ tsconfig?: string;
3057
2914
  /**
3058
- * Gracefully cancel the current test run. Vitest will wait until all running tests are finished before cancelling.
2915
+ * Minimum time in milliseconds it takes to spawn the typechecker.
2916
+ * @default 10_000
3059
2917
  */
3060
- cancelCurrentRun(reason: CancelReason): Promise<void>;
3061
- private initializeGlobalSetup;
2918
+ spawnTimeout?: number;
2919
+ }
2920
+ interface UserConfig extends InlineConfig {
3062
2921
  /**
3063
- * Update snapshots in specified files. If no files are provided, it will update files with failed tests and obsolete snapshots.
3064
- * @param files The list of files on the file system
2922
+ * Path to the config file.
2923
+ *
2924
+ * Default resolving to `vitest.config.*`, `vite.config.*`
2925
+ *
2926
+ * Setting to `false` will disable config resolving.
3065
2927
  */
3066
- updateSnapshot(files?: string[]): Promise<TestRunResult>;
2928
+ config?: string | false | undefined;
3067
2929
  /**
3068
- * Enable the mode that allows updating snapshots when running tests.
3069
- * This method doesn't run any tests.
2930
+ * Do not run tests when Vitest starts.
3070
2931
  *
3071
- * Every test that runs after this method is called will update snapshots.
3072
- * To disable the mode, call `resetSnapshotUpdate`.
2932
+ * Vitest will only run tests if it's called programmatically or the test file changes.
2933
+ *
2934
+ * If CLI file filters are passed, standalone mode is ignored.
3073
2935
  */
3074
- enableSnapshotUpdate(): void;
2936
+ standalone?: boolean;
3075
2937
  /**
3076
- * Disable the mode that allows updating snapshots when running tests.
2938
+ * Use happy-dom
3077
2939
  */
3078
- resetSnapshotUpdate(): void;
2940
+ dom?: boolean;
3079
2941
  /**
3080
- * Set the global test name pattern to a regexp.
3081
- * This method doesn't run any tests.
2942
+ * Run tests that cover a list of source files
3082
2943
  */
3083
- setGlobalTestNamePattern(pattern: string | RegExp): void;
2944
+ related?: string[] | string;
3084
2945
  /**
3085
- * Resets the global test name pattern. This method doesn't run any tests.
2946
+ * Overrides Vite mode
2947
+ * @default 'test'
3086
2948
  */
3087
- resetGlobalTestNamePattern(): void;
3088
- private _rerunTimer;
3089
- // we can't use a single `triggerId` yet because vscode extension relies on this
3090
- private scheduleRerun;
2949
+ mode?: string;
3091
2950
  /**
3092
- * Invalidate a file in all projects.
2951
+ * Runs tests that are affected by the changes in the repository, or between specified branch or commit hash
2952
+ * Requires initialized git repository
2953
+ * @default false
3093
2954
  */
3094
- invalidateFile(filepath: string): void;
3095
- /** @deprecated use `invalidateFile` */
3096
- updateLastChanged(filepath: string): void;
3097
- private reportCoverage;
2955
+ changed?: boolean | string;
3098
2956
  /**
3099
- * Closes all projects and their associated resources.
3100
- * This can only be called once; the closing promise is cached until the server restarts.
2957
+ * Test suite shard to execute in a format of <index>/<count>.
2958
+ * Will divide tests into a `count` numbers, and run only the `indexed` part.
2959
+ * Cannot be used with enabled watch.
2960
+ * @example --shard=2/3
3101
2961
  */
3102
- close(): Promise<void>;
2962
+ shard?: string;
3103
2963
  /**
3104
- * Closes all projects and exit the process
3105
- * @param force If true, the process will exit immediately after closing the projects.
2964
+ * Name of the project or projects to run.
3106
2965
  */
3107
- exit(force?: boolean): Promise<void>;
2966
+ project?: string | string[];
3108
2967
  /**
3109
- * @deprecated use `globTestSpecifications` instead
2968
+ * Additional exclude patterns
3110
2969
  */
3111
- globTestSpecs(filters?: string[]): Promise<TestSpecification[]>;
2970
+ cliExclude?: string[];
3112
2971
  /**
3113
- * @deprecated use `globTestSpecifications` instead
2972
+ * Override vite config's clearScreen from cli
3114
2973
  */
3115
- globTestFiles(filters?: string[]): Promise<TestSpecification[]>;
3116
- /** @deprecated filter by `this.projects` yourself */
3117
- getModuleProjects(filepath: string): TestProject[];
2974
+ clearScreen?: boolean;
3118
2975
  /**
3119
- * Should the server be kept running after the tests are done.
2976
+ * benchmark.compare option exposed at the top level for cli
3120
2977
  */
3121
- shouldKeepServer(): boolean;
2978
+ compare?: string;
3122
2979
  /**
3123
- * Register a handler that will be called when the server is restarted due to a config change.
2980
+ * benchmark.outputJson option exposed at the top level for cli
3124
2981
  */
3125
- onServerRestart(fn: OnServerRestartHandler): void;
2982
+ outputJson?: string;
3126
2983
  /**
3127
- * Register a handler that will be called when the test run is cancelled with `vitest.cancelCurrentRun`.
2984
+ * Directory of blob reports to merge
2985
+ * @default '.vitest-reports'
3128
2986
  */
3129
- onCancel(fn: (reason: CancelReason) => Awaitable$1<void>): void;
2987
+ mergeReports?: string;
2988
+ }
2989
+ type OnUnhandledErrorCallback = (error: (TestError | Error) & {
2990
+ type: string;
2991
+ }) => boolean | void;
2992
+ interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config" | "filters" | "browser" | "coverage" | "testNamePattern" | "related" | "api" | "reporters" | "resolveSnapshotPath" | "benchmark" | "shard" | "cache" | "sequence" | "typecheck" | "runner" | "poolOptions" | "pool" | "cliExclude" | "diff" | "setupFiles" | "snapshotEnvironment" | "bail" | "name"> {
2993
+ mode: VitestRunMode;
2994
+ name: ProjectName["label"];
2995
+ color?: ProjectName["color"];
2996
+ base?: string;
2997
+ diff?: string | SerializedDiffOptions;
2998
+ bail?: number;
2999
+ setupFiles: string[];
3000
+ snapshotEnvironment?: string;
3001
+ config?: string;
3002
+ filters?: string[];
3003
+ testNamePattern?: RegExp;
3004
+ related?: string[];
3005
+ coverage: ResolvedCoverageOptions;
3006
+ snapshotOptions: SnapshotStateOptions;
3007
+ browser: ResolvedBrowserOptions;
3008
+ pool: Pool;
3009
+ poolOptions?: ResolvedPoolOptions;
3010
+ reporters: (InlineReporter | ReporterWithOptions)[];
3011
+ defines: Record<string, any>;
3012
+ api: ApiConfig & {
3013
+ token: string;
3014
+ };
3015
+ cliExclude?: string[];
3016
+ project: string[];
3017
+ benchmark?: Required<Omit<BenchmarkUserOptions, "outputFile" | "compare" | "outputJson">> & Pick<BenchmarkUserOptions, "outputFile" | "compare" | "outputJson">;
3018
+ shard?: {
3019
+ index: number;
3020
+ count: number;
3021
+ };
3022
+ cache: {
3023
+ /**
3024
+ * @deprecated
3025
+ */
3026
+ dir: string;
3027
+ } | false;
3028
+ sequence: {
3029
+ sequencer: TestSequencerConstructor;
3030
+ hooks: SequenceHooks;
3031
+ setupFiles: SequenceSetupFiles;
3032
+ shuffle?: boolean;
3033
+ concurrent?: boolean;
3034
+ seed: number;
3035
+ groupOrder: number;
3036
+ };
3037
+ typecheck: Omit<TypecheckConfig, "enabled"> & {
3038
+ enabled: boolean;
3039
+ };
3040
+ runner?: string;
3041
+ maxWorkers: number;
3042
+ }
3043
+ type NonProjectOptions = "shard" | "watch" | "run" | "cache" | "update" | "reporters" | "outputFile" | "teardownTimeout" | "silent" | "forceRerunTriggers" | "testNamePattern" | "ui" | "open" | "uiBase" | "snapshotFormat" | "resolveSnapshotPath" | "passWithNoTests" | "onConsoleLog" | "onStackTrace" | "dangerouslyIgnoreUnhandledErrors" | "slowTestThreshold" | "inspect" | "inspectBrk" | "coverage" | "maxWorkers" | "fileParallelism" | "watchTriggerPatterns";
3044
+ interface ServerDepsOptions {
3130
3045
  /**
3131
- * Register a handler that will be called when the server is closed.
3046
+ * Externalize means that Vite will bpass the package to native Node.
3047
+ *
3048
+ * Externalized dependencies will not be applied Vite's transformers and resolvers.
3049
+ * And does not support HMR on reload.
3050
+ *
3051
+ * Typically, packages under `node_modules` are externalized.
3132
3052
  */
3133
- onClose(fn: () => Awaitable$1<void>): void;
3053
+ external?: (string | RegExp)[];
3134
3054
  /**
3135
- * Register a handler that will be called when the tests are rerunning.
3055
+ * Vite will process inlined modules.
3056
+ *
3057
+ * This could be helpful to handle packages that ship `.js` in ESM format (that Node can't handle).
3058
+ *
3059
+ * If `true`, every dependency will be inlined
3136
3060
  */
3137
- onTestsRerun(fn: OnTestsRerunHandler): void;
3061
+ inline?: (string | RegExp)[] | true;
3138
3062
  /**
3139
- * Register a handler that will be called when a file is changed.
3140
- * This callback should return `true` of `false` indicating whether the test file needs to be rerun.
3141
- * @example
3142
- * const testsToRun = [resolve('./test.spec.ts')]
3143
- * vitest.onFilterWatchedSpecification(specification => testsToRun.includes(specification.moduleId))
3063
+ * Try to guess the CJS version of a package when it's invalid ESM
3064
+ * @default false
3144
3065
  */
3145
- onFilterWatchedSpecification(fn: (specification: TestSpecification) => boolean): void;
3066
+ fallbackCJS?: boolean;
3067
+ }
3068
+ type ProjectConfig = Omit<InlineConfig, NonProjectOptions | "sequencer" | "deps" | "poolOptions"> & {
3069
+ mode?: string;
3070
+ sequencer?: Omit<SequenceOptions, "sequencer" | "seed">;
3071
+ deps?: Omit<DepsOptions, "moduleDirectories">;
3072
+ poolOptions?: {
3073
+ threads?: Pick<NonNullable<PoolOptions["threads"]>, "singleThread" | "isolate">;
3074
+ vmThreads?: Pick<NonNullable<PoolOptions["vmThreads"]>, "singleThread">;
3075
+ forks?: Pick<NonNullable<PoolOptions["forks"]>, "singleFork" | "isolate">;
3076
+ };
3077
+ };
3078
+ type ResolvedProjectConfig = Omit<ResolvedConfig, Exclude<NonProjectOptions, "coverage" | "watch">>;
3079
+ interface UserWorkspaceConfig extends UserConfig$1 {
3080
+ test?: ProjectConfig;
3081
+ }
3082
+ type UserProjectConfigFn = (env: ConfigEnv) => UserWorkspaceConfig | Promise<UserWorkspaceConfig>;
3083
+ type UserProjectConfigExport = UserWorkspaceConfig | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
3084
+ type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
3146
3085
  /**
3147
- * Check if the project with a given name should be included.
3086
+ * Relative path to the extendable config. All other options will be merged with this config.
3087
+ * If `true`, the project will inherit all options from the root config.
3088
+ * @example '../vite.config.ts'
3148
3089
  */
3149
- matchesProjectFilter(name: string): boolean;
3150
- }
3151
- type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
3152
- type OnTestsRerunHandler = (testFiles: TestSpecification[]) => Promise<void> | void;
3090
+ extends?: string | true;
3091
+ });
3092
+ type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
3153
3093
 
3154
- export { CoverageMap as C, TestSpecification as K, Logger as L, TestModule as M, TestProject as T, Vitest as V, VitestPackageInstaller as X, getFilePoolName as _, TestCase as a4, TestCollection as a5, BasicReporter as aC, BenchmarkReporter as aD, BenchmarkReportsMap as aE, DefaultReporter as aF, DotReporter as aG, GithubActionsReporter as aH, HangingProcessReporter as aI, JsonReporter as aJ, JUnitReporter as aK, ReportersMap as aL, TapFlatReporter as aM, TapReporter as aN, VerboseBenchmarkReporter as aO, VerboseReporter as aP, BaseReporter as aQ, TestSuite as ad };
3155
- export type { SerializedTestProject as $, ApiConfig as A, BaseCoverageOptions as B, DepsOptimizationOptions as D, ProjectConfig as E, BenchmarkUserOptions as F, BrowserTesterOptions as G, VitestOptions as H, InlineConfig as I, TestSequencer as J, ModuleDiagnostic as N, OnServerRestartHandler as O, Pool as P, OnTestsRerunHandler as Q, ResolvedCoverageOptions as R, SerializedTestSpecification as S, UserWorkspaceConfig as U, WorkspaceProjectConfiguration as W, ProcessPool as Y, WorkspaceSpec as Z, ReportContext as a, HTMLOptions as a0, JsonOptions$1 as a1, JUnitOptions as a2, TaskOptions as a3, TestDiagnostic as a6, TestModuleState as a7, TestResult as a8, TestResultFailed as a9, ReportedHookContext as aA, TestRunEndReason as aB, BenchmarkBuiltinReporters as aR, BuiltinReporterOptions as aS, BuiltinReporters as aT, JsonAssertionResult as aU, JsonTestResult as aV, JsonTestResults as aW, TestResultPassed as aa, TestResultSkipped as ab, TestState as ac, TestSuiteState as ae, TestSequencerConstructor as af, BrowserBuiltinProvider as ag, BrowserCommand as ah, BrowserCommandContext as ai, BrowserInstanceOption as aj, BrowserModuleMocker as ak, BrowserOrchestrator as al, BrowserProvider as am, BrowserProviderInitializationOptions as an, BrowserProviderModule as ao, BrowserProviderOptions as ap, BrowserServerState as aq, BrowserServerStateSession as ar, CDPSession as as, ParentProjectBrowser as at, ProjectBrowser as au, ResolvedBrowserOptions as av, ResolvedProjectConfig as aw, ResolveSnapshotPathHandler as ax, ResolveSnapshotPathHandlerContext as ay, TestRunResult as az, TestProjectConfiguration as b, CoverageV8Options as c, UserProjectConfigFn as d, UserProjectConfigExport as e, TestProjectInlineConfiguration as f, WatcherTriggerPattern as g, CoverageProvider as h, CoverageProviderModule as i, CoverageReporter as j, CoverageProviderName as k, CoverageOptions as l, CoverageIstanbulOptions as m, CustomProviderOptions as n, Reporter as o, BrowserScript as p, BrowserConfigOptions as q, BuiltinEnvironment as r, VitestEnvironment as s, PoolOptions as t, CSSModuleScopeStrategy as u, VitestRunMode as v, TransformModePatterns as w, TypecheckConfig as x, UserConfig as y, ResolvedConfig as z };
3094
+ export { TestSuite as B, CoverageMap as C, experimental_getRunnerTask as E, Logger as L, TestProject as T, Vitest as V, GithubActionsReporter as aA, HangingProcessReporter as aB, JsonReporter as aC, JUnitReporter as aD, ReportersMap as aE, TapFlatReporter as aF, TapReporter as aG, VerboseBenchmarkReporter as aH, VerboseReporter as aI, BaseReporter as aJ, BenchmarkReporter as aw, BenchmarkReportsMap as ax, DefaultReporter as ay, DotReporter as az, TestSpecification as k, VitestPackageInstaller as n, TestCase as q, TestCollection as r, TestModule as t };
3095
+ export type { BrowserProvider as $, ApiConfig as A, TestSuiteState as D, TestSequencerConstructor as F, BenchmarkUserOptions as G, HTMLOptions as H, InlineConfig as I, JsonOptions as J, BrowserBuiltinProvider as K, ModuleDiagnostic as M, BrowserCommand as N, OnServerRestartHandler as O, Pool as P, BrowserCommandContext as Q, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, BrowserConfigOptions as X, BrowserInstanceOption as Y, BrowserModuleMocker as Z, BrowserOrchestrator as _, TestProjectConfiguration as a, BrowserProviderOption as a0, BrowserScript as a1, BrowserServerState as a2, BrowserServerStateSession as a3, CDPSession as a4, ParentProjectBrowser as a5, ProjectBrowser as a6, ResolvedBrowserOptions as a7, ToMatchScreenshotComparators as a8, ToMatchScreenshotOptions as a9, BenchmarkBuiltinReporters as aK, BuiltinReporterOptions as aL, BuiltinReporters as aM, JsonAssertionResult as aN, JsonTestResult as aO, JsonTestResults as aP, BuiltinEnvironment as aa, CSSModuleScopeStrategy as ab, DepsOptimizationOptions as ac, EnvironmentOptions as ad, PoolOptions as ae, ProjectConfig as af, ResolvedProjectConfig as ag, ResolveSnapshotPathHandler as ah, ResolveSnapshotPathHandlerContext as ai, TypecheckConfig as aj, VitestEnvironment as ak, BaseCoverageOptions as al, CoverageIstanbulOptions as am, CoverageOptions as an, CoverageProvider as ao, CoverageProviderModule as ap, CoverageReporter as aq, CustomProviderOptions as ar, TestRunResult as as, ReportedHookContext as at, Reporter as au, TestRunEndReason as av, ReportContext as b, CoverageV8Options as c, UserProjectConfigFn as d, UserProjectConfigExport as e, UserConfig as f, TestProjectInlineConfiguration as g, ResolvedConfig as h, VitestRunMode as i, VitestOptions as j, TestSequencer as l, OnTestsRerunHandler as m, JUnitOptions as o, TaskOptions as p, TestDiagnostic as s, TestModuleState as u, TestResult as v, TestResultFailed as w, TestResultPassed as x, TestResultSkipped as y, TestState as z };