vitest 4.0.0-beta.1 → 4.0.0-beta.11

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 (90) hide show
  1. package/LICENSE.md +83 -2
  2. package/dist/browser.d.ts +19 -16
  3. package/dist/browser.js +11 -7
  4. package/dist/chunks/{benchmark.CYdenmiT.js → benchmark.LXhJ0F0X.js} +7 -9
  5. package/dist/chunks/{benchmark.d.BwvBVTda.d.ts → benchmark.d.DAaHLpsq.d.ts} +4 -4
  6. package/dist/chunks/{browser.d.q8Z0P0q1.d.ts → browser.d.Dx7DO_Ce.d.ts} +5 -5
  7. package/dist/chunks/{cac.D3EzDDZd.js → cac.elvK37c9.js} +71 -153
  8. package/dist/chunks/{cli-api.Dn5gKePv.js → cli-api.C7plPyhs.js} +1376 -1693
  9. package/dist/chunks/{config.d.HJdfX-8k.d.ts → config.d.B_LthbQq.d.ts} +58 -63
  10. package/dist/chunks/{console.CtFJOzRO.js → console.CiTi59Jy.js} +35 -71
  11. package/dist/chunks/{constants.DnKduX2e.js → constants.D_Q9UYh-.js} +1 -9
  12. package/dist/chunks/{coverage.Cwa-XhJt.js → coverage.CG6Uhorw.js} +522 -792
  13. package/dist/chunks/{coverage.DVF1vEu8.js → coverage.D_JHT54q.js} +2 -2
  14. package/dist/chunks/{coverage.d.S9RMNXIe.d.ts → coverage.d.BZtK59WP.d.ts} +10 -8
  15. package/dist/chunks/{creator.GK6I-cL4.js → creator.08Gi-vCA.js} +93 -77
  16. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  17. package/dist/chunks/{environment.d.CUq4cUgQ.d.ts → environment.d.BsToaxti.d.ts} +27 -6
  18. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  19. package/dist/chunks/{global.d.CVbXEflG.d.ts → global.d.BK3X7FW1.d.ts} +2 -5
  20. package/dist/chunks/{globals.Cxal6MLI.js → globals.BjvYA-AD.js} +11 -9
  21. package/dist/chunks/{index.BWf_gE5n.js → index.AZOjjqWP.js} +7 -6
  22. package/dist/chunks/{index.B521nVV-.js → index.Bgo3tNWt.js} +23 -4
  23. package/dist/chunks/{index.TfbsX-3I.js → index.BhY64fF0.js} +16 -26
  24. package/dist/chunks/{index.CZI_8rVt.js → index.BwBttQPf.js} +340 -663
  25. package/dist/chunks/{index.CmSc2RE5.js → index.DIWhzsUh.js} +72 -118
  26. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  27. package/dist/chunks/moduleRunner.d.BNa-CL9e.d.ts +201 -0
  28. package/dist/chunks/{node.fjCdwEIl.js → node.BsdMi6DV.js} +2 -2
  29. package/dist/chunks/{plugin.d.C2EcJUjo.d.ts → plugin.d.C5phQR6o.d.ts} +1 -1
  30. package/dist/chunks/{reporters.d.DxZg19fy.d.ts → reporters.d.CVzhsTvK.d.ts} +1233 -1293
  31. package/dist/chunks/resolveSnapshotEnvironment.DQVamkje.js +81 -0
  32. package/dist/chunks/rpc.jKGRSXIH.js +65 -0
  33. package/dist/chunks/{setup-common.D7ZqXFx-.js → setup-common.NAWRuMRP.js} +18 -30
  34. package/dist/chunks/startModuleRunner.oAuCu1yL.js +682 -0
  35. package/dist/chunks/{suite.d.FvehnV49.d.ts → suite.d.BJWk38HB.d.ts} +1 -1
  36. package/dist/chunks/test.KC5tH8hC.js +214 -0
  37. package/dist/chunks/typechecker.gXq-5P3n.js +1438 -0
  38. package/dist/chunks/{utils.XdZDrNZV.js → utils.DGKhod2J.js} +9 -28
  39. package/dist/chunks/{vi.bdSIJ99Y.js → vi.CiJ0Laa6.js} +159 -306
  40. package/dist/chunks/worker.d.B_Fd9M_w.d.ts +100 -0
  41. package/dist/chunks/worker.rPGLlbkW.js +200 -0
  42. package/dist/cli.js +8 -6
  43. package/dist/config.cjs +3 -9
  44. package/dist/config.d.ts +49 -54
  45. package/dist/config.js +1 -1
  46. package/dist/coverage.d.ts +27 -26
  47. package/dist/coverage.js +6 -8
  48. package/dist/environments.d.ts +9 -13
  49. package/dist/environments.js +1 -1
  50. package/dist/index.d.ts +38 -45
  51. package/dist/index.js +10 -10
  52. package/dist/module-evaluator.d.ts +13 -0
  53. package/dist/module-evaluator.js +276 -0
  54. package/dist/module-runner.js +15 -0
  55. package/dist/node.d.ts +44 -42
  56. package/dist/node.js +30 -36
  57. package/dist/reporters.d.ts +12 -13
  58. package/dist/reporters.js +7 -5
  59. package/dist/runners.d.ts +3 -3
  60. package/dist/runners.js +15 -232
  61. package/dist/snapshot.js +3 -3
  62. package/dist/suite.d.ts +2 -2
  63. package/dist/suite.js +4 -3
  64. package/dist/worker-base.js +203 -0
  65. package/dist/{chunks/vm.BThCzidc.js → worker-vm.js} +179 -228
  66. package/dist/workers/runVmTests.js +39 -56
  67. package/globals.d.ts +17 -17
  68. package/package.json +40 -38
  69. package/browser.d.ts +0 -1
  70. package/dist/chunks/base.Bj3pWTr1.js +0 -38
  71. package/dist/chunks/execute.B7h3T_Hc.js +0 -708
  72. package/dist/chunks/index.D-VkfKhf.js +0 -105
  73. package/dist/chunks/rpc.CsFtxqeq.js +0 -83
  74. package/dist/chunks/runBaseTests.BC7ZIH5L.js +0 -129
  75. package/dist/chunks/typechecker.CVytUJuF.js +0 -874
  76. package/dist/chunks/utils.CAioKnHs.js +0 -61
  77. package/dist/chunks/worker.d.CmvJfRGs.d.ts +0 -8
  78. package/dist/chunks/worker.d.DoNjFAiv.d.ts +0 -169
  79. package/dist/execute.d.ts +0 -148
  80. package/dist/execute.js +0 -13
  81. package/dist/worker.js +0 -124
  82. package/dist/workers/forks.js +0 -43
  83. package/dist/workers/threads.js +0 -31
  84. package/dist/workers/vmForks.js +0 -47
  85. package/dist/workers/vmThreads.js +0 -37
  86. package/dist/workers.d.ts +0 -37
  87. package/dist/workers.js +0 -30
  88. package/execute.d.ts +0 -1
  89. package/utils.d.ts +0 -1
  90. package/workers.d.ts +0 -1
