vitest 0.27.1 → 0.27.3

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 (36) hide show
  1. package/dist/browser.d.ts +3 -3
  2. package/dist/browser.js +12 -11
  3. package/dist/{chunk-api-setup.2be3cc38.js → chunk-api-setup.0a2398d8.js} +4 -3
  4. package/dist/{chunk-env-node.b3664da2.js → chunk-env-node.ffd1183b.js} +33 -0
  5. package/dist/{chunk-integrations-coverage.44413252.js → chunk-integrations-coverage.18366936.js} +3 -1
  6. package/dist/{chunk-integrations-globals.02f1259c.js → chunk-integrations-globals.59b4d460.js} +7 -6
  7. package/dist/{chunk-mock-date.149ed990.js → chunk-mock-date.91595ccd.js} +7 -3
  8. package/dist/{chunk-node-git.125c9008.js → chunk-node-git.59caac18.js} +2 -1
  9. package/dist/{chunk-runtime-chain.4e2aa823.js → chunk-runtime-chain.07d16eac.js} +15 -16
  10. package/dist/{chunk-runtime-error.97854396.js → chunk-runtime-error.f2062967.js} +1 -1
  11. package/dist/{chunk-runtime-mocker.4755840f.js → chunk-runtime-mocker.66533d65.js} +3 -3
  12. package/dist/{chunk-runtime-rpc.25cc9413.js → chunk-runtime-rpc.e79efa9a.js} +1 -1
  13. package/dist/{chunk-runtime-setup.56d71d30.js → chunk-runtime-setup.8ca273cd.js} +20 -13
  14. package/dist/{chunk-snapshot-manager.1a2dbf96.js → chunk-snapshot-manager.d16903ef.js} +147 -4046
  15. package/dist/{chunk-utils-env.f4a39d2c.js → chunk-utils-env.4ebb0106.js} +1 -0
  16. package/dist/{chunk-utils-import.16d9fb0d.js → chunk-utils-import.eb63557e.js} +47 -4
  17. package/dist/{chunk-utils-source-map.4e9b891d.js → chunk-utils-source-map.832515f7.js} +2 -2
  18. package/dist/cli-wrapper.js +2 -1
  19. package/dist/cli.js +8 -6
  20. package/dist/config.cjs +11 -8
  21. package/dist/config.d.ts +16 -3
  22. package/dist/config.js +11 -9
  23. package/dist/entry.js +24 -13
  24. package/dist/environments.d.ts +1 -1
  25. package/dist/environments.js +1 -1
  26. package/dist/{index-1cfc7f58.d.ts → index-2dd51af4.d.ts} +1 -1
  27. package/dist/index.d.ts +8 -4
  28. package/dist/index.js +8 -7
  29. package/dist/loader.js +5 -4
  30. package/dist/node.d.ts +2 -2
  31. package/dist/node.js +9 -7
  32. package/dist/suite.js +6 -5
  33. package/dist/{types-5617096e.d.ts → types-c1386a7d.d.ts} +337 -307
  34. package/dist/vendor-index.57682f0c.js +3964 -0
  35. package/dist/worker.js +11 -8
  36. package/package.json +7 -6
@@ -159,6 +159,282 @@ interface FakeTimerInstallOpts {
159
159
  shouldClearNativeTimers?: boolean | undefined;
160
160
  }
161
161
 
