vitest 0.20.3 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE.md +61 -4
  2. package/dist/browser.d.ts +8 -1902
  3. package/dist/browser.mjs +8 -9
  4. package/dist/{chunk-api-setup.9bff74bb.mjs → chunk-api-setup.ecd02c18.mjs} +8 -7
  5. package/dist/{chunk-constants.16825f0c.mjs → chunk-constants.d3f8437b.mjs} +4 -4
  6. package/dist/{chunk-install-pkg.6c6dc0c2.mjs → chunk-install-pkg.3aa3eae6.mjs} +3 -2
  7. package/dist/{chunk-defaults.6698a2d3.mjs → chunk-integrations-coverage.d205bd87.mjs} +23 -152
  8. package/dist/{chunk-integrations-globals.c5b78414.mjs → chunk-integrations-globals.e81d2091.mjs} +7 -6
  9. package/dist/{chunk-mock-date.9160e13b.mjs → chunk-mock-date.debe9954.mjs} +16 -74
  10. package/dist/chunk-node-git.71b74da4.mjs +80 -0
  11. package/dist/{chunk-runtime-chain.b6c2cdbc.mjs → chunk-runtime-chain.6e363ba2.mjs} +31 -21
  12. package/dist/{chunk-runtime-error.034e03ba.mjs → chunk-runtime-error.975bd80a.mjs} +14 -12
  13. package/dist/{chunk-runtime-hooks.a8401528.mjs → chunk-runtime-hooks.4789e99d.mjs} +3 -3
  14. package/dist/{chunk-runtime-mocker.653847b2.mjs → chunk-runtime-mocker.c91d29ce.mjs} +34 -12
  15. package/dist/{chunk-runtime-rpc.dbf0b31d.mjs → chunk-runtime-rpc.29488183.mjs} +1 -1
  16. package/dist/{chunk-utils-source-map.8198ebd9.mjs → chunk-utils-source-map.2a082ffd.mjs} +2 -1
  17. package/dist/{chunk-vite-node-client.115caed2.mjs → chunk-vite-node-client.d1ead698.mjs} +7 -3
  18. package/dist/{chunk-vite-node-debug.c5887932.mjs → chunk-vite-node-debug.ff1d2a9f.mjs} +3 -2
  19. package/dist/{chunk-vite-node-externalize.91ae6e85.mjs → chunk-vite-node-externalize.3a38c8af.mjs} +167 -39
  20. package/dist/chunk-vite-node-utils.d8e5ff7b.mjs +6921 -0
  21. package/dist/cli-wrapper.mjs +107 -0
  22. package/dist/cli.mjs +16 -14
  23. package/dist/config.cjs +3 -0
  24. package/dist/config.d.ts +7 -69
  25. package/dist/config.mjs +2 -1
  26. package/dist/entry.mjs +8 -9
  27. package/dist/global-74489cc9.d.ts +2098 -0
  28. package/dist/index-9eded9ec.d.ts +116 -0
  29. package/dist/index.d.ts +9 -1928
  30. package/dist/index.mjs +6 -5
  31. package/dist/loader.mjs +74 -17
  32. package/dist/node.d.ts +7 -1682
  33. package/dist/node.mjs +15 -13
  34. package/dist/suite.mjs +5 -4
  35. package/dist/{vendor-index.61438b77.mjs → vendor-index.29636037.mjs} +1 -61
  36. package/dist/{vendor-index.62ce5c33.mjs → vendor-index.2ae8040a.mjs} +0 -0
  37. package/dist/vendor-index.9d9196cc.mjs +61 -0
  38. package/dist/{vendor-index.de788b6a.mjs → vendor-index.ae96af6e.mjs} +14 -14
  39. package/dist/{chunk-node-git.43dbdd42.mjs → vendor-index.fbec8a81.mjs} +5 -73
  40. package/dist/vendor-picocolors.807856aa.mjs +64 -0
  41. package/dist/worker.mjs +7 -6
  42. package/package.json +8 -12
  43. package/vitest.mjs +1 -1
  44. package/dist/chunk-vite-node-utils.7e46948f.mjs +0 -1114
