vitest 0.21.0 → 0.22.1

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 (45) hide show
  1. package/LICENSE.md +61 -4
  2. package/dist/browser.d.ts +4 -5
  3. package/dist/browser.mjs +9 -9
  4. package/dist/{chunk-api-setup.89eb0e7a.mjs → chunk-api-setup.377c28aa.mjs} +9 -9
  5. package/dist/chunk-constants.71e8a211.mjs +284 -0
  6. package/dist/{chunk-install-pkg.6c6dc0c2.mjs → chunk-install-pkg.3aa3eae6.mjs} +3 -2
  7. package/dist/{chunk-defaults.8390340d.mjs → chunk-integrations-coverage.d205bd87.mjs} +23 -152
  8. package/dist/{chunk-integrations-globals.a798d352.mjs → chunk-integrations-globals.60af7da3.mjs} +8 -8
  9. package/dist/{chunk-mock-date.ea3b3121.mjs → chunk-mock-date.304e29b1.mjs} +11 -255
  10. package/dist/chunk-node-git.9a7e3153.mjs +78 -0
  11. package/dist/{chunk-runtime-chain.44b4224d.mjs → chunk-runtime-chain.be610650.mjs} +4 -3
  12. package/dist/{chunk-runtime-error.95e53764.mjs → chunk-runtime-error.1104e45a.mjs} +13 -12
  13. package/dist/{chunk-runtime-hooks.291644ec.mjs → chunk-runtime-hooks.5d7073db.mjs} +3 -3
  14. package/dist/{chunk-runtime-mocker.6190d6a3.mjs → chunk-runtime-mocker.49d21aa6.mjs} +19 -5
  15. package/dist/{chunk-runtime-rpc.fc50dcc0.mjs → chunk-runtime-rpc.57586b73.mjs} +1 -1
  16. package/dist/{chunk-utils-source-map.d307e4ea.mjs → chunk-utils-source-map.bbf3ad19.mjs} +2 -1
  17. package/dist/{chunk-vite-node-client.b59ba135.mjs → chunk-vite-node-client.cddda63d.mjs} +49 -21
  18. package/dist/{chunk-vite-node-debug.dbce2e1f.mjs → chunk-vite-node-debug.536c4c5b.mjs} +3 -3
  19. package/dist/{chunk-vite-node-externalize.80bed9b3.mjs → chunk-vite-node-externalize.c843f497.mjs} +186 -50
  20. package/dist/chunk-vite-node-utils.b432150c.mjs +6921 -0
  21. package/dist/cli-wrapper.mjs +124 -0
  22. package/dist/cli.mjs +16 -15
  23. package/dist/config.cjs +3 -0
  24. package/dist/config.d.ts +6 -3
  25. package/dist/config.mjs +2 -1
  26. package/dist/entry.mjs +9 -9
  27. package/dist/{global-644546f7.d.ts → global-fe52f84b.d.ts} +512 -177
  28. package/dist/{index-3f764034.d.ts → index-ea17aa0c.d.ts} +4 -52
  29. package/dist/index.d.ts +5 -6
  30. package/dist/index.mjs +7 -5
  31. package/dist/loader.mjs +4 -3
  32. package/dist/node.d.ts +3 -3
  33. package/dist/node.mjs +16 -15
  34. package/dist/suite.mjs +6 -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.e0dc0a7e.mjs → vendor-index.fbec8a81.mjs} +5 -73
  40. package/dist/worker.mjs +9 -9
  41. package/package.json +9 -13
  42. package/vitest.mjs +1 -1
  43. package/dist/chunk-constants.9da1ef26.mjs +0 -38
  44. package/dist/chunk-vite-node-utils.96438e82.mjs +0 -1114
  45. package/dist/mocker-5e2a8e41.d.ts +0 -3
@@ -1,4 +1,5 @@
1
- import { ViteDevServer, TransformResult, UserConfig as UserConfig$1, CommonServerOptions, AliasOptions } from 'vite';
1
+ import { ViteDevServer, TransformResult as TransformResult$1, UserConfig as UserConfig$1, CommonServerOptions, AliasOptions } from 'vite';
2
+ import { MessagePort } from 'worker_threads';
2
3
  import { Stats } from 'fs';
3
4
 
4
5
  /**
@@ -237,9 +238,17 @@ interface ViteHotContext {
237
238
  }
238
239
  declare class ModuleCacheMap extends Map<string, ModuleCache$1> {
239
240
  normalizePath(fsPath: string): string;
240
- set(fsPath: string, mod: Partial<ModuleCache$1>): this;
241
- get(fsPath: string): ModuleCache$1 | undefined;
241
+ /**
242
+ * Assign partial data to the map
243
+ */
244
+ update(fsPath: string, mod: Partial<ModuleCache$1>): this;
245
+ set(fsPath: string, mod: ModuleCache$1): this;
246
+ get(fsPath: string): ModuleCache$1;
242
247
  delete(fsPath: string): boolean;
248
+ /**
249
+ * Invalidate modules that dependent on the given modules, up to the main entry
250
+ */
251
+ invalidateDepTree(ids: string[] | Set<string>, invalidated?: Set<string>): Set<string>;
243
252
  }
