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