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