244
253
  declare class ViteNodeRunner {
245
254
  options: ViteNodeRunnerOptions;
@@ -297,17 +306,21 @@ interface FetchResult {
297
306
  }
298
307
  declare type HotContext = Omit<ViteHotContext, 'acceptDeps' | 'decline'>;
299
308
  declare type FetchFunction = (id: string) => Promise<FetchResult>;
300
- declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
309
+ declare type ResolveIdFunction$1 = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
301
310
  declare type CreateHotContextFunction = (runner: ViteNodeRunner, url: string) => HotContext;
302
311
  interface ModuleCache$1 {
303
312
  promise?: Promise<any>;
304
313
  exports?: any;
305
314
  code?: string;
315
+ /**
316
+ * Module ids that imports this module
317
+ */
318
+ importers?: Set<string>;
306
319
  }
307
320
  interface ViteNodeRunnerOptions {
308
321
  root: string;
309
322
  fetchModule: FetchFunction;
310
- resolveId?: ResolveIdFunction;
323
+ resolveId?: ResolveIdFunction$1;
311
324
  createHotContext?: CreateHotContextFunction;
312
325
  base?: string;
313
326
  moduleCache?: ModuleCacheMap;
@@ -363,8 +376,8 @@ declare class Debugger {
363
376
  clearDump(): Promise<void>;
364
377
  encodeId(id: string): string;
365
378
  recordExternalize(id: string, path: string): Promise<void>;
366
- dumpFile(id: string, result: TransformResult | null): Promise<void>;
367
- loadDump(id: string): Promise<TransformResult | null>;
379
+ dumpFile(id: string, result: TransformResult$1 | null): Promise<void>;
380
+ loadDump(id: string): Promise<TransformResult$1 | null>;
368
381
  writeInfo(): Promise<void>;
369
382
  }
370
383
 
@@ -374,6 +387,7 @@ declare class ViteNodeServer {
374
387
  private fetchPromiseMap;
375
388
  private transformPromiseMap;
376
389
  fetchCache: Map<string, {
390
+ duration?: number | undefined;
377
391
  timestamp: number;
378
392
  result: FetchResult;
379
393
  }>;
@@ -383,7 +397,7 @@ declare class ViteNodeServer {
383
397
  shouldExternalize(id: string): Promise<string | false>;
384
398
  resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
385
399
  fetchModule(id: string): Promise<FetchResult>;
386
- transformRequest(id: string): Promise<TransformResult | null | undefined>;
400
+ transformRequest(id: string): Promise<TransformResult$1 | null | undefined>;
387
401
  getTransformMode(id: string): "web" | "ssr";
388
402
  private _fetchModule;
389
403
  private _transformRequest;
@@ -515,6 +529,7 @@ declare class Vitest {
515
529
  snapshot: SnapshotManager;
516
530
  cache: VitestCache;
517
531
  reporters: Reporter[];
532
+ coverageProvider: CoverageProvider | null | undefined;
518
533
  logger: Logger;
519
534
  pool: WorkerPool | undefined;
520
535
  vitenode: ViteNodeServer;
@@ -528,6 +543,7 @@ declare class Vitest {
528
543
  constructor();
529
544
  private _onRestartListeners;
530
545
  setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
546
+ initCoverageProvider(): Promise<CoverageProvider | null | undefined>;
531
547
  getSerializableConfig(): ResolvedConfig;
532
548
  start(filters?: string[]): Promise<void>;
533
549
  private getTestDependencies;
@@ -547,13 +563,15 @@ declare class Vitest {
547
563
  private handleFileChanged;
548
564
  close(): Promise<void>;
549
565
  exit(force?: boolean): Promise<void>;
550
- report<T extends keyof Reporter>(name: T, ...args: ArgumentsType<Reporter[T]>): Promise<void>;
566
+ report<T extends keyof Reporter>(name: T, ...args: ArgumentsType$1<Reporter[T]>): Promise<void>;
551
567
  globTestFiles(filters?: string[]): Promise<string[]>;
552
568
  isTargetFile(id: string, source?: string): Promise<boolean>;
553
569
  isInSourceTestFile(code: string): boolean;
554
- onServerRestarted(fn: () => void): void;
570
+ onServerRestart(fn: OnServerRestartHandler): void;
555
571
  }
556
572
 
573
+ declare type MockMap = Map<string, Record<string, string | null | (() => unknown)>>;
574
+
557
575
  interface TestSequencer {
558
576
  /**
559
577
  * Slicing tests into shards. Will be run before `sort`.
@@ -587,7 +605,7 @@ declare abstract class BaseReporter implements Reporter {
587
605
  onWatcherRerun(files: string[], trigger?: string): Promise<void>;
588
606
  onUserConsoleLog(log: UserConsoleLog): void;
589
607
  shouldLog(log: UserConsoleLog): boolean;
590
- onServerRestart(): void;
608
+ onServerRestart(reason?: string): void;
591
609
  reportSummary(files: File[]): Promise<void>;
592
610
  private printTaskErrors;
593
611
  registerUnhandledRejection(): void;
@@ -690,10 +708,215 @@ declare const ReportersMap: {
690
708
  };
691
709
  declare type BuiltinReporters = keyof typeof ReportersMap;
692
710
 
711
+ interface RollupError extends RollupLogProps {
712
+ parserError?: Error;
713
+ stack?: string;
714
+ watchFiles?: string[];
715
+ }
716
+
717
+ interface RollupWarning extends RollupLogProps {
718
+ chunkName?: string;
719
+ cycle?: string[];
720
+ exportName?: string;
721
+ exporter?: string;
722
+ guess?: string;
723
+ importer?: string;
724
+ missing?: string;
725
+ modules?: string[];
726
+ names?: string[];
727
+ reexporter?: string;
728
+ source?: string;
729
+ sources?: string[];
730
+ }
731
+
732
+ interface RollupLogProps {
733
+ code?: string;
734
+ frame?: string;
735
+ hook?: string;
736
+ id?: string;
737
+ loc?: {
738
+ column: number;
739
+ file?: string;
740
+ line: number;
741
+ };
742
+ message: string;
743
+ name?: string;
744
+ plugin?: string;
745
+ pluginCode?: string;
746
+ pos?: number;
747
+ url?: string;
748
+ }
749
+
750
+ interface ExistingRawSourceMap {
751
+ file?: string;
752
+ mappings: string;
753
+ names: string[];
754
+ sourceRoot?: string;
755
+ sources: string[];
756
+ sourcesContent?: string[];
757
+ version: number;
758
+ }
759
+
760
+ interface SourceMap {
761
+ file: string;
762
+ mappings: string;
763
+ names: string[];
764
+ sources: string[];
765
+ sourcesContent: string[];
766
+ version: number;
767
+ toString(): string;
768
+ toUrl(): string;
769
+ }
770
+
771
+ type SourceMapInput = ExistingRawSourceMap | string | null | { mappings: '' };
772
+
773
+ type PartialNull<T> = {
774
+ [P in keyof T]: T[P] | null;
775
+ };
776
+
777
+ interface ModuleOptions {
778
+ meta: CustomPluginOptions;
779
+ moduleSideEffects: boolean | 'no-treeshake';
780
+ syntheticNamedExports: boolean | string;
781
+ }
782
+
783
+ interface SourceDescription extends Partial<PartialNull<ModuleOptions>> {
784
+ ast?: AcornNode;
785
+ code: string;
786
+ map?: SourceMapInput;
787
+ }
788
+
789
+ interface PluginCache {
790
+ delete(id: string): boolean;
791
+ get<T = any>(id: string): T;
792
+ has(id: string): boolean;
793
+ set<T = any>(id: string, value: T): void;
794
+ }
795
+
796
+ interface MinimalPluginContext {
797
+ meta: PluginContextMeta;
798
+ }
799
+
800
+ interface EmittedAsset {
801
+ fileName?: string;
802
+ name?: string;
803
+ source?: string | Uint8Array;
804
+ type: 'asset';
805
+ }
806
+
807
+ interface EmittedChunk {
808
+ fileName?: string;
809
+ id: string;
810
+ implicitlyLoadedAfterOneOf?: string[];
811
+ importer?: string;
812
+ name?: string;
813
+ preserveSignature?: PreserveEntrySignaturesOption;
814
+ type: 'chunk';
815
+ }
816
+
817
+ type EmittedFile = EmittedAsset | EmittedChunk;
818
+
819
+ type EmitAsset = (name: string, source?: string | Uint8Array) => string;
820
+
821
+ type EmitChunk = (id: string, options?: { name?: string }) => string;
822
+
823
+ type EmitFile = (emittedFile: EmittedFile) => string;
824
+
825
+ interface ModuleInfo extends ModuleOptions {
826
+ ast: AcornNode | null;
827
+ code: string | null;
828
+ dynamicImporters: readonly string[];
829
+ dynamicallyImportedIdResolutions: readonly ResolvedId[];
830
+ dynamicallyImportedIds: readonly string[];
831
+ hasDefaultExport: boolean | null;
832
+ /** @deprecated Use `moduleSideEffects` instead */
833
+ hasModuleSideEffects: boolean | 'no-treeshake';
834
+ id: string;
835
+ implicitlyLoadedAfterOneOf: readonly string[];
836
+ implicitlyLoadedBefore: readonly string[];
837
+ importedIdResolutions: readonly ResolvedId[];
838
+ importedIds: readonly string[];
839
+ importers: readonly string[];
840
+ isEntry: boolean;
841
+ isExternal: boolean;
842
+ isIncluded: boolean | null;
843
+ }
844
+
845
+ type GetModuleInfo = (moduleId: string) => ModuleInfo | null;
846
+
847
+ interface CustomPluginOptions {
848
+ [plugin: string]: any;
849
+ }
850
+
851
+ interface PluginContext extends MinimalPluginContext {
852
+ addWatchFile: (id: string) => void;
853
+ cache: PluginCache;
854
+ /** @deprecated Use `this.emitFile` instead */
855
+ emitAsset: EmitAsset;
856
+ /** @deprecated Use `this.emitFile` instead */
857
+ emitChunk: EmitChunk;
858
+ emitFile: EmitFile;
859
+ error: (err: RollupError | string, pos?: number | { column: number; line: number }) => never;
860
+ /** @deprecated Use `this.getFileName` instead */
861
+ getAssetFileName: (assetReferenceId: string) => string;
862
+ /** @deprecated Use `this.getFileName` instead */
863
+ getChunkFileName: (chunkReferenceId: string) => string;
864
+ getFileName: (fileReferenceId: string) => string;
865
+ getModuleIds: () => IterableIterator<string>;
866
+ getModuleInfo: GetModuleInfo;
867
+ getWatchFiles: () => string[];
868
+ /** @deprecated Use `this.resolve` instead */
869
+ isExternal: IsExternal;
870
+ load: (
871
+ options: { id: string; resolveDependencies?: boolean } & Partial<PartialNull<ModuleOptions>>
872
+ ) => Promise<ModuleInfo>;
873
+ /** @deprecated Use `this.getModuleIds` instead */
874
+ moduleIds: IterableIterator<string>;
875
+ parse: (input: string, options?: any) => AcornNode;
876
+ resolve: (
877
+ source: string,
878
+ importer?: string,
879
+ options?: { custom?: CustomPluginOptions; isEntry?: boolean; skipSelf?: boolean }
880
+ ) => Promise<ResolvedId | null>;
881
+ /** @deprecated Use `this.resolve` instead */
882
+ resolveId: (source: string, importer?: string) => Promise<string | null>;
883
+ setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void;
884
+ warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void;
885
+ }
886
+
887
+ interface PluginContextMeta {
888
+ rollupVersion: string;
889
+ watchMode: boolean;
890
+ }
891
+
892
+ interface ResolvedId extends ModuleOptions {
893
+ external: boolean | 'absolute';
894
+ id: string;
895
+ }
896
+
897
+ type IsExternal = (
898
+ source: string,
899
+ importer: string | undefined,
900
+ isResolved: boolean
901
+ ) => boolean;
902
+
903
+ interface TransformPluginContext extends PluginContext {
904
+ getCombinedSourcemap: () => SourceMap;
905
+ }
906
+
907
+ type TransformResult = string | null | void | Partial<SourceDescription>;
908
+ type PreserveEntrySignaturesOption = false | 'strict' | 'allow-extension' | 'exports-only';
909
+
910
+ interface AcornNode {
911
+ end: number;
912
+ start: number;
913
+ type: string;
914
+ }
915
+
693
916
  declare type Awaitable<T> = T | PromiseLike<T>;
694
917
  declare type Nullable<T> = T | null | undefined;
695
918
  declare type Arrayable<T> = T | Array<T>;
696
- declare type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
919
+ declare type ArgumentsType$1<T> = T extends (...args: infer U) => any ? U : never;
697
920
  declare type MergeInsertions<T> = T extends object ? {
698
921
  [K in keyof T]: MergeInsertions<T[K]>;
699
922
  } : T;
@@ -754,150 +977,20 @@ interface ModuleGraphData {
754
977
  externalized: string[];
755
978
  inlined: string[];
756
979
  }
980
+ declare type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
757
981
 
758
- declare type CoverageReporter = 'clover' | 'cobertura' | 'html-spa' | 'html' | 'json-summary' | 'json' | 'lcov' | 'lcovonly' | 'none' | 'teamcity' | 'text-lcov' | 'text-summary' | 'text';
759
- interface C8Options {
982
+ declare type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
983
+ declare type ReturnType$1<T> = T extends (...args: any) => infer R ? R : never;
984
+ declare type PromisifyFn<T> = ReturnType$1<T> extends Promise<any> ? T : (...args: ArgumentsType<T>) => Promise<Awaited<ReturnType$1<T>>>;
985
+ declare type BirpcFn<T> = PromisifyFn<T> & {
760
986
  /**
761
- * Enable coverage, pass `--coverage` to enable
762
- *
763
- * @default false
764
- */
765
- enabled?: boolean;
766
- /**
767
- * Directory to write coverage report to
987
+ * Send event without asking for response
768
988
  */
769
- reportsDirectory?: string;
770
- /**
771
- * Clean coverage before running tests
772
- *
773
- * @default true
774
- */
775
- clean?: boolean;
776
- /**
777
- * Clean coverage report on watch rerun
778
- *
779
- * @default false
780
- */
781
- cleanOnRerun?: boolean;
782
- /**
783
- * Check thresholds per file
784
- *
785
- * @default false
786
- */
787
- perFile?: boolean;
788
- /**
789
- * Allow files from outside of your cwd.
790
- *
791
- * @default false
792
- */
793
- allowExternal?: any;
794
- /**
795
- * Reporters
796
- *
797
- * @default 'text'
798
- */
799
- reporter?: Arrayable<CoverageReporter>;
800
- /**
801
- * Exclude coverage under /node_modules/
802
- *
803
- * @default true
804
- */
805
- excludeNodeModules?: boolean;
806
- exclude?: string[];
807
- include?: string[];
808
- skipFull?: boolean;
809
- extension?: string | string[];
810
- all?: boolean;
811
- src?: string[];
812
- 100?: boolean;
813
- lines?: number;
814
- functions?: number;
815
- branches?: number;
816
- statements?: number;
817
- }
818
- interface ResolvedC8Options extends Required<C8Options> {
819
- tempDirectory: string;
820
- }
821
-
822
- interface JSDOMOptions {
823
- /**
824
- * The html content for the test.
825
- *
826
- * @default '<!DOCTYPE html>'
827
- */
828
- html?: string | Buffer | ArrayBufferLike;
829
- /**
830
- * referrer just affects the value read from document.referrer.
831
- * It defaults to no referrer (which reflects as the empty string).
832
- */
833
- referrer?: string;
834
- /**
835
- * userAgent affects the value read from navigator.userAgent, as well as the User-Agent header sent while fetching subresources.
836
- *
837
- * @default `Mozilla/5.0 (${process.platform}) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/${jsdomVersion}`
838
- */
839
- userAgent?: string;
840
- /**
841
- * url sets the value returned by window.location, document.URL, and document.documentURI,
842
- * and affects things like resolution of relative URLs within the document
843
- * and the same-origin restrictions and referrer used while fetching subresources.
844
- *
845
- * @default 'http://localhost:3000'.
846
- */
847
- url?: string;
848
- /**
849
- * contentType affects the value read from document.contentType, and how the document is parsed: as HTML or as XML.
850
- * Values that are not "text/html" or an XML mime type will throw.
851
- *
852
- * @default 'text/html'.
853
- */
854
- contentType?: string;
855
- /**
856
- * The maximum size in code units for the separate storage areas used by localStorage and sessionStorage.
857
- * Attempts to store data larger than this limit will cause a DOMException to be thrown. By default, it is set
858
- * to 5,000,000 code units per origin, as inspired by the HTML specification.
859
- *
860
- * @default 5_000_000
861
- */
862
- storageQuota?: number;
863
- /**
864
- * Enable console?
865
- *
866
- * @default false
867
- */
868
- console?: boolean;
869
- /**
870
- * jsdom does not have the capability to render visual content, and will act like a headless browser by default.
871
- * It provides hints to web pages through APIs such as document.hidden that their content is not visible.
872
- *
873
- * When the `pretendToBeVisual` option is set to `true`, jsdom will pretend that it is rendering and displaying
874
- * content.
875
- *
876
- * @default true
877
- */
878
- pretendToBeVisual?: boolean;
879
- /**
880
- * `includeNodeLocations` preserves the location info produced by the HTML parser,
881
- * allowing you to retrieve it with the nodeLocation() method (described below).
882
- *
883
- * It defaults to false to give the best performance,
884
- * and cannot be used with an XML content type since our XML parser does not support location info.
885
- *
886
- * @default false
887
- */
888
- includeNodeLocations?: boolean | undefined;
889
- /**
890
- * @default 'dangerously'
891
- */
892
- runScripts?: 'dangerously' | 'outside-only';
893
- /**
894
- * Enable CookieJar
895
- *
896
- * @default false
897
- */
898
- cookieJar?: boolean;
899
- resources?: 'usable' | any;
900
- }
989
+ asEvent(...args: ArgumentsType<T>): void;
990
+ };
991
+ declare type BirpcReturn<RemoteFunctions> = {
992
+ [K in keyof RemoteFunctions]: BirpcFn<RemoteFunctions[K]>;
993
+ };
901
994
 
902
995
  declare type ChainableFunction<T extends string, Args extends any[], R = any, E = {}> = {
903
996
  (...args: Args): R;
@@ -977,6 +1070,7 @@ declare type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<'concurrent
977
1070
  timeout?: number
978
1071
  ], void, {
979
1072
  each: TestEachFunction;
1073
+ <T extends ExtraContext>(name: string, fn?: TestFunction<T>, timeout?: number): void;
980
1074
  }>;
981
1075
  declare type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & {
982
1076
  each: TestEachFunction;
@@ -985,22 +1079,23 @@ declare type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & {
985
1079
  };
986
1080
  declare type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle', [
987
1081
  name: string,
988
- factory?: SuiteFactory
1082
+ factory?: SuiteFactory<ExtraContext>
989
1083
  ], SuiteCollector<ExtraContext>, {
990
1084
  each: TestEachFunction;
1085
+ <T extends ExtraContext>(name: string, factory?: SuiteFactory<T>): SuiteCollector<T>;
991
1086
  }>;
992
- declare type SuiteAPI<ExtraContext = {}> = ChainableSuiteAPI & {
1087
+ declare type SuiteAPI<ExtraContext = {}> = ChainableSuiteAPI<ExtraContext> & {
993
1088
  each: SuiteEachFunction;
994
1089
  skipIf(condition: any): ChainableSuiteAPI<ExtraContext>;
995
1090
  runIf(condition: any): ChainableSuiteAPI<ExtraContext>;
996
1091
  };
997
1092
  declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
998
1093
  declare type HookCleanupCallback = (() => Awaitable<unknown>) | void;
999
- interface SuiteHooks {
1094
+ interface SuiteHooks<ExtraContext = {}> {
1000
1095
  beforeAll: HookListener<[Suite | File], HookCleanupCallback>[];
1001
1096
  afterAll: HookListener<[Suite | File]>[];
1002
- beforeEach: HookListener<[TestContext, Suite], HookCleanupCallback>[];
1003
- afterEach: HookListener<[TestContext, Suite]>[];
1097
+ beforeEach: HookListener<[TestContext & ExtraContext, Suite], HookCleanupCallback>[];
1098
+ afterEach: HookListener<[TestContext & ExtraContext, Suite]>[];
1004
1099
  }
1005
1100
  interface SuiteCollector<ExtraContext = {}> {
1006
1101
  readonly name: string;
@@ -1010,9 +1105,9 @@ interface SuiteCollector<ExtraContext = {}> {
1010
1105
  tasks: (Suite | Test | SuiteCollector<ExtraContext>)[];
1011
1106
  collect: (file?: File) => Promise<Suite>;
1012
1107
  clear: () => void;
1013
- on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void;
1108
+ on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
1014
1109
  }
1015
- declare type SuiteFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>;
1110
+ declare type SuiteFactory<ExtraContext = {}> = (test: (name: string, fn: TestFunction<ExtraContext>) => void) => Awaitable<void>;
1016
1111
  interface RuntimeContext {
1017
1112
  tasks: (SuiteCollector | Test)[];
1018
1113
  currentSuite: SuiteCollector | null;
@@ -1032,19 +1127,6 @@ interface TestContext {
1032
1127
  expect: Vi.ExpectStatic;
1033
1128
  }
1034
1129
 
1035
- interface Reporter {
1036
- onInit?(ctx: Vitest): void;
1037
- onPathsCollected?: (paths?: string[]) => Awaitable<void>;
1038
- onCollected?: (files?: File[]) => Awaitable<void>;
1039
- onFinished?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
1040
- onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
1041
- onTestRemoved?: (trigger?: string) => Awaitable<void>;
1042
- onWatcherStart?: () => Awaitable<void>;
1043
- onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
1044
- onServerRestart?: () => Awaitable<void>;
1045
- onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
1046
- }
1047
-
1048
1130
  declare type SnapshotData = Record<string, string>;
1049
1131
  declare type SnapshotUpdateState = 'all' | 'new' | 'none';
1050
1132
  interface SnapshotStateOptions {
@@ -1092,6 +1174,259 @@ interface SnapshotSummary {
1092
1174
  updated: number;
1093
1175
  }
1094
1176
 
1177
+ interface WorkerContext {
1178
+ workerId: number;
1179
+ port: MessagePort;
1180
+ config: ResolvedConfig;
1181
+ files: string[];
1182
+ invalidates?: string[];
1183
+ }
1184
+ declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
1185
+ interface AfterSuiteRunMeta {
1186
+ coverage?: unknown;
1187
+ }
1188
+ interface WorkerRPC {
1189
+ fetch: FetchFunction;
1190
+ resolveId: ResolveIdFunction;
1191
+ getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
1192
+ onFinished: (files: File[], errors?: unknown[]) => void;
1193
+ onWorkerExit: (code?: number) => void;
1194
+ onPathsCollected: (paths: string[]) => void;
1195
+ onUserConsoleLog: (log: UserConsoleLog) => void;
1196
+ onUnhandledRejection: (err: unknown) => void;
1197
+ onCollected: (files: File[]) => void;
1198
+ onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
1199
+ onTaskUpdate: (pack: TaskResultPack[]) => void;
1200
+ snapshotSaved: (snapshot: SnapshotResult) => void;
1201
+ resolveSnapshotPath: (testPath: string) => string;
1202
+ }
1203
+ interface WorkerGlobalState {
1204
+ ctx: WorkerContext;
1205
+ config: ResolvedConfig;
1206
+ rpc: BirpcReturn<WorkerRPC>;
1207
+ current?: Test;
1208
+ filepath?: string;
1209
+ moduleCache: ModuleCacheMap;
1210
+ browserHashMap?: Map<string, string>;
1211
+ mockMap: MockMap;
1212
+ }
1213
+
1214
+ interface CoverageProvider {
1215
+ name: string;
1216
+ initialize(ctx: Vitest): Promise<void> | void;
1217
+ resolveOptions(): ResolvedCoverageOptions;
1218
+ clean(clean?: boolean): void | Promise<void>;
1219
+ onBeforeFilesRun?(): void | Promise<void>;
1220
+ onAfterSuiteRun(meta: AfterSuiteRunMeta): void | Promise<void>;
1221
+ reportCoverage(): void | Promise<void>;
1222
+ onFileTransform?(sourceCode: string, id: string, pluginCtx: TransformPluginContext): TransformResult | Promise<TransformResult>;
1223
+ }
1224
+ interface CoverageProviderModule {
1225
+ /**
1226
+ * Factory for creating a new coverage provider
1227
+ */
1228
+ getProvider(): CoverageProvider | Promise<CoverageProvider>;
1229
+ /**
1230
+ * Executed on after each run in the worker thread. Possible to return a payload passed to the provider
1231
+ */
1232
+ takeCoverage?(): unknown | Promise<unknown>;
1233
+ }
1234
+ declare type CoverageReporter = 'clover' | 'cobertura' | 'html-spa' | 'html' | 'json-summary' | 'json' | 'lcov' | 'lcovonly' | 'none' | 'teamcity' | 'text-lcov' | 'text-summary' | 'text';
1235
+ declare type CoverageOptions = BaseCoverageOptions & {
1236
+ provider?: null | CoverageProviderModule;
1237
+ } | CoverageC8Options & {
1238
+ provider?: 'c8';
1239
+ } | CoverageIstanbulOptions & {
1240
+ provider?: 'istanbul';
1241
+ };
1242
+ declare type ResolvedCoverageOptions = {
1243
+ tempDirectory: string;
1244
+ } & Required<CoverageOptions>;
1245
+ interface BaseCoverageOptions {
1246
+ /**
1247
+ * Enable coverage, pass `--coverage` to enable
1248
+ *
1249
+ * @default false
1250
+ */
1251
+ enabled?: boolean;
1252
+ /**
1253
+ * Clean coverage before running tests
1254
+ *
1255
+ * @default true
1256
+ */
1257
+ clean?: boolean;
1258
+ /**
1259
+ * Clean coverage report on watch rerun
1260
+ *
1261
+ * @default false
1262
+ */
1263
+ cleanOnRerun?: boolean;
1264
+ /**
1265
+ * Directory to write coverage report to
1266
+ */
1267
+ reportsDirectory?: string;
1268
+ /**
1269
+ * Reporters
1270
+ *
1271
+ * @default 'text'
1272
+ */
1273
+ reporter?: Arrayable<CoverageReporter>;
1274
+ /**
1275
+ * List of files excluded from coverage as glob patterns
1276
+ */
1277
+ exclude?: string[];
1278
+ /**
1279
+ * Do not show files with 100% statement, branch, and function coverage
1280
+ */
1281
+ skipFull?: boolean;
1282
+ /**
1283
+ * Check thresholds per file
1284
+ *
1285
+ * @default false
1286
+ */
1287
+ perFile?: boolean;
1288
+ /**
1289
+ * Threshold for lines
1290
+ */
1291
+ lines?: number;
1292
+ /**
1293
+ * Threshold for functions
1294
+ */
1295
+ functions?: number;
1296
+ /**
1297
+ * Threshold for branches
1298
+ */
1299
+ branches?: number;
1300
+ /**
1301
+ * Threshold for statements
1302
+ */
1303
+ statements?: number;
1304
+ /**
1305
+ * Extensions for files to be included in coverage
1306
+ */
1307
+ extension?: string | string[];
1308
+ }
1309
+ interface CoverageIstanbulOptions extends BaseCoverageOptions {
1310
+ ignoreClassMethods?: string[];
1311
+ watermarks?: {
1312
+ statements?: [number, number];
1313
+ functions?: [number, number];
1314
+ branches?: [number, number];
1315
+ lines?: [number, number];
1316
+ };
1317
+ }
1318
+ interface CoverageC8Options extends BaseCoverageOptions {
1319
+ /**
1320
+ * Allow files from outside of your cwd.
1321
+ *
1322
+ * @default false
1323
+ */
1324
+ allowExternal?: any;
1325
+ /**
1326
+ * Exclude coverage under /node_modules/
1327
+ *
1328
+ * @default true
1329
+ */
1330
+ excludeNodeModules?: boolean;
1331
+ include?: string[];
1332
+ all?: boolean;
1333
+ src?: string[];
1334
+ 100?: boolean;
1335
+ }
1336
+
1337
+ interface JSDOMOptions {
1338
+ /**
1339
+ * The html content for the test.
1340
+ *
1341
+ * @default '<!DOCTYPE html>'
1342
+ */
1343
+ html?: string | Buffer | ArrayBufferLike;
1344
+ /**
1345
+ * referrer just affects the value read from document.referrer.
1346
+ * It defaults to no referrer (which reflects as the empty string).
1347
+ */
1348
+ referrer?: string;
1349
+ /**
1350
+ * userAgent affects the value read from navigator.userAgent, as well as the User-Agent header sent while fetching subresources.
1351
+ *
1352
+ * @default `Mozilla/5.0 (${process.platform}) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/${jsdomVersion}`
1353
+ */
1354
+ userAgent?: string;
1355
+ /**
1356
+ * url sets the value returned by window.location, document.URL, and document.documentURI,
1357
+ * and affects things like resolution of relative URLs within the document
1358
+ * and the same-origin restrictions and referrer used while fetching subresources.
1359
+ *
1360
+ * @default 'http://localhost:3000'.
1361
+ */
1362
+ url?: string;
1363
+ /**
1364
+ * contentType affects the value read from document.contentType, and how the document is parsed: as HTML or as XML.
1365
+ * Values that are not "text/html" or an XML mime type will throw.
1366
+ *
1367
+ * @default 'text/html'.
1368
+ */
1369
+ contentType?: string;
1370
+ /**
1371
+ * The maximum size in code units for the separate storage areas used by localStorage and sessionStorage.
1372
+ * Attempts to store data larger than this limit will cause a DOMException to be thrown. By default, it is set
1373
+ * to 5,000,000 code units per origin, as inspired by the HTML specification.
1374
+ *
1375
+ * @default 5_000_000
1376
+ */
1377
+ storageQuota?: number;
1378
+ /**
1379
+ * Enable console?
1380
+ *
1381
+ * @default false
1382
+ */
1383
+ console?: boolean;
1384
+ /**
1385
+ * jsdom does not have the capability to render visual content, and will act like a headless browser by default.
1386
+ * It provides hints to web pages through APIs such as document.hidden that their content is not visible.
1387
+ *
1388
+ * When the `pretendToBeVisual` option is set to `true`, jsdom will pretend that it is rendering and displaying
1389
+ * content.
1390
+ *
1391
+ * @default true
1392
+ */
1393
+ pretendToBeVisual?: boolean;
1394
+ /**
1395
+ * `includeNodeLocations` preserves the location info produced by the HTML parser,
1396
+ * allowing you to retrieve it with the nodeLocation() method (described below).
1397
+ *
1398
+ * It defaults to false to give the best performance,
1399
+ * and cannot be used with an XML content type since our XML parser does not support location info.
1400
+ *
1401
+ * @default false
1402
+ */
1403
+ includeNodeLocations?: boolean | undefined;
1404
+ /**
1405
+ * @default 'dangerously'
1406
+ */
1407
+ runScripts?: 'dangerously' | 'outside-only';
1408
+ /**
1409
+ * Enable CookieJar
1410
+ *
1411
+ * @default false
1412
+ */
1413
+ cookieJar?: boolean;
1414
+ resources?: 'usable' | any;
1415
+ }
1416
+
1417
+ interface Reporter {
1418
+ onInit?(ctx: Vitest): void;
1419
+ onPathsCollected?: (paths?: string[]) => Awaitable<void>;
1420
+ onCollected?: (files?: File[]) => Awaitable<void>;
1421
+ onFinished?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
1422
+ onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
1423
+ onTestRemoved?: (trigger?: string) => Awaitable<void>;
1424
+ onWatcherStart?: () => Awaitable<void>;
1425
+ onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
1426
+ onServerRestart?: (reason?: string) => Awaitable<void>;
1427
+ onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
1428
+ }
1429
+
1095
1430
  declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime';
1096
1431
  declare type ApiConfig = Pick<CommonServerOptions, 'port' | 'strictPort' | 'host'>;
1097
1432
 
@@ -1291,7 +1626,7 @@ interface InlineConfig {
1291
1626
  /**
1292
1627
  * Coverage options
1293
1628
  */
1294
- coverage?: C8Options;
1629
+ coverage?: CoverageOptions;
1295
1630
  /**
1296
1631
  * run test names with the specified pattern
1297
1632
  */
@@ -1378,7 +1713,7 @@ interface InlineConfig {
1378
1713
  */
1379
1714
  allowOnly?: boolean;
1380
1715
  /**
1381
- * Show heap usage after each test. Usefull for debugging memory leaks.
1716
+ * Show heap usage after each test. Useful for debugging memory leaks.
1382
1717
  */
1383
1718
  logHeapUsage?: boolean;
1384
1719
  /**
@@ -1495,7 +1830,7 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
1495
1830
  filters?: string[];
1496
1831
  testNamePattern?: RegExp;
1497
1832
  related?: string[];
1498
- coverage: ResolvedC8Options;
1833
+ coverage: ResolvedCoverageOptions;
1499
1834
  snapshotOptions: SnapshotStateOptions;
1500
1835
  reporters: (Reporter | BuiltinReporters)[];
1501
1836
  defines: Record<string, any>;
@@ -1774,4 +2109,4 @@ declare global {
1774
2109
  }
1775
2110
  }
1776
2111
 
1777
- export { CoverageReporter as $, ApiConfig as A, BuiltinEnvironment as B, ArgumentsType as C, DoneCallback as D, EnvironmentOptions as E, FakeTimerInstallOpts as F, MergeInsertions as G, HookListener as H, InlineConfig as I, JSDOMOptions as J, DeepMerge as K, MutableArray as L, ModuleGraphData as M, Nullable as N, Constructable as O, ModuleCache as P, EnvironmentReturn as Q, ResolvedConfig as R, Suite as S, TaskResultPack as T, UserConfig as U, Vitest as V, Environment as W, UserConsoleLog as X, Position as Y, ParsedStack as Z, ErrorWithDiff as _, File as a, C8Options as a0, ResolvedC8Options as a1, ViteNodeResolveId as a2, FetchFunction as a3, RawSourceMap as a4, ModuleCacheMap as a5, ViteNodeRunnerOptions as a6, ViteNodeRunner as a7, TestSequencer as a8, startVitest as a9, TestSequencerConstructor as aa, Reporter as b, RunMode as c, TaskState as d, TaskBase as e, TaskResult as f, Test as g, Task as h, TestFunction as i, TestAPI as j, SuiteAPI as k, HookCleanupCallback as l, SuiteHooks as m, SuiteCollector as n, SuiteFactory as o, RuntimeContext as p, TestContext as q, SnapshotData as r, SnapshotUpdateState as s, SnapshotStateOptions as t, SnapshotMatchOptions as u, SnapshotResult as v, UncheckedSnapshot as w, SnapshotSummary as x, Awaitable as y, Arrayable as z };
2112
+ export { Environment as $, ApiConfig as A, BuiltinEnvironment as B, WorkerRPC as C, DoneCallback as D, EnvironmentOptions as E, FakeTimerInstallOpts as F, WorkerGlobalState as G, HookListener as H, InlineConfig as I, JSDOMOptions as J, Awaitable as K, Arrayable as L, ModuleGraphData as M, Nullable as N, ArgumentsType$1 as O, MergeInsertions as P, DeepMerge as Q, ResolvedConfig as R, Suite as S, TaskResultPack as T, UserConfig as U, Vitest as V, WorkerContext as W, MutableArray as X, Constructable as Y, ModuleCache as Z, EnvironmentReturn as _, File as a, UserConsoleLog as a0, Position as a1, ParsedStack as a2, ErrorWithDiff as a3, OnServerRestartHandler as a4, CoverageProvider as a5, CoverageProviderModule as a6, CoverageReporter as a7, CoverageOptions as a8, ResolvedCoverageOptions as a9, BaseCoverageOptions as aa, CoverageIstanbulOptions as ab, CoverageC8Options as ac, ModuleCacheMap as ad, ViteNodeRunnerOptions as ae, MockMap as af, ViteNodeRunner as ag, TestSequencer as ah, startVitest as ai, TestSequencerConstructor as aj, Reporter as b, RunMode as c, TaskState as d, TaskBase as e, TaskResult as f, Test as g, Task as h, TestFunction as i, TestAPI as j, SuiteAPI as k, HookCleanupCallback as l, SuiteHooks as m, SuiteCollector as n, SuiteFactory as o, RuntimeContext as p, TestContext as q, SnapshotData as r, SnapshotUpdateState as s, SnapshotStateOptions as t, SnapshotMatchOptions as u, SnapshotResult as v, UncheckedSnapshot as w, SnapshotSummary as x, ResolveIdFunction as y, AfterSuiteRunMeta as z };