162
+ type ChainableFunction<T extends string, Args extends any[], R = any, E = {}> = {
163
+ (...args: Args): R;
164
+ } & {
165
+ [x in T]: ChainableFunction<T, Args, R, E>;
166
+ } & {
167
+ fn: (this: Record<T, boolean | undefined>, ...args: Args) => R;
168
+ } & E;
169
+
170
+ interface BenchmarkUserOptions {
171
+ /**
172
+ * Include globs for benchmark test files
173
+ *
174
+ * @default ['**\/*.{bench,benchmark}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
175
+ */
176
+ include?: string[];
177
+ /**
178
+ * Exclude globs for benchmark test files
179
+ * @default ['node_modules', 'dist', '.idea', '.git', '.cache']
180
+ */
181
+ exclude?: string[];
182
+ /**
183
+ * Include globs for in-source benchmark test files
184
+ *
185
+ * @default []
186
+ */
187
+ includeSource?: string[];
188
+ /**
189
+ * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
190
+ * and/or paths to custom reporters
191
+ */
192
+ reporters?: Arrayable<BenchmarkBuiltinReporters | Reporter>;
193
+ /**
194
+ * Write test results to a file when the `--reporter=json` option is also specified.
195
+ * Also definable individually per reporter by using an object instead.
196
+ */
197
+ outputFile?: string | (Partial<Record<BenchmarkBuiltinReporters, string>> & Record<string, string>);
198
+ }
199
+ interface Benchmark extends TaskBase {
200
+ type: 'benchmark';
201
+ suite: Suite;
202
+ result?: TaskResult;
203
+ fails?: boolean;
204
+ task?: Task$1;
205
+ }
206
+ interface BenchmarkResult extends TaskResult$1 {
207
+ name: string;
208
+ rank: number;
209
+ }
210
+ type BenchFunction = (this: Bench) => Promise<void> | void;
211
+ type BenchmarkAPI = ChainableFunction<'skip' | 'only' | 'todo', [
212
+ name: string,
213
+ fn?: BenchFunction,
214
+ options?: Options
215
+ ], void> & {
216
+ skipIf(condition: any): BenchmarkAPI;
217
+ runIf(condition: any): BenchmarkAPI;
218
+ };
219
+
220
+ type Awaitable<T> = T | PromiseLike<T>;
221
+ type Nullable<T> = T | null | undefined;
222
+ type Arrayable<T> = T | Array<T>;
223
+ type ArgumentsType$1<T> = T extends (...args: infer U) => any ? U : never;
224
+ type MergeInsertions<T> = T extends object ? {
225
+ [K in keyof T]: MergeInsertions<T[K]>;
226
+ } : T;
227
+ type DeepMerge<F, S> = MergeInsertions<{
228
+ [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;
229
+ }>;
230
+ type MutableArray<T extends readonly any[]> = {
231
+ -readonly [k in keyof T]: T[k];
232
+ };
233
+ interface Constructable {
234
+ new (...args: any[]): any;
235
+ }
236
+ interface ModuleCache {
237
+ promise?: Promise<any>;
238
+ exports?: any;
239
+ code?: string;
240
+ }
241
+ interface EnvironmentReturn {
242
+ teardown: (global: any) => Awaitable<void>;
243
+ }
244
+ interface Environment {
245
+ name: string;
246
+ setup(global: any, options: Record<string, any>): Awaitable<EnvironmentReturn>;
247
+ }
248
+ interface UserConsoleLog {
249
+ content: string;
250
+ type: 'stdout' | 'stderr';
251
+ taskId?: string;
252
+ time: number;
253
+ size: number;
254
+ }
255
+ interface ParsedStack {
256
+ method: string;
257
+ file: string;
258
+ line: number;
259
+ column: number;
260
+ }
261
+ interface ErrorWithDiff extends Error {
262
+ name: string;
263
+ nameStr?: string;
264
+ stack?: string;
265
+ stackStr?: string;
266
+ stacks?: ParsedStack[];
267
+ showDiff?: boolean;
268
+ actual?: any;
269
+ expected?: any;
270
+ operator?: string;
271
+ type?: string;
272
+ frame?: string;
273
+ }
274
+ interface ModuleGraphData {
275
+ graph: Record<string, string[]>;
276
+ externalized: string[];
277
+ inlined: string[];
278
+ }
279
+ type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
280
+
281
+ type RunMode = 'run' | 'skip' | 'only' | 'todo';
282
+ type TaskState = RunMode | 'pass' | 'fail';
283
+ interface TaskBase {
284
+ id: string;
285
+ name: string;
286
+ mode: RunMode;
287
+ concurrent?: boolean;
288
+ shuffle?: boolean;
289
+ suite?: Suite;
290
+ file?: File;
291
+ result?: TaskResult;
292
+ retry?: number;
293
+ logs?: UserConsoleLog[];
294
+ meta?: any;
295
+ }
296
+ interface TaskResult {
297
+ state: TaskState;
298
+ duration?: number;
299
+ startTime?: number;
300
+ heap?: number;
301
+ /**
302
+ * @deprecated Use "errors" instead
303
+ */
304
+ error?: ErrorWithDiff;
305
+ errors?: ErrorWithDiff[];
306
+ htmlError?: string;
307
+ hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
308
+ benchmark?: BenchmarkResult;
309
+ retryCount?: number;
310
+ }
311
+ type TaskResultPack = [id: string, result: TaskResult | undefined];
312
+ interface Suite extends TaskBase {
313
+ type: 'suite';
314
+ tasks: Task[];
315
+ filepath?: string;
316
+ benchmark?: Bench;
317
+ projectName?: string;
318
+ }
319
+ interface File extends Suite {
320
+ filepath: string;
321
+ collectDuration?: number;
322
+ setupDuration?: number;
323
+ }
324
+ interface Test<ExtraContext = {}> extends TaskBase {
325
+ type: 'test';
326
+ suite: Suite;
327
+ result?: TaskResult;
328
+ fails?: boolean;
329
+ context: TestContext & ExtraContext;
330
+ onFailed?: OnTestFailedHandler[];
331
+ }
332
+ type Task = Test | Suite | File | Benchmark;
333
+ type DoneCallback = (error?: any) => void;
334
+ type TestFunction<ExtraContext = {}> = (context: TestContext & ExtraContext) => Awaitable<any> | void;
335
+ type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
336
+ 1: [T[0]];
337
+ 2: [T[0], T[1]];
338
+ 3: [T[0], T[1], T[2]];
339
+ 4: [T[0], T[1], T[2], T[3]];
340
+ 5: [T[0], T[1], T[2], T[3], T[4]];
341
+ 6: [T[0], T[1], T[2], T[3], T[4], T[5]];
342
+ 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6]];
343
+ 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7]];
344
+ 9: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8]];
345
+ 10: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]];
346
+ fallback: Array<T extends ReadonlyArray<infer U> ? U : any>;
347
+ }[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'];
348
+ interface SuiteEachFunction {
349
+ <T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T) => Awaitable<void>) => void;
350
+ <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string, fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>) => void;
351
+ <T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => Awaitable<void>) => void;
352
+ }
353
+ interface TestEachFunction {
354
+ <T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T) => Awaitable<void>, options?: number | TestOptions) => void;
355
+ <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string, fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>, options?: number | TestOptions) => void;
356
+ <T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => Awaitable<void>, options?: number | TestOptions) => void;
357
+ (...args: [TemplateStringsArray, ...any]): (name: string, fn: (...args: any[]) => Awaitable<void>, options?: number | TestOptions) => void;
358
+ }
359
+ type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [
360
+ name: string,
361
+ fn?: TestFunction<ExtraContext>,
362
+ options?: number | TestOptions
363
+ ], void, {
364
+ each: TestEachFunction;
365
+ <T extends ExtraContext>(name: string, fn?: TestFunction<T>, options?: number | TestOptions): void;
366
+ }>;
367
+ interface TestOptions {
368
+ /**
369
+ * Test timeout.
370
+ */
371
+ timeout?: number;
372
+ /**
373
+ * Times to retry the test if fails. Useful for making flaky tests more stable.
374
+ * When retries is up, the last test error will be thrown.
375
+ *
376
+ * @default 1
377
+ */
378
+ retry?: number;
379
+ }
380
+ type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & {
381
+ each: TestEachFunction;
382
+ skipIf(condition: any): ChainableTestAPI<ExtraContext>;
383
+ runIf(condition: any): ChainableTestAPI<ExtraContext>;
384
+ };
385
+ type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle', [
386
+ name: string,
387
+ factory?: SuiteFactory<ExtraContext>,
388
+ options?: number | TestOptions
389
+ ], SuiteCollector<ExtraContext>, {
390
+ each: TestEachFunction;
391
+ <T extends ExtraContext>(name: string, factory?: SuiteFactory<T>): SuiteCollector<T>;
392
+ }>;
393
+ type SuiteAPI<ExtraContext = {}> = ChainableSuiteAPI<ExtraContext> & {
394
+ each: SuiteEachFunction;
395
+ skipIf(condition: any): ChainableSuiteAPI<ExtraContext>;
396
+ runIf(condition: any): ChainableSuiteAPI<ExtraContext>;
397
+ };
398
+ type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
399
+ type HookCleanupCallback = (() => Awaitable<unknown>) | void;
400
+ interface SuiteHooks<ExtraContext = {}> {
401
+ beforeAll: HookListener<[Suite | File], HookCleanupCallback>[];
402
+ afterAll: HookListener<[Suite | File]>[];
403
+ beforeEach: HookListener<[TestContext & ExtraContext, Suite], HookCleanupCallback>[];
404
+ afterEach: HookListener<[TestContext & ExtraContext, Suite]>[];
405
+ }
406
+ interface SuiteCollector<ExtraContext = {}> {
407
+ readonly name: string;
408
+ readonly mode: RunMode;
409
+ type: 'collector';
410
+ test: TestAPI<ExtraContext>;
411
+ benchmark: BenchmarkAPI;
412
+ tasks: (Suite | Test | Benchmark | SuiteCollector<ExtraContext>)[];
413
+ collect: (file?: File) => Promise<Suite>;
414
+ clear: () => void;
415
+ on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
416
+ }
417
+ type SuiteFactory<ExtraContext = {}> = (test: (name: string, fn: TestFunction<ExtraContext>) => void) => Awaitable<void>;
418
+ interface RuntimeContext {
419
+ tasks: (SuiteCollector | Test)[];
420
+ currentSuite: SuiteCollector | null;
421
+ }
422
+ interface TestContext {
423
+ /**
424
+ * Metadata of the current test
425
+ */
426
+ meta: Readonly<Test>;
427
+ /**
428
+ * A expect instance bound to the test
429
+ */
430
+ expect: Vi.ExpectStatic;
431
+ /**
432
+ * Extract hooks on test failed
433
+ */
434
+ onTestFailed: (fn: OnTestFailedHandler) => void;
435
+ }
436
+ type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
437
+
162
438
  declare class SnapshotManager {
163
439
  options: SnapshotStateOptions;
164
440
  summary: SnapshotSummary;
@@ -226,6 +502,7 @@ declare class Typechecker {
226
502
  protected collectFileTests(filepath: string): Promise<FileInformation | null>;
227
503
  protected getFiles(): string[];
228
504
  collectTests(): Promise<Record<string, FileInformation>>;
505
+ protected markPassed(file: File): void;
229
506
  protected prepareResults(output: string): Promise<{
230
507
  files: File[];
231
508
  sourceErrors: TypeCheckError[];
@@ -404,6 +681,7 @@ declare class Vitest {
404
681
  * @returns A value indicating whether rerun is needed (changedTests was mutated)
405
682
  */
406
683
  private handleFileChanged;
684
+ private reportCoverage;
407
685
  close(): Promise<void>;
408
686
  /**
409
687
  * Close the thread pool and exit the process
@@ -438,7 +716,7 @@ declare abstract class BaseReporter implements Reporter {
438
716
  start: number;
439
717
  end: number;
440
718
  watchFilters?: string[];
441
- isTTY: false;
719
+ isTTY: boolean;
442
720
  ctx: Vitest;
443
721
  private _filesInWatchMode;
444
722
  private _lastRunTimeout;
@@ -465,6 +743,11 @@ declare abstract class BaseReporter implements Reporter {
465
743
  registerUnhandledRejection(): void;
466
744
  }
467
745
 
746
+ declare class BasicReporter extends BaseReporter {
747
+ isTTY: boolean;
748
+ reportSummary(files: File[]): Promise<void>;
749
+ }
750
+
468
751
  interface ListRendererOptions$1 {
469
752
  renderSucceed?: boolean;
470
753
  logger: Logger;
@@ -606,6 +889,7 @@ type BenchmarkBuiltinReporters = keyof typeof BenchmarkReportsMap;
606
889
 
607
890
  declare const ReportersMap: {
608
891
  default: typeof DefaultReporter;
892
+ basic: typeof BasicReporter;
609
893
  verbose: typeof VerboseReporter;
610
894
  dot: typeof DotReporter;
611
895
  json: typeof JsonReporter$1;
@@ -799,88 +1083,27 @@ interface PluginContextMeta {
799
1083
 
800
1084
  interface ResolvedId extends ModuleOptions {
801
1085
  external: boolean | 'absolute';
802
- id: string;
803
- }
804
-
805
- type IsExternal = (
806
- source: string,
807
- importer: string | undefined,
808
- isResolved: boolean
809
- ) => boolean;
810
-
811
- interface TransformPluginContext extends PluginContext {
812
- getCombinedSourcemap: () => SourceMap;
813
- }
814
-
815
- type TransformResult = string | null | void | Partial<SourceDescription>;
816
- type PreserveEntrySignaturesOption = false | 'strict' | 'allow-extension' | 'exports-only';
817
-
818
- interface AcornNode {
819
- end: number;
820
- start: number;
821
- type: string;
822
- }
823
-
824
- type Awaitable<T> = T | PromiseLike<T>;
825
- type Nullable<T> = T | null | undefined;
826
- type Arrayable<T> = T | Array<T>;
827
- type ArgumentsType$1<T> = T extends (...args: infer U) => any ? U : never;
828
- type MergeInsertions<T> = T extends object ? {
829
- [K in keyof T]: MergeInsertions<T[K]>;
830
- } : T;
831
- type DeepMerge<F, S> = MergeInsertions<{
832
- [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;
833
- }>;
834
- type MutableArray<T extends readonly any[]> = {
835
- -readonly [k in keyof T]: T[k];
836
- };
837
- interface Constructable {
838
- new (...args: any[]): any;
839
- }
840
- interface ModuleCache {
841
- promise?: Promise<any>;
842
- exports?: any;
843
- code?: string;
844
- }
845
- interface EnvironmentReturn {
846
- teardown: (global: any) => Awaitable<void>;
847
- }
848
- interface Environment {
849
- name: string;
850
- setup(global: any, options: Record<string, any>): Awaitable<EnvironmentReturn>;
851
- }
852
- interface UserConsoleLog {
853
- content: string;
854
- type: 'stdout' | 'stderr';
855
- taskId?: string;
856
- time: number;
857
- size: number;
858
- }
859
- interface ParsedStack {
860
- method: string;
861
- file: string;
862
- line: number;
863
- column: number;
1086
+ id: string;
864
1087
  }
865
- interface ErrorWithDiff extends Error {
866
- name: string;
867
- nameStr?: string;
868
- stack?: string;
869
- stackStr?: string;
870
- stacks?: ParsedStack[];
871
- showDiff?: boolean;
872
- actual?: any;
873
- expected?: any;
874
- operator?: string;
875
- type?: string;
876
- frame?: string;
1088
+
1089
+ type IsExternal = (
1090
+ source: string,
1091
+ importer: string | undefined,
1092
+ isResolved: boolean
1093
+ ) => boolean;
1094
+
1095
+ interface TransformPluginContext extends PluginContext {
1096
+ getCombinedSourcemap: () => SourceMap;
877
1097
  }
878
- interface ModuleGraphData {
879
- graph: Record<string, string[]>;
880
- externalized: string[];
881
- inlined: string[];
1098
+
1099
+ type TransformResult = string | null | void | Partial<SourceDescription>;
1100
+ type PreserveEntrySignaturesOption = false | 'strict' | 'allow-extension' | 'exports-only';
1101
+
1102
+ interface AcornNode {
1103
+ end: number;
1104
+ start: number;
1105
+ type: string;
882
1106
  }
883
- type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
884
1107
 
885
1108
  declare type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
886
1109
  declare type ReturnType$1<T> = T extends (...args: any) => infer R ? R : never;
@@ -895,221 +1118,6 @@ declare type BirpcReturn<RemoteFunctions> = {
895
1118
  [K in keyof RemoteFunctions]: BirpcFn<RemoteFunctions[K]>;
896
1119
  };
897
1120
 
898
- type ChainableFunction<T extends string, Args extends any[], R = any, E = {}> = {
899
- (...args: Args): R;
900
- } & {
901
- [x in T]: ChainableFunction<T, Args, R, E>;
902
- } & {
903
- fn: (this: Record<T, boolean | undefined>, ...args: Args) => R;
904
- } & E;
905
-
906
- interface BenchmarkUserOptions {
907
- /**
908
- * Include globs for benchmark test files
909
- *
910
- * @default ['**\/*.{bench,benchmark}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
911
- */
912
- include?: string[];
913
- /**
914
- * Exclude globs for benchmark test files
915
- * @default ['node_modules', 'dist', '.idea', '.git', '.cache']
916
- */
917
- exclude?: string[];
918
- /**
919
- * Include globs for in-source benchmark test files
920
- *
921
- * @default []
922
- */
923
- includeSource?: string[];
924
- /**
925
- * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
926
- * and/or paths to custom reporters
927
- */
928
- reporters?: Arrayable<BenchmarkBuiltinReporters | Reporter>;
929
- /**
930
- * Write test results to a file when the `--reporter=json` option is also specified.
931
- * Also definable individually per reporter by using an object instead.
932
- */
933
- outputFile?: string | (Partial<Record<BenchmarkBuiltinReporters, string>> & Record<string, string>);
934
- }
935
- interface Benchmark extends TaskBase {
936
- type: 'benchmark';
937
- suite: Suite;
938
- result?: TaskResult;
939
- fails?: boolean;
940
- task?: Task$1;
941
- }
942
- interface BenchmarkResult extends TaskResult$1 {
943
- name: string;
944
- rank: number;
945
- }
946
- type BenchFunction = (this: Bench) => Promise<void> | void;
947
- type BenchmarkAPI = ChainableFunction<'skip' | 'only' | 'todo', [
948
- name: string,
949
- fn?: BenchFunction,
950
- options?: Options
951
- ], void> & {
952
- skipIf(condition: any): BenchmarkAPI;
953
- runIf(condition: any): BenchmarkAPI;
954
- };
955
-
956
- type RunMode = 'run' | 'skip' | 'only' | 'todo';
957
- type TaskState = RunMode | 'pass' | 'fail';
958
- interface TaskBase {
959
- id: string;
960
- name: string;
961
- mode: RunMode;
962
- concurrent?: boolean;
963
- shuffle?: boolean;
964
- suite?: Suite;
965
- file?: File;
966
- result?: TaskResult;
967
- retry?: number;
968
- logs?: UserConsoleLog[];
969
- meta?: any;
970
- }
971
- interface TaskResult {
972
- state: TaskState;
973
- duration?: number;
974
- startTime?: number;
975
- heap?: number;
976
- /**
977
- * @deprecated Use "errors" instead
978
- */
979
- error?: ErrorWithDiff;
980
- errors?: ErrorWithDiff[];
981
- htmlError?: string;
982
- hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
983
- benchmark?: BenchmarkResult;
984
- retryCount?: number;
985
- }
986
- type TaskResultPack = [id: string, result: TaskResult | undefined];
987
- interface Suite extends TaskBase {
988
- type: 'suite';
989
- tasks: Task[];
990
- filepath?: string;
991
- benchmark?: Bench;
992
- projectName?: string;
993
- }
994
- interface File extends Suite {
995
- filepath: string;
996
- collectDuration?: number;
997
- setupDuration?: number;
998
- }
999
- interface Test<ExtraContext = {}> extends TaskBase {
1000
- type: 'test';
1001
- suite: Suite;
1002
- result?: TaskResult;
1003
- fails?: boolean;
1004
- context: TestContext & ExtraContext;
1005
- onFailed?: OnTestFailedHandler[];
1006
- }
1007
- type Task = Test | Suite | File | Benchmark;
1008
- type DoneCallback = (error?: any) => void;
1009
- type TestFunction<ExtraContext = {}> = (context: TestContext & ExtraContext) => Awaitable<any> | void;
1010
- type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
1011
- 1: [T[0]];
1012
- 2: [T[0], T[1]];
1013
- 3: [T[0], T[1], T[2]];
1014
- 4: [T[0], T[1], T[2], T[3]];
1015
- 5: [T[0], T[1], T[2], T[3], T[4]];
1016
- 6: [T[0], T[1], T[2], T[3], T[4], T[5]];
1017
- 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6]];
1018
- 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7]];
1019
- 9: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8]];
1020
- 10: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]];
1021
- fallback: Array<T extends ReadonlyArray<infer U> ? U : any>;
1022
- }[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'];
1023
- interface SuiteEachFunction {
1024
- <T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T) => Awaitable<void>) => void;
1025
- <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string, fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>) => void;
1026
- <T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => Awaitable<void>) => void;
1027
- }
1028
- interface TestEachFunction {
1029
- <T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T) => Awaitable<void>, options?: number | TestOptions) => void;
1030
- <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string, fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>, options?: number | TestOptions) => void;
1031
- <T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => Awaitable<void>, options?: number | TestOptions) => void;
1032
- (...args: [TemplateStringsArray, ...any]): (name: string, fn: (...args: any[]) => Awaitable<void>, options?: number | TestOptions) => void;
1033
- }
1034
- type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [
1035
- name: string,
1036
- fn?: TestFunction<ExtraContext>,
1037
- options?: number | TestOptions
1038
- ], void, {
1039
- each: TestEachFunction;
1040
- <T extends ExtraContext>(name: string, fn?: TestFunction<T>, options?: number | TestOptions): void;
1041
- }>;
1042
- interface TestOptions {
1043
- /**
1044
- * Test timeout.
1045
- */
1046
- timeout?: number;
1047
- /**
1048
- * Times to retry the test if fails. Useful for making flaky tests more stable.
1049
- * When retries is up, the last test error will be thrown.
1050
- *
1051
- * @default 1
1052
- */
1053
- retry?: number;
1054
- }
1055
- type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & {
1056
- each: TestEachFunction;
1057
- skipIf(condition: any): ChainableTestAPI<ExtraContext>;
1058
- runIf(condition: any): ChainableTestAPI<ExtraContext>;
1059
- };
1060
- type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle', [
1061
- name: string,
1062
- factory?: SuiteFactory<ExtraContext>,
1063
- options?: number | TestOptions
1064
- ], SuiteCollector<ExtraContext>, {
1065
- each: TestEachFunction;
1066
- <T extends ExtraContext>(name: string, factory?: SuiteFactory<T>): SuiteCollector<T>;
1067
- }>;
1068
- type SuiteAPI<ExtraContext = {}> = ChainableSuiteAPI<ExtraContext> & {
1069
- each: SuiteEachFunction;
1070
- skipIf(condition: any): ChainableSuiteAPI<ExtraContext>;
1071
- runIf(condition: any): ChainableSuiteAPI<ExtraContext>;
1072
- };
1073
- type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
1074
- type HookCleanupCallback = (() => Awaitable<unknown>) | void;
1075
- interface SuiteHooks<ExtraContext = {}> {
1076
- beforeAll: HookListener<[Suite | File], HookCleanupCallback>[];
1077
- afterAll: HookListener<[Suite | File]>[];
1078
- beforeEach: HookListener<[TestContext & ExtraContext, Suite], HookCleanupCallback>[];
1079
- afterEach: HookListener<[TestContext & ExtraContext, Suite]>[];
1080
- }
1081
- interface SuiteCollector<ExtraContext = {}> {
1082
- readonly name: string;
1083
- readonly mode: RunMode;
1084
- type: 'collector';
1085
- test: TestAPI<ExtraContext>;
1086
- benchmark: BenchmarkAPI;
1087
- tasks: (Suite | Test | Benchmark | SuiteCollector<ExtraContext>)[];
1088
- collect: (file?: File) => Promise<Suite>;
1089
- clear: () => void;
1090
- on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
1091
- }
1092
- type SuiteFactory<ExtraContext = {}> = (test: (name: string, fn: TestFunction<ExtraContext>) => void) => Awaitable<void>;
1093
- interface RuntimeContext {
1094
- tasks: (SuiteCollector | Test)[];
1095
- currentSuite: SuiteCollector | null;
1096
- }
1097
- interface TestContext {
1098
- /**
1099
- * Metadata of the current test
1100
- */
1101
- meta: Readonly<Test>;
1102
- /**
1103
- * A expect instance bound to the test
1104
- */
1105
- expect: Vi.ExpectStatic;
1106
- /**
1107
- * Extract hooks on test failed
1108
- */
1109
- onTestFailed: (fn: OnTestFailedHandler) => void;
1110
- }
1111
- type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
1112
-
1113
1121
  type SnapshotData = Record<string, string>;