@@ -0,0 +1,2098 @@
1
+ import { ViteDevServer, TransformResult as TransformResult$1, UserConfig as UserConfig$1, CommonServerOptions, AliasOptions } from 'vite';
2
+ import { MessagePort } from 'worker_threads';
3
+ import { Stats } from 'fs';
4
+
5
+ /**
6
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ */
11
+ declare type Colors = {
12
+ comment: {
13
+ close: string;
14
+ open: string;
15
+ };
16
+ content: {
17
+ close: string;
18
+ open: string;
19
+ };
20
+ prop: {
21
+ close: string;
22
+ open: string;
23
+ };
24
+ tag: {
25
+ close: string;
26
+ open: string;
27
+ };
28
+ value: {
29
+ close: string;
30
+ open: string;
31
+ };
32
+ };
33
+ declare type Indent = (arg0: string) => string;
34
+ declare type Refs = Array<unknown>;
35
+ declare type Print = (arg0: unknown) => string;
36
+ declare type ThemeReceived = {
37
+ comment?: string;
38
+ content?: string;
39
+ prop?: string;
40
+ tag?: string;
41
+ value?: string;
42
+ };
43
+ declare type CompareKeys = ((a: string, b: string) => number) | undefined;
44
+ interface PrettyFormatOptions {
45
+ callToJSON?: boolean;
46
+ compareKeys?: CompareKeys;
47
+ escapeRegex?: boolean;
48
+ escapeString?: boolean;
49
+ highlight?: boolean;
50
+ indent?: number;
51
+ maxDepth?: number;
52
+ min?: boolean;
53
+ plugins?: Plugins;
54
+ printBasicPrototype?: boolean;
55
+ printFunctionName?: boolean;
56
+ theme?: ThemeReceived;
57
+ }
58
+ declare type OptionsReceived = PrettyFormatOptions;
59
+ declare type Config = {
60
+ callToJSON: boolean;
61
+ compareKeys: CompareKeys;
62
+ colors: Colors;
63
+ escapeRegex: boolean;
64
+ escapeString: boolean;
65
+ indent: string;
66
+ maxDepth: number;
67
+ min: boolean;
68
+ plugins: Plugins;
69
+ printBasicPrototype: boolean;
70
+ printFunctionName: boolean;
71
+ spacingInner: string;
72
+ spacingOuter: string;
73
+ };
74
+ declare type Printer = (val: unknown, config: Config, indentation: string, depth: number, refs: Refs, hasCalledToJSON?: boolean) => string;
75
+ declare type Test$1 = (arg0: any) => boolean;
76
+ declare type NewPlugin = {
77
+ serialize: (val: any, config: Config, indentation: string, depth: number, refs: Refs, printer: Printer) => string;
78
+ test: Test$1;
79
+ };
80
+ declare type PluginOptions = {
81
+ edgeSpacing: string;
82
+ min: boolean;
83
+ spacing: string;
84
+ };
85
+ declare type OldPlugin = {
86
+ print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
87
+ test: Test$1;
88
+ };
89
+ declare type Plugin = NewPlugin | OldPlugin;
90
+ declare type Plugins = Array<Plugin>;
91
+
92
+ // Type definitions for @sinonjs/fake-timers 8.1
93
+ // Project: https://github.com/sinonjs/fake-timers
94
+ // Definitions by: Wim Looman <https://github.com/Nemo157>
95
+ // Rogier Schouten <https://github.com/rogierschouten>
96
+ // Yishai Zehavi <https://github.com/zyishai>
97
+ // Remco Haszing <https://github.com/remcohaszing>
98
+ // Jaden Simon <https://github.com/JadenSimon>
99
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
100
+ // TypeScript Version: 2.3
101
+
102
+ /**
103
+ * Names of clock methods that may be faked by install.
104
+ */
105
+ type FakeMethod =
106
+ | 'setTimeout'
107
+ | 'clearTimeout'
108
+ | 'setImmediate'
109
+ | 'clearImmediate'
110
+ | 'setInterval'
111
+ | 'clearInterval'
112
+ | 'Date'
113
+ | 'nextTick'
114
+ | 'hrtime'
115
+ | 'requestAnimationFrame'
116
+ | 'cancelAnimationFrame'
117
+ | 'requestIdleCallback'
118
+ | 'cancelIdleCallback'
119
+ | 'performance'
120
+ | 'queueMicrotask';
121
+
122
+ interface FakeTimerInstallOpts {
123
+ /**
124
+ * Installs fake timers with the specified unix epoch (default: 0)
125
+ */
126
+ now?: number | Date | undefined;
127
+
128
+ /**
129
+ * An array with names of global methods and APIs to fake. By default, `@sinonjs/fake-timers` does not replace `nextTick()` and `queueMicrotask()`.
130
+ * For instance, `FakeTimers.install({ toFake: ['setTimeout', 'nextTick'] })` will fake only `setTimeout()` and `nextTick()`
131
+ */
132
+ toFake?: FakeMethod[] | undefined;
133
+
134
+ /**
135
+ * The maximum number of timers that will be run when calling runAll() (default: 1000)
136
+ */
137
+ loopLimit?: number | undefined;
138
+
139
+ /**
140
+ * Tells @sinonjs/fake-timers to increment mocked time automatically based on the real system time shift (e.g. the mocked time will be incremented by
141
+ * 20ms for every 20ms change in the real system time) (default: false)
142
+ */
143
+ shouldAdvanceTime?: boolean | undefined;
144
+
145
+ /**
146
+ * Relevant only when using with shouldAdvanceTime: true. increment mocked time by advanceTimeDelta ms every advanceTimeDelta ms change
147
+ * in the real system time (default: 20)
148
+ */
149
+ advanceTimeDelta?: number | undefined;
150
+
151
+ /**
152
+ * Tells FakeTimers to clear 'native' (i.e. not fake) timers by delegating to their respective handlers. These are not cleared by
153
+ * default, leading to potentially unexpected behavior if timers existed prior to installing FakeTimers. (default: false)
154
+ */
155
+ shouldClearNativeTimers?: boolean | undefined;
156
+ }
157
+
158
+ interface UpdatePayload {
159
+ type: 'update'
160
+ updates: Update[]
161
+ }
162
+
163
+ interface Update {
164
+ type: 'js-update' | 'css-update'
165
+ path: string
166
+ acceptedPath: string
167
+ timestamp: number
168
+ }
169
+
170
+ interface PrunePayload {
171
+ type: 'prune'
172
+ paths: string[]
173
+ }
174
+
175
+ interface FullReloadPayload {
176
+ type: 'full-reload'
177
+ path?: string
178
+ }
179
+
180
+ interface ErrorPayload {
181
+ type: 'error'
182
+ err: {
183
+ [name: string]: any
184
+ message: string
185
+ stack: string
186
+ id?: string
187
+ frame?: string
188
+ plugin?: string
189
+ pluginCode?: string
190
+ loc?: {
191
+ file?: string
192
+ line: number
193
+ column: number
194
+ }
195
+ }
196
+ }
197
+
198
+ interface CustomEventMap {
199
+ 'vite:beforeUpdate': UpdatePayload
200
+ 'vite:beforePrune': PrunePayload
201
+ 'vite:beforeFullReload': FullReloadPayload
202
+ 'vite:error': ErrorPayload
203
+ }
204
+
205
+ type InferCustomEventPayload<T extends string> =
206
+ T extends keyof CustomEventMap ? CustomEventMap[T] : any
207
+
208
+ type ModuleNamespace = Record<string, any> & {
209
+ [Symbol.toStringTag]: 'Module'
210
+ }
211
+
212
+ interface ViteHotContext {
213
+ readonly data: any
214
+
215
+ accept(): void
216
+ accept(cb: (mod: ModuleNamespace | undefined) => void): void
217
+ accept(dep: string, cb: (mod: ModuleNamespace | undefined) => void): void
218
+ accept(
219
+ deps: readonly string[],
220
+ cb: (mods: Array<ModuleNamespace | undefined>) => void
221
+ ): void
222
+
223
+ acceptExports(exportNames: string | readonly string[]): void
224
+ acceptExports(
225
+ exportNames: string | readonly string[],
226
+ cb: (mod: ModuleNamespace | undefined) => void
227
+ ): void
228
+
229
+ dispose(cb: (data: any) => void): void
230
+ decline(): void
231
+ invalidate(): void
232
+
233
+ on<T extends string>(
234
+ event: T,
235
+ cb: (payload: InferCustomEventPayload<T>) => void
236
+ ): void
237
+ send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
238
+ }
239
+ declare class ModuleCacheMap extends Map<string, ModuleCache$1> {
240
+ normalizePath(fsPath: string): string;
241
+ set(fsPath: string, mod: Partial<ModuleCache$1>): this;
242
+ get(fsPath: string): ModuleCache$1 | undefined;
243
+ delete(fsPath: string): boolean;
244
+ }
245
+ declare class ViteNodeRunner {
246
+ options: ViteNodeRunnerOptions;
247
+ root: string;
248
+ debug: boolean;
249
+ /**
250
+ * Holds the cache of modules
251
+ * Keys of the map are filepaths, or plain package names
252
+ */
253
+ moduleCache: ModuleCacheMap;
254
+ constructor(options: ViteNodeRunnerOptions);
255
+ executeFile(file: string): Promise<any>;
256
+ executeId(id: string): Promise<any>;
257
+ /** @internal */
258
+ cachedRequest(rawId: string, callstack: string[]): Promise<any>;
259
+ /** @internal */
260
+ directRequest(id: string, fsPath: string, _callstack: string[]): Promise<any>;
261
+ prepareContext(context: Record<string, any>): Record<string, any>;
262
+ shouldResolveId(dep: string): boolean;
263
+ /**
264
+ * Define if a module should be interop-ed
265
+ * This function mostly for the ability to override by subclass
266
+ */
267
+ shouldInterop(path: string, mod: any): boolean;
268
+ /**
269
+ * Import a module and interop it
270
+ */
271
+ interopedImport(path: string): Promise<any>;
272
+ hasNestedDefault(target: any): any;
273
+ }
274
+ interface DepsHandlingOptions {
275
+ external?: (string | RegExp)[];
276
+ inline?: (string | RegExp)[] | true;
277
+ /**
278
+ * Try to guess the CJS version of a package when it's invalid ESM
279
+ * @default false
280
+ */
281
+ fallbackCJS?: boolean;
282
+ }
283
+ interface StartOfSourceMap {
284
+ file?: string;
285
+ sourceRoot?: string;
286
+ }
287
+ interface RawSourceMap extends StartOfSourceMap {
288
+ version: string;
289
+ sources: string[];
290
+ names: string[];
291
+ sourcesContent?: string[];
292
+ mappings: string;
293
+ }
294
+ interface FetchResult {
295
+ code?: string;
296
+ externalize?: string;
297
+ map?: RawSourceMap;
298
+ }
299
+ declare type HotContext = Omit<ViteHotContext, 'acceptDeps' | 'decline'>;
300
+ declare type FetchFunction = (id: string) => Promise<FetchResult>;
301
+ declare type ResolveIdFunction$1 = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
302
+ declare type CreateHotContextFunction = (runner: ViteNodeRunner, url: string) => HotContext;
303
+ interface ModuleCache$1 {
304
+ promise?: Promise<any>;
305
+ exports?: any;
306
+ code?: string;
307
+ }
308
+ interface ViteNodeRunnerOptions {
309
+ root: string;
310
+ fetchModule: FetchFunction;
311
+ resolveId?: ResolveIdFunction$1;
312
+ createHotContext?: CreateHotContextFunction;
313
+ base?: string;
314
+ moduleCache?: ModuleCacheMap;
315
+ interopDefault?: boolean;
316
+ requestStubs?: Record<string, any>;
317
+ debug?: boolean;
318
+ }
319
+ interface ViteNodeResolveId {
320
+ external?: boolean | 'absolute' | 'relative';
321
+ id: string;
322
+ meta?: Record<string, any> | null;
323
+ moduleSideEffects?: boolean | 'no-treeshake' | null;
324
+ syntheticNamedExports?: boolean | string | null;
325
+ }
326
+ interface ViteNodeServerOptions {
327
+ /**
328
+ * Inject inline sourcemap to modules
329
+ * @default 'inline'
330
+ */
331
+ sourcemap?: 'inline' | boolean;
332
+ /**
333
+ * Deps handling
334
+ */
335
+ deps?: DepsHandlingOptions;
336
+ /**
337
+ * Transform method for modules
338
+ */
339
+ transformMode?: {
340
+ ssr?: RegExp[];
341
+ web?: RegExp[];
342
+ };
343
+ debug?: DebuggerOptions;
344
+ }
345
+ interface DebuggerOptions {
346
+ /**
347
+ * Dump the transformed module to filesystem
348
+ * Passing a string will dump to the specified path
349
+ */
350
+ dumpModules?: boolean | string;
351
+ /**
352
+ * Read dumpped module from filesystem whenever exists.
353
+ * Useful for debugging by modifying the dump result from the filesystem.
354
+ */
355
+ loadDumppedModules?: boolean;
356
+ }
357
+
358
+ declare class Debugger {
359
+ options: DebuggerOptions;
360
+ dumpDir: string | undefined;
361
+ initPromise: Promise<void> | undefined;
362
+ externalizeMap: Map<string, string>;
363
+ constructor(root: string, options: DebuggerOptions);
364
+ clearDump(): Promise<void>;
365
+ encodeId(id: string): string;
366
+ recordExternalize(id: string, path: string): Promise<void>;
367
+ dumpFile(id: string, result: TransformResult$1 | null): Promise<void>;
368
+ loadDump(id: string): Promise<TransformResult$1 | null>;
369
+ writeInfo(): Promise<void>;
370
+ }
371
+
372
+ declare class ViteNodeServer {
373
+ server: ViteDevServer;
374
+ options: ViteNodeServerOptions;
375
+ private fetchPromiseMap;
376
+ private transformPromiseMap;
377
+ fetchCache: Map<string, {
378
+ timestamp: number;
379
+ result: FetchResult;
380
+ }>;
381
+ externalizeCache: Map<string, Promise<string | false>>;
382
+ debugger?: Debugger;
383
+ constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
384
+ shouldExternalize(id: string): Promise<string | false>;
385
+ resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
386
+ fetchModule(id: string): Promise<FetchResult>;
387
+ transformRequest(id: string): Promise<TransformResult$1 | null | undefined>;
388
+ getTransformMode(id: string): "web" | "ssr";
389
+ private _fetchModule;
390
+ private _transformRequest;
391
+ }
392
+
393
+ declare class SnapshotManager {
394
+ options: SnapshotStateOptions;
395
+ summary: SnapshotSummary;
396
+ extension: string;
397
+ constructor(options: SnapshotStateOptions);
398
+ clear(): void;
399
+ add(result: SnapshotResult): void;
400
+ resolvePath(testPath: string): string;
401
+ }
402
+
403
+ declare type RunWithFiles = (files: string[], invalidates?: string[]) => Promise<void>;
404
+ interface WorkerPool {
405
+ runTests: RunWithFiles;
406
+ close: () => Promise<void>;
407
+ }
408
+
409
+ interface CollectingPromise {
410
+ promise: Promise<void>;
411
+ resolve: () => void;
412
+ }
413
+ declare class StateManager {
414
+ filesMap: Map<string, File>;
415
+ pathsSet: Set<string>;
416
+ collectingPromise: CollectingPromise | undefined;
417
+ idMap: Map<string, Task>;
418
+ taskFileMap: WeakMap<Task, File>;
419
+ errorsSet: Set<unknown>;
420
+ catchError(err: unknown, type: string): void;
421
+ clearErrors(): void;
422
+ getUnhandledErrors(): unknown[];
423
+ startCollectingPaths(): void;
424
+ finishCollectingPaths(): void;
425
+ getPaths(): Promise<string[]>;
426
+ getFiles(keys?: string[]): File[];
427
+ getFilepaths(): string[];
428
+ getFailedFilepaths(): string[];
429
+ collectPaths(paths?: string[]): void;
430
+ collectFiles(files?: File[]): void;
431
+ clearFiles(paths?: string[]): void;
432
+ updateId(task: Task): void;
433
+ updateTasks(packs: TaskResultPack[]): void;
434
+ updateUserLog(log: UserConsoleLog): void;
435
+ }
436
+
437
+ declare class Logger {
438
+ ctx: Vitest;
439
+ console: Console;
440
+ outputStream: NodeJS.WriteStream & {
441
+ fd: 1;
442
+ };
443
+ errorStream: NodeJS.WriteStream & {
444
+ fd: 2;
445
+ };
446
+ logUpdate: ((...text: string[]) => void) & {
447
+ clear(): void;
448
+ done(): void;
449
+ };
450
+ private _clearScreenPending;
451
+ constructor(ctx: Vitest, console?: Console);
452
+ log(...args: any[]): void;
453
+ error(...args: any[]): void;
454
+ warn(...args: any[]): void;
455
+ clearScreen(message: string, force?: boolean): void;
456
+ private _clearScreen;
457
+ printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
458
+ printNoTestFound(filters?: string[]): void;
459
+ printBanner(): void;
460
+ printUnhandledErrors(errors: unknown[]): Promise<void>;
461
+ }
462
+
463
+ interface SuiteResultCache {
464
+ failed: boolean;
465
+ duration: number;
466
+ }
467
+ declare class ResultsCache {
468
+ private cache;
469
+ private cachePath;
470
+ private version;
471
+ private root;
472
+ getCachePath(): string | null;
473
+ setConfig(root: string, config: ResolvedConfig['cache']): void;
474
+ getResults(fsPath: string): SuiteResultCache | undefined;
475
+ readFromCache(): Promise<void>;
476
+ updateResults(files: File[]): void;
477
+ removeFromCache(filepath: string): void;
478
+ writeToCache(): Promise<void>;
479
+ }
480
+
481
+ interface CliOptions extends UserConfig {
482
+ /**
483
+ * Override the watch mode
484
+ */
485
+ run?: boolean;
486
+ }
487
+ declare function startVitest(cliFilters: string[], options: CliOptions, viteOverrides?: UserConfig$1): Promise<boolean>;
488
+
489
+ declare type FileStatsCache = Pick<Stats, 'size'>;
490
+ declare class FilesStatsCache {
491
+ cache: Map<string, FileStatsCache>;
492
+ getStats(fsPath: string): FileStatsCache | undefined;
493
+ updateStats(fsPath: string): Promise<void>;
494
+ removeStats(fsPath: string): void;
495
+ }
496
+
497
+ declare class VitestCache {
498
+ results: ResultsCache;
499
+ stats: FilesStatsCache;
500
+ getFileTestResults(id: string): SuiteResultCache | undefined;
501
+ getFileStats(id: string): {
502
+ size: number;
503
+ } | undefined;
504
+ static resolveCacheDir(root: string, dir: string | undefined): string;
505
+ static clearCache(options: CliOptions): Promise<{
506
+ dir: string;
507
+ cleared: boolean;
508
+ }>;
509
+ }
510
+
511
+ declare class Vitest {
512
+ config: ResolvedConfig;
513
+ configOverride: Partial<ResolvedConfig> | undefined;
514
+ server: ViteDevServer;
515
+ state: StateManager;
516
+ snapshot: SnapshotManager;
517
+ cache: VitestCache;
518
+ reporters: Reporter[];
519
+ coverageProvider: CoverageProvider | null | undefined;
520
+ logger: Logger;
521
+ pool: WorkerPool | undefined;
522
+ vitenode: ViteNodeServer;
523
+ invalidates: Set<string>;
524
+ changedTests: Set<string>;
525
+ runningPromise?: Promise<void>;
526
+ closingPromise?: Promise<void>;
527
+ isFirstRun: boolean;
528
+ restartsCount: number;
529
+ runner: ViteNodeRunner;
530
+ constructor();
531
+ private _onRestartListeners;
532
+ setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
533
+ initCoverageProvider(): Promise<CoverageProvider | null | undefined>;
534
+ getSerializableConfig(): ResolvedConfig;
535
+ start(filters?: string[]): Promise<void>;
536
+ private getTestDependencies;
537
+ filterTestsBySource(tests: string[]): Promise<string[]>;
538
+ runFiles(paths: string[]): Promise<void>;
539
+ rerunFiles(files?: string[], trigger?: string): Promise<void>;
540
+ changeNamePattern(pattern: string, files?: string[], trigger?: string): Promise<void>;
541
+ rerunFailed(): Promise<void>;
542
+ updateSnapshot(files?: string[]): Promise<void>;
543
+ private _rerunTimer;
544
+ private scheduleRerun;
545
+ private unregisterWatcher;
546
+ private registerWatcher;
547
+ /**
548
+ * @returns A value indicating whether rerun is needed (changedTests was mutated)
549
+ */
550
+ private handleFileChanged;
551
+ close(): Promise<void>;
552
+ exit(force?: boolean): Promise<void>;
553
+ report<T extends keyof Reporter>(name: T, ...args: ArgumentsType$1<Reporter[T]>): Promise<void>;
554
+ globTestFiles(filters?: string[]): Promise<string[]>;
555
+ isTargetFile(id: string, source?: string): Promise<boolean>;
556
+ isInSourceTestFile(code: string): boolean;
557
+ onServerRestarted(fn: () => void): void;
558
+ }
559
+
560
+ declare type MockMap = Map<string, Record<string, string | null | (() => unknown)>>;
561
+
562
+ interface TestSequencer {
563
+ /**
564
+ * Slicing tests into shards. Will be run before `sort`.
565
+ * Only run, if `shard` is defined.
566
+ */
567
+ shard(files: string[]): Awaitable<string[]>;
568
+ sort(files: string[]): Awaitable<string[]>;
569
+ }
570
+ interface TestSequencerConstructor {
571
+ new (ctx: Vitest): TestSequencer;
572
+ }
573
+
574
+ declare abstract class BaseReporter implements Reporter {
575
+ start: number;
576
+ end: number;
577
+ watchFilters?: string[];
578
+ isTTY: false;
579
+ ctx: Vitest;
580
+ private _filesInWatchMode;
581
+ private _lastRunTimeout;
582
+ private _lastRunTimer;
583
+ private _lastRunCount;
584
+ private _timeStart;
585
+ constructor();
586
+ onInit(ctx: Vitest): void;
587
+ relative(path: string): string;
588
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
589
+ onTaskUpdate(packs: TaskResultPack[]): void;
590
+ onWatcherStart(): Promise<void>;
591
+ private resetLastRunLog;
592
+ onWatcherRerun(files: string[], trigger?: string): Promise<void>;
593
+ onUserConsoleLog(log: UserConsoleLog): void;
594
+ shouldLog(log: UserConsoleLog): boolean;
595
+ onServerRestart(): void;
596
+ reportSummary(files: File[]): Promise<void>;
597
+ private printTaskErrors;
598
+ registerUnhandledRejection(): void;
599
+ }
600
+
601
+ interface ListRendererOptions {
602
+ renderSucceed?: boolean;
603
+ logger: Logger;
604
+ showHeap: boolean;
605
+ }
606
+ declare const createListRenderer: (_tasks: Task[], options: ListRendererOptions) => {
607
+ start(): any;
608
+ update(_tasks: Task[]): any;
609
+ stop(): Promise<any>;
610
+ clear(): void;
611
+ };
612
+
613
+ declare class DefaultReporter extends BaseReporter {
614
+ renderer?: ReturnType<typeof createListRenderer>;
615
+ rendererOptions: ListRendererOptions;
616
+ onTestRemoved(trigger?: string): Promise<void>;
617
+ onCollected(): void;
618
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
619
+ onWatcherStart(): Promise<void>;
620
+ stopListRender(): Promise<void>;
621
+ onWatcherRerun(files: string[], trigger?: string): Promise<void>;
622
+ onUserConsoleLog(log: UserConsoleLog): void;
623
+ }
624
+
625
+ declare class DotReporter extends BaseReporter {
626
+ renderer?: ReturnType<typeof createListRenderer>;
627
+ onCollected(): void;
628
+ onFinished(files?: File[], errors?: unknown[]): Promise<void>;
629
+ onWatcherStart(): Promise<void>;
630
+ stopListRender(): Promise<void>;
631
+ onWatcherRerun(files: string[], trigger?: string): Promise<void>;
632
+ onUserConsoleLog(log: UserConsoleLog): void;
633
+ }
634
+
635
+ interface Callsite {
636
+ line: number;
637
+ column: number;
638
+ }
639
+ declare class JsonReporter implements Reporter {
640
+ start: number;
641
+ ctx: Vitest;
642
+ onInit(ctx: Vitest): void;
643
+ protected logTasks(files: File[]): Promise<void>;
644
+ onFinished(files?: File[]): Promise<void>;
645
+ /**
646
+ * Writes the report to an output file if specified in the config,
647
+ * or logs it to the console otherwise.
648
+ * @param report
649
+ */
650
+ writeReport(report: string): Promise<void>;
651
+ protected getFailureLocation(test: Test): Callsite | undefined;
652
+ }
653
+
654
+ declare class VerboseReporter extends DefaultReporter {
655
+ constructor();
656
+ onTaskUpdate(packs: TaskResultPack[]): void;
657
+ }
658
+
659
+ declare class TapReporter implements Reporter {
660
+ protected ctx: Vitest;
661
+ private logger;
662
+ onInit(ctx: Vitest): void;
663
+ static getComment(task: Task): string;
664
+ private logErrorDetails;
665
+ protected logTasks(tasks: Task[]): void;
666
+ onFinished(files?: File[]): Promise<void>;
667
+ }
668
+
669
+ declare class JUnitReporter implements Reporter {
670
+ private ctx;
671
+ private reportFile?;
672
+ private baseLog;
673
+ private logger;
674
+ onInit(ctx: Vitest): Promise<void>;
675
+ writeElement(name: string, attrs: Record<string, any>, children: () => Promise<void>): Promise<void>;
676
+ writeErrorDetails(error: ErrorWithDiff): Promise<void>;
677
+ writeLogs(task: Task, type: 'err' | 'out'): Promise<void>;
678
+ writeTasks(tasks: Task[], filename: string): Promise<void>;
679
+ onFinished(files?: File[]): Promise<void>;
680
+ }
681
+
682
+ declare class TapFlatReporter extends TapReporter {
683
+ onInit(ctx: Vitest): void;
684
+ onFinished(files?: File[]): Promise<void>;
685
+ }
686
+
687
+ declare const ReportersMap: {
688
+ default: typeof DefaultReporter;
689
+ verbose: typeof VerboseReporter;
690
+ dot: typeof DotReporter;
691
+ json: typeof JsonReporter;
692
+ tap: typeof TapReporter;
693
+ 'tap-flat': typeof TapFlatReporter;
694
+ junit: typeof JUnitReporter;
695
+ };
696
+ declare type BuiltinReporters = keyof typeof ReportersMap;
697
+
698
+ interface RollupError extends RollupLogProps {
699
+ parserError?: Error;
700
+ stack?: string;
701
+ watchFiles?: string[];
702
+ }
703
+
704
+ interface RollupWarning extends RollupLogProps {
705
+ chunkName?: string;
706
+ cycle?: string[];
707
+ exportName?: string;
708
+ exporter?: string;
709
+ guess?: string;
710
+ importer?: string;
711
+ missing?: string;
712
+ modules?: string[];
713
+ names?: string[];
714
+ reexporter?: string;
715
+ source?: string;
716
+ sources?: string[];
717
+ }
718
+
719
+ interface RollupLogProps {
720
+ code?: string;
721
+ frame?: string;
722
+ hook?: string;
723
+ id?: string;
724
+ loc?: {
725
+ column: number;
726
+ file?: string;
727
+ line: number;
728
+ };
729
+ message: string;
730
+ name?: string;
731
+ plugin?: string;
732
+ pluginCode?: string;
733
+ pos?: number;
734
+ url?: string;
735
+ }
736
+
737
+ interface ExistingRawSourceMap {
738
+ file?: string;
739
+ mappings: string;
740
+ names: string[];
741
+ sourceRoot?: string;
742
+ sources: string[];
743
+ sourcesContent?: string[];
744
+ version: number;
745
+ }
746
+
747
+ interface SourceMap {
748
+ file: string;
749
+ mappings: string;
750
+ names: string[];
751
+ sources: string[];
752
+ sourcesContent: string[];
753
+ version: number;
754
+ toString(): string;
755
+ toUrl(): string;
756
+ }
757
+
758
+ type SourceMapInput = ExistingRawSourceMap | string | null | { mappings: '' };
759
+
760
+ type PartialNull<T> = {
761
+ [P in keyof T]: T[P] | null;
762
+ };
763
+
764
+ interface ModuleOptions {
765
+ meta: CustomPluginOptions;
766
+ moduleSideEffects: boolean | 'no-treeshake';
767
+ syntheticNamedExports: boolean | string;
768
+ }
769
+
770
+ interface SourceDescription extends Partial<PartialNull<ModuleOptions>> {
771
+ ast?: AcornNode;
772
+ code: string;
773
+ map?: SourceMapInput;
774
+ }
775
+
776
+ interface PluginCache {
777
+ delete(id: string): boolean;
778
+ get<T = any>(id: string): T;
779
+ has(id: string): boolean;
780
+ set<T = any>(id: string, value: T): void;
781
+ }
782
+
783
+ interface MinimalPluginContext {
784
+ meta: PluginContextMeta;
785
+ }
786
+
787
+ interface EmittedAsset {
788
+ fileName?: string;
789
+ name?: string;
790
+ source?: string | Uint8Array;
791
+ type: 'asset';
792
+ }
793
+
794
+ interface EmittedChunk {
795
+ fileName?: string;
796
+ id: string;
797
+ implicitlyLoadedAfterOneOf?: string[];
798
+ importer?: string;
799
+ name?: string;
800
+ preserveSignature?: PreserveEntrySignaturesOption;
801
+ type: 'chunk';
802
+ }
803
+
804
+ type EmittedFile = EmittedAsset | EmittedChunk;
805
+
806
+ type EmitAsset = (name: string, source?: string | Uint8Array) => string;
807
+
808
+ type EmitChunk = (id: string, options?: { name?: string }) => string;
809
+
810
+ type EmitFile = (emittedFile: EmittedFile) => string;
811
+
812
+ interface ModuleInfo extends ModuleOptions {
813
+ ast: AcornNode | null;
814
+ code: string | null;
815
+ dynamicImporters: readonly string[];
816
+ dynamicallyImportedIdResolutions: readonly ResolvedId[];
817
+ dynamicallyImportedIds: readonly string[];
818
+ hasDefaultExport: boolean | null;
819
+ /** @deprecated Use `moduleSideEffects` instead */
820
+ hasModuleSideEffects: boolean | 'no-treeshake';
821
+ id: string;
822
+ implicitlyLoadedAfterOneOf: readonly string[];
823
+ implicitlyLoadedBefore: readonly string[];
824
+ importedIdResolutions: readonly ResolvedId[];
825
+ importedIds: readonly string[];
826
+ importers: readonly string[];
827
+ isEntry: boolean;
828
+ isExternal: boolean;
829
+ isIncluded: boolean | null;
830
+ }
831
+
832
+ type GetModuleInfo = (moduleId: string) => ModuleInfo | null;
833
+
834
+ interface CustomPluginOptions {
835
+ [plugin: string]: any;
836
+ }
837
+
838
+ interface PluginContext extends MinimalPluginContext {
839
+ addWatchFile: (id: string) => void;
840
+ cache: PluginCache;
841
+ /** @deprecated Use `this.emitFile` instead */
842
+ emitAsset: EmitAsset;
843
+ /** @deprecated Use `this.emitFile` instead */
844
+ emitChunk: EmitChunk;
845
+ emitFile: EmitFile;
846
+ error: (err: RollupError | string, pos?: number | { column: number; line: number }) => never;
847
+ /** @deprecated Use `this.getFileName` instead */
848
+ getAssetFileName: (assetReferenceId: string) => string;
849
+ /** @deprecated Use `this.getFileName` instead */
850
+ getChunkFileName: (chunkReferenceId: string) => string;
851
+ getFileName: (fileReferenceId: string) => string;
852
+ getModuleIds: () => IterableIterator<string>;
853
+ getModuleInfo: GetModuleInfo;
854
+ getWatchFiles: () => string[];
855
+ /** @deprecated Use `this.resolve` instead */
856
+ isExternal: IsExternal;
857
+ load: (
858
+ options: { id: string; resolveDependencies?: boolean } & Partial<PartialNull<ModuleOptions>>
859
+ ) => Promise<ModuleInfo>;
860
+ /** @deprecated Use `this.getModuleIds` instead */
861
+ moduleIds: IterableIterator<string>;
862
+ parse: (input: string, options?: any) => AcornNode;
863
+ resolve: (
864
+ source: string,
865
+ importer?: string,
866
+ options?: { custom?: CustomPluginOptions; isEntry?: boolean; skipSelf?: boolean }
867
+ ) => Promise<ResolvedId | null>;
868
+ /** @deprecated Use `this.resolve` instead */
869
+ resolveId: (source: string, importer?: string) => Promise<string | null>;
870
+ setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void;
871
+ warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void;
872
+ }
873
+
874
+ interface PluginContextMeta {
875
+ rollupVersion: string;
876
+ watchMode: boolean;
877
+ }
878
+
879
+ interface ResolvedId extends ModuleOptions {
880
+ external: boolean | 'absolute';
881
+ id: string;
882
+ }
883
+
884
+ type IsExternal = (
885
+ source: string,
886
+ importer: string | undefined,
887
+ isResolved: boolean
888
+ ) => boolean;
889
+
890
+ interface TransformPluginContext extends PluginContext {
891
+ getCombinedSourcemap: () => SourceMap;
892
+ }
893
+
894
+ type TransformResult = string | null | void | Partial<SourceDescription>;
895
+ type PreserveEntrySignaturesOption = false | 'strict' | 'allow-extension' | 'exports-only';
896
+
897
+ interface AcornNode {
898
+ end: number;
899
+ start: number;
900
+ type: string;
901
+ }
902
+
903
+ declare type Awaitable<T> = T | PromiseLike<T>;
904
+ declare type Nullable<T> = T | null | undefined;
905
+ declare type Arrayable<T> = T | Array<T>;
906
+ declare type ArgumentsType$1<T> = T extends (...args: infer U) => any ? U : never;
907
+ declare type MergeInsertions<T> = T extends object ? {
908
+ [K in keyof T]: MergeInsertions<T[K]>;
909
+ } : T;
910
+ declare type DeepMerge<F, S> = MergeInsertions<{
911
+ [K in keyof F | keyof S]: K extends keyof S & keyof F ? DeepMerge<F[K], S[K]> : K extends keyof S ? S[K] : K extends keyof F ? F[K] : never;
912
+ }>;
913
+ declare type MutableArray<T extends readonly any[]> = {
914
+ -readonly [k in keyof T]: T[k];
915
+ };
916
+ interface Constructable {
917
+ new (...args: any[]): any;
918
+ }
919
+ interface ModuleCache {
920
+ promise?: Promise<any>;
921
+ exports?: any;
922
+ code?: string;
923
+ }
924
+ interface EnvironmentReturn {
925
+ teardown: (global: any) => Awaitable<void>;
926
+ }
927
+ interface Environment {
928
+ name: string;
929
+ setup(global: any, options: Record<string, any>): Awaitable<EnvironmentReturn>;
930
+ }
931
+ interface UserConsoleLog {
932
+ content: string;
933
+ type: 'stdout' | 'stderr';
934
+ taskId?: string;
935
+ time: number;
936
+ size: number;
937
+ }
938
+ interface Position {
939
+ source?: string;
940
+ line: number;
941
+ column: number;
942
+ }
943
+ interface ParsedStack {
944
+ method: string;
945
+ file: string;
946
+ line: number;
947
+ column: number;
948
+ sourcePos?: Position;
949
+ }
950
+ interface ErrorWithDiff extends Error {
951
+ name: string;
952
+ nameStr?: string;
953
+ stack?: string;
954
+ stackStr?: string;
955
+ stacks?: ParsedStack[];
956
+ showDiff?: boolean;
957
+ actual?: any;
958
+ expected?: any;
959
+ operator?: string;
960
+ type?: string;
961
+ }
962
+ interface ModuleGraphData {
963
+ graph: Record<string, string[]>;
964
+ externalized: string[];
965
+ inlined: string[];
966
+ }
967
+
968
+ declare type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
969
+ declare type ReturnType$1<T> = T extends (...args: any) => infer R ? R : never;
970
+ declare type PromisifyFn<T> = ReturnType$1<T> extends Promise<any> ? T : (...args: ArgumentsType<T>) => Promise<Awaited<ReturnType$1<T>>>;
971
+ declare type BirpcFn<T> = PromisifyFn<T> & {
972
+ /**
973
+ * Send event without asking for response
974
+ */
975
+ asEvent(...args: ArgumentsType<T>): void;
976
+ };
977
+ declare type BirpcReturn<RemoteFunctions> = {
978
+ [K in keyof RemoteFunctions]: BirpcFn<RemoteFunctions[K]>;
979
+ };
980
+
981
+ declare type ChainableFunction<T extends string, Args extends any[], R = any, E = {}> = {
982
+ (...args: Args): R;
983
+ } & {
984
+ [x in T]: ChainableFunction<T, Args, R, E>;
985
+ } & E;
986
+
987
+ declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
988
+ declare type TaskState = RunMode | 'pass' | 'fail';
989
+ interface TaskBase {
990
+ id: string;
991
+ name: string;
992
+ mode: RunMode;
993
+ concurrent?: boolean;
994
+ shuffle?: boolean;
995
+ suite?: Suite;
996
+ file?: File;
997
+ result?: TaskResult;
998
+ logs?: UserConsoleLog[];
999
+ }
1000
+ interface TaskResult {
1001
+ state: TaskState;
1002
+ duration?: number;
1003
+ startTime?: number;
1004
+ heap?: number;
1005
+ error?: ErrorWithDiff;
1006
+ htmlError?: string;
1007
+ hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
1008
+ }
1009
+ declare type TaskResultPack = [id: string, result: TaskResult | undefined];
1010
+ interface Suite extends TaskBase {
1011
+ type: 'suite';
1012
+ tasks: Task[];
1013
+ filepath?: string;
1014
+ }
1015
+ interface File extends Suite {
1016
+ filepath: string;
1017
+ collectDuration?: number;
1018
+ setupDuration?: number;
1019
+ }
1020
+ interface Test<ExtraContext = {}> extends TaskBase {
1021
+ type: 'test';
1022
+ suite: Suite;
1023
+ result?: TaskResult;
1024
+ fails?: boolean;
1025
+ context: TestContext & ExtraContext;
1026
+ }
1027
+ declare type Task = Test | Suite | File;
1028
+ declare type DoneCallback = (error?: any) => void;
1029
+ declare type TestFunction<ExtraContext = {}> = (context: TestContext & ExtraContext) => Awaitable<any> | void;
1030
+ declare type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
1031
+ 1: [T[0]];
1032
+ 2: [T[0], T[1]];
1033
+ 3: [T[0], T[1], T[2]];
1034
+ 4: [T[0], T[1], T[2], T[3]];
1035
+ 5: [T[0], T[1], T[2], T[3], T[4]];
1036
+ 6: [T[0], T[1], T[2], T[3], T[4], T[5]];
1037
+ 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6]];
1038
+ 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7]];
1039
+ 9: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8]];
1040
+ 10: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]];
1041
+ fallback: Array<T extends ReadonlyArray<infer U> ? U : any>;
1042
+ }[T extends Readonly<[any]> ? 1 : T extends Readonly<[any, any]> ? 2 : T extends Readonly<[any, any, any]> ? 3 : T extends Readonly<[any, any, any, any]> ? 4 : T extends Readonly<[any, any, any, any, any]> ? 5 : T extends Readonly<[any, any, any, any, any, any]> ? 6 : T extends Readonly<[any, any, any, any, any, any, any]> ? 7 : T extends Readonly<[any, any, any, any, any, any, any, any]> ? 8 : T extends Readonly<[any, any, any, any, any, any, any, any, any]> ? 9 : T extends Readonly<[any, any, any, any, any, any, any, any, any, any]> ? 10 : 'fallback'];
1043
+ interface SuiteEachFunction {
1044
+ <T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T) => Awaitable<void>) => void;
1045
+ <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string, fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>) => void;
1046
+ <T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => Awaitable<void>) => void;
1047
+ }
1048
+ interface TestEachFunction {
1049
+ <T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T) => Awaitable<void>, timeout?: number) => void;
1050
+ <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string, fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>, timeout?: number) => void;
1051
+ <T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => Awaitable<void>, timeout?: number) => void;
1052
+ }
1053
+ declare type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [
1054
+ name: string,
1055
+ fn?: TestFunction<ExtraContext>,
1056
+ timeout?: number
1057
+ ], void, {
1058
+ each: TestEachFunction;
1059
+ <T extends ExtraContext>(name: string, fn?: TestFunction<T>, timeout?: number): void;
1060
+ }>;
1061
+ declare type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & {
1062
+ each: TestEachFunction;
1063
+ skipIf(condition: any): ChainableTestAPI<ExtraContext>;
1064
+ runIf(condition: any): ChainableTestAPI<ExtraContext>;
1065
+ };
1066
+ declare type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle', [
1067
+ name: string,
1068
+ factory?: SuiteFactory<ExtraContext>
1069
+ ], SuiteCollector<ExtraContext>, {
1070
+ each: TestEachFunction;
1071
+ <T extends ExtraContext>(name: string, factory?: SuiteFactory<T>): SuiteCollector<T>;
1072
+ }>;
1073
+ declare type SuiteAPI<ExtraContext = {}> = ChainableSuiteAPI<ExtraContext> & {
1074
+ each: SuiteEachFunction;
1075
+ skipIf(condition: any): ChainableSuiteAPI<ExtraContext>;
1076
+ runIf(condition: any): ChainableSuiteAPI<ExtraContext>;
1077
+ };
1078
+ declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
1079
+ declare type HookCleanupCallback = (() => Awaitable<unknown>) | void;
1080
+ interface SuiteHooks<ExtraContext = {}> {
1081
+ beforeAll: HookListener<[Suite | File], HookCleanupCallback>[];
1082
+ afterAll: HookListener<[Suite | File]>[];
1083
+ beforeEach: HookListener<[TestContext & ExtraContext, Suite], HookCleanupCallback>[];
1084
+ afterEach: HookListener<[TestContext & ExtraContext, Suite]>[];
1085
+ }
1086
+ interface SuiteCollector<ExtraContext = {}> {
1087
+ readonly name: string;
1088
+ readonly mode: RunMode;
1089
+ type: 'collector';
1090
+ test: TestAPI<ExtraContext>;
1091
+ tasks: (Suite | Test | SuiteCollector<ExtraContext>)[];
1092
+ collect: (file?: File) => Promise<Suite>;
1093
+ clear: () => void;
1094
+ on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
1095
+ }
1096
+ declare type SuiteFactory<ExtraContext = {}> = (test: (name: string, fn: TestFunction<ExtraContext>) => void) => Awaitable<void>;
1097
+ interface RuntimeContext {
1098
+ tasks: (SuiteCollector | Test)[];
1099
+ currentSuite: SuiteCollector | null;
1100
+ }
1101
+ interface TestContext {
1102
+ /**
1103
+ * @deprecated Use promise instead
1104
+ */
1105
+ (error?: any): void;
1106
+ /**
1107
+ * Metadata of the current test
1108
+ */
1109
+ meta: Readonly<Test>;
1110
+ /**
1111
+ * A expect instance bound to the test
1112
+ */
1113
+ expect: Vi.ExpectStatic;
1114
+ }
1115
+
1116
+ declare type SnapshotData = Record<string, string>;
1117
+ declare type SnapshotUpdateState = 'all' | 'new' | 'none';
1118
+ interface SnapshotStateOptions {
1119
+ updateSnapshot: SnapshotUpdateState;
1120
+ expand?: boolean;
1121
+ snapshotFormat?: OptionsReceived;
1122
+ resolveSnapshotPath?: (path: string, extension: string) => string;
1123
+ }
1124
+ interface SnapshotMatchOptions {
1125
+ testName: string;
1126
+ received: unknown;
1127
+ key?: string;
1128
+ inlineSnapshot?: string;
1129
+ isInline: boolean;
1130
+ error?: Error;
1131
+ }
1132
+ interface SnapshotResult {
1133
+ filepath: string;
1134
+ added: number;
1135
+ fileDeleted: boolean;
1136
+ matched: number;
1137
+ unchecked: number;
1138
+ uncheckedKeys: Array<string>;
1139
+ unmatched: number;
1140
+ updated: number;
1141
+ }
1142
+ interface UncheckedSnapshot {
1143
+ filePath: string;
1144
+ keys: Array<string>;
1145
+ }
1146
+ interface SnapshotSummary {
1147
+ added: number;
1148
+ didUpdate: boolean;
1149
+ failure: boolean;
1150
+ filesAdded: number;
1151
+ filesRemoved: number;
1152
+ filesRemovedList: Array<string>;
1153
+ filesUnmatched: number;
1154
+ filesUpdated: number;
1155
+ matched: number;
1156
+ total: number;
1157
+ unchecked: number;
1158
+ uncheckedKeysByFile: Array<UncheckedSnapshot>;
1159
+ unmatched: number;
1160
+ updated: number;
1161
+ }
1162
+
1163
+ interface WorkerContext {
1164
+ workerId: number;
1165
+ port: MessagePort;
1166
+ config: ResolvedConfig;
1167
+ files: string[];
1168
+ invalidates?: string[];
1169
+ }
1170
+ declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
1171
+ interface AfterSuiteRunMeta {
1172
+ coverage?: unknown;
1173
+ }
1174
+ interface WorkerRPC {
1175
+ fetch: FetchFunction;
1176
+ resolveId: ResolveIdFunction;
1177
+ getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
1178
+ onFinished: (files: File[], errors?: unknown[]) => void;
1179
+ onWorkerExit: (code?: number) => void;
1180
+ onPathsCollected: (paths: string[]) => void;
1181
+ onUserConsoleLog: (log: UserConsoleLog) => void;
1182
+ onUnhandledRejection: (err: unknown) => void;
1183
+ onCollected: (files: File[]) => void;
1184
+ onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
1185
+ onTaskUpdate: (pack: TaskResultPack[]) => void;
1186
+ snapshotSaved: (snapshot: SnapshotResult) => void;
1187
+ resolveSnapshotPath: (testPath: string) => string;
1188
+ }
1189
+ interface WorkerGlobalState {
1190
+ ctx: WorkerContext;
1191
+ config: ResolvedConfig;
1192
+ rpc: BirpcReturn<WorkerRPC>;
1193
+ current?: Test;
1194
+ filepath?: string;
1195
+ moduleCache: ModuleCacheMap;
1196
+ browserHashMap?: Map<string, string>;
1197
+ mockMap: MockMap;
1198
+ }
1199
+
1200
+ interface CoverageProvider {
1201
+ name: string;
1202
+ initialize(ctx: Vitest): Promise<void> | void;
1203
+ resolveOptions(): ResolvedCoverageOptions;
1204
+ clean(clean?: boolean): void | Promise<void>;
1205
+ onBeforeFilesRun?(): void | Promise<void>;
1206
+ onAfterSuiteRun(meta: AfterSuiteRunMeta): void | Promise<void>;
1207
+ reportCoverage(): void | Promise<void>;
1208
+ onFileTransform?(sourceCode: string, id: string, pluginCtx: TransformPluginContext): TransformResult | Promise<TransformResult>;
1209
+ }
1210
+ interface CoverageProviderModule {
1211
+ /**
1212
+ * Factory for creating a new coverage provider
1213
+ */
1214
+ getProvider(): CoverageProvider | Promise<CoverageProvider>;
1215
+ /**
1216
+ * Executed on after each run in the worker thread. Possible to return a payload passed to the provider
1217
+ */
1218
+ takeCoverage?(): unknown | Promise<unknown>;
1219
+ }
1220
+ declare type CoverageReporter = 'clover' | 'cobertura' | 'html-spa' | 'html' | 'json-summary' | 'json' | 'lcov' | 'lcovonly' | 'none' | 'teamcity' | 'text-lcov' | 'text-summary' | 'text';
1221
+ declare type CoverageOptions = BaseCoverageOptions & {
1222
+ provider?: null | CoverageProviderModule;
1223
+ } | CoverageC8Options & {
1224
+ provider?: 'c8';
1225
+ } | CoverageIstanbulOptions & {
1226
+ provider?: 'istanbul';
1227
+ };
1228
+ declare type ResolvedCoverageOptions = {
1229
+ tempDirectory: string;
1230
+ } & Required<CoverageOptions>;
1231
+ interface BaseCoverageOptions {
1232
+ /**
1233
+ * Enable coverage, pass `--coverage` to enable
1234
+ *
1235
+ * @default false
1236
+ */
1237
+ enabled?: boolean;
1238
+ /**
1239
+ * Clean coverage before running tests
1240
+ *
1241
+ * @default true
1242
+ */
1243
+ clean?: boolean;
1244
+ /**
1245
+ * Clean coverage report on watch rerun
1246
+ *
1247
+ * @default false
1248
+ */
1249
+ cleanOnRerun?: boolean;
1250
+ /**
1251
+ * Directory to write coverage report to
1252
+ */
1253
+ reportsDirectory?: string;
1254
+ /**
1255
+ * Reporters
1256
+ *
1257
+ * @default 'text'
1258
+ */
1259
+ reporter?: Arrayable<CoverageReporter>;
1260
+ /**
1261
+ * List of files excluded from coverage as glob patterns
1262
+ */
1263
+ exclude?: string[];
1264
+ /**
1265
+ * Do not show files with 100% statement, branch, and function coverage
1266
+ */
1267
+ skipFull?: boolean;
1268
+ /**
1269
+ * Check thresholds per file
1270
+ *
1271
+ * @default false
1272
+ */
1273
+ perFile?: boolean;
1274
+ /**
1275
+ * Threshold for lines
1276
+ */
1277
+ lines?: number;
1278
+ /**
1279
+ * Threshold for functions
1280
+ */
1281
+ functions?: number;
1282
+ /**
1283
+ * Threshold for branches
1284
+ */
1285
+ branches?: number;
1286
+ /**
1287
+ * Threshold for statements
1288
+ */
1289
+ statements?: number;
1290
+ /**
1291
+ * Extensions for files to be included in coverage
1292
+ */
1293
+ extension?: string | string[];
1294
+ }
1295
+ interface CoverageIstanbulOptions extends BaseCoverageOptions {
1296
+ ignoreClassMethods?: string[];
1297
+ watermarks?: {
1298
+ statements?: [number, number];
1299
+ functions?: [number, number];
1300
+ branches?: [number, number];
1301
+ lines?: [number, number];
1302
+ };
1303
+ }
1304
+ interface CoverageC8Options extends BaseCoverageOptions {
1305
+ /**
1306
+ * Allow files from outside of your cwd.
1307
+ *
1308
+ * @default false
1309
+ */
1310
+ allowExternal?: any;
1311
+ /**
1312
+ * Exclude coverage under /node_modules/
1313
+ *
1314
+ * @default true
1315
+ */
1316
+ excludeNodeModules?: boolean;
1317
+ include?: string[];
1318
+ all?: boolean;
1319
+ src?: string[];
1320
+ 100?: boolean;
1321
+ }
1322
+
1323
+ interface JSDOMOptions {
1324
+ /**
1325
+ * The html content for the test.
1326
+ *
1327
+ * @default '<!DOCTYPE html>'
1328
+ */
1329
+ html?: string | Buffer | ArrayBufferLike;
1330
+ /**
1331
+ * referrer just affects the value read from document.referrer.
1332
+ * It defaults to no referrer (which reflects as the empty string).
1333
+ */
1334
+ referrer?: string;
1335
+ /**
1336
+ * userAgent affects the value read from navigator.userAgent, as well as the User-Agent header sent while fetching subresources.
1337
+ *
1338
+ * @default `Mozilla/5.0 (${process.platform}) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/${jsdomVersion}`
1339
+ */
1340
+ userAgent?: string;
1341
+ /**
1342
+ * url sets the value returned by window.location, document.URL, and document.documentURI,
1343
+ * and affects things like resolution of relative URLs within the document
1344
+ * and the same-origin restrictions and referrer used while fetching subresources.
1345
+ *
1346
+ * @default 'http://localhost:3000'.
1347
+ */
1348
+ url?: string;
1349
+ /**
1350
+ * contentType affects the value read from document.contentType, and how the document is parsed: as HTML or as XML.
1351
+ * Values that are not "text/html" or an XML mime type will throw.
1352
+ *
1353
+ * @default 'text/html'.
1354
+ */
1355
+ contentType?: string;
1356
+ /**
1357
+ * The maximum size in code units for the separate storage areas used by localStorage and sessionStorage.
1358
+ * Attempts to store data larger than this limit will cause a DOMException to be thrown. By default, it is set
1359
+ * to 5,000,000 code units per origin, as inspired by the HTML specification.
1360
+ *
1361
+ * @default 5_000_000
1362
+ */
1363
+ storageQuota?: number;
1364
+ /**
1365
+ * Enable console?
1366
+ *
1367
+ * @default false
1368
+ */
1369
+ console?: boolean;
1370
+ /**
1371
+ * jsdom does not have the capability to render visual content, and will act like a headless browser by default.
1372
+ * It provides hints to web pages through APIs such as document.hidden that their content is not visible.
1373
+ *
1374
+ * When the `pretendToBeVisual` option is set to `true`, jsdom will pretend that it is rendering and displaying
1375
+ * content.
1376
+ *
1377
+ * @default true
1378
+ */
1379
+ pretendToBeVisual?: boolean;
1380
+ /**
1381
+ * `includeNodeLocations` preserves the location info produced by the HTML parser,
1382
+ * allowing you to retrieve it with the nodeLocation() method (described below).
1383
+ *
1384
+ * It defaults to false to give the best performance,
1385
+ * and cannot be used with an XML content type since our XML parser does not support location info.
1386
+ *
1387
+ * @default false
1388
+ */
1389
+ includeNodeLocations?: boolean | undefined;
1390
+ /**
1391
+ * @default 'dangerously'
1392
+ */
1393
+ runScripts?: 'dangerously' | 'outside-only';
1394
+ /**
1395
+ * Enable CookieJar
1396
+ *
1397
+ * @default false
1398
+ */
1399
+ cookieJar?: boolean;
1400
+ resources?: 'usable' | any;
1401
+ }
1402
+
1403
+ interface Reporter {
1404
+ onInit?(ctx: Vitest): void;
1405
+ onPathsCollected?: (paths?: string[]) => Awaitable<void>;
1406
+ onCollected?: (files?: File[]) => Awaitable<void>;
1407
+ onFinished?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
1408
+ onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
1409
+ onTestRemoved?: (trigger?: string) => Awaitable<void>;
1410
+ onWatcherStart?: () => Awaitable<void>;
1411
+ onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
1412
+ onServerRestart?: () => Awaitable<void>;
1413
+ onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
1414
+ }
1415
+
1416
+ declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime';
1417
+ declare type ApiConfig = Pick<CommonServerOptions, 'port' | 'strictPort' | 'host'>;
1418
+
1419
+ interface EnvironmentOptions {
1420
+ /**
1421
+ * jsdom options.
1422
+ */
1423
+ jsdom?: JSDOMOptions;
1424
+ }
1425
+ interface InlineConfig {
1426
+ /**
1427
+ * Include globs for test files
1428
+ *
1429
+ * @default ['**\/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
1430
+ */
1431
+ include?: string[];
1432
+ /**
1433
+ * Exclude globs for test files
1434
+ * @default ['node_modules', 'dist', '.idea', '.git', '.cache']
1435
+ */
1436
+ exclude?: string[];
1437
+ /**
1438
+ * Include globs for in-source test files
1439
+ *
1440
+ * @default []
1441
+ */
1442
+ includeSource?: string[];
1443
+ /**
1444
+ * Handling for dependencies inlining or externalizing
1445
+ */
1446
+ deps?: {
1447
+ /**
1448
+ * Externalize means that Vite will bypass the package to native Node.
1449
+ *
1450
+ * Externalized dependencies will not be applied Vite's transformers and resolvers.
1451
+ * And does not support HMR on reload.
1452
+ *
1453
+ * Typically, packages under `node_modules` are externalized.
1454
+ */
1455
+ external?: (string | RegExp)[];
1456
+ /**
1457
+ * Vite will process inlined modules.
1458
+ *
1459
+ * This could be helpful to handle packages that ship `.js` in ESM format (that Node can't handle).
1460
+ *
1461
+ * If `true`, every dependency will be inlined
1462
+ */
1463
+ inline?: (string | RegExp)[] | true;
1464
+ /**
1465
+ * Interpret CJS module's default as named exports
1466
+ *
1467
+ * @default true
1468
+ */
1469
+ interopDefault?: boolean;
1470
+ /**
1471
+ * When a dependency is a valid ESM package, try to guess the cjs version based on the path.
1472
+ * This will significantly improve the performance in huge repo, but might potentially
1473
+ * cause some misalignment if a package have different logic in ESM and CJS mode.
1474
+ *
1475
+ * @default false
1476
+ */
1477
+ fallbackCJS?: boolean;
1478
+ /**
1479
+ * Use experimental Node loader to resolve imports inside node_modules using Vite resolve algorithm.
1480
+ * @default false
1481
+ */
1482
+ registerNodeLoader?: boolean;
1483
+ };
1484
+ /**
1485
+ * Base directory to scan for the test files
1486
+ *
1487
+ * @default `config.root`
1488
+ */
1489
+ dir?: string;
1490
+ /**
1491
+ * Register apis globally
1492
+ *
1493
+ * @default false
1494
+ */
1495
+ globals?: boolean;
1496
+ /**
1497
+ * Running environment
1498
+ *
1499
+ * Supports 'node', 'jsdom', 'happy-dom', 'edge-runtime'
1500
+ *
1501
+ * @default 'node'
1502
+ */
1503
+ environment?: BuiltinEnvironment;
1504
+ /**
1505
+ * Environment options.
1506
+ */
1507
+ environmentOptions?: EnvironmentOptions;
1508
+ /**
1509
+ * Update snapshot
1510
+ *
1511
+ * @default false
1512
+ */
1513
+ update?: boolean;
1514
+ /**
1515
+ * Watch mode
1516
+ *
1517
+ * @default true
1518
+ */
1519
+ watch?: boolean;
1520
+ /**
1521
+ * Project root
1522
+ *
1523
+ * @default process.cwd()
1524
+ */
1525
+ root?: string;
1526
+ /**
1527
+ * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
1528
+ * and/or paths to custom reporters
1529
+ */
1530
+ reporters?: Arrayable<BuiltinReporters | Reporter | Omit<string, BuiltinReporters>>;
1531
+ /**
1532
+ * diff output length
1533
+ */
1534
+ outputTruncateLength?: number;
1535
+ /**
1536
+ * number of diff output lines
1537
+ */
1538
+ outputDiffLines?: number;
1539
+ /**
1540
+ * Write test results to a file when the --reporter=json` or `--reporter=junit` option is also specified.
1541
+ * Also definable individually per reporter by using an object instead.
1542
+ */
1543
+ outputFile?: string | (Partial<Record<BuiltinReporters, string>> & Record<string, string>);
1544
+ /**
1545
+ * Enable multi-threading
1546
+ *
1547
+ * @default true
1548
+ */
1549
+ threads?: boolean;
1550
+ /**
1551
+ * Maximum number of threads
1552
+ *
1553
+ * @default available CPUs
1554
+ */
1555
+ maxThreads?: number;
1556
+ /**
1557
+ * Minimum number of threads
1558
+ *
1559
+ * @default available CPUs
1560
+ */
1561
+ minThreads?: number;
1562
+ /**
1563
+ * Default timeout of a test in milliseconds
1564
+ *
1565
+ * @default 5000
1566
+ */
1567
+ testTimeout?: number;
1568
+ /**
1569
+ * Default timeout of a hook in milliseconds
1570
+ *
1571
+ * @default 10000
1572
+ */
1573
+ hookTimeout?: number;
1574
+ /**
1575
+ * Default timeout to wait for close when Vitest shuts down, in milliseconds
1576
+ *
1577
+ * @default 1000
1578
+ */
1579
+ teardownTimeout?: number;
1580
+ /**
1581
+ * Silent mode
1582
+ *
1583
+ * @default false
1584
+ */
1585
+ silent?: boolean;
1586
+ /**
1587
+ * Path to setup files
1588
+ */
1589
+ setupFiles?: string | string[];
1590
+ /**
1591
+ * Path to global setup files
1592
+ */
1593
+ globalSetup?: string | string[];
1594
+ /**
1595
+ * Glob pattern of file paths to be ignore from triggering watch rerun
1596
+ */
1597
+ watchExclude?: string[];
1598
+ /**
1599
+ * Glob patter of file paths that will trigger the whole suite rerun
1600
+ *
1601
+ * Useful if you are testing calling CLI commands
1602
+ *
1603
+ * @default []
1604
+ */
1605
+ forceRerunTriggers?: string[];
1606
+ /**
1607
+ * Isolate environment for each test file
1608
+ *
1609
+ * @default true
1610
+ */
1611
+ isolate?: boolean;
1612
+ /**
1613
+ * Coverage options
1614
+ */
1615
+ coverage?: CoverageOptions;
1616
+ /**
1617
+ * run test names with the specified pattern
1618
+ */
1619
+ testNamePattern?: string | RegExp;
1620
+ /**
1621
+ * Will call `.mockClear()` on all spies before each test
1622
+ * @default false
1623
+ */
1624
+ clearMocks?: boolean;
1625
+ /**
1626
+ * Will call `.mockReset()` on all spies before each test
1627
+ * @default false
1628
+ */
1629
+ mockReset?: boolean;
1630
+ /**
1631
+ * Will call `.mockRestore()` on all spies before each test
1632
+ * @default false
1633
+ */
1634
+ restoreMocks?: boolean;
1635
+ /**
1636
+ * Serve API options.
1637
+ *
1638
+ * When set to true, the default port is 51204.
1639
+ *
1640
+ * @default false
1641
+ */
1642
+ api?: boolean | number | ApiConfig;
1643
+ /**
1644
+ * Enable Vitest UI
1645
+ * @internal WIP
1646
+ */
1647
+ ui?: boolean;
1648
+ /**
1649
+ * Use in browser environment
1650
+ * @experimental
1651
+ */
1652
+ browser?: boolean;
1653
+ /**
1654
+ * Open UI automatically.
1655
+ *
1656
+ * @default true
1657
+ */
1658
+ open?: boolean;
1659
+ /**
1660
+ * Base url for the UI
1661
+ *
1662
+ * @default '/__vitest__/'
1663
+ */
1664
+ uiBase?: string;
1665
+ /**
1666
+ * Determine the transform method of modules
1667
+ */
1668
+ transformMode?: {
1669
+ /**
1670
+ * Use SSR transform pipeline for the specified files.
1671
+ * Vite plugins will receive `ssr: true` flag when processing those files.
1672
+ *
1673
+ * @default [/\.([cm]?[jt]sx?|json)$/]
1674
+ */
1675
+ ssr?: RegExp[];
1676
+ /**
1677
+ * First do a normal transform pipeline (targeting browser),
1678
+ * then then do a SSR rewrite to run the code in Node.
1679
+ * Vite plugins will receive `ssr: false` flag when processing those files.
1680
+ *
1681
+ * @default other than `ssr`
1682
+ */
1683
+ web?: RegExp[];
1684
+ };
1685
+ /**
1686
+ * Format options for snapshot testing.
1687
+ */
1688
+ snapshotFormat?: PrettyFormatOptions;
1689
+ /**
1690
+ * Resolve custom snapshot path
1691
+ */
1692
+ resolveSnapshotPath?: (path: string, extension: string) => string;
1693
+ /**
1694
+ * Pass with no tests
1695
+ */
1696
+ passWithNoTests?: boolean;
1697
+ /**
1698
+ * Allow tests and suites that are marked as only
1699
+ */
1700
+ allowOnly?: boolean;
1701
+ /**
1702
+ * Show heap usage after each test. Useful for debugging memory leaks.
1703
+ */
1704
+ logHeapUsage?: boolean;
1705
+ /**
1706
+ * Custom environment variables assigned to `process.env` before running tests.
1707
+ */
1708
+ env?: Record<string, string>;
1709
+ /**
1710
+ * Options for @sinon/fake-timers
1711
+ */
1712
+ fakeTimers?: FakeTimerInstallOpts;
1713
+ /**
1714
+ * Custom handler for console.log in tests.
1715
+ *
1716
+ * Return `false` to ignore the log.
1717
+ */
1718
+ onConsoleLog?: (log: string, type: 'stdout' | 'stderr') => false | void;
1719
+ /**
1720
+ * Indicates if CSS files should be processed.
1721
+ *
1722
+ * When excluded, the CSS files will be replaced with empty strings to bypass the subsequent processing.
1723
+ *
1724
+ * @default { include: [/\.module\./] }
1725
+ */
1726
+ css?: boolean | {
1727
+ include?: RegExp | RegExp[];
1728
+ exclude?: RegExp | RegExp[];
1729
+ };
1730
+ /**
1731
+ * A number of tests that are allowed to run at the same time marked with `test.concurrent`.
1732
+ * @default 5
1733
+ */
1734
+ maxConcurrency?: number;
1735
+ /**
1736
+ * Options for configuring cache policy.
1737
+ * @default { dir: 'node_modules/.vitest' }
1738
+ */
1739
+ cache?: false | {
1740
+ dir?: string;
1741
+ };
1742
+ /**
1743
+ * Options for configuring the order of running tests.
1744
+ */
1745
+ sequence?: {
1746
+ /**
1747
+ * Class that handles sorting and sharding algorithm.
1748
+ * If you only need to change sorting, you can extend
1749
+ * your custom sequencer from `BaseSequencer` from `vitest/node`.
1750
+ * @default BaseSequencer
1751
+ */
1752
+ sequencer?: TestSequencerConstructor;
1753
+ /**
1754
+ * Should tests run in random order.
1755
+ * @default false
1756
+ */
1757
+ shuffle?: boolean;
1758
+ /**
1759
+ * Seed for the random number generator.
1760
+ * @default Date.now()
1761
+ */
1762
+ seed?: number;
1763
+ };
1764
+ /**
1765
+ * Specifies an `Object`, or an `Array` of `Object`,
1766
+ * which defines aliases used to replace values in `import` or `require` statements.
1767
+ * Will be merged with the default aliases inside `resolve.alias`.
1768
+ */
1769
+ alias?: AliasOptions;
1770
+ /**
1771
+ * Ignore any unhandled errors that occur
1772
+ */
1773
+ dangerouslyIgnoreUnhandledErrors?: boolean;
1774
+ }
1775
+ interface UserConfig extends InlineConfig {
1776
+ /**
1777
+ * Path to the config file.
1778
+ *
1779
+ * Default resolving to one of:
1780
+ * - `vitest.config.js`
1781
+ * - `vitest.config.ts`
1782
+ * - `vite.config.js`
1783
+ * - `vite.config.ts`
1784
+ */
1785
+ config?: string | undefined;
1786
+ /**
1787
+ * Use happy-dom
1788
+ */
1789
+ dom?: boolean;
1790
+ /**
1791
+ * Run tests that cover a list of source files
1792
+ */
1793
+ related?: string[] | string;
1794
+ /**
1795
+ * Overrides Vite mode
1796
+ * @default 'test'
1797
+ */
1798
+ mode?: string;
1799
+ /**
1800
+ * Runs tests that are affected by the changes in the repository, or between specified branch or commit hash
1801
+ * Requires initialized git repository
1802
+ * @default false
1803
+ */
1804
+ changed?: boolean | string;
1805
+ /**
1806
+ * Test suite shard to execute in a format of <index>/<count>.
1807
+ * Will divide tests into a `count` numbers, and run only the `indexed` part.
1808
+ * Cannot be used with enabled watch.
1809
+ * @example --shard=2/3
1810
+ */
1811
+ shard?: string;
1812
+ }
1813
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard' | 'cache' | 'sequence'> {
1814
+ base?: string;
1815
+ config?: string;
1816
+ filters?: string[];
1817
+ testNamePattern?: RegExp;
1818
+ related?: string[];
1819
+ coverage: ResolvedCoverageOptions;
1820
+ snapshotOptions: SnapshotStateOptions;
1821
+ reporters: (Reporter | BuiltinReporters)[];
1822
+ defines: Record<string, any>;
1823
+ api?: ApiConfig;
1824
+ shard?: {
1825
+ index: number;
1826
+ count: number;
1827
+ };
1828
+ cache: {
1829
+ dir: string;
1830
+ } | false;
1831
+ sequence: {
1832
+ sequencer: TestSequencerConstructor;
1833
+ shuffle?: boolean;
1834
+ seed?: number;
1835
+ };
1836
+ }
1837
+
1838
+ declare type VitestInlineConfig = InlineConfig;
1839
+ declare module 'vite' {
1840
+ interface UserConfig {
1841
+ /**
1842
+ * Options for Vitest
1843
+ */
1844
+ test?: VitestInlineConfig;
1845
+ }
1846
+ }
1847
+
1848
+ declare type Formatter = (input: string | number | null | undefined) => string;
1849
+
1850
+ interface MatcherHintOptions {
1851
+ comment?: string;
1852
+ expectedColor?: Formatter;
1853
+ isDirectExpectCall?: boolean;
1854
+ isNot?: boolean;
1855
+ promise?: string;
1856
+ receivedColor?: Formatter;
1857
+ secondArgument?: string;
1858
+ secondArgumentColor?: Formatter;
1859
+ }
1860
+ interface DiffOptions {
1861
+ aAnnotation?: string;
1862
+ aColor?: Formatter;
1863
+ aIndicator?: string;
1864
+ bAnnotation?: string;
1865
+ bColor?: Formatter;
1866
+ bIndicator?: string;
1867
+ changeColor?: Formatter;
1868
+ changeLineTrailingSpaceColor?: Formatter;
1869
+ commonColor?: Formatter;
1870
+ commonIndicator?: string;
1871
+ commonLineTrailingSpaceColor?: Formatter;
1872
+ contextLines?: number;
1873
+ emptyFirstOrLastLinePlaceholder?: string;
1874
+ expand?: boolean;
1875
+ includeChangeCounts?: boolean;
1876
+ omitAnnotationLines?: boolean;
1877
+ patchColor?: Formatter;
1878
+ compareKeys?: any;
1879
+ }
1880
+
1881
+ declare const EXPECTED_COLOR: Formatter;
1882
+ declare const RECEIVED_COLOR: Formatter;
1883
+ declare const INVERTED_COLOR: Formatter;
1884
+ declare const BOLD_WEIGHT: Formatter;
1885
+ declare const DIM_COLOR: Formatter;
1886
+ declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
1887
+ declare function stringify(object: unknown, maxDepth?: number, options?: PrettyFormatOptions): string;
1888
+ declare const printReceived: (object: unknown) => string;
1889
+ declare const printExpected: (value: unknown) => string;
1890
+ declare function diff(a: any, b: any, options?: DiffOptions): string;
1891
+
1892
+ declare const jestMatcherUtils_EXPECTED_COLOR: typeof EXPECTED_COLOR;
1893
+ declare const jestMatcherUtils_RECEIVED_COLOR: typeof RECEIVED_COLOR;
1894
+ declare const jestMatcherUtils_INVERTED_COLOR: typeof INVERTED_COLOR;
1895
+ declare const jestMatcherUtils_BOLD_WEIGHT: typeof BOLD_WEIGHT;
1896
+ declare const jestMatcherUtils_DIM_COLOR: typeof DIM_COLOR;
1897
+ declare const jestMatcherUtils_matcherHint: typeof matcherHint;
1898
+ declare const jestMatcherUtils_stringify: typeof stringify;
1899
+ declare const jestMatcherUtils_printReceived: typeof printReceived;
1900
+ declare const jestMatcherUtils_printExpected: typeof printExpected;
1901
+ declare const jestMatcherUtils_diff: typeof diff;
1902
+ declare namespace jestMatcherUtils {
1903
+ export {
1904
+ jestMatcherUtils_EXPECTED_COLOR as EXPECTED_COLOR,
1905
+ jestMatcherUtils_RECEIVED_COLOR as RECEIVED_COLOR,
1906
+ jestMatcherUtils_INVERTED_COLOR as INVERTED_COLOR,
1907
+ jestMatcherUtils_BOLD_WEIGHT as BOLD_WEIGHT,
1908
+ jestMatcherUtils_DIM_COLOR as DIM_COLOR,
1909
+ jestMatcherUtils_matcherHint as matcherHint,
1910
+ jestMatcherUtils_stringify as stringify,
1911
+ jestMatcherUtils_printReceived as printReceived,
1912
+ jestMatcherUtils_printExpected as printExpected,
1913
+ jestMatcherUtils_diff as diff,
1914
+ };
1915
+ }
1916
+
1917
+ /**
1918
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
1919
+ *
1920
+ * This source code is licensed under the MIT license found in the
1921
+ * LICENSE file in the root directory of this source tree.
1922
+ */
1923
+
1924
+ interface SnapshotReturnOptions {
1925
+ actual: string;
1926
+ count: number;
1927
+ expected?: string;
1928
+ key: string;
1929
+ pass: boolean;
1930
+ }
1931
+ interface SaveStatus {
1932
+ deleted: boolean;
1933
+ saved: boolean;
1934
+ }
1935
+ declare class SnapshotState {
1936
+ testFilePath: string;
1937
+ snapshotPath: string;
1938
+ private _counters;
1939
+ private _dirty;
1940
+ private _updateSnapshot;
1941
+ private _snapshotData;
1942
+ private _initialData;
1943
+ private _inlineSnapshots;
1944
+ private _uncheckedKeys;
1945
+ private _snapshotFormat;
1946
+ added: number;
1947
+ expand: boolean;
1948
+ matched: number;
1949
+ unmatched: number;
1950
+ updated: number;
1951
+ constructor(testFilePath: string, snapshotPath: string, options: SnapshotStateOptions);
1952
+ markSnapshotsAsCheckedForTest(testName: string): void;
1953
+ private _inferInlineSnapshotStack;
1954
+ private _addSnapshot;
1955
+ clear(): void;
1956
+ save(): Promise<SaveStatus>;
1957
+ getUncheckedCount(): number;
1958
+ getUncheckedKeys(): Array<string>;
1959
+ removeUncheckedKeys(): void;
1960
+ match({ testName, received, key, inlineSnapshot, isInline, error, }: SnapshotMatchOptions): SnapshotReturnOptions;
1961
+ pack(): Promise<SnapshotResult>;
1962
+ }
1963
+
1964
+ declare type Tester = (a: any, b: any) => boolean | undefined;
1965
+ interface MatcherState {
1966
+ assertionCalls: number;
1967
+ currentTestName?: string;
1968
+ dontThrow?: () => void;
1969
+ error?: Error;
1970
+ equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
1971
+ expand?: boolean;
1972
+ expectedAssertionsNumber?: number | null;
1973
+ expectedAssertionsNumberErrorGen?: (() => Error) | null;
1974
+ isExpectingAssertions?: boolean;
1975
+ isExpectingAssertionsError?: Error | null;
1976
+ isNot: boolean;
1977
+ promise: string;
1978
+ snapshotState: SnapshotState;
1979
+ suppressedErrors: Array<Error>;
1980
+ testPath?: string;
1981
+ utils: typeof jestMatcherUtils & {
1982
+ iterableEquality: Tester;
1983
+ subsetEquality: Tester;
1984
+ };
1985
+ }
1986
+ interface SyncExpectationResult {
1987
+ pass: boolean;
1988
+ message: () => string;
1989
+ actual?: any;
1990
+ expected?: any;
1991
+ }
1992
+ declare type AsyncExpectationResult = Promise<SyncExpectationResult>;
1993
+ declare type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
1994
+ interface RawMatcherFn<T extends MatcherState = MatcherState> {
1995
+ (this: T, received: any, expected: any, options?: any): ExpectationResult;
1996
+ }
1997
+ declare type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>;
1998
+
1999
+ declare type Promisify<O> = {
2000
+ [K in keyof O]: O[K] extends (...args: infer A) => infer R ? O extends R ? Promisify<O[K]> : (...args: A) => Promise<R> : O[K];
2001
+ };
2002
+ declare global {
2003
+ namespace jest {
2004
+ interface Matchers<R, T = {}> {
2005
+ }
2006
+ }
2007
+ namespace Vi {
2008
+ interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
2009
+ <T>(actual: T, message?: string): Vi.Assertion<T>;
2010
+ extend(expects: MatchersObject): void;
2011
+ assertions(expected: number): void;
2012
+ hasAssertions(): void;
2013
+ anything(): any;
2014
+ any(constructor: unknown): any;
2015
+ addSnapshotSerializer(plugin: Plugin): void;
2016
+ getState(): MatcherState;
2017
+ setState(state: Partial<MatcherState>): void;
2018
+ not: AsymmetricMatchersContaining;
2019
+ }
2020
+ interface AsymmetricMatchersContaining {
2021
+ stringContaining(expected: string): any;
2022
+ objectContaining(expected: any): any;
2023
+ arrayContaining<T = unknown>(expected: Array<T>): any;
2024
+ stringMatching(expected: string | RegExp): any;
2025
+ }
2026
+ interface JestAssertion<T = any> extends jest.Matchers<void, T> {
2027
+ toMatchSnapshot<U extends {
2028
+ [P in keyof T]: any;
2029
+ }>(snapshot: Partial<U>, message?: string): void;
2030
+ toMatchSnapshot(message?: string): void;
2031
+ matchSnapshot<U extends {
2032
+ [P in keyof T]: any;
2033
+ }>(snapshot: Partial<U>, message?: string): void;
2034
+ matchSnapshot(message?: string): void;
2035
+ toMatchInlineSnapshot<U extends {
2036
+ [P in keyof T]: any;
2037
+ }>(properties: Partial<U>, snapshot?: string, message?: string): void;
2038
+ toMatchInlineSnapshot(snapshot?: string, message?: string): void;
2039
+ toThrowErrorMatchingSnapshot(message?: string): void;
2040
+ toThrowErrorMatchingInlineSnapshot(snapshot?: string, message?: string): void;
2041
+ toEqual<E>(expected: E): void;
2042
+ toStrictEqual<E>(expected: E): void;
2043
+ toBe<E>(expected: E): void;
2044
+ toMatch(expected: string | RegExp): void;
2045
+ toMatchObject<E extends {} | any[]>(expected: E): void;
2046
+ toContain<E>(item: E): void;
2047
+ toContainEqual<E>(item: E): void;
2048
+ toBeTruthy(): void;
2049
+ toBeFalsy(): void;
2050
+ toBeGreaterThan(num: number | bigint): void;
2051
+ toBeGreaterThanOrEqual(num: number | bigint): void;
2052
+ toBeLessThan(num: number | bigint): void;
2053
+ toBeLessThanOrEqual(num: number | bigint): void;
2054
+ toBeNaN(): void;
2055
+ toBeUndefined(): void;
2056
+ toBeNull(): void;
2057
+ toBeDefined(): void;
2058
+ toBeTypeOf(expected: 'bigint' | 'boolean' | 'function' | 'number' | 'object' | 'string' | 'symbol' | 'undefined'): void;
2059
+ toBeInstanceOf<E>(expected: E): void;
2060
+ toBeCalledTimes(times: number): void;
2061
+ toHaveLength(length: number): void;
2062
+ toHaveProperty<E>(property: string | string[], value?: E): void;
2063
+ toBeCloseTo(number: number, numDigits?: number): void;
2064
+ toHaveBeenCalledTimes(times: number): void;
2065
+ toHaveBeenCalledOnce(): void;
2066
+ toHaveBeenCalled(): void;
2067
+ toBeCalled(): void;
2068
+ toHaveBeenCalledWith<E extends any[]>(...args: E): void;
2069
+ toBeCalledWith<E extends any[]>(...args: E): void;
2070
+ toHaveBeenNthCalledWith<E extends any[]>(n: number, ...args: E): void;
2071
+ nthCalledWith<E extends any[]>(nthCall: number, ...args: E): void;
2072
+ toHaveBeenLastCalledWith<E extends any[]>(...args: E): void;
2073
+ lastCalledWith<E extends any[]>(...args: E): void;
2074
+ toThrow(expected?: string | Constructable | RegExp | Error): void;
2075
+ toThrowError(expected?: string | Constructable | RegExp | Error): void;
2076
+ toReturn(): void;
2077
+ toHaveReturned(): void;
2078
+ toReturnTimes(times: number): void;
2079
+ toHaveReturnedTimes(times: number): void;
2080
+ toReturnWith<E>(value: E): void;
2081
+ toHaveReturnedWith<E>(value: E): void;
2082
+ toHaveLastReturnedWith<E>(value: E): void;
2083
+ lastReturnedWith<E>(value: E): void;
2084
+ toHaveNthReturnedWith<E>(nthCall: number, value: E): void;
2085
+ nthReturnedWith<E>(nthCall: number, value: E): void;
2086
+ toSatisfy<E>(matcher: (value: E) => boolean, message?: string): void;
2087
+ }
2088
+ type VitestAssertion<A, T> = {
2089
+ [K in keyof A]: A[K] extends Chai.Assertion ? Assertion<T> : A[K] extends (...args: any[]) => any ? A[K] : VitestAssertion<A[K], T>;
2090
+ } & ((type: string, message?: string) => Assertion);
2091
+ interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T> {
2092
+ resolves: Promisify<Assertion<T>>;
2093
+ rejects: Promisify<Assertion<T>>;
2094
+ }
2095
+ }
2096
+ }
2097
+
2098
+ export { Environment as $, ApiConfig as A, BuiltinEnvironment as B, WorkerRPC as C, DoneCallback as D, EnvironmentOptions as E, FakeTimerInstallOpts as F, WorkerGlobalState as G, HookListener as H, InlineConfig as I, JSDOMOptions as J, Awaitable as K, Arrayable as L, ModuleGraphData as M, Nullable as N, ArgumentsType$1 as O, MergeInsertions as P, DeepMerge as Q, ResolvedConfig as R, Suite as S, TaskResultPack as T, UserConfig as U, Vitest as V, WorkerContext as W, MutableArray as X, Constructable as Y, ModuleCache as Z, EnvironmentReturn as _, File as a, UserConsoleLog as a0, Position as a1, ParsedStack as a2, ErrorWithDiff as a3, CoverageProvider as a4, CoverageProviderModule as a5, CoverageReporter as a6, CoverageOptions as a7, ResolvedCoverageOptions as a8, BaseCoverageOptions as a9, CoverageIstanbulOptions as aa, CoverageC8Options as ab, ModuleCacheMap as ac, ViteNodeRunnerOptions as ad, MockMap as ae, ViteNodeRunner as af, TestSequencer as ag, startVitest as ah, TestSequencerConstructor as ai, Reporter as b, RunMode as c, TaskState as d, TaskBase as e, TaskResult as f, Test as g, Task as h, TestFunction as i, TestAPI as j, SuiteAPI as k, HookCleanupCallback as l, SuiteHooks as m, SuiteCollector as n, SuiteFactory as o, RuntimeContext as p, TestContext as q, SnapshotData as r, SnapshotUpdateState as s, SnapshotStateOptions as t, SnapshotMatchOptions as u, SnapshotResult as v, UncheckedSnapshot as w, SnapshotSummary as x, ResolveIdFunction as y, AfterSuiteRunMeta as z };