@@ -1,23 +1,22 @@
1
- import { Task, CancelReason, TaskMeta, Suite, File, TestAnnotation, ImportDuration, TaskResultPack, TaskEventPack, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
2
- import { P as ProvidedContext, U as UserConsoleLog, b as Awaitable$1, c as Arrayable$1, A as AfterSuiteRunMeta, L as LabelColor } from './environment.d.CUq4cUgQ.js';
3
- import { ParsedStack, Awaitable, TestError, SerializedError, Arrayable } 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 { ViteDevServer, ModuleNode, TransformResult as TransformResult$1, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
6
- import { Console } from 'node:console';
7
- import { B as BrowserTesterOptions, S as SerializedTestSpecification } from './browser.d.q8Z0P0q1.js';
5
+ import { ViteDevServer, TransformResult as TransformResult$1, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
8
6
  import { MockedModule } from '@vitest/mocker';
9
7
  import { StackTraceParserOptions } from '@vitest/utils/source-map';
10
- import { a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.HJdfX-8k.js';
8
+ import { B as BrowserTesterOptions, S as SerializedTestSpecification } from './browser.d.Dx7DO_Ce.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';
13
+ import { chai } from '@vitest/expect';
16
14
  import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
17
- import { B as BenchmarkResult } from './benchmark.d.BwvBVTda.js';
18
- import { a as RuntimeCoverageProviderModule } from './coverage.d.S9RMNXIe.js';
15
+ import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
16
+ import { a as RuntimeCoverageProviderModule } from './coverage.d.BZtK59WP.js';
19
17
  import { SnapshotManager } from '@vitest/snapshot/manager';
20
18
  import { Stats } from 'node:fs';
19
+ import { Console } from 'node:console';
21
20
 
22
21
  type ChaiConfig = Omit<Partial<typeof chai.config>, "useProxy" | "proxyExcludedKeys">;
23
22
 
@@ -70,57 +69,6 @@ interface ConstructorOptionsOverride {
70
69
  resources?: "usable";
71
70
  }
72
71
 
73
- declare class TypeCheckError extends Error {
74
- message: string;
75
- stacks: ParsedStack[];
76
- name: string;
77
- constructor(message: string, stacks: ParsedStack[]);
78
- }
79
-
80
- interface ErrorOptions {
81
- type?: string;
82
- fullStack?: boolean;
83
- project?: TestProject;
84
- verbose?: boolean;
85
- screenshotPaths?: string[];
86
- task?: Task;
87
- showCodeFrame?: boolean;
88
- }
89
- type Listener = () => void;
90
- declare class Logger {
91
- ctx: Vitest;
92
- outputStream: NodeJS.WriteStream | Writable;
93
- errorStream: NodeJS.WriteStream | Writable;
94
- private _clearScreenPending;
95
- private _highlights;
96
- private cleanupListeners;
97
- console: Console;
98
- constructor(ctx: Vitest, outputStream?: NodeJS.WriteStream | Writable, errorStream?: NodeJS.WriteStream | Writable);
99
- log(...args: any[]): void;
100
- error(...args: any[]): void;
101
- warn(...args: any[]): void;
102
- clearFullScreen(message?: string): void;
103
- clearScreen(message: string, force?: boolean): void;
104
- private _clearScreen;
105
- printError(err: unknown, options?: ErrorOptions): void;
106
- deprecate(message: string): void;
107
- clearHighlightCache(filename?: string): void;
108
- highlight(filename: string, source: string): string;
109
- printNoTestFound(filters?: string[]): void;
110
- printBanner(): void;
111
- printBrowserBanner(project: TestProject): void;
112
- printUnhandledErrors(errors: unknown[]): void;
113
- printSourceTypeErrors(errors: TypeCheckError[]): void;
114
- getColumns(): number;
115
- onTerminalCleanup(listener: Listener): void;
116
- private addCleanupListeners;
117
- private registerUnhandledRejection;
118
- }
119
-
120
- interface BrowserProviderInitializationOptions {
121
- browser: string;
122
- options?: BrowserProviderOptions;
123
- }
124
72
  interface CDPSession {
125
73
  send: (method: string, params?: Record<string, unknown>) => Promise<unknown>;
126
74
  on: (event: string, listener: (...args: unknown[]) => void) => void;
@@ -132,6 +80,11 @@ interface BrowserModuleMocker {
132
80
  delete: (sessionId: string, url: string) => Promise<void>;
133
81
  clear: (sessionId: string) => Promise<void>;
134
82
  }
83
+ interface BrowserProviderOption {
84
+ name: string;
85
+ supportedBrowser?: ReadonlyArray<string>;
86
+ factory: (project: TestProject) => BrowserProvider;
87
+ }
135
88
  interface BrowserProvider {
136
89
  name: string;
137
90
  mocker?: BrowserModuleMocker;
@@ -139,21 +92,14 @@ interface BrowserProvider {
139
92
  * @experimental opt-in into file parallelisation
140
93
  */
141
94
  supportsParallelism: boolean;
142
- getSupportedBrowsers: () => readonly string[];
143
95
  getCommandsContext: (sessionId: string) => Record<string, unknown>;
144
- openPage: (sessionId: string, url: string, beforeNavigate?: () => Promise<void>) => Promise<void>;
96
+ openPage: (sessionId: string, url: string) => Promise<void>;
145
97
  getCDPSession?: (sessionId: string) => Promise<CDPSession>;
146
98
  close: () => Awaitable<void>;
147
- // eslint-disable-next-line ts/method-signature-style -- we want to allow extended options
148
- initialize(ctx: TestProject, options: BrowserProviderInitializationOptions): Awaitable<void>;
149
99
  }
150
- interface BrowserProviderModule {
151
- new (): BrowserProvider;
152
- }
153
- interface BrowserProviderOptions {}
154
100
  type BrowserBuiltinProvider = "webdriverio" | "playwright" | "preview";
155
- type UnsupportedProperties = "browser" | "typecheck" | "alias" | "sequence" | "root" | "pool" | "poolOptions" | "runner" | "api" | "deps" | "testTransformMode" | "poolMatchGlobs" | "environmentMatchGlobs" | "environment" | "environmentOptions" | "server" | "benchmark" | "name";
156
- interface BrowserInstanceOption extends BrowserProviderOptions, Omit<ProjectConfig, UnsupportedProperties>, Pick<BrowserConfigOptions, "headless" | "locators" | "viewport" | "testerHtmlPath" | "screenshotDirectory" | "screenshotFailures"> {
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"> {
157
103
  /**
158
104
  * Name of the browser
159
105
  */
@@ -168,32 +114,13 @@ interface BrowserConfigOptions {
168
114
  */
169
115
  enabled?: boolean;
170
116
  /**
171
- * Name of the browser
172
- * @deprecated use `instances` instead. if both are defined, this will filter `instances` by name.
173
- */
174
- name?: string;
175
- /**
176
117
  * Configurations for different browser setups
177
118
  */
178
- instances?: BrowserInstanceOption[];
119
+ instances: BrowserInstanceOption[];
179
120
  /**
180
121
  * Browser provider
181
- *
182
- * @default 'preview'
183
- */
184
- provider?: BrowserBuiltinProvider | (string & {});
185
- /**
186
- * Options that are passed down to a browser provider.
187
- * To support type hinting, add one of the types to your tsconfig.json "compilerOptions.types" field:
188
- *
189
- * - for webdriverio: `@vitest/browser/providers/webdriverio`
190
- * - for playwright: `@vitest/browser/providers/playwright`
191
- *
192
- * @example
193
- * { playwright: { launch: { devtools: true } }
194
- * @deprecated use `instances` instead
195
122
  */
196
- providerOptions?: BrowserProviderOptions;
123
+ provider?: BrowserProviderOption;
197
124
  /**
198
125
  * enable headless mode
199
126
  *
@@ -233,12 +160,12 @@ interface BrowserConfigOptions {
233
160
  * Width of the viewport
234
161
  * @default 414
235
162
  */
236
- width: number
163
+ width: number;
237
164
  /**
238
165
  * Height of the viewport
239
166
  * @default 896
240
167
  */
241
- height: number
168
+ height: number;
242
169
  };
243
170
  /**
244
171
  * Locator options
@@ -248,7 +175,7 @@ interface BrowserConfigOptions {
248
175
  * Attribute used to locate elements by test id
249
176
  * @default 'data-testid'
250
177
  */
251
- testIdAttribute?: string
178
+ testIdAttribute?: string;
252
179
  };
253
180
  /**
254
181
  * Directory where screenshots will be saved when page.screenshot() is called
@@ -263,11 +190,6 @@ interface BrowserConfigOptions {
263
190
  */
264
191
  screenshotFailures?: boolean;
265
192
  /**
266
- * Scripts injected into the tester iframe.
267
- * @deprecated Will be removed in the future, use `testerHtmlPath` instead.
268
- */
269
- testerScripts?: BrowserScript[];
270
- /**
271
193
  * Path to the index.html file that will be used to run tests.
272
194
  */
273
195
  testerHtmlPath?: string;
@@ -286,13 +208,31 @@ interface BrowserConfigOptions {
286
208
  * @default 30000
287
209
  */
288
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
+ };
222
+ /**
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
229
+ */
230
+ trackUnhandledErrors?: boolean;
289
231
  }
290
232
  interface BrowserCommandContext {
291
233
  testPath: string | undefined;
292
234
  provider: BrowserProvider;
293
235
  project: TestProject;
294
- /** @deprecated use `sessionId` instead */
295
- contextId: string;
296
236
  sessionId: string;
297
237
  }
298
238
  interface BrowserServerStateSession {
@@ -354,7 +294,6 @@ interface BrowserScript {
354
294
  }
355
295
  interface ResolvedBrowserOptions extends BrowserConfigOptions {
356
296
  name: string;
357
- providerOptions?: BrowserProviderOptions;
358
297
  enabled: boolean;
359
298
  headless: boolean;
360
299
  isolate: boolean;
@@ -362,665 +301,1065 @@ interface ResolvedBrowserOptions extends BrowserConfigOptions {
362
301
  api: ApiConfig;
363
302
  ui: boolean;
364
303
  viewport: {
365
- width: number
366
- height: number
304
+ width: number;
305
+ height: number;
367
306
  };
368
307
  screenshotFailures: boolean;
369
308
  locators: {
370
- testIdAttribute: string
309
+ testIdAttribute: string;
371
310
  };
372
311
  }
373
-
374
- declare class ReportedTaskImplementation {
375
- /**
376
- * The project associated with the test or suite.
377
- */
378
- readonly project: TestProject;
312
+ type ToMatchScreenshotResolvePath = (data: {
379
313
  /**
380
- * Unique identifier.
381
- * This ID is deterministic and will be the same for the same test across multiple runs.
382
- * The ID is based on the project name, module url and test order.
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"
383
332
  */
384
- readonly id: string;
333
+ arg: string;
385
334
  /**
386
- * Location in the module where the test or suite is defined.
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.
387
339
  */
388
- readonly location: {
389
- line: number
390
- column: number
391
- } | undefined;
340
+ ext: string;
392
341
  /**
393
- * Checks if the test did not fail the suite.
394
- * If the test is not finished yet or was skipped, it will return `true`.
342
+ * The instance's browser name.
395
343
  */
396
- ok(): boolean;
344
+ browserName: string;
397
345
  /**
398
- * Custom metadata that was attached to the test during its execution.
346
+ * The value of {@linkcode process.platform}.
399
347
  */
400
- meta(): TaskMeta;
401
- }
402
- declare class TestCase extends ReportedTaskImplementation {
403
- #private;
404
- readonly type = "test";
348
+ platform: NodeJS.Platform;
405
349
  /**
406
- * Direct reference to the test module where the test or suite is defined.
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.
407
353
  */
408
- readonly module: TestModule;
354
+ screenshotDirectory: string;
409
355
  /**
410
- * Name of the test.
356
+ * Absolute path to the project's
357
+ * {@linkcode https://vitest.dev/config/#root|root}.
411
358
  */
412
- readonly name: string;
359
+ root: string;
413
360
  /**
414
- * Options that the test was initiated with.
361
+ * Path to the test file, relative to the project's
362
+ * {@linkcode https://vitest.dev/config/#root|root}.
415
363
  */
416
- readonly options: TaskOptions;
364
+ testFileDirectory: string;
417
365
  /**
418
- * Parent suite. If the test was called directly inside the module, the parent will be the module itself.
366
+ * The test's filename.
419
367
  */
420
- readonly parent: TestSuite | TestModule;
368
+ testFileName: string;
421
369
  /**
422
- * Full name of the test including all parent suites separated with `>`.
370
+ * The {@linkcode https://vitest.dev/api/#test|test}'s name, including
371
+ * parent {@linkcode https://vitest.dev/api/#describe|describe}, sanitized.
423
372
  */
424
- get fullName(): string;
373
+ testName: string;
425
374
  /**
426
- * Test results.
427
- * - **pending**: Test was collected, but didn't finish running yet.
428
- * - **passed**: Test passed successfully
429
- * - **failed**: Test failed to execute
430
- * - **skipped**: Test was skipped during collection or dynamically with `ctx.skip()`.
375
+ * The value provided to
376
+ * {@linkcode https://vitest.dev/config/#attachmentsdir|attachmentsDir},
377
+ * if none is provided, its default value.
431
378
  */
432
- result(): TestResult;
379
+ attachmentsDir: string;
380
+ }) => string;
381
+ interface ToMatchScreenshotOptions {
433
382
  /**
434
- * Test annotations added via the `task.annotate` API during the test execution.
383
+ * Overrides default reference screenshot path.
384
+ *
385
+ * @default `${root}/${testFileDirectory}/${screenshotDirectory}/${testFileName}/${arg}-${browserName}-${platform}${ext}`
435
386
  */
436
- annotations(): ReadonlyArray<TestAnnotation>;
387
+ resolveScreenshotPath?: ToMatchScreenshotResolvePath;
437
388
  /**
438
- * Useful information about the test like duration, memory usage, etc.
439
- * Diagnostic is only available after the test has finished.
389
+ * Overrides default screenshot path used for diffs.
390
+ *
391
+ * @default `${root}/${attachmentsDir}/${testFileDirectory}/${testFileName}/${arg}-${browserName}-${platform}${ext}`
440
392
  */
441
- diagnostic(): TestDiagnostic | undefined;
393
+ resolveDiffPath?: ToMatchScreenshotResolvePath;
442
394
  }
443
- declare class TestCollection {
444
- #private;
445
- constructor(task: Suite | File, project: TestProject);
395
+ interface ToMatchScreenshotComparators {}
396
+
397
+ type BuiltinPool = "browser" | "threads" | "forks" | "vmThreads" | "vmForks" | "typescript";
398
+ type Pool = BuiltinPool | (string & {});
399
+ interface PoolOptions extends Record<string, unknown> {
446
400
  /**
447
- * Returns the test or suite at a specific index.
401
+ * Run tests in `node:worker_threads`.
402
+ *
403
+ * Test isolation (when enabled) is done by spawning a new thread for each test file.
404
+ *
405
+ * This pool is used by default.
448
406
  */
449
- at(index: number): TestCase | TestSuite | undefined;
407
+ threads?: ThreadsOptions & WorkerContextOptions;
450
408
  /**
451
- * The number of tests and suites in the collection.
409
+ * Run tests in `node:child_process` using [`fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
410
+ *
411
+ * Test isolation (when enabled) is done by spawning a new child process for each test file.
452
412
  */
453
- get size(): number;
413
+ forks?: ForksOptions & WorkerContextOptions;
454
414
  /**
455
- * Returns the collection in array form for easier manipulation.
415
+ * Run tests in isolated `node:vm`.
416
+ * Test files are run parallel using `node:worker_threads`.
417
+ *
418
+ * This makes tests run faster, but VM module is unstable. Your tests might leak memory.
456
419
  */
457
- array(): (TestCase | TestSuite)[];
420
+ vmThreads?: ThreadsOptions & VmOptions;
458
421
  /**
459
- * Filters all tests that are part of this collection and its children.
422
+ * Run tests in isolated `node:vm`.
423
+ *
424
+ * Test files are run parallel using `node:child_process` [`fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
425
+ *
426
+ * This makes tests run faster, but VM module is unstable. Your tests might leak memory.
460
427
  */
461
- allTests(state?: TestState): Generator<TestCase, undefined, void>;
428
+ vmForks?: ForksOptions & VmOptions;
429
+ }
430
+ interface ResolvedPoolOptions extends PoolOptions {
431
+ threads?: ResolvedThreadsOptions & WorkerContextOptions;
432
+ forks?: ResolvedForksOptions & WorkerContextOptions;
433
+ vmThreads?: ResolvedThreadsOptions & VmOptions;
434
+ vmForks?: ResolvedForksOptions & VmOptions;
435
+ }
436
+ interface ThreadsOptions {
437
+ /** Maximum amount of threads to use */
438
+ maxThreads?: number | string;
462
439
  /**
463
- * Filters only the tests that are part of this collection.
440
+ * Run tests inside a single thread.
441
+ *
442
+ * @default false
464
443
  */
465
- tests(state?: TestState): Generator<TestCase, undefined, void>;
444
+ singleThread?: boolean;
466
445
  /**
467
- * Filters only the suites that are part of this collection.
446
+ * Use Atomics to synchronize threads
447
+ *
448
+ * This can improve performance in some cases, but might cause segfault in older Node versions.
449
+ *
450
+ * @default false
468
451
  */
469
- suites(): Generator<TestSuite, undefined, void>;
452
+ useAtomics?: boolean;
453
+ }
454
+ interface ResolvedThreadsOptions extends ThreadsOptions {
455
+ maxThreads?: number;
456
+ }
457
+ interface ForksOptions {
458
+ /** Maximum amount of child processes to use */
459
+ maxForks?: number | string;
470
460
  /**
471
- * Filters all suites that are part of this collection and its children.
461
+ * Run tests inside a single fork.
462
+ *
463
+ * @default false
472
464
  */
473
- allSuites(): Generator<TestSuite, undefined, void>;
474
- [Symbol.iterator](): Generator<TestSuite | TestCase, undefined, void>;
465
+ singleFork?: boolean;
475
466
  }
476
-
477
- type ReportedHookContext = {
478
- readonly name: "beforeAll" | "afterAll"
479
- readonly entity: TestSuite | TestModule
480
- } | {
481
- readonly name: "beforeEach" | "afterEach"
482
- readonly entity: TestCase
483
- };
484
- declare abstract class SuiteImplementation extends ReportedTaskImplementation {
467
+ interface ResolvedForksOptions extends ForksOptions {
468
+ maxForks?: number;
469
+ }
470
+ interface WorkerContextOptions {
485
471
  /**
486
- * Collection of suites and tests that are part of this suite.
472
+ * Isolate test environment by recycling `worker_threads` or `child_process` after each test
473
+ *
474
+ * @default true
487
475
  */
488
- readonly children: TestCollection;
476
+ isolate?: boolean;
489
477
  /**
490
- * Errors that happened outside of the test run during collection, like syntax errors.
478
+ * Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
479
+ *
480
+ * See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
481
+ *
482
+ * Set to `process.execArgv` to pass all arguments of the current process.
483
+ *
484
+ * Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
485
+ *
486
+ * @default [] // no execution arguments are passed
491
487
  */
492
- errors(): SerializedError[];
488
+ execArgv?: string[];
493
489
  }
494
- declare class TestSuite extends SuiteImplementation {
495
- #private;
496
- readonly type = "suite";
490
+ interface VmOptions {
497
491
  /**
498
- * Name of the test or the suite.
492
+ * Specifies the memory limit for `worker_thread` or `child_process` before they are recycled.
493
+ * If you see memory leaks, try to tinker this value.
499
494
  */
500
- readonly name: string;
495
+ memoryLimit?: string | number;
496
+ /** Isolation is always enabled */
497
+ isolate?: true;
501
498
  /**
502
- * Direct reference to the test module where the test or suite is defined.
499
+ * Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
500
+ *
501
+ * See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
502
+ *
503
+ * Set to `process.execArgv` to pass all arguments of the current process.
504
+ *
505
+ * Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
506
+ *
507
+ * @default [] // no execution arguments are passed
503
508
  */
504
- readonly module: TestModule;
509
+ execArgv?: string[];
510
+ }
511
+
512
+ declare class TestSpecification {
505
513
  /**
506
- * Parent suite. If suite was called directly inside the module, the parent will be the module itself.
514
+ * The task ID associated with the test module.
507
515
  */
508
- readonly parent: TestSuite | TestModule;
516
+ readonly taskId: string;
509
517
  /**
510
- * Options that suite was initiated with.
518
+ * The test project that the module belongs to.
511
519
  */
512
- readonly options: TaskOptions;
520
+ readonly project: TestProject;
513
521
  /**
514
- * Checks if the suite has any failed tests.
515
- * This will also return `false` if suite failed during collection.
522
+ * The ID of the module in the Vite module graph. It is usually an absolute file path.
516
523
  */
517
- ok: () => boolean;
524
+ readonly moduleId: string;
518
525
  /**
519
- * The meta information attached to the suite during its collection or execution.
526
+ * The current test pool. It's possible to have multiple pools in a single test project with `poolMatchGlob` and `typecheck.enabled`.
527
+ * @experimental In Vitest 4, the project will only support a single pool and this property will be removed.
520
528
  */
521
- meta: () => TaskMeta;
529
+ readonly pool: Pool;
522
530
  /**
523
- * Checks the running state of the suite.
531
+ * Line numbers of the test locations to run.
524
532
  */
525
- state(): TestSuiteState;
533
+ readonly testLines: number[] | undefined;
534
+ constructor(project: TestProject, moduleId: string, pool: Pool, testLines?: number[] | undefined);
526
535
  /**
527
- * Full name of the suite including all parent suites separated with `>`.
536
+ * Test module associated with the specification.
528
537
  */
529
- get fullName(): string;
538
+ get testModule(): TestModule | undefined;
539
+ toJSON(): SerializedTestSpecification;
530
540
  }
531
- declare class TestModule extends SuiteImplementation {
532
- readonly location: undefined;
533
- readonly type = "module";
541
+
542
+ declare class TestProject {
543
+ options?: InitializeProjectOptions | undefined;
534
544
  /**
535
- * This is usually an absolute UNIX file path.
536
- * It can be a virtual ID if the file is not on the disk.
537
- * This value corresponds to the ID in the Vite's module graph.
545
+ * The global Vitest instance.
546
+ * @experimental The public Vitest API is experimental and does not follow semver.
538
547
  */
539
- readonly moduleId: string;
548
+ readonly vitest: Vitest;
540
549
  /**
541
- * Checks the running state of the test file.
550
+ * Resolved global configuration. If there are no workspace projects, this will be the same as `config`.
542
551
  */
543
- state(): TestModuleState;
552
+ readonly globalConfig: ResolvedConfig;
544
553
  /**
545
- * Checks if the module has any failed tests.
546
- * This will also return `false` if module failed during collection.
554
+ * Browser instance if the browser is enabled. This is initialized when the tests run for the first time.
547
555
  */
548
- ok: () => boolean;
556
+ browser?: ProjectBrowser;
549
557
  /**
550
- * The meta information attached to the module during its collection or execution.
558
+ * Temporary directory for the project. This is unique for each project. Vitest stores transformed content here.
551
559
  */
552
- meta: () => TaskMeta;
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);
553
568
  /**
554
- * Useful information about the module like duration, memory usage, etc.
555
- * If the module was not executed yet, all diagnostic values will return `0`.
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.
556
572
  */
557
- diagnostic(): ModuleDiagnostic;
558
- }
559
- interface TaskOptions {
560
- readonly each: boolean | undefined;
561
- readonly fails: boolean | undefined;
562
- readonly concurrent: boolean | undefined;
563
- readonly shuffle: boolean | undefined;
564
- readonly retry: number | undefined;
565
- readonly repeats: number | undefined;
566
- readonly mode: "run" | "only" | "skip" | "todo";
567
- }
568
- type TestSuiteState = "skipped" | "pending" | "failed" | "passed";
569
- type TestModuleState = TestSuiteState | "queued";
570
- type TestState = TestResult["state"];
571
- type TestResult = TestResultPassed | TestResultFailed | TestResultSkipped | TestResultPending;
572
- interface TestResultPending {
573
+ get hash(): string;
573
574
  /**
574
- * The test was collected, but didn't finish running yet.
575
+ * Provide a value to the test context. This value will be available to all tests with `inject`.
575
576
  */
576
- readonly state: "pending";
577
+ provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
577
578
  /**
578
- * Pending tests have no errors.
579
+ * Get the provided context. The project context is merged with the global context.
579
580
  */
580
- readonly errors: undefined;
581
- }
582
- interface TestResultPassed {
581
+ getProvidedContext(): ProvidedContext;
583
582
  /**
584
- * The test passed successfully.
583
+ * Creates a new test specification. Specifications describe how to run tests.
584
+ * @param moduleId The file path
585
585
  */
586
- readonly state: "passed";
586
+ createSpecification(moduleId: string, locations?: number[] | undefined, pool?: string): TestSpecification;
587
+ toJSON(): SerializedTestProject;
587
588
  /**
588
- * Errors that were thrown during the test execution.
589
- *
590
- * **Note**: If test was retried successfully, errors will still be reported.
589
+ * Vite's dev server instance. Every workspace project has its own server.
591
590
  */
592
- readonly errors: ReadonlyArray<TestError> | undefined;
593
- }
594
- interface TestResultFailed {
591
+ get vite(): ViteDevServer;
595
592
  /**
596
- * The test failed to execute.
593
+ * Resolved project configuration.
597
594
  */
598
- readonly state: "failed";
595
+ get config(): ResolvedConfig;
599
596
  /**
600
- * Errors that were thrown during the test execution.
597
+ * The name of the project or an empty string if not set.
601
598
  */
602
- readonly errors: ReadonlyArray<TestError>;
603
- }
604
- interface TestResultSkipped {
599
+ get name(): string;
605
600
  /**
606
- * The test was skipped with `only` (on another test), `skip` or `todo` flag.
607
- * You can see which one was used in the `options.mode` option.
601
+ * The color used when reporting tasks of this project.
608
602
  */
609
- readonly state: "skipped";
603
+ get color(): ProjectName["color"];
610
604
  /**
611
- * Skipped tests have no errors.
605
+ * Serialized project configuration. This is the config that tests receive.
612
606
  */
613
- readonly errors: undefined;
607
+ get serializedConfig(): SerializedConfig;
614
608
  /**
615
- * A custom note passed down to `ctx.skip(note)`.
609
+ * Check if this is the root project. The root project is the one that has the root config.
616
610
  */
617
- readonly note: string | undefined;
618
- }
619
- interface TestDiagnostic {
611
+ isRootProject(): boolean;
612
+ onTestsRerun(cb: OnTestsRerunHandler): void;
620
613
  /**
621
- * If the duration of the test is above `slowTestThreshold`.
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.
622
616
  */
623
- readonly slow: boolean;
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;
624
630
  /**
625
- * The amount of memory used by the test in bytes.
626
- * This value is only available if the test was executed with `logHeapUsage` flag.
631
+ * Test if a file matches the test globs. This does the actual glob matching if the test is not cached, unlike `isCachedTestFile`.
627
632
  */
628
- readonly heap: number | undefined;
633
+ matchesTestGlob(moduleId: string, source?: () => string): boolean;
634
+ private isInSourceTestCode;
635
+ private filterFiles;
636
+ private _parentBrowser?;
629
637
  /**
630
- * The time it takes to execute the test in ms.
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.
631
640
  */
632
- readonly duration: number;
641
+ close(): Promise<void>;
633
642
  /**
634
- * The time in ms when the test started.
643
+ * Import a file using Vite module runner.
644
+ * @param moduleId The ID of the module in Vite module graph
635
645
  */
636
- readonly startTime: number;
646
+ import<T>(moduleId: string): Promise<T>;
647
+ private _setHash;
648
+ private _serializeOverriddenConfig;
649
+ private clearTmpDir;
650
+ }
651
+ interface SerializedTestProject {
652
+ name: string;
653
+ serializedConfig: SerializedConfig;
654
+ context: ProvidedContext;
655
+ }
656
+ interface InitializeProjectOptions extends TestProjectInlineConfiguration {
657
+ configFile: string | false;
658
+ }
659
+
660
+ declare class ReportedTaskImplementation {
637
661
  /**
638
- * The amount of times the test was retried.
662
+ * The project associated with the test or suite.
639
663
  */
640
- readonly retryCount: number;
664
+ readonly project: TestProject;
641
665
  /**
642
- * The amount of times the test was repeated as configured by `repeats` option.
643
- * This value can be lower if the test failed during the repeat and no `retry` is configured.
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.
644
669
  */
645
- readonly repeatCount: number;
670
+ readonly id: string;
646
671
  /**
647
- * If test passed on a second retry.
672
+ * Location in the module where the test or suite is defined.
648
673
  */
649
- readonly flaky: boolean;
650
- }
651
- interface ModuleDiagnostic {
674
+ readonly location: {
675
+ line: number;
676
+ column: number;
677
+ } | undefined;
652
678
  /**
653
- * The time it takes to import and initiate an environment.
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`.
654
681
  */
655
- readonly environmentSetupDuration: number;
682
+ ok(): boolean;
656
683
  /**
657
- * The time it takes Vitest to setup test harness (runner, mocks, etc.).
684
+ * Custom metadata that was attached to the test during its execution.
658
685
  */
659
- readonly prepareDuration: number;
686
+ meta(): TaskMeta;
687
+ }
688
+ declare class TestCase extends ReportedTaskImplementation {
689
+ #private;
690
+ readonly type = "test";
660
691
  /**
661
- * The time it takes to import the test module.
662
- * This includes importing everything in the module and executing suite callbacks.
692
+ * Direct reference to the test module where the test or suite is defined.
663
693
  */
664
- readonly collectDuration: number;
694
+ readonly module: TestModule;
665
695
  /**
666
- * The time it takes to import the setup module.
696
+ * Name of the test.
667
697
  */
668
- readonly setupDuration: number;
698
+ readonly name: string;
669
699
  /**
670
- * Accumulated duration of all tests and hooks in the module.
700
+ * Options that the test was initiated with.
671
701
  */
672
- readonly duration: number;
702
+ readonly options: TaskOptions;
673
703
  /**
674
- * The amount of memory used by the test module in bytes.
675
- * This value is only available if the test was executed with `logHeapUsage` flag.
704
+ * Parent suite. If the test was called directly inside the module, the parent will be the module itself.
676
705
  */
677
- readonly heap: number | undefined;
706
+ readonly parent: TestSuite | TestModule;
678
707
  /**
679
- * The time spent importing every non-externalized dependency that Vitest has processed.
708
+ * Full name of the test including all parent suites separated with `>`.
680
709
  */
681
- readonly importDurations: Record<string, ImportDuration>;
682
- }
683
-
684
- type BuiltinPool = "browser" | "threads" | "forks" | "vmThreads" | "vmForks" | "typescript";
685
- type Pool = BuiltinPool | (string & {});
686
- interface PoolOptions extends Record<string, unknown> {
710
+ get fullName(): string;
687
711
  /**
688
- * Run tests in `node:worker_threads`.
689
- *
690
- * Test isolation (when enabled) is done by spawning a new thread for each test file.
691
- *
692
- * This pool is used by default.
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()`.
693
717
  */
694
- threads?: ThreadsOptions & WorkerContextOptions;
718
+ result(): TestResult;
695
719
  /**
696
- * Run tests in `node:child_process` using [`fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
697
- *
698
- * Test isolation (when enabled) is done by spawning a new child process for each test file.
720
+ * Test annotations added via the `task.annotate` API during the test execution.
699
721
  */
700
- forks?: ForksOptions & WorkerContextOptions;
722
+ annotations(): ReadonlyArray<TestAnnotation>;
701
723
  /**
702
- * Run tests in isolated `node:vm`.
703
- * Test files are run parallel using `node:worker_threads`.
704
- *
705
- * This makes tests run faster, but VM module is unstable. Your tests might leak memory.
706
- */
707
- vmThreads?: ThreadsOptions & VmOptions;
708
- /**
709
- * Run tests in isolated `node:vm`.
710
- *
711
- * Test files are run parallel using `node:child_process` [`fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
712
- *
713
- * This makes tests run faster, but VM module is unstable. Your tests might leak memory.
724
+ * Useful information about the test like duration, memory usage, etc.
725
+ * Diagnostic is only available after the test has finished.
714
726
  */
715
- vmForks?: ForksOptions & VmOptions;
716
- }
717
- interface ResolvedPoolOptions extends PoolOptions {
718
- threads?: ResolvedThreadsOptions & WorkerContextOptions;
719
- forks?: ResolvedForksOptions & WorkerContextOptions;
720
- vmThreads?: ResolvedThreadsOptions & VmOptions;
721
- vmForks?: ResolvedForksOptions & VmOptions;
727
+ diagnostic(): TestDiagnostic | undefined;
722
728
  }
723
- interface ThreadsOptions {
724
- /** Minimum amount of threads to use */
725
- minThreads?: number | string;
726
- /** Maximum amount of threads to use */
727
- maxThreads?: number | string;
729
+ declare class TestCollection {
730
+ #private;
731
+ constructor(task: Suite | File, project: TestProject);
728
732
  /**
729
- * Run tests inside a single thread.
730
- *
731
- * @default false
733
+ * Returns the test or suite at a specific index.
732
734
  */
733
- singleThread?: boolean;
735
+ at(index: number): TestCase | TestSuite | undefined;
734
736
  /**
735
- * Use Atomics to synchronize threads
736
- *
737
- * This can improve performance in some cases, but might cause segfault in older Node versions.
738
- *
739
- * @default false
737
+ * The number of tests and suites in the collection.
740
738
  */
741
- useAtomics?: boolean;
742
- }
743
- interface ResolvedThreadsOptions extends ThreadsOptions {
744
- minThreads?: number;
745
- maxThreads?: number;
746
- }
747
- interface ForksOptions {
748
- /** Minimum amount of child processes to use */
749
- minForks?: number | string;
750
- /** Maximum amount of child processes to use */
751
- maxForks?: number | string;
739
+ get size(): number;
752
740
  /**
753
- * Run tests inside a single fork.
754
- *
755
- * @default false
741
+ * Returns the collection in array form for easier manipulation.
756
742
  */
757
- singleFork?: boolean;
758
- }
759
- interface ResolvedForksOptions extends ForksOptions {
760
- minForks?: number;
761
- maxForks?: number;
762
- }
763
- interface WorkerContextOptions {
743
+ array(): (TestCase | TestSuite)[];
764
744
  /**
765
- * Isolate test environment by recycling `worker_threads` or `child_process` after each test
766
- *
767
- * @default true
745
+ * Filters all tests that are part of this collection and its children.
768
746
  */
769
- isolate?: boolean;
747
+ allTests(state?: TestState): Generator<TestCase, undefined, void>;
770
748
  /**
771
- * Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
772
- *
773
- * See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
774
- *
775
- * Set to `process.execArgv` to pass all arguments of the current process.
776
- *
777
- * Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
778
- *
779
- * @default [] // no execution arguments are passed
749
+ * Filters only the tests that are part of this collection.
780
750
  */
781
- execArgv?: string[];
782
- }
783
- interface VmOptions {
751
+ tests(state?: TestState): Generator<TestCase, undefined, void>;
784
752
  /**
785
- * Specifies the memory limit for `worker_thread` or `child_process` before they are recycled.
786
- * If you see memory leaks, try to tinker this value.
753
+ * Filters only the suites that are part of this collection.
787
754
  */
788
- memoryLimit?: string | number;
789
- /** Isolation is always enabled */
790
- isolate?: true;
755
+ suites(): Generator<TestSuite, undefined, void>;
791
756
  /**
792
- * Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
793
- *
794
- * See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
795
- *
796
- * Set to `process.execArgv` to pass all arguments of the current process.
797
- *
798
- * Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
799
- *
800
- * @default [] // no execution arguments are passed
757
+ * Filters all suites that are part of this collection and its children.
801
758
  */
802
- execArgv?: string[];
759
+ allSuites(): Generator<TestSuite, undefined, void>;
760
+ [Symbol.iterator](): Generator<TestSuite | TestCase, undefined, void>;
803
761
  }
804
762
 
805
- declare class TestSpecification {
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 {
806
771
  /**
807
- * @deprecated use `project` instead
772
+ * Collection of suites and tests that are part of this suite.
808
773
  */
809
- readonly 0: TestProject;
774
+ readonly children: TestCollection;
810
775
  /**
811
- * @deprecated use `moduleId` instead
776
+ * Errors that happened outside of the test run during collection, like syntax errors.
812
777
  */
813
- readonly 1: string;
778
+ errors(): SerializedError[];
779
+ }
780
+ declare class TestSuite extends SuiteImplementation {
781
+ #private;
782
+ readonly type = "suite";
814
783
  /**
815
- * @deprecated use `pool` instead
784
+ * Name of the test or the suite.
816
785
  */
817
- readonly 2: {
818
- pool: Pool
819
- };
786
+ readonly name: string;
820
787
  /**
821
- * The task ID associated with the test module.
788
+ * Direct reference to the test module where the test or suite is defined.
822
789
  */
823
- readonly taskId: string;
790
+ readonly module: TestModule;
824
791
  /**
825
- * The test project that the module belongs to.
792
+ * Parent suite. If suite was called directly inside the module, the parent will be the module itself.
826
793
  */
827
- readonly project: TestProject;
794
+ readonly parent: TestSuite | TestModule;
828
795
  /**
829
- * The ID of the module in the Vite module graph. It is usually an absolute file path.
796
+ * Options that suite was initiated with.
830
797
  */
831
- readonly moduleId: string;
798
+ readonly options: TaskOptions;
832
799
  /**
833
- * The current test pool. It's possible to have multiple pools in a single test project with `poolMatchGlob` and `typecheck.enabled`.
834
- * @experimental In Vitest 4, the project will only support a single pool and this property will be removed.
800
+ * Checks if the suite has any failed tests.
801
+ * This will also return `false` if suite failed during collection.
835
802
  */
836
- readonly pool: Pool;
803
+ ok: () => boolean;
837
804
  /**
838
- * Line numbers of the test locations to run.
805
+ * The meta information attached to the suite during its collection or execution.
839
806
  */
840
- readonly testLines: number[] | undefined;
841
- constructor(project: TestProject, moduleId: string, pool: Pool, testLines?: number[] | undefined);
807
+ meta: () => TaskMeta;
842
808
  /**
843
- * Test module associated with the specification.
809
+ * Checks the running state of the suite.
844
810
  */
845
- get testModule(): TestModule | undefined;
846
- toJSON(): SerializedTestSpecification;
811
+ state(): TestSuiteState;
847
812
  /**
848
- * for backwards compatibility
849
- * @deprecated
813
+ * Full name of the suite including all parent suites separated with `>`.
850
814
  */
851
- [Symbol.iterator](): Generator<string | TestProject, void, unknown>;
815
+ get fullName(): string;
852
816
  }
853
-
854
- declare class TestProject {
855
- /** @deprecated */
856
- path: string | number;
857
- options?: InitializeProjectOptions | undefined;
817
+ declare class TestModule extends SuiteImplementation {
818
+ readonly location: undefined;
819
+ readonly type = "module";
858
820
  /**
859
- * The global Vitest instance.
860
- * @experimental The public Vitest API is experimental and does not follow semver.
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.
861
824
  */
862
- readonly vitest: Vitest;
825
+ readonly moduleId: string;
863
826
  /**
864
- * Resolved global configuration. If there are no workspace projects, this will be the same as `config`.
827
+ * Module id relative to the project. This is the same as `task.name`.
865
828
  */
866
- readonly globalConfig: ResolvedConfig;
829
+ readonly relativeModuleId: string;
867
830
  /**
868
- * Browser instance if the browser is enabled. This is initialized when the tests run for the first time.
831
+ * Checks the running state of the test file.
869
832
  */
870
- browser?: ProjectBrowser;
871
- /** @deprecated use `vitest` instead */
872
- ctx: Vitest;
833
+ state(): TestModuleState;
873
834
  /**
874
- * Temporary directory for the project. This is unique for each project. Vitest stores transformed content here.
835
+ * Checks if the module has any failed tests.
836
+ * This will also return `false` if module failed during collection.
875
837
  */
876
- readonly tmpDir: string;
877
- private runner;
878
- private closingPromise;
879
- private testFilesList;
880
- private typecheckFilesList;
881
- private _globalSetups?;
882
- private _provided;
883
- constructor(path: string | number, vitest: Vitest, options?: InitializeProjectOptions | undefined);
838
+ ok: () => boolean;
884
839
  /**
885
- * The unique hash of this project. This value is consistent between the reruns.
886
- *
887
- * It is based on the root of the project (not consistent between OS) and its name.
840
+ * The meta information attached to the module during its collection or execution.
888
841
  */
889
- get hash(): string;
890
- // "provide" is a property, not a method to keep the context when destructed in the global setup,
891
- // making it a method would be a breaking change, and can be done in Vitest 3 at minimum
842
+ meta: () => TaskMeta;
892
843
  /**
893
- * Provide a value to the test context. This value will be available to all tests with `inject`.
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`.
894
846
  */
895
- provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
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 {
896
863
  /**
897
- * Get the provided context. The project context is merged with the global context.
864
+ * The test was collected, but didn't finish running yet.
898
865
  */
899
- getProvidedContext(): ProvidedContext;
866
+ readonly state: "pending";
900
867
  /**
901
- * Creates a new test specification. Specifications describe how to run tests.
902
- * @param moduleId The file path
868
+ * Pending tests have no errors.
903
869
  */
904
- createSpecification(moduleId: string, locations?: number[] | undefined, pool?: string): TestSpecification;
905
- toJSON(): SerializedTestProject;
870
+ readonly errors: undefined;
871
+ }
872
+ interface TestResultPassed {
906
873
  /**
907
- * Vite's dev server instance. Every workspace project has its own server.
874
+ * The test passed successfully.
908
875
  */
909
- get vite(): ViteDevServer;
876
+ readonly state: "passed";
910
877
  /**
911
- * Resolved project configuration.
878
+ * Errors that were thrown during the test execution.
879
+ *
880
+ * **Note**: If test was retried successfully, errors will still be reported.
912
881
  */
913
- get config(): ResolvedConfig;
882
+ readonly errors: ReadonlyArray<TestError> | undefined;
883
+ }
884
+ interface TestResultFailed {
914
885
  /**
915
- * The name of the project or an empty string if not set.
886
+ * The test failed to execute.
916
887
  */
917
- get name(): string;
888
+ readonly state: "failed";
918
889
  /**
919
- * The color used when reporting tasks of this project.
890
+ * Errors that were thrown during the test execution.
920
891
  */
921
- get color(): ProjectName["color"];
892
+ readonly errors: ReadonlyArray<TestError>;
893
+ }
894
+ interface TestResultSkipped {
922
895
  /**
923
- * Serialized project configuration. This is the config that tests receive.
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.
924
898
  */
925
- get serializedConfig(): SerializedConfig;
926
- /** @deprecated use `vite` instead */
927
- get server(): ViteDevServer;
899
+ readonly state: "skipped";
928
900
  /**
929
- * Check if this is the root project. The root project is the one that has the root config.
901
+ * Skipped tests have no errors.
930
902
  */
931
- isRootProject(): boolean;
932
- /** @deprecated use `isRootProject` instead */
933
- isCore(): boolean;
934
- /** @deprecated use `createSpecification` instead */
935
- createSpec(moduleId: string, pool: string): WorkspaceSpec;
936
- /** @deprecated */
937
- initializeGlobalSetup(): Promise<void>;
938
- onTestsRerun(cb: OnTestsRerunHandler): void;
939
- /** @deprecated */
940
- teardownGlobalSetup(): Promise<void>;
941
- /** @deprecated use `vitest.logger` instead */
942
- get logger(): Logger;
943
- // it's possible that file path was imported with different queries (?raw, ?url, etc)
944
- /** @deprecated use `.vite` or `.browser.vite` directly */
945
- getModulesByFilepath(file: string): Set<ModuleNode>;
946
- /** @deprecated use `.vite` or `.browser.vite` directly */
947
- getModuleById(id: string): ModuleNode | undefined;
948
- /** @deprecated use `.vite` or `.browser.vite` directly */
949
- getSourceMapModuleById(id: string): TransformResult$1["map"] | undefined;
950
- /** @deprecated use `vitest.reporters` instead */
951
- get reporters(): Reporter[];
903
+ readonly errors: undefined;
952
904
  /**
953
- * Get all files in the project that match the globs in the config and the filters.
954
- * @param filters String filters to match the test files.
905
+ * A custom note passed down to `ctx.skip(note)`.
955
906
  */
956
- globTestFiles(filters?: string[]): Promise<{
957
- /**
958
- * Test files that match the filters.
959
- */
960
- testFiles: string[]
961
- /**
962
- * Typecheck test files that match the filters. This will be empty unless `typecheck.enabled` is `true`.
963
- */
964
- typecheckTestFiles: string[]
965
- }>;
966
- private globAllTestFiles;
967
- isBrowserEnabled(): boolean;
968
- private markTestFile;
969
- /** @deprecated use `serializedConfig` instead */
970
- getSerializableConfig(): SerializedConfig;
907
+ readonly note: string | undefined;
908
+ }
909
+ interface TestDiagnostic {
971
910
  /**
972
- * Test if a file matches the test globs. This does the actual glob matching if the test is not cached, unlike `isCachedTestFile`.
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
+
978
+ interface CoverageSummaryData {
979
+ lines: Totals;
980
+ statements: Totals;
981
+ branches: Totals;
982
+ functions: Totals;
983
+ }
984
+
985
+ declare class CoverageSummary {
986
+ constructor(data: CoverageSummary | CoverageSummaryData);
987
+ merge(obj: CoverageSummary): CoverageSummary;
988
+ toJSON(): CoverageSummaryData;
989
+ isEmpty(): boolean;
990
+ data: CoverageSummaryData;
991
+ lines: Totals;
992
+ statements: Totals;
993
+ branches: Totals;
994
+ functions: Totals;
995
+ }
996
+
997
+ interface CoverageMapData {
998
+ [key: string]: FileCoverage | FileCoverageData;
999
+ }
1000
+
1001
+ declare class CoverageMap {
1002
+ constructor(data: CoverageMapData | CoverageMap);
1003
+ addFileCoverage(pathOrObject: string | FileCoverage | FileCoverageData): void;
1004
+ files(): string[];
1005
+ fileCoverageFor(filename: string): FileCoverage;
1006
+ filter(callback: (key: string) => boolean): void;
1007
+ getCoverageSummary(): CoverageSummary;
1008
+ merge(data: CoverageMapData | CoverageMap): void;
1009
+ toJSON(): CoverageMapData;
1010
+ data: CoverageMapData;
1011
+ }
1012
+
1013
+ interface Location {
1014
+ line: number;
1015
+ column: number;
1016
+ }
1017
+
1018
+ interface Range {
1019
+ start: Location;
1020
+ end: Location;
1021
+ }
1022
+
1023
+ interface BranchMapping {
1024
+ loc: Range;
1025
+ type: string;
1026
+ locations: Range[];
1027
+ line: number;
1028
+ }
1029
+
1030
+ interface FunctionMapping {
1031
+ name: string;
1032
+ decl: Range;
1033
+ loc: Range;
1034
+ line: number;
1035
+ }
1036
+
1037
+ interface FileCoverageData {
1038
+ path: string;
1039
+ statementMap: { [key: string]: Range };
1040
+ fnMap: { [key: string]: FunctionMapping };
1041
+ branchMap: { [key: string]: BranchMapping };
1042
+ s: { [key: string]: number };
1043
+ f: { [key: string]: number };
1044
+ b: { [key: string]: number[] };
1045
+ }
1046
+
1047
+ interface Totals {
1048
+ total: number;
1049
+ covered: number;
1050
+ skipped: number;
1051
+ pct: number;
1052
+ }
1053
+
1054
+ interface Coverage {
1055
+ covered: number;
1056
+ total: number;
1057
+ coverage: number;
1058
+ }
1059
+
1060
+ declare class FileCoverage implements FileCoverageData {
1061
+ constructor(data: string | FileCoverage | FileCoverageData);
1062
+ merge(other: FileCoverageData): void;
1063
+ getBranchCoverageByLine(): { [line: number]: Coverage };
1064
+ getLineCoverage(): { [line: number]: number };
1065
+ getUncoveredLines(): number[];
1066
+ resetHits(): void;
1067
+ computeBranchTotals(): Totals;
1068
+ computeSimpleTotals(): Totals;
1069
+ toSummary(): CoverageSummary;
1070
+ toJSON(): object;
1071
+
1072
+ data: FileCoverageData;
1073
+ path: string;
1074
+ statementMap: { [key: string]: Range };
1075
+ fnMap: { [key: string]: FunctionMapping };
1076
+ branchMap: { [key: string]: BranchMapping };
1077
+ s: { [key: string]: number };
1078
+ f: { [key: string]: number };
1079
+ b: { [key: string]: number[] };
1080
+ }
1081
+
1082
+ interface Node {
1083
+ isRoot(): boolean;
1084
+ visit(visitor: Visitor, state: any): void;
1085
+ }
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;
1093
+ }
1094
+
1095
+ interface FileOptions {
1096
+ file: string;
1097
+ }
1098
+
1099
+ interface ProjectOptions {
1100
+ projectRoot: string;
1101
+ }
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;
1117
+ }
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;
1131
+ }
1132
+
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;
1141
+ }
1142
+
1143
+ interface TextOptions extends FileOptions {
1144
+ maxCols: number;
1145
+ skipEmpty: boolean;
1146
+ skipFull: boolean;
1147
+ }
1148
+ type TextLcovOptions = ProjectOptions;
1149
+ type TextSummaryOptions = FileOptions;
1150
+
1151
+ interface LinkMapper {
1152
+ getPath(node: string | Node): string;
1153
+ relativePath(source: string | Node, target: string | Node): string;
1154
+ assetPath(node: Node, name: string): string;
1155
+ }
1156
+
1157
+ type TransformResult = string | Partial<TransformResult$1> | undefined | null | void;
1158
+ type CoverageResults = unknown;
1159
+ interface CoverageProvider {
1160
+ name: string;
1161
+ /** Called when provider is being initialized before tests run */
1162
+ initialize: (ctx: Vitest) => Promise<void> | void;
1163
+ /** Called when setting coverage options for Vitest context (`ctx.config.coverage`) */
1164
+ resolveOptions: () => ResolvedCoverageOptions;
1165
+ /** Callback to clean previous reports */
1166
+ clean: (clean?: boolean) => void | Promise<void>;
1167
+ /** Called with coverage results after a single test file has been run */
1168
+ onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void | Promise<void>;
1169
+ /** Callback called when test run fails */
1170
+ onTestFailure?: () => void | Promise<void>;
1171
+ /** Callback to generate final coverage results */
1172
+ generateCoverage: (reportContext: ReportContext) => CoverageResults | Promise<CoverageResults>;
1173
+ /** Callback to convert coverage results to coverage reports. Called with results returned from `generateCoverage` */
1174
+ reportCoverage: (coverage: CoverageResults, reportContext: ReportContext) => void | Promise<void>;
1175
+ /** Callback for `--merge-reports` options. Called with multiple coverage results generated by `generateCoverage`. */
1176
+ mergeReports?: (coverages: CoverageResults[]) => void | Promise<void>;
1177
+ /** Callback called for instrumenting files with coverage counters. */
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>;
1181
+ }
1182
+ interface ReportContext {
1183
+ /** Indicates whether all tests were run. False when only specific tests were run. */
1184
+ allTestsRun?: boolean;
1185
+ }
1186
+ interface CoverageProviderModule extends RuntimeCoverageProviderModule {
1187
+ /**
1188
+ * Factory for creating a new coverage provider
1189
+ */
1190
+ getProvider: () => CoverageProvider | Promise<CoverageProvider>;
1191
+ }
1192
+ type CoverageReporter = keyof ReportOptions | (string & {});
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>];
1194
+ type CoverageProviderName = "v8" | "istanbul" | "custom" | undefined;
1195
+ type CoverageOptions<T extends CoverageProviderName = CoverageProviderName> = T extends "istanbul" ? {
1196
+ provider: T;
1197
+ } & CoverageIstanbulOptions : T extends "v8" ? {
1198
+ /**
1199
+ * Provider to use for coverage collection.
1200
+ *
1201
+ * @default 'v8'
1202
+ */
1203
+ provider: T;
1204
+ } & CoverageV8Options : T extends "custom" ? {
1205
+ provider: T;
1206
+ } & CustomProviderOptions : {
1207
+ provider?: T;
1208
+ } & CoverageV8Options;
1209
+ /** Fields that have default values. Internally these will always be defined. */
1210
+ type FieldsWithDefaultValues = "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "exclude" | "reportOnFailure" | "allowExternal" | "processingConcurrency";
1211
+ type ResolvedCoverageOptions<T extends CoverageProviderName = CoverageProviderName> = CoverageOptions<T> & Required<Pick<CoverageOptions<T>, FieldsWithDefaultValues>> & {
1212
+ reporter: CoverageReporterWithOptions[];
1213
+ };
1214
+ interface BaseCoverageOptions {
1215
+ /**
1216
+ * Enables coverage collection. Can be overridden using `--coverage` CLI option.
1217
+ *
1218
+ * @default false
1219
+ */
1220
+ enabled?: boolean;
1221
+ /**
1222
+ * List of files included in coverage as glob patterns.
1223
+ * By default only files covered by tests are included.
1224
+ *
1225
+ * See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
1226
+ */
1227
+ include?: string[];
1228
+ /**
1229
+ * List of files excluded from coverage as glob patterns.
1230
+ * Files are first checked against `coverage.include`.
1231
+ *
1232
+ * See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
1233
+ */
1234
+ exclude?: string[];
1235
+ /**
1236
+ * Clean coverage results before running tests
1237
+ *
1238
+ * @default true
1239
+ */
1240
+ clean?: boolean;
1241
+ /**
1242
+ * Clean coverage report on watch rerun
1243
+ *
1244
+ * @default true
1245
+ */
1246
+ cleanOnRerun?: boolean;
1247
+ /**
1248
+ * Directory to write coverage report to
1249
+ *
1250
+ * @default './coverage'
1251
+ */
1252
+ reportsDirectory?: string;
1253
+ /**
1254
+ * Coverage reporters to use.
1255
+ * See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters.
1256
+ *
1257
+ * @default ['text', 'html', 'clover', 'json']
1258
+ */
1259
+ reporter?: Arrayable<CoverageReporter> | (CoverageReporter | [CoverageReporter] | CoverageReporterWithOptions)[];
1260
+ /**
1261
+ * Do not show files with 100% statement, branch, and function coverage
1262
+ *
1263
+ * @default false
1264
+ */
1265
+ skipFull?: boolean;
1266
+ /**
1267
+ * Configurations for thresholds
1268
+ *
1269
+ * @example
1270
+ *
1271
+ * ```ts
1272
+ * {
1273
+ * // Thresholds for all files
1274
+ * functions: 95,
1275
+ * branches: 70,
1276
+ * perFile: true,
1277
+ * autoUpdate: true,
1278
+ *
1279
+ * // Thresholds for utilities
1280
+ * 'src/utils/**.ts': {
1281
+ * lines: 100,
1282
+ * statements: 95,
1283
+ * }
1284
+ * }
1285
+ * ```
1286
+ */
1287
+ thresholds?: Thresholds | ({
1288
+ [glob: string]: Pick<Thresholds, 100 | "statements" | "functions" | "branches" | "lines">;
1289
+ } & Thresholds);
1290
+ /**
1291
+ * Watermarks for statements, lines, branches and functions.
1292
+ *
1293
+ * Default value is `[50,80]` for each property.
1294
+ */
1295
+ watermarks?: {
1296
+ statements?: [number, number];
1297
+ functions?: [number, number];
1298
+ branches?: [number, number];
1299
+ lines?: [number, number];
1300
+ };
1301
+ /**
1302
+ * Generate coverage report even when tests fail.
1303
+ *
1304
+ * @default false
1305
+ */
1306
+ reportOnFailure?: boolean;
1307
+ /**
1308
+ * Collect coverage of files outside the project `root`.
1309
+ *
1310
+ * @default false
1311
+ */
1312
+ allowExternal?: boolean;
1313
+ /**
1314
+ * Apply exclusions again after coverage has been remapped to original sources.
1315
+ * This is useful when your source files are transpiled and may contain source maps
1316
+ * of non-source files.
1317
+ *
1318
+ * Use this option when you are seeing files that show up in report even if they
1319
+ * match your `coverage.exclude` patterns.
1320
+ *
1321
+ * @default false
973
1322
  */
974
- matchesTestGlob(moduleId: string, source?: () => string): boolean;
975
- /** @deprecated use `matchesTestGlob` instead */
976
- isTargetFile(id: string, source?: string): Promise<boolean>;
977
- private isInSourceTestCode;
978
- private filterFiles;
979
- private _parentBrowser?;
1323
+ excludeAfterRemap?: boolean;
980
1324
  /**
981
- * Closes the project and all associated resources. This can only be called once; the closing promise is cached until the server restarts.
982
- * If the resources are needed again, create a new project.
1325
+ * Concurrency limit used when processing the coverage results.
1326
+ * Defaults to `Math.min(20, os.availableParallelism?.() ?? os.cpus().length)`
983
1327
  */
984
- close(): Promise<void>;
1328
+ processingConcurrency?: number;
985
1329
  /**
986
- * Import a file using Vite module runner.
987
- * @param moduleId The ID of the module in Vite module graph
1330
+ * Set to array of class method names to ignore for coverage
1331
+ *
1332
+ * @default []
988
1333
  */
989
- import<T>(moduleId: string): Promise<T>;
990
- /** @deprecated use `name` instead */
991
- getName(): string;
992
- /** @deprecated internal */
993
- setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
994
- private _setHash;
995
- private _serializeOverriddenConfig;
996
- private clearTmpDir;
997
- /** @deprecated */
998
- initBrowserProvider(): Promise<void>;
999
- }
1000
-
1001
- interface SerializedTestProject {
1002
- name: string;
1003
- serializedConfig: SerializedConfig;
1004
- context: ProvidedContext;
1334
+ ignoreClassMethods?: string[];
1005
1335
  }
1006
- interface InitializeProjectOptions extends TestProjectInlineConfiguration {
1007
- configFile: string | false;
1336
+ interface CoverageIstanbulOptions extends BaseCoverageOptions {}
1337
+ interface CoverageV8Options extends BaseCoverageOptions {}
1338
+ interface CustomProviderOptions extends Pick<BaseCoverageOptions, FieldsWithDefaultValues> {
1339
+ /** Name of the module or path to a file to load the custom provider from */
1340
+ customProviderModule: string;
1008
1341
  }
1009
-
1010
- /**
1011
- * @deprecated use TestSpecification instead
1012
- */
1013
- type WorkspaceSpec = TestSpecification & [project: TestProject, file: string, options: {
1014
- pool: Pool
1015
- }];
1016
- type RunWithFiles = (files: TestSpecification[], invalidates?: string[]) => Awaitable<void>;
1017
- interface ProcessPool {
1018
- name: string;
1019
- runTests: RunWithFiles;
1020
- collectTests: RunWithFiles;
1021
- close?: () => Awaitable<void>;
1342
+ interface Thresholds {
1343
+ /** Set global thresholds to `100` */
1344
+ 100?: boolean;
1345
+ /** Check thresholds per file. */
1346
+ perFile?: boolean;
1347
+ /**
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
1350
+ *
1351
+ * @default false
1352
+ */
1353
+ autoUpdate?: boolean | ((newThreshold: number) => number);
1354
+ /** Thresholds for statements */
1355
+ statements?: number;
1356
+ /** Thresholds for functions */
1357
+ functions?: number;
1358
+ /** Thresholds for branches */
1359
+ branches?: number;
1360
+ /** Thresholds for lines */
1361
+ lines?: number;
1022
1362
  }
1023
- declare function getFilePoolName(project: TestProject, file: string): Pool;
1024
1363
 
1025
1364
  interface TestRunResult {
1026
1365
  testModules: TestModule[];
@@ -1062,14 +1401,61 @@ declare class VitestCache {
1062
1401
  constructor(version: string);
1063
1402
  getFileTestResults(key: string): SuiteResultCache | undefined;
1064
1403
  getFileStats(key: string): {
1065
- size: number
1404
+ size: number;
1066
1405
  } | undefined;
1067
1406
  static resolveCacheDir(root: string, dir?: string, projectName?: string): string;
1068
1407
  }
1069
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
+
1070
1456
  declare class VitestPackageInstaller {
1071
1457
  isPackageExists(name: string, options?: {
1072
- paths?: string[]
1458
+ paths?: string[];
1073
1459
  }): boolean;
1074
1460
  ensureInstalled(dependency: string, root: string, version?: string): Promise<boolean>;
1075
1461
  }
@@ -1081,9 +1467,11 @@ declare class BlobReporter implements Reporter {
1081
1467
  start: number;
1082
1468
  ctx: Vitest;
1083
1469
  options: BlobOptions;
1470
+ coverage: unknown | undefined;
1084
1471
  constructor(options: BlobOptions);
1085
1472
  onInit(ctx: Vitest): void;
1086
- onFinished(files: File[] | undefined, errors: unknown[] | undefined, coverage: unknown): Promise<void>;
1473
+ onCoverage(coverage: unknown): void;
1474
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): Promise<void>;
1087
1475
  }
1088
1476
  interface MergedBlobs {
1089
1477
  files: File[];
@@ -1101,7 +1489,12 @@ declare class StateManager {
1101
1489
  processTimeoutCauses: Set<string>;
1102
1490
  reportedTasksMap: WeakMap<Task, TestModule | TestCase | TestSuite>;
1103
1491
  blobs?: MergedBlobs;
1104
- catchError(err: unknown, type: string): void;
1492
+ transformTime: number;
1493
+ onUnhandledError?: OnUnhandledErrorCallback;
1494
+ constructor(options: {
1495
+ onUnhandledError?: OnUnhandledErrorCallback;
1496
+ });
1497
+ catchError(error: unknown, type: string): void;
1105
1498
  clearErrors(): void;
1106
1499
  getUnhandledErrors(): unknown[];
1107
1500
  addProcessTimeoutCause(cause: string): void;
@@ -1125,6 +1518,36 @@ declare class StateManager {
1125
1518
  cancelFiles(files: string[], project: TestProject): void;
1126
1519
  }
1127
1520
 
1521
+ declare class VitestWatcher {
1522
+ private vitest;
1523
+ /**
1524
+ * Modules that will be invalidated on the next run.
1525
+ */
1526
+ readonly invalidates: Set<string>;
1527
+ /**
1528
+ * Test files that have changed and need to be rerun.
1529
+ */
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;
1541
+ /**
1542
+ * @returns A value indicating whether rerun is needed (changedTests was mutated)
1543
+ */
1544
+ private handleFileChanged;
1545
+ }
1546
+ interface WatcherTriggerPattern {
1547
+ pattern: RegExp;
1548
+ testsToRun: (file: string, match: RegExpMatchArray) => string[] | string | null | undefined | void;
1549
+ }
1550
+
1128
1551
  interface VitestOptions {
1129
1552
  packageInstaller?: VitestPackageInstaller;
1130
1553
  stdin?: NodeJS.ReadStream;
@@ -1163,17 +1586,24 @@ declare class Vitest {
1163
1586
  * If projects were filtered with `--project` flag, they won't appear here.
1164
1587
  */
1165
1588
  projects: TestProject[];
1589
+ /**
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.
1595
+ */
1596
+ readonly watcher: VitestWatcher;
1166
1597
  private isFirstRun;
1167
1598
  private restartsCount;
1168
1599
  private readonly specifications;
1169
- private readonly watcher;
1170
1600
  private pool;
1171
1601
  private _config?;
1172
1602
  private _vite?;
1173
1603
  private _state?;
1174
1604
  private _cache?;
1175
1605
  private _snapshot?;
1176
- private _workspaceConfigPath?;
1606
+ private _coverageProvider?;
1177
1607
  constructor(mode: VitestRunMode, cliOptions: UserConfig, options?: VitestOptions);
1178
1608
  private _onRestartListeners;
1179
1609
  private _onClose;
@@ -1181,16 +1611,10 @@ declare class Vitest {
1181
1611
  private _onCancelListeners;
1182
1612
  private _onUserTestsRerun;
1183
1613
  private _onFilterWatchedSpecification;
1184
- /** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
1185
- get invalidates(): Set<string>;
1186
- /** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
1187
- get changedTests(): Set<string>;
1188
1614
  /**
1189
1615
  * The global config.
1190
1616
  */
1191
1617
  get config(): ResolvedConfig;
1192
- /** @deprecated use `vitest.vite` instead */
1193
- get server(): ViteDevServer;
1194
1618
  /**
1195
1619
  * Global Vite's dev server instance.
1196
1620
  */
@@ -1208,8 +1632,9 @@ declare class Vitest {
1208
1632
  * Test results and test file stats cache. Primarily used by the sequencer to sort tests.
1209
1633
  */
1210
1634
  get cache(): VitestCache;
1211
- /** @deprecated internal */
1212
- setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
1635
+ enableCoverage(): Promise<void>;
1636
+ disableCoverage(): void;
1637
+ private _coverageOverrideCache;
1213
1638
  /**
1214
1639
  * Inject new test projects into the workspace.
1215
1640
  * @param config Glob, config path or a custom config options.
@@ -1224,23 +1649,20 @@ declare class Vitest {
1224
1649
  * Get global provided context.
1225
1650
  */
1226
1651
  getProvidedContext(): ProvidedContext;
1227
- /** @deprecated use `getRootProject` instead */
1228
- getCoreWorkspaceProject(): TestProject;
1229
1652
  /**
1230
1653
  * Return project that has the root (or "global") config.
1231
1654
  */
1232
1655
  getRootProject(): TestProject;
1233
- /**
1234
- * @deprecated use Reported Task API instead
1235
- */
1236
- getProjectByTaskId(taskId: string): TestProject;
1237
1656
  getProjectByName(name: string): TestProject;
1238
1657
  /**
1239
1658
  * Import a file using Vite module runner. The file will be transformed by Vite and executed in a separate context.
1240
1659
  * @param moduleId The ID of the module in Vite module graph
1241
1660
  */
1242
1661
  import<T>(moduleId: string): Promise<T>;
1243
- private resolveWorkspaceConfigPath;
1662
+ /**
1663
+ * Creates a coverage provider if `coverage` is enabled in the config.
1664
+ */
1665
+ createCoverageProvider(): Promise<CoverageProvider | null>;
1244
1666
  private resolveProjects;
1245
1667
  /**
1246
1668
  * Glob test files in every project and create a TestSpecification for each file and pool.
@@ -1253,8 +1675,6 @@ declare class Vitest {
1253
1675
  */
1254
1676
  mergeReports(directory?: string): Promise<TestRunResult>;
1255
1677
  collect(filters?: string[]): Promise<TestRunResult>;
1256
- /** @deprecated use `getRelevantTestSpecifications` instead */
1257
- listFiles(filters?: string[]): Promise<TestSpecification[]>;
1258
1678
  /**
1259
1679
  * Returns the list of test files that match the config and filters.
1260
1680
  * @param filters String filters to match the test files
@@ -1275,11 +1695,10 @@ declare class Vitest {
1275
1695
  */
1276
1696
  init(): Promise<void>;
1277
1697
  /**
1278
- * @deprecated remove when vscode extension supports "getModuleSpecifications"
1698
+ * If there is a test run happening, returns a promise that will
1699
+ * resolve when the test run is finished.
1279
1700
  */
1280
- getProjectsByTestFile(file: string): WorkspaceSpec[];
1281
- /** @deprecated */
1282
- getFileWorkspaceSpecs(file: string): WorkspaceSpec[];
1701
+ waitForTestRunEnd(): Promise<void>;
1283
1702
  /**
1284
1703
  * Get test specifications associated with the given module. If module is not a test file, an empty array is returned.
1285
1704
  *
@@ -1304,6 +1723,11 @@ declare class Vitest {
1304
1723
  */
1305
1724
  rerunTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
1306
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>;
1307
1731
  /**
1308
1732
  * Collect tests in specified modules. Vitest will run the files to collect tests.
1309
1733
  * @param specifications A list of specifications to run.
@@ -1337,18 +1761,19 @@ declare class Vitest {
1337
1761
  */
1338
1762
  setGlobalTestNamePattern(pattern: string | RegExp): void;
1339
1763
  /**
1764
+ * Returns the regexp used for the global test name pattern.
1765
+ */
1766
+ getGlobalTestNamePattern(): RegExp | undefined;
1767
+ /**
1340
1768
  * Resets the global test name pattern. This method doesn't run any tests.
1341
1769
  */
1342
1770
  resetGlobalTestNamePattern(): void;
1343
1771
  private _rerunTimer;
1344
- // we can't use a single `triggerId` yet because vscode extension relies on this
1345
1772
  private scheduleRerun;
1346
1773
  /**
1347
1774
  * Invalidate a file in all projects.
1348
1775
  */
1349
1776
  invalidateFile(filepath: string): void;
1350
- /** @deprecated use `invalidateFile` */
1351
- updateLastChanged(filepath: string): void;
1352
1777
  private reportCoverage;
1353
1778
  /**
1354
1779
  * Closes all projects and their associated resources.
@@ -1361,16 +1786,6 @@ declare class Vitest {
1361
1786
  */
1362
1787
  exit(force?: boolean): Promise<void>;
1363
1788
  /**
1364
- * @deprecated use `globTestSpecifications` instead
1365
- */
1366
- globTestSpecs(filters?: string[]): Promise<TestSpecification[]>;
1367
- /**
1368
- * @deprecated use `globTestSpecifications` instead
1369
- */
1370
- globTestFiles(filters?: string[]): Promise<TestSpecification[]>;
1371
- /** @deprecated filter by `this.projects` yourself */
1372
- getModuleProjects(filepath: string): TestProject[];
1373
- /**
1374
1789
  * Should the server be kept running after the tests are done.
1375
1790
  */
1376
1791
  shouldKeepServer(): boolean;
@@ -1415,26 +1830,6 @@ interface Reporter {
1415
1830
  * @experimental
1416
1831
  */
1417
1832
  onBrowserInit?: (project: TestProject) => Awaitable$1<void>;
1418
- /**
1419
- * @deprecated use `onTestRunStart` instead
1420
- */
1421
- onPathsCollected?: (paths?: string[]) => Awaitable$1<void>;
1422
- /**
1423
- * @deprecated use `onTestRunStart` instead
1424
- */
1425
- onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable$1<void>;
1426
- /**
1427
- * @deprecated use `onTestModuleCollected` instead
1428
- */
1429
- onCollected?: (files: File[]) => Awaitable$1<void>;
1430
- /**
1431
- * @deprecated use `onTestRunEnd` instead
1432
- */
1433
- onFinished?: (files: File[], errors: unknown[], coverage?: unknown) => Awaitable$1<void>;
1434
- /**
1435
- * @deprecated use `onTestModuleQueued`, `onTestModuleStart`, `onTestModuleEnd`, `onTestCaseReady`, `onTestCaseResult` instead
1436
- */
1437
- onTaskUpdate?: (packs: TaskResultPack[], events: TaskEventPack[]) => Awaitable$1<void>;
1438
1833
  onTestRemoved?: (trigger?: string) => Awaitable$1<void>;
1439
1834
  onWatcherStart?: (files?: File[], errors?: unknown[]) => Awaitable$1<void>;
1440
1835
  onWatcherRerun?: (files: string[], trigger?: string) => Awaitable$1<void>;
@@ -1510,173 +1905,68 @@ declare abstract class BaseReporter implements Reporter {
1510
1905
  failedUnwatchedFiles: TestModule[];
1511
1906
  isTTY: boolean;
1512
1907
  ctx: Vitest;
1513
- renderSucceed: boolean;
1514
- protected verbose: boolean;
1515
- private _filesInWatchMode;
1516
- private _timeStart;
1517
- constructor(options?: BaseOptions);
1518
- onInit(ctx: Vitest): void;
1519
- log(...messages: any): void;
1520
- error(...messages: any): void;
1521
- relative(path: string): string;
1522
- onFinished(files?: File[], errors?: unknown[]): void;
1523
- onTestCaseResult(testCase: TestCase): void;
1524
- onTestSuiteResult(testSuite: TestSuite): void;
1525
- onTestModuleEnd(testModule: TestModule): void;
1526
- private logFailedTask;
1527
- protected printTestModule(testModule: TestModule): void;
1528
- protected printTestCase(moduleState: TestModuleState, test: TestCase): void;
1529
- private getModuleLog;
1530
- protected printTestSuite(_suite: TestSuite): void;
1531
- protected getTestName(test: Task, separator?: string): string;
1532
- protected getFullName(test: Task, separator?: string): string;
1533
- protected formatShortError(error: TestError): string;
1534
- protected getTestIndentation(_test: Task): string;
1535
- protected printAnnotations(test: TestCase, console: "log" | "error", padding?: number): void;
1536
- protected getDurationPrefix(task: Task): string;
1537
- onWatcherStart(files?: File[], errors?: unknown[]): void;
1538
- onWatcherRerun(files: string[], trigger?: string): void;
1539
- onUserConsoleLog(log: UserConsoleLog, taskState?: TestResult["state"]): void;
1540
- onTestRemoved(trigger?: string): void;
1541
- shouldLog(log: UserConsoleLog, taskState?: TestResult["state"]): boolean;
1542
- onServerRestart(reason?: string): void;
1543
- reportSummary(files: File[], errors: unknown[]): void;
1544
- reportTestSummary(files: File[], errors: unknown[]): void;
1545
- private printErrorsSummary;
1546
- reportBenchmarkSummary(files: File[]): void;
1547
- private printTaskErrors;
1548
- }
1549
-
1550
- interface DefaultReporterOptions extends BaseOptions {
1551
- summary?: boolean;
1552
- }
1553
- declare class DefaultReporter extends BaseReporter {
1554
- private options;
1555
- private summary?;
1556
- constructor(options?: DefaultReporterOptions);
1557
- onTestRunStart(specifications: ReadonlyArray<TestSpecification>): void;
1558
- onTestModuleQueued(file: TestModule): void;
1559
- onTestModuleCollected(module: TestModule): void;
1560
- onTestModuleEnd(module: TestModule): void;
1561
- onTestCaseReady(test: TestCase): void;
1562
- onTestCaseResult(test: TestCase): void;
1563
- onHookStart(hook: ReportedHookContext): void;
1564
- onHookEnd(hook: ReportedHookContext): void;
1565
- onInit(ctx: Vitest): void;
1566
- onTestRunEnd(): void;
1567
- }
1568
-
1569
- interface HTMLOptions {
1570
- outputFile?: string;
1571
- }
1572
-
1573
- interface CoverageSummaryData {
1574
- lines: Totals;
1575
- statements: Totals;
1576
- branches: Totals;
1577
- functions: Totals;
1578
- }
1579
-
1580
- declare class CoverageSummary {
1581
- constructor(data: CoverageSummary | CoverageSummaryData);
1582
- merge(obj: CoverageSummary): CoverageSummary;
1583
- toJSON(): CoverageSummaryData;
1584
- isEmpty(): boolean;
1585
- data: CoverageSummaryData;
1586
- lines: Totals;
1587
- statements: Totals;
1588
- branches: Totals;
1589
- functions: Totals;
1590
- }
1591
-
1592
- interface CoverageMapData {
1593
- [key: string]: FileCoverage | FileCoverageData;
1594
- }
1595
-
1596
- declare class CoverageMap {
1597
- constructor(data: CoverageMapData | CoverageMap);
1598
- addFileCoverage(pathOrObject: string | FileCoverage | FileCoverageData): void;
1599
- files(): string[];
1600
- fileCoverageFor(filename: string): FileCoverage;
1601
- filter(callback: (key: string) => boolean): void;
1602
- getCoverageSummary(): CoverageSummary;
1603
- merge(data: CoverageMapData | CoverageMap): void;
1604
- toJSON(): CoverageMapData;
1605
- data: CoverageMapData;
1606
- }
1607
-
1608
- interface Location {
1609
- line: number;
1610
- column: number;
1611
- }
1612
-
1613
- interface Range {
1614
- start: Location;
1615
- end: Location;
1616
- }
1617
-
1618
- interface BranchMapping {
1619
- loc: Range;
1620
- type: string;
1621
- locations: Range[];
1622
- line: number;
1623
- }
1624
-
1625
- interface FunctionMapping {
1626
- name: string;
1627
- decl: Range;
1628
- loc: Range;
1629
- line: number;
1630
- }
1631
-
1632
- interface FileCoverageData {
1633
- path: string;
1634
- statementMap: { [key: string]: Range };
1635
- fnMap: { [key: string]: FunctionMapping };
1636
- branchMap: { [key: string]: BranchMapping };
1637
- s: { [key: string]: number };
1638
- f: { [key: string]: number };
1639
- b: { [key: string]: number[] };
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(testSuite: TestSuite): void;
1926
+ protected getTestName(test: Task, _separator?: string): string;
1927
+ protected getFullName(test: Task, separator?: string): string;
1928
+ protected getTestIndentation(test: Task): string;
1929
+ protected printAnnotations(test: TestCase, console: "log" | "error", padding?: number): void;
1930
+ protected getEntityPrefix(entity: TestCase | TestModule | TestSuite): string;
1931
+ protected getTestCaseSuffix(testCase: TestCase): string;
1932
+ protected getStateSymbol(test: TestCase | TestModule | TestSuite): string;
1933
+ private getDurationPrefix;
1934
+ onWatcherStart(files?: File[], errors?: unknown[]): void;
1935
+ onWatcherRerun(files: string[], trigger?: string): void;
1936
+ onUserConsoleLog(log: UserConsoleLog, taskState?: TestResult["state"]): void;
1937
+ onTestRemoved(trigger?: string): void;
1938
+ shouldLog(log: UserConsoleLog, taskState?: TestResult["state"]): boolean;
1939
+ onServerRestart(reason?: string): void;
1940
+ reportSummary(files: File[], errors: unknown[]): void;
1941
+ reportTestSummary(files: File[], errors: unknown[]): void;
1942
+ private printErrorsSummary;
1943
+ reportBenchmarkSummary(files: File[]): void;
1944
+ private printTaskErrors;
1640
1945
  }
1641
1946
 
1642
- interface Totals {
1643
- total: number;
1644
- covered: number;
1645
- skipped: number;
1646
- pct: number;
1947
+ interface DefaultReporterOptions extends BaseOptions {
1948
+ summary?: boolean;
1647
1949
  }
1648
-
1649
- interface Coverage {
1650
- covered: number;
1651
- total: number;
1652
- coverage: number;
1950
+ declare class DefaultReporter extends BaseReporter {
1951
+ private options;
1952
+ private summary?;
1953
+ constructor(options?: DefaultReporterOptions);
1954
+ onTestRunStart(specifications: ReadonlyArray<TestSpecification>): void;
1955
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): void;
1956
+ onTestModuleQueued(file: TestModule): void;
1957
+ onTestModuleCollected(module: TestModule): void;
1958
+ onTestModuleEnd(module: TestModule): void;
1959
+ onTestCaseReady(test: TestCase): void;
1960
+ onTestCaseResult(test: TestCase): void;
1961
+ onHookStart(hook: ReportedHookContext): void;
1962
+ onHookEnd(hook: ReportedHookContext): void;
1963
+ onInit(ctx: Vitest): void;
1653
1964
  }
1654
1965
 
1655
- declare class FileCoverage implements FileCoverageData {
1656
- constructor(data: string | FileCoverage | FileCoverageData);
1657
- merge(other: FileCoverageData): void;
1658
- getBranchCoverageByLine(): { [line: number]: Coverage };
1659
- getLineCoverage(): { [line: number]: number };
1660
- getUncoveredLines(): number[];
1661
- resetHits(): void;
1662
- computeBranchTotals(): Totals;
1663
- computeSimpleTotals(): Totals;
1664
- toSummary(): CoverageSummary;
1665
- toJSON(): object;
1666
-
1667
- data: FileCoverageData;
1668
- path: string;
1669
- statementMap: { [key: string]: Range };
1670
- fnMap: { [key: string]: FunctionMapping };
1671
- branchMap: { [key: string]: BranchMapping };
1672
- s: { [key: string]: number };
1673
- f: { [key: string]: number };
1674
- b: { [key: string]: number[] };
1966
+ interface HTMLOptions {
1967
+ outputFile?: string;
1675
1968
  }
1676
1969
 
1677
- // for compatibility reasons, the reporter produces a JSON similar to the one produced by the Jest JSON reporter
1678
- // the following types are extracted from the Jest repository (and simplified)
1679
- // the commented-out fields are the missing ones
1680
1970
  type Status = "passed" | "failed" | "skipped" | "pending" | "todo" | "disabled";
1681
1971
  type Milliseconds = number;
1682
1972
  interface Callsite {
@@ -1717,17 +2007,18 @@ interface JsonTestResults {
1717
2007
  snapshot: SnapshotSummary;
1718
2008
  coverageMap?: CoverageMap | null | undefined;
1719
2009
  }
1720
- interface JsonOptions$1 {
2010
+ interface JsonOptions {
1721
2011
  outputFile?: string;
1722
2012
  }
1723
2013
  declare class JsonReporter implements Reporter {
1724
2014
  start: number;
1725
2015
  ctx: Vitest;
1726
- options: JsonOptions$1;
1727
- constructor(options: JsonOptions$1);
2016
+ options: JsonOptions;
2017
+ coverageMap?: CoverageMap;
2018
+ constructor(options: JsonOptions);
1728
2019
  onInit(ctx: Vitest): void;
1729
- protected logTasks(files: File[], coverageMap?: CoverageMap | null): Promise<void>;
1730
- onFinished(files?: File[], _errors?: unknown[], coverageMap?: unknown): Promise<void>;
2020
+ onCoverage(coverageMap: unknown): void;
2021
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): Promise<void>;
1731
2022
  /**
1732
2023
  * Writes the report to an output file if specified in the config,
1733
2024
  * or logs it to the console otherwise.
@@ -1742,8 +2033,6 @@ interface ClassnameTemplateVariables {
1742
2033
  }
1743
2034
  interface JUnitOptions {
1744
2035
  outputFile?: string;
1745
- /** @deprecated Use `classnameTemplate` instead. */
1746
- classname?: string;
1747
2036
  /**
1748
2037
  * Template for the classname attribute. Can be either a string or a function. The string can contain placeholders {filename} and {filepath}.
1749
2038
  */
@@ -1773,7 +2062,7 @@ declare class JUnitReporter implements Reporter {
1773
2062
  writeElement(name: string, attrs: Record<string, any>, children: () => Promise<void>): Promise<void>;
1774
2063
  writeLogs(task: Task, type: "err" | "out"): Promise<void>;
1775
2064
  writeTasks(tasks: Task[], filename: string): Promise<void>;
1776
- onFinished(files?: File[]): Promise<void>;
2065
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): Promise<void>;
1777
2066
  }
1778
2067
 
1779
2068
  declare class DotReporter extends BaseReporter {
@@ -1781,10 +2070,9 @@ declare class DotReporter extends BaseReporter {
1781
2070
  private tests;
1782
2071
  private finishedTests;
1783
2072
  onInit(ctx: Vitest): void;
1784
- // Ignore default logging of base reporter
1785
2073
  printTestModule(): void;
1786
2074
  onWatcherRerun(files: string[], trigger?: string): void;
1787
- onFinished(files?: File[], errors?: unknown[]): void;
2075
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): void;
1788
2076
  onTestModuleCollected(module: TestModule): void;
1789
2077
  onTestCaseReady(test: TestCase): void;
1790
2078
  onTestCaseResult(test: TestCase): void;
@@ -1801,7 +2089,7 @@ declare class GithubActionsReporter implements Reporter {
1801
2089
  constructor(options?: GithubActionsReporterOptions);
1802
2090
  onInit(ctx: Vitest): void;
1803
2091
  onTestCaseAnnotate(testCase: TestCase, annotation: TestAnnotation): void;
1804
- onFinished(files?: File[], errors?: unknown[]): void;
2092
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): void;
1805
2093
  }
1806
2094
 
1807
2095
  declare class HangingProcessReporter implements Reporter {
@@ -1817,37 +2105,38 @@ declare class TapReporter implements Reporter {
1817
2105
  static getComment(task: Task): string;
1818
2106
  private logErrorDetails;
1819
2107
  protected logTasks(tasks: Task[]): void;
1820
- onFinished(files?: File[]): void;
2108
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): void;
1821
2109
  }
1822
2110
 
1823
2111
  declare class TapFlatReporter extends TapReporter {
1824
2112
  onInit(ctx: Vitest): void;
1825
- onFinished(files?: File[]): void;
2113
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): void;
2114
+ }
2115
+
2116
+ declare class TreeReporter extends DefaultReporter {
2117
+ protected verbose: boolean;
2118
+ renderSucceed: boolean;
1826
2119
  }
1827
2120
 
1828
2121
  declare class VerboseReporter extends DefaultReporter {
1829
2122
  protected verbose: boolean;
1830
2123
  renderSucceed: boolean;
1831
- printTestModule(module: TestModule): void;
2124
+ printTestModule(_module: TestModule): void;
1832
2125
  onTestCaseResult(test: TestCase): void;
1833
- protected printTestSuite(testSuite: TestSuite): void;
1834
- protected getTestName(test: Task): string;
1835
- protected getTestIndentation(test: Task): string;
1836
- protected formatShortError(): string;
1837
2126
  }
1838
2127
 
1839
2128
  type FormattedBenchmarkResult = BenchmarkResult & {
1840
- id: string
2129
+ id: string;
1841
2130
  };
1842
2131
 
1843
2132
  declare function renderTable(options: {
1844
- tasks: Task[]
1845
- level: number
1846
- shallow?: boolean
1847
- showHeap: boolean
1848
- columns: number
1849
- slowTestThreshold: number
1850
- compare?: Record<Task["id"], FormattedBenchmarkResult>
2133
+ tasks: Task[];
2134
+ level: number;
2135
+ shallow?: boolean;
2136
+ showHeap: boolean;
2137
+ columns: number;
2138
+ slowTestThreshold: number;
2139
+ compare?: Record<Task["id"], FormattedBenchmarkResult>;
1851
2140
  }): string;
1852
2141
 
1853
2142
  declare class BenchmarkReporter extends DefaultReporter {
@@ -1857,7 +2146,7 @@ declare class BenchmarkReporter extends DefaultReporter {
1857
2146
  onTestSuiteResult(testSuite: TestSuite): void;
1858
2147
  protected printTestModule(testModule: TestModule): void;
1859
2148
  private printSuiteTable;
1860
- onFinished(files?: File[], errors?: unknown[]): Promise<void>;
2149
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): Promise<void>;
1861
2150
  }
1862
2151
 
1863
2152
  declare class VerboseBenchmarkReporter extends BenchmarkReporter {
@@ -1865,380 +2154,97 @@ declare class VerboseBenchmarkReporter extends BenchmarkReporter {
1865
2154
  }
1866
2155
 
1867
2156
  declare const BenchmarkReportsMap: {
1868
- default: typeof BenchmarkReporter
1869
- verbose: typeof VerboseBenchmarkReporter
2157
+ default: typeof BenchmarkReporter;
2158
+ verbose: typeof VerboseBenchmarkReporter;
1870
2159
  };
1871
2160
  type BenchmarkBuiltinReporters = keyof typeof BenchmarkReportsMap;
1872
2161
 
1873
2162
  declare const ReportersMap: {
1874
- default: typeof DefaultReporter
1875
- blob: typeof BlobReporter
1876
- verbose: typeof VerboseReporter
1877
- dot: typeof DotReporter
1878
- json: typeof JsonReporter
1879
- tap: typeof TapReporter
1880
- "tap-flat": typeof TapFlatReporter
1881
- junit: typeof JUnitReporter
1882
- "hanging-process": typeof HangingProcessReporter
1883
- "github-actions": typeof GithubActionsReporter
2163
+ default: typeof DefaultReporter;
2164
+ blob: typeof BlobReporter;
2165
+ verbose: typeof VerboseReporter;
2166
+ dot: typeof DotReporter;
2167
+ json: typeof JsonReporter;
2168
+ tap: typeof TapReporter;
2169
+ "tap-flat": typeof TapFlatReporter;
2170
+ junit: typeof JUnitReporter;
2171
+ tree: typeof TreeReporter;
2172
+ "hanging-process": typeof HangingProcessReporter;
2173
+ "github-actions": typeof GithubActionsReporter;
1884
2174
  };
1885
2175
  type BuiltinReporters = keyof typeof ReportersMap;
1886
- interface BuiltinReporterOptions {
1887
- "default": DefaultReporterOptions;
1888
- "verbose": DefaultReporterOptions;
1889
- "dot": BaseOptions;
1890
- "json": JsonOptions$1;
1891
- "blob": BlobOptions;
1892
- "tap": never;
1893
- "tap-flat": never;
1894
- "junit": JUnitOptions;
1895
- "hanging-process": never;
1896
- "html": HTMLOptions;
1897
- }
1898
-
1899
- interface TestSequencer {
1900
- /**
1901
- * Slicing tests into shards. Will be run before `sort`.
1902
- * Only run, if `shard` is defined.
1903
- */
1904
- shard: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
1905
- sort: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
1906
- }
1907
- interface TestSequencerConstructor {
1908
- new (ctx: Vitest): TestSequencer;
1909
- }
1910
-
1911
- interface WatcherTriggerPattern {
1912
- pattern: RegExp;
1913
- testsToRun: (file: string, match: RegExpMatchArray) => string[] | string | null | undefined | void;
1914
- }
1915
-
1916
- interface BenchmarkUserOptions {
1917
- /**
1918
- * Include globs for benchmark test files
1919
- *
1920
- * @default ['**\/*.{bench,benchmark}.?(c|m)[jt]s?(x)']
1921
- */
1922
- include?: string[];
1923
- /**
1924
- * Exclude globs for benchmark test files
1925
- * @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.*']
1926
- */
1927
- exclude?: string[];
1928
- /**
1929
- * Include globs for in-source benchmark test files
1930
- *
1931
- * @default []
1932
- */
1933
- includeSource?: string[];
1934
- /**
1935
- * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
1936
- * and/or paths to custom reporters
1937
- *
1938
- * @default ['default']
1939
- */
1940
- reporters?: Arrayable<BenchmarkBuiltinReporters | Reporter>;
1941
- /**
1942
- * @deprecated Use `benchmark.outputJson` instead
1943
- */
1944
- outputFile?: string | (Partial<Record<BenchmarkBuiltinReporters, string>> & Record<string, string>);
1945
- /**
1946
- * benchmark output file to compare against
1947
- */
1948
- compare?: string;
1949
- /**
1950
- * benchmark output file
1951
- */
1952
- outputJson?: string;
1953
- /**
1954
- * Include `samples` array of benchmark results for API or custom reporter usages.
1955
- * This is disabled by default to reduce memory usage.
1956
- * @default false
1957
- */
1958
- includeSamples?: boolean;
1959
- }
1960
-
1961
- interface Node {
1962
- isRoot(): boolean;
1963
- visit(visitor: Visitor, state: any): void;
1964
- }
1965
-
1966
- interface Visitor<N extends Node = Node> {
1967
- onStart(root: N, state: any): void;
1968
- onSummary(root: N, state: any): void;
1969
- onDetail(root: N, state: any): void;
1970
- onSummaryEnd(root: N, state: any): void;
1971
- onEnd(root: N, state: any): void;
1972
- }
1973
-
1974
- interface FileOptions {
1975
- file: string;
1976
- }
1977
-
1978
- interface ProjectOptions {
1979
- projectRoot: string;
1980
- }
1981
-
1982
- interface ReportOptions {
1983
- clover: CloverOptions;
1984
- cobertura: CoberturaOptions;
1985
- "html-spa": HtmlSpaOptions;
1986
- html: HtmlOptions;
1987
- json: JsonOptions;
1988
- "json-summary": JsonSummaryOptions;
1989
- lcov: LcovOptions;
1990
- lcovonly: LcovOnlyOptions;
1991
- none: never;
1992
- teamcity: TeamcityOptions;
1993
- text: TextOptions;
1994
- "text-lcov": TextLcovOptions;
1995
- "text-summary": TextSummaryOptions;
1996
- }
1997
-
1998
- interface CloverOptions extends FileOptions, ProjectOptions {}
1999
-
2000
- interface CoberturaOptions extends FileOptions, ProjectOptions {}
2001
-
2002
- interface HtmlSpaOptions extends HtmlOptions {
2003
- metricsToShow: Array<"lines" | "branches" | "functions" | "statements">;
2004
- }
2005
- interface HtmlOptions {
2006
- verbose: boolean;
2007
- skipEmpty: boolean;
2008
- subdir: string;
2009
- linkMapper: LinkMapper;
2010
- }
2011
-
2012
- type JsonOptions = FileOptions;
2013
- type JsonSummaryOptions = FileOptions;
2014
-
2015
- interface LcovOptions extends FileOptions, ProjectOptions {}
2016
- interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
2017
-
2018
- interface TeamcityOptions extends FileOptions {
2019
- blockName: string;
2020
- }
2021
-
2022
- interface TextOptions extends FileOptions {
2023
- maxCols: number;
2024
- skipEmpty: boolean;
2025
- skipFull: boolean;
2026
- }
2027
- type TextLcovOptions = ProjectOptions;
2028
- type TextSummaryOptions = FileOptions;
2029
-
2030
- interface LinkMapper {
2031
- getPath(node: string | Node): string;
2032
- relativePath(source: string | Node, target: string | Node): string;
2033
- assetPath(node: Node, name: string): string;
2034
- }
2035
-
2036
- type TransformResult = string | Partial<TransformResult$1> | undefined | null | void;
2037
- type CoverageResults = unknown;
2038
- interface CoverageProvider {
2039
- name: string;
2040
- /** Called when provider is being initialized before tests run */
2041
- initialize: (ctx: Vitest) => Promise<void> | void;
2042
- /** Called when setting coverage options for Vitest context (`ctx.config.coverage`) */
2043
- resolveOptions: () => ResolvedCoverageOptions;
2044
- /** Callback to clean previous reports */
2045
- clean: (clean?: boolean) => void | Promise<void>;
2046
- /** Called with coverage results after a single test file has been run */
2047
- onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void | Promise<void>;
2048
- /** Callback called when test run fails */
2049
- onTestFailure?: () => void | Promise<void>;
2050
- /** Callback to generate final coverage results */
2051
- generateCoverage: (reportContext: ReportContext) => CoverageResults | Promise<CoverageResults>;
2052
- /** Callback to convert coverage results to coverage reports. Called with results returned from `generateCoverage` */
2053
- reportCoverage: (coverage: CoverageResults, reportContext: ReportContext) => void | Promise<void>;
2054
- /** Callback for `--merge-reports` options. Called with multiple coverage results generated by `generateCoverage`. */
2055
- mergeReports?: (coverages: CoverageResults[]) => void | Promise<void>;
2056
- /** Callback called for instrumenting files with coverage counters. */
2057
- onFileTransform?: (sourceCode: string, id: string, pluginCtx: any) => TransformResult | Promise<TransformResult>;
2058
- }
2059
- interface ReportContext {
2060
- /** Indicates whether all tests were run. False when only specific tests were run. */
2061
- allTestsRun?: boolean;
2176
+ interface BuiltinReporterOptions {
2177
+ "default": DefaultReporterOptions;
2178
+ "verbose": DefaultReporterOptions;
2179
+ "dot": BaseOptions;
2180
+ "tree": BaseOptions;
2181
+ "json": JsonOptions;
2182
+ "blob": BlobOptions;
2183
+ "tap": never;
2184
+ "tap-flat": never;
2185
+ "junit": JUnitOptions;
2186
+ "hanging-process": never;
2187
+ "html": HTMLOptions;
2062
2188
  }
2063
- interface CoverageProviderModule extends RuntimeCoverageProviderModule {
2189
+
2190
+ interface TestSequencer {
2064
2191
  /**
2065
- * Factory for creating a new coverage provider
2192
+ * Slicing tests into shards. Will be run before `sort`.
2193
+ * Only run, if `shard` is defined.
2066
2194
  */
2067
- getProvider: () => CoverageProvider | Promise<CoverageProvider>;
2195
+ shard: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
2196
+ sort: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
2068
2197
  }
2069
- type CoverageReporter = keyof ReportOptions | (string & {});
2070
- type CoverageReporterWithOptions<ReporterName extends CoverageReporter = CoverageReporter> = ReporterName extends keyof ReportOptions ? ReportOptions[ReporterName] extends never ? [ReporterName, object] : [ReporterName, Partial<ReportOptions[ReporterName]>] : [ReporterName, Record<string, unknown>];
2071
- type CoverageProviderName = "v8" | "istanbul" | "custom" | undefined;
2072
- type CoverageOptions<T extends CoverageProviderName = CoverageProviderName> = T extends "istanbul" ? {
2073
- provider: T
2074
- } & CoverageIstanbulOptions : T extends "v8" ? {
2075
- /**
2076
- * Provider to use for coverage collection.
2077
- *
2078
- * @default 'v8'
2079
- */
2080
- provider: T
2081
- } & CoverageV8Options : T extends "custom" ? {
2082
- provider: T
2083
- } & CustomProviderOptions : {
2084
- provider?: T
2085
- } & CoverageV8Options;
2086
- /** Fields that have default values. Internally these will always be defined. */
2087
- type FieldsWithDefaultValues = "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "exclude" | "reportOnFailure" | "allowExternal" | "processingConcurrency";
2088
- type ResolvedCoverageOptions<T extends CoverageProviderName = CoverageProviderName> = CoverageOptions<T> & Required<Pick<CoverageOptions<T>, FieldsWithDefaultValues>> & {
2089
- reporter: CoverageReporterWithOptions[]
2090
- };
2091
- interface BaseCoverageOptions {
2092
- /**
2093
- * Enables coverage collection. Can be overridden using `--coverage` CLI option.
2094
- *
2095
- * @default false
2096
- */
2097
- enabled?: boolean;
2198
+ interface TestSequencerConstructor {
2199
+ new (ctx: Vitest): TestSequencer;
2200
+ }
2201
+
2202
+ interface BenchmarkUserOptions {
2098
2203
  /**
2099
- * List of files included in coverage as glob patterns.
2100
- * By default only files covered by tests are included.
2204
+ * Include globs for benchmark test files
2101
2205
  *
2102
- * See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
2206
+ * @default ['**\/*.{bench,benchmark}.?(c|m)[jt]s?(x)']
2103
2207
  */
2104
2208
  include?: string[];
2105
2209
  /**
2106
- * List of files excluded from coverage as glob patterns.
2107
- * Files are first checked against `coverage.include`.
2108
- *
2109
- * See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
2210
+ * Exclude globs for benchmark test files
2211
+ * @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.*']
2110
2212
  */
2111
2213
  exclude?: string[];
2112
2214
  /**
2113
- * Clean coverage results before running tests
2114
- *
2115
- * @default true
2116
- */
2117
- clean?: boolean;
2118
- /**
2119
- * Clean coverage report on watch rerun
2120
- *
2121
- * @default true
2122
- */
2123
- cleanOnRerun?: boolean;
2124
- /**
2125
- * Directory to write coverage report to
2126
- *
2127
- * @default './coverage'
2128
- */
2129
- reportsDirectory?: string;
2130
- /**
2131
- * Coverage reporters to use.
2132
- * See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters.
2133
- *
2134
- * @default ['text', 'html', 'clover', 'json']
2135
- */
2136
- reporter?: Arrayable$1<CoverageReporter> | (CoverageReporter | [CoverageReporter] | CoverageReporterWithOptions)[];
2137
- /**
2138
- * Do not show files with 100% statement, branch, and function coverage
2139
- *
2140
- * @default false
2141
- */
2142
- skipFull?: boolean;
2143
- /**
2144
- * Configurations for thresholds
2145
- *
2146
- * @example
2147
- *
2148
- * ```ts
2149
- * {
2150
- * // Thresholds for all files
2151
- * functions: 95,
2152
- * branches: 70,
2153
- * perFile: true,
2154
- * autoUpdate: true,
2155
- *
2156
- * // Thresholds for utilities
2157
- * 'src/utils/**.ts': {
2158
- * lines: 100,
2159
- * statements: 95,
2160
- * }
2161
- * }
2162
- * ```
2163
- */
2164
- thresholds?: Thresholds | ({
2165
- [glob: string]: Pick<Thresholds, 100 | "statements" | "functions" | "branches" | "lines">
2166
- } & Thresholds);
2167
- /**
2168
- * Watermarks for statements, lines, branches and functions.
2169
- *
2170
- * Default value is `[50,80]` for each property.
2171
- */
2172
- watermarks?: {
2173
- statements?: [number, number]
2174
- functions?: [number, number]
2175
- branches?: [number, number]
2176
- lines?: [number, number]
2177
- };
2178
- /**
2179
- * Generate coverage report even when tests fail.
2215
+ * Include globs for in-source benchmark test files
2180
2216
  *
2181
- * @default false
2217
+ * @default []
2182
2218
  */
2183
- reportOnFailure?: boolean;
2219
+ includeSource?: string[];
2184
2220
  /**
2185
- * Collect coverage of files outside the project `root`.
2221
+ * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
2222
+ * and/or paths to custom reporters
2186
2223
  *
2187
- * @default false
2224
+ * @default ['default']
2188
2225
  */
2189
- allowExternal?: boolean;
2226
+ reporters?: Arrayable$1<BenchmarkBuiltinReporters | Reporter>;
2190
2227
  /**
2191
- * Apply exclusions again after coverage has been remapped to original sources.
2192
- * This is useful when your source files are transpiled and may contain source maps
2193
- * of non-source files.
2194
- *
2195
- * Use this option when you are seeing files that show up in report even if they
2196
- * match your `coverage.exclude` patterns.
2197
- *
2198
- * @default false
2228
+ * @deprecated Use `benchmark.outputJson` instead
2199
2229
  */
2200
- excludeAfterRemap?: boolean;
2230
+ outputFile?: string | (Partial<Record<BenchmarkBuiltinReporters, string>> & Record<string, string>);
2201
2231
  /**
2202
- * Concurrency limit used when processing the coverage results.
2203
- * Defaults to `Math.min(20, os.availableParallelism?.() ?? os.cpus().length)`
2232
+ * benchmark output file to compare against
2204
2233
  */
2205
- processingConcurrency?: number;
2234
+ compare?: string;
2206
2235
  /**
2207
- * Set to array of class method names to ignore for coverage
2208
- *
2209
- * @default []
2236
+ * benchmark output file
2210
2237
  */
2211
- ignoreClassMethods?: string[];
2212
- }
2213
- interface CoverageIstanbulOptions extends BaseCoverageOptions {}
2214
- interface CoverageV8Options extends BaseCoverageOptions {}
2215
- interface CustomProviderOptions extends Pick<BaseCoverageOptions, FieldsWithDefaultValues> {
2216
- /** Name of the module or path to a file to load the custom provider from */
2217
- customProviderModule: string;
2218
- }
2219
- interface Thresholds {
2220
- /** Set global thresholds to `100` */
2221
- 100?: boolean;
2222
- /** Check thresholds per file. */
2223
- perFile?: boolean;
2238
+ outputJson?: string;
2224
2239
  /**
2225
- * Update threshold values automatically when current coverage is higher than earlier thresholds
2226
- *
2240
+ * Include `samples` array of benchmark results for API or custom reporter usages.
2241
+ * This is disabled by default to reduce memory usage.
2227
2242
  * @default false
2228
2243
  */
2229
- autoUpdate?: boolean;
2230
- /** Thresholds for statements */
2231
- statements?: number;
2232
- /** Thresholds for functions */
2233
- functions?: number;
2234
- /** Thresholds for branches */
2235
- branches?: number;
2236
- /** Thresholds for lines */
2237
- lines?: number;
2244
+ includeSamples?: boolean;
2238
2245
  }
2239
2246
 
2240
2247
  type BuiltinEnvironment = "node" | "jsdom" | "happy-dom" | "edge-runtime";
2241
- // Record is used, so user can get intellisense for builtin environments, but still allow custom environments
2242
2248
  type VitestEnvironment = BuiltinEnvironment | (string & Record<never, never>);
2243
2249
 
2244
2250
  type CSSModuleScopeStrategy = "stable" | "scoped" | "non-scoped";
@@ -2284,12 +2290,12 @@ interface SequenceOptions {
2284
2290
  * earlier if you enable this option.
2285
2291
  * @default false
2286
2292
  */
2287
- files?: boolean
2293
+ files?: boolean;
2288
2294
  /**
2289
2295
  * Should tests run in random order.
2290
2296
  * @default false
2291
2297
  */
2292
- tests?: boolean
2298
+ tests?: boolean;
2293
2299
  };
2294
2300
  /**
2295
2301
  * Should tests run in parallel.
@@ -2318,33 +2324,13 @@ interface SequenceOptions {
2318
2324
  hooks?: SequenceHooks;
2319
2325
  }
2320
2326
  type DepsOptimizationOptions = Omit<DepOptimizationConfig, "disabled" | "noDiscovery"> & {
2321
- enabled?: boolean
2327
+ enabled?: boolean;
2322
2328
  };
2323
- interface TransformModePatterns {
2324
- /**
2325
- * Use SSR transform pipeline for all modules inside specified tests.
2326
- * Vite plugins will receive `ssr: true` flag when processing those files.
2327
- *
2328
- * @default tests with node or edge environment
2329
- */
2330
- ssr?: string[];
2331
- /**
2332
- * First do a normal transform pipeline (targeting browser),
2333
- * then then do a SSR rewrite to run the code in Node.
2334
- * Vite plugins will receive `ssr: false` flag when processing those files.
2335
- *
2336
- * @default tests with jsdom or happy-dom environment
2337
- */
2338
- web?: string[];
2339
- }
2340
2329
  interface DepsOptions {
2341
2330
  /**
2342
2331
  * Enable dependency optimization. This can improve the performance of your tests.
2343
2332
  */
2344
- optimizer?: {
2345
- web?: DepsOptimizationOptions
2346
- ssr?: DepsOptimizationOptions
2347
- };
2333
+ optimizer?: Partial<Record<"client" | "ssr" | ({} & string), DepsOptimizationOptions>>;
2348
2334
  web?: {
2349
2335
  /**
2350
2336
  * Should Vitest process assets (.png, .svg, .jpg, etc) files and resolve them like Vite does in the browser.
@@ -2355,7 +2341,7 @@ interface DepsOptions {
2355
2341
  *
2356
2342
  * @default true
2357
2343
  */
2358
- transformAssets?: boolean
2344
+ transformAssets?: boolean;
2359
2345
  /**
2360
2346
  * Should Vitest process CSS (.css, .scss, .sass, etc) files and resolve them like Vite does in the browser.
2361
2347
  *
@@ -2365,7 +2351,7 @@ interface DepsOptions {
2365
2351
  *
2366
2352
  * @default true
2367
2353
  */
2368
- transformCss?: boolean
2354
+ transformCss?: boolean;
2369
2355
  /**
2370
2356
  * Regexp pattern to match external files that should be transformed.
2371
2357
  *
@@ -2375,46 +2361,15 @@ interface DepsOptions {
2375
2361
  *
2376
2362
  * @default []
2377
2363
  */
2378
- transformGlobPattern?: RegExp | RegExp[]
2364
+ transformGlobPattern?: RegExp | RegExp[];
2379
2365
  };
2380
2366
  /**
2381
- * Externalize means that Vite will bypass the package to native Node.
2382
- *
2383
- * Externalized dependencies will not be applied Vite's transformers and resolvers.
2384
- * And does not support HMR on reload.
2385
- *
2386
- * Typically, packages under `node_modules` are externalized.
2387
- *
2388
- * @deprecated If you rely on vite-node directly, use `server.deps.external` instead. Otherwise, consider using `deps.optimizer.{web,ssr}.exclude`.
2389
- */
2390
- external?: (string | RegExp)[];
2391
- /**
2392
- * Vite will process inlined modules.
2393
- *
2394
- * This could be helpful to handle packages that ship `.js` in ESM format (that Node can't handle).
2395
- *
2396
- * If `true`, every dependency will be inlined
2397
- *
2398
- * @deprecated If you rely on vite-node directly, use `server.deps.inline` instead. Otherwise, consider using `deps.optimizer.{web,ssr}.include`.
2399
- */
2400
- inline?: (string | RegExp)[] | true;
2401
- /**
2402
2367
  * Interpret CJS module's default as named exports
2403
2368
  *
2404
2369
  * @default true
2405
2370
  */
2406
2371
  interopDefault?: boolean;
2407
2372
  /**
2408
- * When a dependency is a valid ESM package, try to guess the cjs version based on the path.
2409
- * This will significantly improve the performance in huge repo, but might potentially
2410
- * cause some misalignment if a package have different logic in ESM and CJS mode.
2411
- *
2412
- * @default false
2413
- *
2414
- * @deprecated Use `server.deps.fallbackCJS` instead.
2415
- */
2416
- fallbackCJS?: boolean;
2417
- /**
2418
2373
  * A list of directories relative to the config file that should be treated as module directories.
2419
2374
  *
2420
2375
  * @default ['node_modules']
@@ -2461,10 +2416,9 @@ interface InlineConfig {
2461
2416
  *
2462
2417
  */
2463
2418
  deps?: DepsOptions;
2464
- /**
2465
- * Vite-node server options
2466
- */
2467
- server?: Omit<ViteNodeServerOptions, "transformMode">;
2419
+ server?: {
2420
+ deps?: ServerDepsOptions;
2421
+ };
2468
2422
  /**
2469
2423
  * Base directory to scan for the test files
2470
2424
  *
@@ -2492,23 +2446,6 @@ interface InlineConfig {
2492
2446
  */
2493
2447
  environmentOptions?: EnvironmentOptions;
2494
2448
  /**
2495
- * Automatically assign environment based on globs. The first match will be used.
2496
- * This has effect only when running tests inside Node.js.
2497
- *
2498
- * Format: [glob, environment-name]
2499
- *
2500
- * @deprecated use [`projects`](https://vitest.dev/config/#projects) instead
2501
- * @default []
2502
- * @example [
2503
- * // all tests in tests/dom will run in jsdom
2504
- * ['tests/dom/**', 'jsdom'],
2505
- * // all tests in tests/ with .edge.test.ts will run in edge-runtime
2506
- * ['**\/*.edge.test.ts', 'edge-runtime'],
2507
- * // ...
2508
- * ]
2509
- */
2510
- environmentMatchGlobs?: [string, VitestEnvironment][];
2511
- /**
2512
2449
  * Run tests in an isolated environment. This option has no effect on vmThreads pool.
2513
2450
  *
2514
2451
  * Disabling this option might improve performance if your code doesn't rely on side effects.
@@ -2533,41 +2470,17 @@ interface InlineConfig {
2533
2470
  */
2534
2471
  maxWorkers?: number | string;
2535
2472
  /**
2536
- * Minimum number or percentage of workers to run tests in. `poolOptions.{threads,vmThreads}.minThreads`/`poolOptions.forks.minForks` has higher priority.
2537
- */
2538
- minWorkers?: number | string;
2539
- /**
2540
2473
  * Should all test files run in parallel. Doesn't affect tests running in the same file.
2541
- * Setting this to `false` will override `maxWorkers` and `minWorkers` options to `1`.
2474
+ * Setting this to `false` will override `maxWorkers` option to `1`.
2542
2475
  *
2543
2476
  * @default true
2544
2477
  */
2545
2478
  fileParallelism?: boolean;
2546
2479
  /**
2547
- * Automatically assign pool based on globs. The first match will be used.
2548
- *
2549
- * Format: [glob, pool-name]
2550
- *
2551
- * @deprecated use [`projects`](https://vitest.dev/config/#projects) instead
2552
- * @default []
2553
- * @example [
2554
- * // all tests in "forks" directory will run using "poolOptions.forks" API
2555
- * ['tests/forks/**', 'forks'],
2556
- * // all other tests will run based on "poolOptions.threads" option, if you didn't specify other globs
2557
- * // ...
2558
- * ]
2559
- */
2560
- poolMatchGlobs?: [string, Exclude<Pool, "browser">][];
2561
- /**
2562
2480
  * Options for projects
2563
2481
  */
2564
2482
  projects?: TestProjectConfiguration[];
2565
2483
  /**
2566
- * Path to a workspace configuration file
2567
- * @deprecated use `projects` instead
2568
- */
2569
- workspace?: string | TestProjectConfiguration[];
2570
- /**
2571
2484
  * Update snapshot
2572
2485
  *
2573
2486
  * @default false
@@ -2591,7 +2504,7 @@ interface InlineConfig {
2591
2504
  *
2592
2505
  * @default []
2593
2506
  */
2594
- reporters?: Arrayable$1<ReporterName | InlineReporter> | ((ReporterName | InlineReporter) | [ReporterName] | ReporterWithOptions)[];
2507
+ reporters?: Arrayable<ReporterName | InlineReporter> | ((ReporterName | InlineReporter) | [ReporterName] | ReporterWithOptions)[];
2595
2508
  /**
2596
2509
  * Write test results to a file when the --reporter=json` or `--reporter=junit` option is also specified.
2597
2510
  * Also definable individually per reporter by using an object instead.
@@ -2638,7 +2551,7 @@ interface InlineConfig {
2638
2551
  */
2639
2552
  globalSetup?: string | string[];
2640
2553
  /**
2641
- * Glob patter of file paths that will trigger the whole suite rerun
2554
+ * Glob pattern of file paths that will trigger the whole suite rerun
2642
2555
  *
2643
2556
  * Useful if you are testing calling CLI commands
2644
2557
  *
@@ -2717,13 +2630,11 @@ interface InlineConfig {
2717
2630
  */
2718
2631
  uiBase?: string;
2719
2632
  /**
2720
- * Determine the transform method for all modules imported inside a test that matches the glob pattern.
2721
- */
2722
- testTransformMode?: TransformModePatterns;
2723
- /**
2724
2633
  * Format options for snapshot testing.
2725
2634
  */
2726
- snapshotFormat?: Omit<PrettyFormatOptions, "plugins">;
2635
+ snapshotFormat?: Omit<PrettyFormatOptions, "plugins" | "compareKeys"> & {
2636
+ compareKeys?: null | undefined;
2637
+ };
2727
2638
  /**
2728
2639
  * Path to a module which has a default export of diff config.
2729
2640
  */
@@ -2776,6 +2687,10 @@ interface InlineConfig {
2776
2687
  */
2777
2688
  onStackTrace?: (error: TestError, frame: ParsedStack) => boolean | void;
2778
2689
  /**
2690
+ * A callback that can return `false` to ignore an unhandled error
2691
+ */
2692
+ onUnhandledError?: OnUnhandledErrorCallback;
2693
+ /**
2779
2694
  * Indicates if CSS files should be processed.
2780
2695
  *
2781
2696
  * When excluded, the CSS files will be replaced with empty strings to bypass the subsequent processing.
@@ -2783,11 +2698,11 @@ interface InlineConfig {
2783
2698
  * @default { include: [], modules: { classNameStrategy: false } }
2784
2699
  */
2785
2700
  css?: boolean | {
2786
- include?: RegExp | RegExp[]
2787
- exclude?: RegExp | RegExp[]
2701
+ include?: RegExp | RegExp[];
2702
+ exclude?: RegExp | RegExp[];
2788
2703
  modules?: {
2789
- classNameStrategy?: CSSModuleScopeStrategy
2790
- }
2704
+ classNameStrategy?: CSSModuleScopeStrategy;
2705
+ };
2791
2706
  };
2792
2707
  /**
2793
2708
  * A number of tests that are allowed to run at the same time marked with `test.concurrent`.
@@ -2802,7 +2717,7 @@ interface InlineConfig {
2802
2717
  /**
2803
2718
  * @deprecated Use Vite's "cacheDir" instead if you want to change the cache director. Note caches will be written to "cacheDir\/vitest".
2804
2719
  */
2805
- dir: string
2720
+ dir: string;
2806
2721
  };
2807
2722
  /**
2808
2723
  * Options for configuring the order of running tests.
@@ -2855,19 +2770,19 @@ interface InlineConfig {
2855
2770
  /**
2856
2771
  * Enable inspector
2857
2772
  */
2858
- enabled?: boolean
2773
+ enabled?: boolean;
2859
2774
  /**
2860
2775
  * Port to run inspector on
2861
2776
  */
2862
- port?: number
2777
+ port?: number;
2863
2778
  /**
2864
2779
  * Host to run inspector on
2865
2780
  */
2866
- host?: string
2781
+ host?: string;
2867
2782
  /**
2868
2783
  * Wait for debugger to connect before running tests
2869
2784
  */
2870
- waitForDebugger?: boolean
2785
+ waitForDebugger?: boolean;
2871
2786
  };
2872
2787
  /**
2873
2788
  * Define variables that will be returned from `inject` in the test environment.
@@ -2896,7 +2811,7 @@ interface InlineConfig {
2896
2811
  /**
2897
2812
  * Throw an error if tests don't have any expect() assertions.
2898
2813
  */
2899
- requireAssertions?: boolean
2814
+ requireAssertions?: boolean;
2900
2815
  /**
2901
2816
  * Default options for expect.poll()
2902
2817
  */
@@ -2905,13 +2820,13 @@ interface InlineConfig {
2905
2820
  * Timeout in milliseconds
2906
2821
  * @default 1000
2907
2822
  */
2908
- timeout?: number
2823
+ timeout?: number;
2909
2824
  /**
2910
2825
  * Polling interval in milliseconds
2911
2826
  * @default 50
2912
2827
  */
2913
- interval?: number
2914
- }
2828
+ interval?: number;
2829
+ };
2915
2830
  };
2916
2831
  /**
2917
2832
  * Modify default Chai config. Vitest uses Chai for `expect` and `assert` matches.
@@ -3021,7 +2936,7 @@ interface UserConfig extends InlineConfig {
3021
2936
  *
3022
2937
  * Vitest will only run tests if it's called programmatically or the test file changes.
3023
2938
  *
3024
- * CLI file filters will be ignored.
2939
+ * If CLI file filters are passed, standalone mode is ignored.
3025
2940
  */
3026
2941
  standalone?: boolean;
3027
2942
  /**
@@ -3076,6 +2991,9 @@ interface UserConfig extends InlineConfig {
3076
2991
  */
3077
2992
  mergeReports?: string;
3078
2993
  }
2994
+ type OnUnhandledErrorCallback = (error: (TestError | Error) & {
2995
+ type: string;
2996
+ }) => boolean | void;
3079
2997
  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"> {
3080
2998
  mode: VitestRunMode;
3081
2999
  name: ProjectName["label"];
@@ -3097,53 +3015,75 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config"
3097
3015
  reporters: (InlineReporter | ReporterWithOptions)[];
3098
3016
  defines: Record<string, any>;
3099
3017
  api: ApiConfig & {
3100
- token: string
3018
+ token: string;
3101
3019
  };
3102
3020
  cliExclude?: string[];
3103
3021
  project: string[];
3104
3022
  benchmark?: Required<Omit<BenchmarkUserOptions, "outputFile" | "compare" | "outputJson">> & Pick<BenchmarkUserOptions, "outputFile" | "compare" | "outputJson">;
3105
3023
  shard?: {
3106
- index: number
3107
- count: number
3024
+ index: number;
3025
+ count: number;
3108
3026
  };
3109
3027
  cache: {
3110
3028
  /**
3111
3029
  * @deprecated
3112
3030
  */
3113
- dir: string
3031
+ dir: string;
3114
3032
  } | false;
3115
3033
  sequence: {
3116
- sequencer: TestSequencerConstructor
3117
- hooks: SequenceHooks
3118
- setupFiles: SequenceSetupFiles
3119
- shuffle?: boolean
3120
- concurrent?: boolean
3121
- seed: number
3122
- groupOrder: number
3034
+ sequencer: TestSequencerConstructor;
3035
+ hooks: SequenceHooks;
3036
+ setupFiles: SequenceSetupFiles;
3037
+ shuffle?: boolean;
3038
+ concurrent?: boolean;
3039
+ seed: number;
3040
+ groupOrder: number;
3123
3041
  };
3124
3042
  typecheck: Omit<TypecheckConfig, "enabled"> & {
3125
- enabled: boolean
3043
+ enabled: boolean;
3126
3044
  };
3127
3045
  runner?: string;
3128
3046
  maxWorkers: number;
3129
- minWorkers: number;
3130
3047
  }
3131
- 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";
3048
+ 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";
3049
+ interface ServerDepsOptions {
3050
+ /**
3051
+ * Externalize means that Vite will bpass the package to native Node.
3052
+ *
3053
+ * Externalized dependencies will not be applied Vite's transformers and resolvers.
3054
+ * And does not support HMR on reload.
3055
+ *
3056
+ * Typically, packages under `node_modules` are externalized.
3057
+ */
3058
+ external?: (string | RegExp)[];
3059
+ /**
3060
+ * Vite will process inlined modules.
3061
+ *
3062
+ * This could be helpful to handle packages that ship `.js` in ESM format (that Node can't handle).
3063
+ *
3064
+ * If `true`, every dependency will be inlined
3065
+ */
3066
+ inline?: (string | RegExp)[] | true;
3067
+ /**
3068
+ * Try to guess the CJS version of a package when it's invalid ESM
3069
+ * @default false
3070
+ */
3071
+ fallbackCJS?: boolean;
3072
+ }
3132
3073
  type ProjectConfig = Omit<InlineConfig, NonProjectOptions | "sequencer" | "deps" | "poolOptions"> & {
3133
- mode?: string
3134
- sequencer?: Omit<SequenceOptions, "sequencer" | "seed">
3135
- deps?: Omit<DepsOptions, "moduleDirectories">
3074
+ mode?: string;
3075
+ sequencer?: Omit<SequenceOptions, "sequencer" | "seed">;
3076
+ deps?: Omit<DepsOptions, "moduleDirectories">;
3136
3077
  poolOptions?: {
3137
- threads?: Pick<NonNullable<PoolOptions["threads"]>, "singleThread" | "isolate">
3138
- vmThreads?: Pick<NonNullable<PoolOptions["vmThreads"]>, "singleThread">
3139
- forks?: Pick<NonNullable<PoolOptions["forks"]>, "singleFork" | "isolate">
3140
- }
3078
+ threads?: Pick<NonNullable<PoolOptions["threads"]>, "singleThread" | "isolate">;
3079
+ vmThreads?: Pick<NonNullable<PoolOptions["vmThreads"]>, "singleThread">;
3080
+ forks?: Pick<NonNullable<PoolOptions["forks"]>, "singleFork" | "isolate">;
3081
+ };
3141
3082
  };
3142
3083
  type ResolvedProjectConfig = Omit<ResolvedConfig, Exclude<NonProjectOptions, "coverage" | "watch">>;
3143
3084
  interface UserWorkspaceConfig extends UserConfig$1 {
3144
3085
  test?: ProjectConfig;
3145
3086
  }
3146
- // TODO: remove types when "workspace" support is removed
3147
3087
  type UserProjectConfigFn = (env: ConfigEnv) => UserWorkspaceConfig | Promise<UserWorkspaceConfig>;
3148
3088
  type UserProjectConfigExport = UserWorkspaceConfig | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
3149
3089
  type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
@@ -3152,9 +3092,9 @@ type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
3152
3092
  * If `true`, the project will inherit all options from the root config.
3153
3093
  * @example '../vite.config.ts'
3154
3094
  */
3155
- extends?: string | true
3095
+ extends?: string | true;
3156
3096
  });
3157
3097
  type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
3158
3098
 
3159
- export { CoverageMap as C, TestSuite as E, Logger as L, TestProject as T, Vitest as V, BenchmarkReportsMap as aA, DefaultReporter as aB, DotReporter as aC, GithubActionsReporter as aD, HangingProcessReporter as aE, JsonReporter as aF, JUnitReporter as aG, ReportersMap as aH, TapFlatReporter as aI, TapReporter as aJ, VerboseBenchmarkReporter as aK, VerboseReporter as aL, BaseReporter as aM, BenchmarkReporter as az, TestSpecification as l, VitestPackageInstaller as n, getFilePoolName as p, TestCase as s, TestCollection as t, TestModule as v };
3160
- export type { BrowserOrchestrator as $, ApiConfig as A, TestResultSkipped as B, TestState as D, TestSuiteState as F, TestSequencerConstructor as G, HTMLOptions as H, InlineConfig as I, JsonOptions$1 as J, BenchmarkUserOptions as K, ModuleDiagnostic as M, BrowserBuiltinProvider as N, OnServerRestartHandler as O, ProcessPool as P, BrowserCommand as Q, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, BrowserCommandContext as X, BrowserConfigOptions as Y, BrowserInstanceOption as Z, BrowserModuleMocker as _, TestProjectConfiguration as a, BrowserProvider as a0, BrowserProviderInitializationOptions as a1, BrowserProviderModule as a2, BrowserProviderOptions as a3, BrowserScript as a4, BrowserServerState as a5, BrowserServerStateSession as a6, CDPSession as a7, ParentProjectBrowser as a8, ProjectBrowser as a9, BenchmarkBuiltinReporters as aN, BuiltinReporterOptions as aO, BuiltinReporters as aP, JsonAssertionResult as aQ, JsonTestResult as aR, JsonTestResults as aS, ResolvedBrowserOptions as aa, BuiltinEnvironment as ab, CSSModuleScopeStrategy as ac, DepsOptimizationOptions as ad, EnvironmentOptions as ae, Pool as af, PoolOptions as ag, ProjectConfig as ah, ResolvedProjectConfig as ai, ResolveSnapshotPathHandler as aj, ResolveSnapshotPathHandlerContext as ak, TransformModePatterns as al, TypecheckConfig as am, VitestEnvironment as an, BaseCoverageOptions as ao, CoverageIstanbulOptions as ap, CoverageOptions as aq, CoverageProvider as ar, CoverageProviderModule as as, CoverageReporter as at, CustomProviderOptions as au, TestRunResult as av, ReportedHookContext as aw, Reporter as ax, TestRunEndReason as ay, 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 k, OnTestsRerunHandler as m, WorkspaceSpec as o, JUnitOptions as q, TaskOptions as r, TestDiagnostic as u, TestModuleState as w, TestResult as x, TestResultFailed as y, TestResultPassed as z };
3099
+ 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 };
3100
+ 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 };