1114
1122
  type SnapshotUpdateState = 'all' | 'new' | 'none';
1115
1123
  interface SnapshotStateOptions {
@@ -1176,7 +1184,7 @@ interface WorkerRPC {
1176
1184
  onWorkerExit: (error: unknown, code?: number) => void;
1177
1185
  onPathsCollected: (paths: string[]) => void;
1178
1186
  onUserConsoleLog: (log: UserConsoleLog) => void;
1179
- onUnhandledRejection: (err: unknown) => void;
1187
+ onUnhandledError: (err: unknown, type: string) => void;
1180
1188
  onCollected: (files: File[]) => void;
1181
1189
  onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
1182
1190
  onTaskUpdate: (pack: TaskResultPack[]) => void;
@@ -1201,9 +1209,13 @@ interface CoverageProvider {
1201
1209
  clean(clean?: boolean): void | Promise<void>;
1202
1210
  onBeforeFilesRun?(): void | Promise<void>;
1203
1211
  onAfterSuiteRun(meta: AfterSuiteRunMeta): void | Promise<void>;
1204
- reportCoverage(): void | Promise<void>;
1212
+ reportCoverage(reportContext?: ReportContext): void | Promise<void>;
1205
1213
  onFileTransform?(sourceCode: string, id: string, pluginCtx: TransformPluginContext): TransformResult | Promise<TransformResult>;
1206
1214
  }
1215
+ interface ReportContext {
1216
+ /** Indicates whether all tests were run. False when only specific tests were run. */
1217
+ allTestsRun?: boolean;
1218
+ }
1207
1219
  interface CoverageProviderModule {
1208
1220
  /**
1209
1221
  * Factory for creating a new coverage provider
@@ -1215,16 +1227,19 @@ interface CoverageProviderModule {
1215
1227
  takeCoverage?(): unknown | Promise<unknown>;
1216
1228
  }
1217
1229
  type CoverageReporter = 'clover' | 'cobertura' | 'html-spa' | 'html' | 'json-summary' | 'json' | 'lcov' | 'lcovonly' | 'none' | 'teamcity' | 'text-lcov' | 'text-summary' | 'text';
1218
- type CoverageOptions = BaseCoverageOptions & {
1219
- provider?: null | CoverageProviderModule;
1220
- } | CoverageC8Options & {
1221
- provider?: 'c8';
1222
- } | CoverageIstanbulOptions & {
1223
- provider?: 'istanbul';
1230
+ type Provider = 'c8' | 'istanbul' | CoverageProviderModule | undefined;
1231
+ type CoverageOptions<T extends Provider = Provider> = T extends CoverageProviderModule ? ({
1232
+ provider: T;
1233
+ } & BaseCoverageOptions) : T extends 'istanbul' ? ({
1234
+ provider: T;
1235
+ } & CoverageIstanbulOptions) : ({
1236
+ provider?: T;
1237
+ } & CoverageC8Options);
1238
+ /** Fields that have default values. Internally these will always be defined. */
1239
+ type FieldsWithDefaultValues = 'enabled' | 'clean' | 'cleanOnRerun' | 'reportsDirectory' | 'exclude' | 'extension' | 'reporter';
1240
+ type ResolvedCoverageOptions<T extends Provider = Provider> = CoverageOptions<T> & Required<Pick<CoverageOptions<T>, FieldsWithDefaultValues>> & {
1241
+ reporter: CoverageReporter[];
1224
1242
  };
1225
- type ResolvedCoverageOptions = {
1226
- tempDirectory: string;
1227
- } & Required<CoverageOptions>;
1228
1243
  interface BaseCoverageOptions {
1229
1244
  /**
1230
1245
  * Enables coverage collection. Can be overriden using `--coverage` CLI option.
@@ -1564,6 +1579,21 @@ interface InlineConfig {
1564
1579
  * Environment options.
1565
1580
  */
1566
1581
  environmentOptions?: EnvironmentOptions;
1582
+ /**
1583
+ * Automatically assign environment based on globs. The first match will be used.
1584
+ *
1585
+ * Format: [glob, environment-name]
1586
+ *
1587
+ * @default []
1588
+ * @example [
1589
+ * // all tests in tests/dom will run in jsdom
1590
+ * ['tests/dom/**', 'jsdom'],
1591
+ * // all tests in tests/ with .edge.test.ts will run in edge-runtime
1592
+ * ['**\/*.edge.test.ts', 'edge-runtime'],
1593
+ * // ...
1594
+ * ]
1595
+ */
1596
+ environmentMatchGlobs?: [string, VitestEnvironment][];
1567
1597
  /**
1568
1598
  * Update snapshot
1569
1599
  *
@@ -2265,4 +2295,4 @@ type Context = RootAndTarget & {
2265
2295
  lastActivePath?: string;
2266
2296
  };
2267
2297
 
2268
- export { WorkerContext as $, ApiConfig as A, BuiltinEnvironment as B, CollectLineNumbers as C, DoneCallback as D, EnvironmentOptions as E, FakeTimerInstallOpts as F, SuiteFactory as G, HookListener as H, InlineConfig as I, JSDOMOptions as J, RuntimeContext as K, TestContext as L, MockFactoryWithHelper as M, Vitest as N, OnTestFailedHandler as O, SnapshotData as P, SnapshotUpdateState as Q, RuntimeConfig as R, SequenceHooks as S, TaskResultPack as T, UserConfig as U, VitestEnvironment as V, SnapshotStateOptions as W, SnapshotMatchOptions as X, SnapshotResult as Y, UncheckedSnapshot as Z, SnapshotSummary as _, File as a, ResolveIdFunction as a0, AfterSuiteRunMeta as a1, WorkerRPC as a2, WorkerGlobalState as a3, Awaitable as a4, Nullable as a5, Arrayable as a6, ArgumentsType$1 as a7, MergeInsertions as a8, DeepMerge as a9, TestSequencerConstructor as aA, MutableArray as aa, Constructable as ab, ModuleCache as ac, EnvironmentReturn as ad, Environment as ae, UserConsoleLog as af, ParsedStack as ag, ErrorWithDiff as ah, OnServerRestartHandler as ai, CoverageProvider as aj, CoverageProviderModule as ak, CoverageReporter as al, CoverageOptions as am, ResolvedCoverageOptions as an, BaseCoverageOptions as ao, CoverageIstanbulOptions as ap, CoverageC8Options as aq, BenchmarkUserOptions as ar, Benchmark as as, BenchmarkResult as at, BenchFunction as au, BenchmarkAPI as av, MockFactory as aw, MockMap as ax, TestSequencer as ay, startVitest as az, ResolvedConfig as b, ModuleGraphData as c, Reporter as d, RawErrsMap as e, TscErrorInfo as f, CollectLines as g, RootAndTarget as h, Context as i, CSSModuleScopeStrategy as j, VitestRunMode as k, TypecheckConfig as l, RunMode as m, TaskState as n, TaskBase as o, TaskResult as p, Suite as q, Test as r, Task as s, TestFunction as t, TestOptions as u, TestAPI as v, SuiteAPI as w, HookCleanupCallback as x, SuiteHooks as y, SuiteCollector as z };
2298
+ export { WorkerContext as $, ApiConfig as A, BuiltinEnvironment as B, CollectLineNumbers as C, DoneCallback as D, EnvironmentOptions as E, FakeTimerInstallOpts as F, SuiteFactory as G, HookListener as H, InlineConfig as I, JSDOMOptions as J, RuntimeContext as K, TestContext as L, MockFactoryWithHelper as M, Vitest as N, OnTestFailedHandler as O, SnapshotData as P, SnapshotUpdateState as Q, RuntimeConfig as R, SequenceHooks as S, TaskResultPack as T, UserConfig as U, VitestEnvironment as V, SnapshotStateOptions as W, SnapshotMatchOptions as X, SnapshotResult as Y, UncheckedSnapshot as Z, SnapshotSummary as _, File as a, ResolveIdFunction as a0, AfterSuiteRunMeta as a1, WorkerRPC as a2, WorkerGlobalState as a3, Awaitable as a4, Nullable as a5, Arrayable as a6, ArgumentsType$1 as a7, MergeInsertions as a8, DeepMerge as a9, startVitest as aA, TestSequencerConstructor as aB, MutableArray as aa, Constructable as ab, ModuleCache as ac, EnvironmentReturn as ad, Environment as ae, UserConsoleLog as af, ParsedStack as ag, ErrorWithDiff as ah, OnServerRestartHandler as ai, CoverageProvider as aj, ReportContext as ak, CoverageProviderModule as al, CoverageReporter as am, CoverageOptions as an, ResolvedCoverageOptions as ao, BaseCoverageOptions as ap, CoverageIstanbulOptions as aq, CoverageC8Options as ar, BenchmarkUserOptions as as, Benchmark as at, BenchmarkResult as au, BenchFunction as av, BenchmarkAPI as aw, MockFactory as ax, MockMap as ay, TestSequencer as az, ResolvedConfig as b, ModuleGraphData as c, Reporter as d, RawErrsMap as e, TscErrorInfo as f, CollectLines as g, RootAndTarget as h, Context as i, CSSModuleScopeStrategy as j, VitestRunMode as k, TypecheckConfig as l, RunMode as m, TaskState as n, TaskBase as o, TaskResult as p, Suite as q, Test as r, Task as s, TestFunction as t, TestOptions as u, TestAPI as v, SuiteAPI as w, HookCleanupCallback as x, SuiteHooks as y, SuiteCollector as z };