vitest 4.0.0-beta.5 → 4.0.0-beta.7

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 (64) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/{base.DMfOuRWD.js → base.BXI97p6t.js} +7 -16
  5. package/dist/chunks/{benchmark.CtuRzf-i.js → benchmark.UW6Ezvxy.js} +4 -9
  6. package/dist/chunks/{browser.d.Cawq_X_N.d.ts → browser.d.DOMmqJQx.d.ts} +1 -1
  7. package/dist/chunks/{cac.CKnbxhn2.js → cac.Dsn7ixFt.js} +38 -113
  8. package/dist/chunks/{cli-api.COn58yrl.js → cli-api.DfGJyldU.js} +829 -1232
  9. package/dist/chunks/{config.d.CKNVOKm0.d.ts → config.d._GBBbReY.d.ts} +1 -0
  10. package/dist/chunks/{console.Duv2dVIC.js → console.B0quX7yH.js} +32 -68
  11. package/dist/chunks/{coverage.B6cReEn1.js → coverage.Dvxug1RM.js} +210 -579
  12. package/dist/chunks/{creator.DUVZ6rfm.js → creator.KEg6n5IC.js} +28 -74
  13. package/dist/chunks/{date.Bq6ZW5rf.js → date.-jtEtIeV.js} +6 -17
  14. package/dist/chunks/{git.BVQ8w_Sw.js → git.BFNcloKD.js} +1 -2
  15. package/dist/chunks/{globals.CJQ63oO0.js → globals.lgsmH00r.js} +5 -5
  16. package/dist/chunks/{index.QZr3S3vQ.js → index.AR8aAkCC.js} +2 -2
  17. package/dist/chunks/{index.DQhAfQQU.js → index.C3EbxYwt.js} +276 -607
  18. package/dist/chunks/{index.oWRWx-nj.js → index.CsFXYRkW.js} +17 -36
  19. package/dist/chunks/{index.DgN0Zk9a.js → index.D2B6d2vv.js} +14 -24
  20. package/dist/chunks/{index.BRtIe7r8.js → index.DfviD7lX.js} +55 -110
  21. package/dist/chunks/{inspector.C914Efll.js → inspector.CvQD-Nie.js} +10 -25
  22. package/dist/chunks/{moduleRunner.d.mmOmOGrW.d.ts → moduleRunner.d.CX4DuqOx.d.ts} +2 -2
  23. package/dist/chunks/{node.4JV5OXkt.js → node.BOqcT2jW.js} +1 -1
  24. package/dist/chunks/{plugin.d.CvOlgjxK.d.ts → plugin.d.vcD4xbMS.d.ts} +1 -1
  25. package/dist/chunks/{reporters.d.CYE9sT5z.d.ts → reporters.d.BC86JJdB.d.ts} +799 -758
  26. package/dist/chunks/{resolver.D5bG4zy5.js → resolver.Bx6lE0iq.js} +21 -64
  27. package/dist/chunks/{rpc.DGoW_Vl-.js → rpc.RpPylpp0.js} +7 -21
  28. package/dist/chunks/{runBaseTests.B3KcKqlF.js → runBaseTests.D6sfuWBM.js} +25 -54
  29. package/dist/chunks/{setup-common.lgPs-bYv.js → setup-common.hLGRxhC8.js} +9 -22
  30. package/dist/chunks/{startModuleRunner.C8FtT_BY.js → startModuleRunner.C8TW8zTN.js} +83 -205
  31. package/dist/chunks/{typechecker.BgoW4nTA.js → typechecker.DSo_maXz.js} +97 -209
  32. package/dist/chunks/{utils.CcGm2cd1.js → utils.C2YI6McM.js} +4 -13
  33. package/dist/chunks/{utils.B9FY3b73.js → utils.C7__0Iv5.js} +5 -14
  34. package/dist/chunks/{vi.DGAfBY4R.js → vi.BfdOiD4j.js} +110 -267
  35. package/dist/chunks/{vm.BKfKvaKl.js → vm.BHBje7cC.js} +73 -177
  36. package/dist/chunks/{worker.d.Db-UVmXc.d.ts → worker.d.BKu8cnnX.d.ts} +1 -1
  37. package/dist/chunks/{worker.d.D9QWnzAe.d.ts → worker.d.DYlqbejz.d.ts} +1 -1
  38. package/dist/cli.js +3 -3
  39. package/dist/config.d.ts +7 -7
  40. package/dist/coverage.d.ts +4 -4
  41. package/dist/coverage.js +2 -2
  42. package/dist/environments.js +1 -1
  43. package/dist/index.d.ts +6 -6
  44. package/dist/index.js +5 -5
  45. package/dist/module-evaluator.d.ts +3 -3
  46. package/dist/module-evaluator.js +33 -84
  47. package/dist/module-runner.js +2 -2
  48. package/dist/node.d.ts +11 -9
  49. package/dist/node.js +16 -27
  50. package/dist/reporters.d.ts +5 -5
  51. package/dist/reporters.js +3 -3
  52. package/dist/runners.d.ts +1 -1
  53. package/dist/runners.js +23 -51
  54. package/dist/snapshot.js +2 -2
  55. package/dist/suite.js +2 -2
  56. package/dist/worker.js +18 -34
  57. package/dist/workers/forks.js +4 -4
  58. package/dist/workers/runVmTests.js +19 -37
  59. package/dist/workers/threads.js +4 -4
  60. package/dist/workers/vmForks.js +7 -7
  61. package/dist/workers/vmThreads.js +7 -7
  62. package/dist/workers.d.ts +3 -3
  63. package/dist/workers.js +11 -11
  64. package/package.json +11 -11
@@ -1,13 +1,13 @@
1
- import { Task, CancelReason, TaskMeta, Suite, File, TestAnnotation, ImportDuration, TaskResultPack, TaskEventPack, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
2
- import { P as ProvidedContext, U as UserConsoleLog, b as Awaitable$1, c as Arrayable$1, A as AfterSuiteRunMeta, L as LabelColor } from './environment.d.2fYMoz3o.js';
3
- import { ParsedStack, Awaitable, TestError, SerializedError, Arrayable } from '@vitest/utils';
1
+ import { Task, CancelReason, TaskMeta, Suite, File, TestAnnotation, ImportDuration, Test, TaskResultPack, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
2
+ import { ParsedStack, Awaitable, TestError, SerializedError, Arrayable as Arrayable$1 } from '@vitest/utils';
3
+ import { P as ProvidedContext, c as Arrayable, A as AfterSuiteRunMeta, U as UserConsoleLog, b as Awaitable$1, L as LabelColor } from './environment.d.2fYMoz3o.js';
4
4
  import { Writable } from 'node:stream';
5
5
  import { ViteDevServer, ModuleNode, TransformResult as TransformResult$1, DepOptimizationConfig, ServerOptions, UserConfig as UserConfig$1, ConfigEnv, AliasOptions } from 'vite';
6
6
  import { Console } from 'node:console';
7
- import { B as BrowserTesterOptions, S as SerializedTestSpecification } from './browser.d.Cawq_X_N.js';
7
+ import { B as BrowserTesterOptions, S as SerializedTestSpecification } from './browser.d.DOMmqJQx.js';
8
8
  import { MockedModule } from '@vitest/mocker';
9
9
  import { StackTraceParserOptions } from '@vitest/utils/source-map';
10
- import { a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.CKNVOKm0.js';
10
+ import { a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d._GBBbReY.js';
11
11
  import { PrettyFormatOptions } from '@vitest/pretty-format';
12
12
  import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
13
13
  import { SerializedDiffOptions } from '@vitest/utils/diff';
@@ -108,7 +108,7 @@ declare class Logger {
108
108
  printNoTestFound(filters?: string[]): void;
109
109
  printBanner(): void;
110
110
  printBrowserBanner(project: TestProject): void;
111
- printUnhandledErrors(errors: unknown[]): void;
111
+ printUnhandledErrors(errors: ReadonlyArray<unknown>): void;
112
112
  printSourceTypeErrors(errors: TypeCheckError[]): void;
113
113
  getColumns(): number;
114
114
  onTerminalCleanup(listener: Listener): void;
@@ -296,6 +296,15 @@ interface BrowserConfigOptions {
296
296
  comparatorOptions?: ToMatchScreenshotComparators[ComparatorName];
297
297
  } }[keyof ToMatchScreenshotComparators] & ToMatchScreenshotOptions;
298
298
  };
299
+ /**
300
+ * Enables tracking uncaught errors and exceptions so they can be reported by Vitest.
301
+ *
302
+ * If you need to hide certain errors, it is recommended to use [`onUnhandledError`](https://vitest.dev/config/#onunhandlederror) option instead.
303
+ *
304
+ * Disabling this will completely remove all Vitest error handlers, which can help debugging with the "Pause on exceptions" checkbox turned on.
305
+ * @default true
306
+ */
307
+ trackUnhandledErrors?: boolean;
299
308
  }
300
309
  interface BrowserCommandContext {
301
310
  testPath: string | undefined;
@@ -772,6 +781,10 @@ interface ModuleDiagnostic {
772
781
  */
773
782
  readonly importDurations: Record<string, ImportDuration>;
774
783
  }
784
+ declare function experimental_getRunnerTask(entity: TestCase): Test;
785
+ declare function experimental_getRunnerTask(entity: TestSuite): Suite;
786
+ declare function experimental_getRunnerTask(entity: TestModule): File;
787
+ declare function experimental_getRunnerTask(entity: TestCase | TestSuite | TestModule): Suite | File | Test;
775
788
 
776
789
  type BuiltinPool = "browser" | "threads" | "forks" | "vmThreads" | "vmForks" | "typescript";
777
790
  type Pool = BuiltinPool | (string & {});
@@ -966,9 +979,9 @@ declare class TestProject {
966
979
  * Temporary directory for the project. This is unique for each project. Vitest stores transformed content here.
967
980
  */
968
981
  readonly tmpDir: string;
982
+ /** @inetrnal */ testFilesList: string[] | null;
969
983
  private runner;
970
984
  private closingPromise;
971
- private testFilesList;
972
985
  private typecheckFilesList;
973
986
  private _globalSetups?;
974
987
  private _provided;
@@ -1114,214 +1127,636 @@ interface ProcessPool {
1114
1127
  }
1115
1128
  declare function getFilePoolName(project: TestProject): Pool;
1116
1129
 
1117
- interface TestRunResult {
1118
- testModules: TestModule[];
1119
- unhandledErrors: unknown[];
1130
+ interface CoverageSummaryData {
1131
+ lines: Totals;
1132
+ statements: Totals;
1133
+ branches: Totals;
1134
+ functions: Totals;
1120
1135
  }
1121
1136
 
1122
- interface SuiteResultCache {
1123
- failed: boolean;
1124
- duration: number;
1137
+ declare class CoverageSummary {
1138
+ constructor(data: CoverageSummary | CoverageSummaryData);
1139
+ merge(obj: CoverageSummary): CoverageSummary;
1140
+ toJSON(): CoverageSummaryData;
1141
+ isEmpty(): boolean;
1142
+ data: CoverageSummaryData;
1143
+ lines: Totals;
1144
+ statements: Totals;
1145
+ branches: Totals;
1146
+ functions: Totals;
1125
1147
  }
1126
- declare class ResultsCache {
1127
- private cache;
1128
- private workspacesKeyMap;
1129
- private cachePath;
1130
- private version;
1131
- private root;
1132
- constructor(version: string);
1133
- getCachePath(): string | null;
1134
- setConfig(root: string, config: ResolvedConfig["cache"]): void;
1135
- getResults(key: string): SuiteResultCache | undefined;
1136
- readFromCache(): Promise<void>;
1137
- updateResults(files: File[]): void;
1138
- removeFromCache(filepath: string): void;
1139
- writeToCache(): Promise<void>;
1148
+
1149
+ interface CoverageMapData {
1150
+ [key: string]: FileCoverage | FileCoverageData;
1140
1151
  }
1141
1152
 
1142
- type FileStatsCache = Pick<Stats, "size">;
1143
- declare class FilesStatsCache {
1144
- cache: Map<string, FileStatsCache>;
1145
- getStats(key: string): FileStatsCache | undefined;
1146
- populateStats(root: string, specs: TestSpecification[]): Promise<void>;
1147
- updateStats(fsPath: string, key: string): Promise<void>;
1148
- removeStats(fsPath: string): void;
1153
+ declare class CoverageMap {
1154
+ constructor(data: CoverageMapData | CoverageMap);
1155
+ addFileCoverage(pathOrObject: string | FileCoverage | FileCoverageData): void;
1156
+ files(): string[];
1157
+ fileCoverageFor(filename: string): FileCoverage;
1158
+ filter(callback: (key: string) => boolean): void;
1159
+ getCoverageSummary(): CoverageSummary;
1160
+ merge(data: CoverageMapData | CoverageMap): void;
1161
+ toJSON(): CoverageMapData;
1162
+ data: CoverageMapData;
1149
1163
  }
1150
1164
 
1151
- declare class VitestCache {
1152
- results: ResultsCache;
1153
- stats: FilesStatsCache;
1154
- constructor(version: string);
1155
- getFileTestResults(key: string): SuiteResultCache | undefined;
1156
- getFileStats(key: string): {
1157
- size: number;
1158
- } | undefined;
1159
- static resolveCacheDir(root: string, dir?: string, projectName?: string): string;
1165
+ interface Location {
1166
+ line: number;
1167
+ column: number;
1160
1168
  }
1161
1169
 
1162
- declare class VitestPackageInstaller {
1163
- isPackageExists(name: string, options?: {
1164
- paths?: string[];
1165
- }): boolean;
1166
- ensureInstalled(dependency: string, root: string, version?: string): Promise<boolean>;
1170
+ interface Range {
1171
+ start: Location;
1172
+ end: Location;
1167
1173
  }
1168
1174
 
1169
- interface BlobOptions {
1170
- outputFile?: string;
1175
+ interface BranchMapping {
1176
+ loc: Range;
1177
+ type: string;
1178
+ locations: Range[];
1179
+ line: number;
1171
1180
  }
1172
- declare class BlobReporter implements Reporter {
1173
- start: number;
1174
- ctx: Vitest;
1175
- options: BlobOptions;
1176
- constructor(options: BlobOptions);
1177
- onInit(ctx: Vitest): void;
1178
- onFinished(files: File[] | undefined, errors: unknown[] | undefined, coverage: unknown): Promise<void>;
1181
+
1182
+ interface FunctionMapping {
1183
+ name: string;
1184
+ decl: Range;
1185
+ loc: Range;
1186
+ line: number;
1179
1187
  }
1180
- interface MergedBlobs {
1181
- files: File[];
1182
- errors: unknown[];
1183
- coverages: unknown[];
1184
- executionTimes: number[];
1188
+
1189
+ interface FileCoverageData {
1190
+ path: string;
1191
+ statementMap: { [key: string]: Range };
1192
+ fnMap: { [key: string]: FunctionMapping };
1193
+ branchMap: { [key: string]: BranchMapping };
1194
+ s: { [key: string]: number };
1195
+ f: { [key: string]: number };
1196
+ b: { [key: string]: number[] };
1185
1197
  }
1186
1198
 
1187
- declare class StateManager {
1188
- filesMap: Map<string, File[]>;
1189
- pathsSet: Set<string>;
1190
- idMap: Map<string, Task>;
1191
- taskFileMap: WeakMap<Task, File>;
1192
- errorsSet: Set<unknown>;
1193
- processTimeoutCauses: Set<string>;
1194
- reportedTasksMap: WeakMap<Task, TestModule | TestCase | TestSuite>;
1195
- blobs?: MergedBlobs;
1196
- transformTime: number;
1197
- onUnhandledError?: OnUnhandledErrorCallback;
1198
- constructor(options: {
1199
- onUnhandledError?: OnUnhandledErrorCallback;
1200
- });
1201
- catchError(error: unknown, type: string): void;
1202
- clearErrors(): void;
1203
- getUnhandledErrors(): unknown[];
1204
- addProcessTimeoutCause(cause: string): void;
1205
- getProcessTimeoutCauses(): string[];
1206
- getPaths(): string[];
1207
- /**
1208
- * Return files that were running or collected.
1209
- */
1210
- getFiles(keys?: string[]): File[];
1211
- getTestModules(keys?: string[]): TestModule[];
1212
- getFilepaths(): string[];
1213
- getFailedFilepaths(): string[];
1214
- collectPaths(paths?: string[]): void;
1215
- collectFiles(project: TestProject, files?: File[]): void;
1216
- clearFiles(project: TestProject, paths?: string[]): void;
1217
- updateId(task: Task, project: TestProject): void;
1218
- getReportedEntity(task: Task): TestModule | TestCase | TestSuite | undefined;
1219
- updateTasks(packs: TaskResultPack[]): void;
1220
- updateUserLog(log: UserConsoleLog): void;
1221
- getCountOfFailedTests(): number;
1222
- cancelFiles(files: string[], project: TestProject): void;
1199
+ interface Totals {
1200
+ total: number;
1201
+ covered: number;
1202
+ skipped: number;
1203
+ pct: number;
1223
1204
  }
1224
1205
 
1225
- interface VitestOptions {
1226
- packageInstaller?: VitestPackageInstaller;
1227
- stdin?: NodeJS.ReadStream;
1228
- stdout?: NodeJS.WriteStream | Writable;
1229
- stderr?: NodeJS.WriteStream | Writable;
1206
+ interface Coverage {
1207
+ covered: number;
1208
+ total: number;
1209
+ coverage: number;
1230
1210
  }
1231
- declare class Vitest {
1232
- readonly mode: VitestRunMode;
1233
- /**
1234
- * Current Vitest version.
1235
- * @example '2.0.0'
1236
- */
1237
- readonly version: string;
1238
- static readonly version: string;
1239
- /**
1240
- * The logger instance used to log messages. It's recommended to use this logger instead of `console`.
1241
- * It's possible to override stdout and stderr streams when initiating Vitest.
1242
- * @example
1243
- * new Vitest('test', {
1244
- * stdout: new Writable(),
1245
- * })
1246
- */
1247
- readonly logger: Logger;
1248
- /**
1249
- * The package installer instance used to install Vitest packages.
1250
- * @example
1251
- * await vitest.packageInstaller.ensureInstalled('@vitest/browser', process.cwd())
1252
- */
1253
- readonly packageInstaller: VitestPackageInstaller;
1254
- /**
1255
- * A path to the built Vitest directory. This is usually a folder in `node_modules`.
1256
- */
1257
- readonly distPath: string;
1258
- /**
1259
- * A list of projects that are currently running.
1260
- * If projects were filtered with `--project` flag, they won't appear here.
1261
- */
1262
- projects: TestProject[];
1263
- private isFirstRun;
1264
- private restartsCount;
1265
- private readonly specifications;
1266
- private readonly watcher;
1267
- private pool;
1268
- private _config?;
1269
- private _vite?;
1270
- private _state?;
1271
- private _cache?;
1272
- private _snapshot?;
1273
- constructor(mode: VitestRunMode, cliOptions: UserConfig, options?: VitestOptions);
1274
- private _onRestartListeners;
1275
- private _onClose;
1276
- private _onSetServer;
1277
- private _onCancelListeners;
1278
- private _onUserTestsRerun;
1279
- private _onFilterWatchedSpecification;
1280
- /** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
1281
- get invalidates(): Set<string>;
1282
- /** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
1283
- get changedTests(): Set<string>;
1284
- /**
1285
- * The global config.
1286
- */
1287
- get config(): ResolvedConfig;
1288
- /** @deprecated use `vitest.vite` instead */
1289
- get server(): ViteDevServer;
1290
- /**
1291
- * Global Vite's dev server instance.
1292
- */
1293
- get vite(): ViteDevServer;
1294
- /**
1295
- * The global test state manager.
1296
- * @experimental The State API is experimental and not subject to semver.
1297
- */
1298
- get state(): StateManager;
1299
- /**
1300
- * The global snapshot manager. You can access the current state on `snapshot.summary`.
1301
- */
1302
- get snapshot(): SnapshotManager;
1303
- /**
1304
- * Test results and test file stats cache. Primarily used by the sequencer to sort tests.
1305
- */
1306
- get cache(): VitestCache;
1307
- /** @deprecated internal */
1308
- setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
1309
- /**
1310
- * Inject new test projects into the workspace.
1311
- * @param config Glob, config path or a custom config options.
1312
- * @returns An array of new test projects. Can be empty if the name was filtered out.
1313
- */
1314
- private injectTestProject;
1315
- /**
1316
- * Provide a value to the test context. This value will be available to all tests with `inject`.
1317
- */
1318
- provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
1319
- /**
1320
- * Get global provided context.
1321
- */
1322
- getProvidedContext(): ProvidedContext;
1323
- /** @deprecated use `getRootProject` instead */
1324
- getCoreWorkspaceProject(): TestProject;
1211
+
1212
+ declare class FileCoverage implements FileCoverageData {
1213
+ constructor(data: string | FileCoverage | FileCoverageData);
1214
+ merge(other: FileCoverageData): void;
1215
+ getBranchCoverageByLine(): { [line: number]: Coverage };
1216
+ getLineCoverage(): { [line: number]: number };
1217
+ getUncoveredLines(): number[];
1218
+ resetHits(): void;
1219
+ computeBranchTotals(): Totals;
1220
+ computeSimpleTotals(): Totals;
1221
+ toSummary(): CoverageSummary;
1222
+ toJSON(): object;
1223
+
1224
+ data: FileCoverageData;
1225
+ path: string;
1226
+ statementMap: { [key: string]: Range };
1227
+ fnMap: { [key: string]: FunctionMapping };
1228
+ branchMap: { [key: string]: BranchMapping };
1229
+ s: { [key: string]: number };
1230
+ f: { [key: string]: number };
1231
+ b: { [key: string]: number[] };
1232
+ }
1233
+
1234
+ interface Node {
1235
+ isRoot(): boolean;
1236
+ visit(visitor: Visitor, state: any): void;
1237
+ }
1238
+
1239
+ interface Visitor<N extends Node = Node> {
1240
+ onStart(root: N, state: any): void;
1241
+ onSummary(root: N, state: any): void;
1242
+ onDetail(root: N, state: any): void;
1243
+ onSummaryEnd(root: N, state: any): void;
1244
+ onEnd(root: N, state: any): void;
1245
+ }
1246
+
1247
+ interface FileOptions {
1248
+ file: string;
1249
+ }
1250
+
1251
+ interface ProjectOptions {
1252
+ projectRoot: string;
1253
+ }
1254
+
1255
+ interface ReportOptions {
1256
+ clover: CloverOptions;
1257
+ cobertura: CoberturaOptions;
1258
+ "html-spa": HtmlSpaOptions;
1259
+ html: HtmlOptions;
1260
+ json: JsonOptions$1;
1261
+ "json-summary": JsonSummaryOptions;
1262
+ lcov: LcovOptions;
1263
+ lcovonly: LcovOnlyOptions;
1264
+ none: never;
1265
+ teamcity: TeamcityOptions;
1266
+ text: TextOptions;
1267
+ "text-lcov": TextLcovOptions;
1268
+ "text-summary": TextSummaryOptions;
1269
+ }
1270
+
1271
+ interface CloverOptions extends FileOptions, ProjectOptions {}
1272
+
1273
+ interface CoberturaOptions extends FileOptions, ProjectOptions {}
1274
+
1275
+ interface HtmlSpaOptions extends HtmlOptions {
1276
+ metricsToShow: Array<"lines" | "branches" | "functions" | "statements">;
1277
+ }
1278
+ interface HtmlOptions {
1279
+ verbose: boolean;
1280
+ skipEmpty: boolean;
1281
+ subdir: string;
1282
+ linkMapper: LinkMapper;
1283
+ }
1284
+
1285
+ type JsonOptions$1 = FileOptions;
1286
+ type JsonSummaryOptions = FileOptions;
1287
+
1288
+ interface LcovOptions extends FileOptions, ProjectOptions {}
1289
+ interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
1290
+
1291
+ interface TeamcityOptions extends FileOptions {
1292
+ blockName: string;
1293
+ }
1294
+
1295
+ interface TextOptions extends FileOptions {
1296
+ maxCols: number;
1297
+ skipEmpty: boolean;
1298
+ skipFull: boolean;
1299
+ }
1300
+ type TextLcovOptions = ProjectOptions;
1301
+ type TextSummaryOptions = FileOptions;
1302
+
1303
+ interface LinkMapper {
1304
+ getPath(node: string | Node): string;
1305
+ relativePath(source: string | Node, target: string | Node): string;
1306
+ assetPath(node: Node, name: string): string;
1307
+ }
1308
+
1309
+ type TransformResult = string | Partial<TransformResult$1> | undefined | null | void;
1310
+ type CoverageResults = unknown;
1311
+ interface CoverageProvider {
1312
+ name: string;
1313
+ /** Called when provider is being initialized before tests run */
1314
+ initialize: (ctx: Vitest) => Promise<void> | void;
1315
+ /** Called when setting coverage options for Vitest context (`ctx.config.coverage`) */
1316
+ resolveOptions: () => ResolvedCoverageOptions;
1317
+ /** Callback to clean previous reports */
1318
+ clean: (clean?: boolean) => void | Promise<void>;
1319
+ /** Called with coverage results after a single test file has been run */
1320
+ onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void | Promise<void>;
1321
+ /** Callback called when test run fails */
1322
+ onTestFailure?: () => void | Promise<void>;
1323
+ /** Callback to generate final coverage results */
1324
+ generateCoverage: (reportContext: ReportContext) => CoverageResults | Promise<CoverageResults>;
1325
+ /** Callback to convert coverage results to coverage reports. Called with results returned from `generateCoverage` */
1326
+ reportCoverage: (coverage: CoverageResults, reportContext: ReportContext) => void | Promise<void>;
1327
+ /** Callback for `--merge-reports` options. Called with multiple coverage results generated by `generateCoverage`. */
1328
+ mergeReports?: (coverages: CoverageResults[]) => void | Promise<void>;
1329
+ /** Callback called for instrumenting files with coverage counters. */
1330
+ onFileTransform?: (sourceCode: string, id: string, pluginCtx: any) => TransformResult | Promise<TransformResult>;
1331
+ }
1332
+ interface ReportContext {
1333
+ /** Indicates whether all tests were run. False when only specific tests were run. */
1334
+ allTestsRun?: boolean;
1335
+ }
1336
+ interface CoverageProviderModule extends RuntimeCoverageProviderModule {
1337
+ /**
1338
+ * Factory for creating a new coverage provider
1339
+ */
1340
+ getProvider: () => CoverageProvider | Promise<CoverageProvider>;
1341
+ }
1342
+ type CoverageReporter = keyof ReportOptions | (string & {});
1343
+ type CoverageReporterWithOptions<ReporterName extends CoverageReporter = CoverageReporter> = ReporterName extends keyof ReportOptions ? ReportOptions[ReporterName] extends never ? [ReporterName, object] : [ReporterName, Partial<ReportOptions[ReporterName]>] : [ReporterName, Record<string, unknown>];
1344
+ type CoverageProviderName = "v8" | "istanbul" | "custom" | undefined;
1345
+ type CoverageOptions<T extends CoverageProviderName = CoverageProviderName> = T extends "istanbul" ? {
1346
+ provider: T;
1347
+ } & CoverageIstanbulOptions : T extends "v8" ? {
1348
+ /**
1349
+ * Provider to use for coverage collection.
1350
+ *
1351
+ * @default 'v8'
1352
+ */
1353
+ provider: T;
1354
+ } & CoverageV8Options : T extends "custom" ? {
1355
+ provider: T;
1356
+ } & CustomProviderOptions : {
1357
+ provider?: T;
1358
+ } & CoverageV8Options;
1359
+ /** Fields that have default values. Internally these will always be defined. */
1360
+ type FieldsWithDefaultValues = "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "exclude" | "reportOnFailure" | "allowExternal" | "processingConcurrency";
1361
+ type ResolvedCoverageOptions<T extends CoverageProviderName = CoverageProviderName> = CoverageOptions<T> & Required<Pick<CoverageOptions<T>, FieldsWithDefaultValues>> & {
1362
+ reporter: CoverageReporterWithOptions[];
1363
+ };
1364
+ interface BaseCoverageOptions {
1365
+ /**
1366
+ * Enables coverage collection. Can be overridden using `--coverage` CLI option.
1367
+ *
1368
+ * @default false
1369
+ */
1370
+ enabled?: boolean;
1371
+ /**
1372
+ * List of files included in coverage as glob patterns.
1373
+ * By default only files covered by tests are included.
1374
+ *
1375
+ * See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
1376
+ */
1377
+ include?: string[];
1378
+ /**
1379
+ * List of files excluded from coverage as glob patterns.
1380
+ * Files are first checked against `coverage.include`.
1381
+ *
1382
+ * See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
1383
+ */
1384
+ exclude?: string[];
1385
+ /**
1386
+ * Clean coverage results before running tests
1387
+ *
1388
+ * @default true
1389
+ */
1390
+ clean?: boolean;
1391
+ /**
1392
+ * Clean coverage report on watch rerun
1393
+ *
1394
+ * @default true
1395
+ */
1396
+ cleanOnRerun?: boolean;
1397
+ /**
1398
+ * Directory to write coverage report to
1399
+ *
1400
+ * @default './coverage'
1401
+ */
1402
+ reportsDirectory?: string;
1403
+ /**
1404
+ * Coverage reporters to use.
1405
+ * See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters.
1406
+ *
1407
+ * @default ['text', 'html', 'clover', 'json']
1408
+ */
1409
+ reporter?: Arrayable<CoverageReporter> | (CoverageReporter | [CoverageReporter] | CoverageReporterWithOptions)[];
1410
+ /**
1411
+ * Do not show files with 100% statement, branch, and function coverage
1412
+ *
1413
+ * @default false
1414
+ */
1415
+ skipFull?: boolean;
1416
+ /**
1417
+ * Configurations for thresholds
1418
+ *
1419
+ * @example
1420
+ *
1421
+ * ```ts
1422
+ * {
1423
+ * // Thresholds for all files
1424
+ * functions: 95,
1425
+ * branches: 70,
1426
+ * perFile: true,
1427
+ * autoUpdate: true,
1428
+ *
1429
+ * // Thresholds for utilities
1430
+ * 'src/utils/**.ts': {
1431
+ * lines: 100,
1432
+ * statements: 95,
1433
+ * }
1434
+ * }
1435
+ * ```
1436
+ */
1437
+ thresholds?: Thresholds | ({
1438
+ [glob: string]: Pick<Thresholds, 100 | "statements" | "functions" | "branches" | "lines">;
1439
+ } & Thresholds);
1440
+ /**
1441
+ * Watermarks for statements, lines, branches and functions.
1442
+ *
1443
+ * Default value is `[50,80]` for each property.
1444
+ */
1445
+ watermarks?: {
1446
+ statements?: [number, number];
1447
+ functions?: [number, number];
1448
+ branches?: [number, number];
1449
+ lines?: [number, number];
1450
+ };
1451
+ /**
1452
+ * Generate coverage report even when tests fail.
1453
+ *
1454
+ * @default false
1455
+ */
1456
+ reportOnFailure?: boolean;
1457
+ /**
1458
+ * Collect coverage of files outside the project `root`.
1459
+ *
1460
+ * @default false
1461
+ */
1462
+ allowExternal?: boolean;
1463
+ /**
1464
+ * Apply exclusions again after coverage has been remapped to original sources.
1465
+ * This is useful when your source files are transpiled and may contain source maps
1466
+ * of non-source files.
1467
+ *
1468
+ * Use this option when you are seeing files that show up in report even if they
1469
+ * match your `coverage.exclude` patterns.
1470
+ *
1471
+ * @default false
1472
+ */
1473
+ excludeAfterRemap?: boolean;
1474
+ /**
1475
+ * Concurrency limit used when processing the coverage results.
1476
+ * Defaults to `Math.min(20, os.availableParallelism?.() ?? os.cpus().length)`
1477
+ */
1478
+ processingConcurrency?: number;
1479
+ /**
1480
+ * Set to array of class method names to ignore for coverage
1481
+ *
1482
+ * @default []
1483
+ */
1484
+ ignoreClassMethods?: string[];
1485
+ }
1486
+ interface CoverageIstanbulOptions extends BaseCoverageOptions {}
1487
+ interface CoverageV8Options extends BaseCoverageOptions {}
1488
+ interface CustomProviderOptions extends Pick<BaseCoverageOptions, FieldsWithDefaultValues> {
1489
+ /** Name of the module or path to a file to load the custom provider from */
1490
+ customProviderModule: string;
1491
+ }
1492
+ interface Thresholds {
1493
+ /** Set global thresholds to `100` */
1494
+ 100?: boolean;
1495
+ /** Check thresholds per file. */
1496
+ perFile?: boolean;
1497
+ /**
1498
+ * Update threshold values automatically when current coverage is higher than earlier thresholds
1499
+ *
1500
+ * @default false
1501
+ */
1502
+ autoUpdate?: boolean;
1503
+ /** Thresholds for statements */
1504
+ statements?: number;
1505
+ /** Thresholds for functions */
1506
+ functions?: number;
1507
+ /** Thresholds for branches */
1508
+ branches?: number;
1509
+ /** Thresholds for lines */
1510
+ lines?: number;
1511
+ }
1512
+
1513
+ interface TestRunResult {
1514
+ testModules: TestModule[];
1515
+ unhandledErrors: unknown[];
1516
+ }
1517
+
1518
+ interface SuiteResultCache {
1519
+ failed: boolean;
1520
+ duration: number;
1521
+ }
1522
+ declare class ResultsCache {
1523
+ private cache;
1524
+ private workspacesKeyMap;
1525
+ private cachePath;
1526
+ private version;
1527
+ private root;
1528
+ constructor(version: string);
1529
+ getCachePath(): string | null;
1530
+ setConfig(root: string, config: ResolvedConfig["cache"]): void;
1531
+ getResults(key: string): SuiteResultCache | undefined;
1532
+ readFromCache(): Promise<void>;
1533
+ updateResults(files: File[]): void;
1534
+ removeFromCache(filepath: string): void;
1535
+ writeToCache(): Promise<void>;
1536
+ }
1537
+
1538
+ type FileStatsCache = Pick<Stats, "size">;
1539
+ declare class FilesStatsCache {
1540
+ cache: Map<string, FileStatsCache>;
1541
+ getStats(key: string): FileStatsCache | undefined;
1542
+ populateStats(root: string, specs: TestSpecification[]): Promise<void>;
1543
+ updateStats(fsPath: string, key: string): Promise<void>;
1544
+ removeStats(fsPath: string): void;
1545
+ }
1546
+
1547
+ declare class VitestCache {
1548
+ results: ResultsCache;
1549
+ stats: FilesStatsCache;
1550
+ constructor(version: string);
1551
+ getFileTestResults(key: string): SuiteResultCache | undefined;
1552
+ getFileStats(key: string): {
1553
+ size: number;
1554
+ } | undefined;
1555
+ static resolveCacheDir(root: string, dir?: string, projectName?: string): string;
1556
+ }
1557
+
1558
+ declare class VitestPackageInstaller {
1559
+ isPackageExists(name: string, options?: {
1560
+ paths?: string[];
1561
+ }): boolean;
1562
+ ensureInstalled(dependency: string, root: string, version?: string): Promise<boolean>;
1563
+ }
1564
+
1565
+ interface BlobOptions {
1566
+ outputFile?: string;
1567
+ }
1568
+ declare class BlobReporter implements Reporter {
1569
+ start: number;
1570
+ ctx: Vitest;
1571
+ options: BlobOptions;
1572
+ coverage: unknown | undefined;
1573
+ constructor(options: BlobOptions);
1574
+ onInit(ctx: Vitest): void;
1575
+ onCoverage(coverage: unknown): void;
1576
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): Promise<void>;
1577
+ }
1578
+ interface MergedBlobs {
1579
+ files: File[];
1580
+ errors: unknown[];
1581
+ coverages: unknown[];
1582
+ executionTimes: number[];
1583
+ }
1584
+
1585
+ declare class StateManager {
1586
+ filesMap: Map<string, File[]>;
1587
+ pathsSet: Set<string>;
1588
+ idMap: Map<string, Task>;
1589
+ taskFileMap: WeakMap<Task, File>;
1590
+ errorsSet: Set<unknown>;
1591
+ processTimeoutCauses: Set<string>;
1592
+ reportedTasksMap: WeakMap<Task, TestModule | TestCase | TestSuite>;
1593
+ blobs?: MergedBlobs;
1594
+ transformTime: number;
1595
+ onUnhandledError?: OnUnhandledErrorCallback;
1596
+ constructor(options: {
1597
+ onUnhandledError?: OnUnhandledErrorCallback;
1598
+ });
1599
+ catchError(error: unknown, type: string): void;
1600
+ clearErrors(): void;
1601
+ getUnhandledErrors(): unknown[];
1602
+ addProcessTimeoutCause(cause: string): void;
1603
+ getProcessTimeoutCauses(): string[];
1604
+ getPaths(): string[];
1605
+ /**
1606
+ * Return files that were running or collected.
1607
+ */
1608
+ getFiles(keys?: string[]): File[];
1609
+ getTestModules(keys?: string[]): TestModule[];
1610
+ getFilepaths(): string[];
1611
+ getFailedFilepaths(): string[];
1612
+ collectPaths(paths?: string[]): void;
1613
+ collectFiles(project: TestProject, files?: File[]): void;
1614
+ clearFiles(project: TestProject, paths?: string[]): void;
1615
+ updateId(task: Task, project: TestProject): void;
1616
+ getReportedEntity(task: Task): TestModule | TestCase | TestSuite | undefined;
1617
+ updateTasks(packs: TaskResultPack[]): void;
1618
+ updateUserLog(log: UserConsoleLog): void;
1619
+ getCountOfFailedTests(): number;
1620
+ cancelFiles(files: string[], project: TestProject): void;
1621
+ }
1622
+
1623
+ declare class VitestWatcher {
1624
+ private vitest;
1625
+ /**
1626
+ * Modules that will be invalidated on the next run.
1627
+ */
1628
+ readonly invalidates: Set<string>;
1629
+ /**
1630
+ * Test files that have changed and need to be rerun.
1631
+ */
1632
+ readonly changedTests: Set<string>;
1633
+ private readonly _onRerun;
1634
+ constructor(vitest: Vitest);
1635
+ unregisterWatcher: () => void;
1636
+ registerWatcher(): this;
1637
+ private scheduleRerun;
1638
+ private getTestFilesFromWatcherTrigger;
1639
+ onFileChange: (id: string) => void;
1640
+ onFileDelete: (id: string) => void;
1641
+ onFileCreate: (id: string) => void;
1642
+ private handleSetupFile;
1643
+ /**
1644
+ * @returns A value indicating whether rerun is needed (changedTests was mutated)
1645
+ */
1646
+ private handleFileChanged;
1647
+ }
1648
+ interface WatcherTriggerPattern {
1649
+ pattern: RegExp;
1650
+ testsToRun: (file: string, match: RegExpMatchArray) => string[] | string | null | undefined | void;
1651
+ }
1652
+
1653
+ interface VitestOptions {
1654
+ packageInstaller?: VitestPackageInstaller;
1655
+ stdin?: NodeJS.ReadStream;
1656
+ stdout?: NodeJS.WriteStream | Writable;
1657
+ stderr?: NodeJS.WriteStream | Writable;
1658
+ }
1659
+ declare class Vitest {
1660
+ readonly mode: VitestRunMode;
1661
+ /**
1662
+ * Current Vitest version.
1663
+ * @example '2.0.0'
1664
+ */
1665
+ readonly version: string;
1666
+ static readonly version: string;
1667
+ /**
1668
+ * The logger instance used to log messages. It's recommended to use this logger instead of `console`.
1669
+ * It's possible to override stdout and stderr streams when initiating Vitest.
1670
+ * @example
1671
+ * new Vitest('test', {
1672
+ * stdout: new Writable(),
1673
+ * })
1674
+ */
1675
+ readonly logger: Logger;
1676
+ /**
1677
+ * The package installer instance used to install Vitest packages.
1678
+ * @example
1679
+ * await vitest.packageInstaller.ensureInstalled('@vitest/browser', process.cwd())
1680
+ */
1681
+ readonly packageInstaller: VitestPackageInstaller;
1682
+ /**
1683
+ * A path to the built Vitest directory. This is usually a folder in `node_modules`.
1684
+ */
1685
+ readonly distPath: string;
1686
+ /**
1687
+ * A list of projects that are currently running.
1688
+ * If projects were filtered with `--project` flag, they won't appear here.
1689
+ */
1690
+ projects: TestProject[];
1691
+ /**
1692
+ * A watcher handler. This is not the file system watcher. The handler only
1693
+ * exposes methods to handle changed files.
1694
+ *
1695
+ * If you have your own watcher, you can use these methods to replicate
1696
+ * Vitest behaviour.
1697
+ */
1698
+ readonly watcher: VitestWatcher;
1699
+ private isFirstRun;
1700
+ private restartsCount;
1701
+ private readonly specifications;
1702
+ private pool;
1703
+ private _config?;
1704
+ private _vite?;
1705
+ private _state?;
1706
+ private _cache?;
1707
+ private _snapshot?;
1708
+ constructor(mode: VitestRunMode, cliOptions: UserConfig, options?: VitestOptions);
1709
+ private _onRestartListeners;
1710
+ private _onClose;
1711
+ private _onSetServer;
1712
+ private _onCancelListeners;
1713
+ private _onUserTestsRerun;
1714
+ private _onFilterWatchedSpecification;
1715
+ /** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
1716
+ get invalidates(): Set<string>;
1717
+ /** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
1718
+ get changedTests(): Set<string>;
1719
+ /**
1720
+ * The global config.
1721
+ */
1722
+ get config(): ResolvedConfig;
1723
+ /** @deprecated use `vitest.vite` instead */
1724
+ get server(): ViteDevServer;
1725
+ /**
1726
+ * Global Vite's dev server instance.
1727
+ */
1728
+ get vite(): ViteDevServer;
1729
+ /**
1730
+ * The global test state manager.
1731
+ * @experimental The State API is experimental and not subject to semver.
1732
+ */
1733
+ get state(): StateManager;
1734
+ /**
1735
+ * The global snapshot manager. You can access the current state on `snapshot.summary`.
1736
+ */
1737
+ get snapshot(): SnapshotManager;
1738
+ /**
1739
+ * Test results and test file stats cache. Primarily used by the sequencer to sort tests.
1740
+ */
1741
+ get cache(): VitestCache;
1742
+ /** @deprecated internal */
1743
+ setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
1744
+ /**
1745
+ * Inject new test projects into the workspace.
1746
+ * @param config Glob, config path or a custom config options.
1747
+ * @returns An array of new test projects. Can be empty if the name was filtered out.
1748
+ */
1749
+ private injectTestProject;
1750
+ /**
1751
+ * Provide a value to the test context. This value will be available to all tests with `inject`.
1752
+ */
1753
+ provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
1754
+ /**
1755
+ * Get global provided context.
1756
+ */
1757
+ getProvidedContext(): ProvidedContext;
1758
+ /** @deprecated use `getRootProject` instead */
1759
+ getCoreWorkspaceProject(): TestProject;
1325
1760
  /**
1326
1761
  * Return project that has the root (or "global") config.
1327
1762
  */
@@ -1336,6 +1771,10 @@ declare class Vitest {
1336
1771
  * @param moduleId The ID of the module in Vite module graph
1337
1772
  */
1338
1773
  import<T>(moduleId: string): Promise<T>;
1774
+ /**
1775
+ * Creates a coverage provider if `coverage` is enabled in the config.
1776
+ */
1777
+ createCoverageProvider(): Promise<CoverageProvider | null>;
1339
1778
  private resolveProjects;
1340
1779
  /**
1341
1780
  * Glob test files in every project and create a TestSpecification for each file and pool.
@@ -1376,6 +1815,11 @@ declare class Vitest {
1376
1815
  /** @deprecated */
1377
1816
  getFileWorkspaceSpecs(file: string): WorkspaceSpec[];
1378
1817
  /**
1818
+ * If there is a test run happening, returns a promise that will
1819
+ * resolve when the test run is finished.
1820
+ */
1821
+ waitForTestRunEnd(): Promise<void>;
1822
+ /**
1379
1823
  * Get test specifications associated with the given module. If module is not a test file, an empty array is returned.
1380
1824
  *
1381
1825
  * **Note:** this method relies on a cache generated by `globTestSpecifications`. If the file was not processed yet, use `project.matchesGlobPattern` instead.
@@ -1399,6 +1843,11 @@ declare class Vitest {
1399
1843
  */
1400
1844
  rerunTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
1401
1845
  private runFiles;
1846
+ experimental_parseSpecifications(specifications: TestSpecification[], options?: {
1847
+ /** @default os.availableParallelism() */
1848
+ concurrency?: number;
1849
+ }): Promise<TestModule[]>;
1850
+ experimental_parseSpecification(specification: TestSpecification): Promise<TestModule>;
1402
1851
  /**
1403
1852
  * Collect tests in specified modules. Vitest will run the files to collect tests.
1404
1853
  * @param specifications A list of specifications to run.
@@ -1436,7 +1885,6 @@ declare class Vitest {
1436
1885
  */
1437
1886
  resetGlobalTestNamePattern(): void;
1438
1887
  private _rerunTimer;
1439
- // we can't use a single `triggerId` yet because vscode extension relies on this
1440
1888
  private scheduleRerun;
1441
1889
  /**
1442
1890
  * Invalidate a file in all projects.
@@ -1510,26 +1958,6 @@ interface Reporter {
1510
1958
  * @experimental
1511
1959
  */
1512
1960
  onBrowserInit?: (project: TestProject) => Awaitable$1<void>;
1513
- /**
1514
- * @deprecated use `onTestRunStart` instead
1515
- */
1516
- onPathsCollected?: (paths?: string[]) => Awaitable$1<void>;
1517
- /**
1518
- * @deprecated use `onTestRunStart` instead
1519
- */
1520
- onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable$1<void>;
1521
- /**
1522
- * @deprecated use `onTestModuleCollected` instead
1523
- */
1524
- onCollected?: (files: File[]) => Awaitable$1<void>;
1525
- /**
1526
- * @deprecated use `onTestRunEnd` instead
1527
- */
1528
- onFinished?: (files: File[], errors: unknown[], coverage?: unknown) => Awaitable$1<void>;
1529
- /**
1530
- * @deprecated use `onTestModuleQueued`, `onTestModuleStart`, `onTestModuleEnd`, `onTestCaseReady`, `onTestCaseResult` instead
1531
- */
1532
- onTaskUpdate?: (packs: TaskResultPack[], events: TaskEventPack[]) => Awaitable$1<void>;
1533
1961
  onTestRemoved?: (trigger?: string) => Awaitable$1<void>;
1534
1962
  onWatcherStart?: (files?: File[], errors?: unknown[]) => Awaitable$1<void>;
1535
1963
  onWatcherRerun?: (files: string[], trigger?: string) => Awaitable$1<void>;
@@ -1589,184 +2017,80 @@ interface Reporter {
1589
2017
  */
1590
2018
  onHookStart?: (hook: ReportedHookContext) => Awaitable$1<void>;
1591
2019
  /**
1592
- * Called after the hook finished running.
1593
- */
1594
- onHookEnd?: (hook: ReportedHookContext) => Awaitable$1<void>;
1595
- onCoverage?: (coverage: unknown) => Awaitable$1<void>;
1596
- }
1597
-
1598
- interface BaseOptions {
1599
- isTTY?: boolean;
1600
- }
1601
- declare abstract class BaseReporter implements Reporter {
1602
- start: number;
1603
- end: number;
1604
- watchFilters?: string[];
1605
- failedUnwatchedFiles: TestModule[];
1606
- isTTY: boolean;
1607
- ctx: Vitest;
1608
- renderSucceed: boolean;
1609
- protected verbose: boolean;
1610
- private _filesInWatchMode;
1611
- private _timeStart;
1612
- constructor(options?: BaseOptions);
1613
- onInit(ctx: Vitest): void;
1614
- log(...messages: any): void;
1615
- error(...messages: any): void;
1616
- relative(path: string): string;
1617
- onFinished(files?: File[], errors?: unknown[]): void;
1618
- onTestCaseResult(testCase: TestCase): void;
1619
- onTestSuiteResult(testSuite: TestSuite): void;
1620
- onTestModuleEnd(testModule: TestModule): void;
1621
- private logFailedTask;
1622
- protected printTestModule(testModule: TestModule): void;
1623
- protected printTestCase(moduleState: TestModuleState, test: TestCase): void;
1624
- private getModuleLog;
1625
- protected printTestSuite(_suite: TestSuite): void;
1626
- protected getTestName(test: Task, separator?: string): string;
1627
- protected getFullName(test: Task, separator?: string): string;
1628
- protected formatShortError(error: TestError): string;
1629
- protected getTestIndentation(_test: Task): string;
1630
- protected printAnnotations(test: TestCase, console: "log" | "error", padding?: number): void;
1631
- protected getDurationPrefix(task: Task): string;
1632
- onWatcherStart(files?: File[], errors?: unknown[]): void;
1633
- onWatcherRerun(files: string[], trigger?: string): void;
1634
- onUserConsoleLog(log: UserConsoleLog, taskState?: TestResult["state"]): void;
1635
- onTestRemoved(trigger?: string): void;
1636
- shouldLog(log: UserConsoleLog, taskState?: TestResult["state"]): boolean;
1637
- onServerRestart(reason?: string): void;
1638
- reportSummary(files: File[], errors: unknown[]): void;
1639
- reportTestSummary(files: File[], errors: unknown[]): void;
1640
- private printErrorsSummary;
1641
- reportBenchmarkSummary(files: File[]): void;
1642
- private printTaskErrors;
1643
- }
1644
-
1645
- interface DefaultReporterOptions extends BaseOptions {
1646
- summary?: boolean;
1647
- }
1648
- declare class DefaultReporter extends BaseReporter {
1649
- private options;
1650
- private summary?;
1651
- constructor(options?: DefaultReporterOptions);
1652
- onTestRunStart(specifications: ReadonlyArray<TestSpecification>): void;
1653
- onTestModuleQueued(file: TestModule): void;
1654
- onTestModuleCollected(module: TestModule): void;
1655
- onTestModuleEnd(module: TestModule): void;
1656
- onTestCaseReady(test: TestCase): void;
1657
- onTestCaseResult(test: TestCase): void;
1658
- onHookStart(hook: ReportedHookContext): void;
1659
- onHookEnd(hook: ReportedHookContext): void;
1660
- onInit(ctx: Vitest): void;
1661
- onTestRunEnd(): void;
1662
- }
1663
-
1664
- interface HTMLOptions {
1665
- outputFile?: string;
1666
- }
1667
-
1668
- interface CoverageSummaryData {
1669
- lines: Totals;
1670
- statements: Totals;
1671
- branches: Totals;
1672
- functions: Totals;
1673
- }
1674
-
1675
- declare class CoverageSummary {
1676
- constructor(data: CoverageSummary | CoverageSummaryData);
1677
- merge(obj: CoverageSummary): CoverageSummary;
1678
- toJSON(): CoverageSummaryData;
1679
- isEmpty(): boolean;
1680
- data: CoverageSummaryData;
1681
- lines: Totals;
1682
- statements: Totals;
1683
- branches: Totals;
1684
- functions: Totals;
1685
- }
1686
-
1687
- interface CoverageMapData {
1688
- [key: string]: FileCoverage | FileCoverageData;
1689
- }
1690
-
1691
- declare class CoverageMap {
1692
- constructor(data: CoverageMapData | CoverageMap);
1693
- addFileCoverage(pathOrObject: string | FileCoverage | FileCoverageData): void;
1694
- files(): string[];
1695
- fileCoverageFor(filename: string): FileCoverage;
1696
- filter(callback: (key: string) => boolean): void;
1697
- getCoverageSummary(): CoverageSummary;
1698
- merge(data: CoverageMapData | CoverageMap): void;
1699
- toJSON(): CoverageMapData;
1700
- data: CoverageMapData;
1701
- }
1702
-
1703
- interface Location {
1704
- line: number;
1705
- column: number;
1706
- }
1707
-
1708
- interface Range {
1709
- start: Location;
1710
- end: Location;
1711
- }
1712
-
1713
- interface BranchMapping {
1714
- loc: Range;
1715
- type: string;
1716
- locations: Range[];
1717
- line: number;
1718
- }
1719
-
1720
- interface FunctionMapping {
1721
- name: string;
1722
- decl: Range;
1723
- loc: Range;
1724
- line: number;
1725
- }
1726
-
1727
- interface FileCoverageData {
1728
- path: string;
1729
- statementMap: { [key: string]: Range };
1730
- fnMap: { [key: string]: FunctionMapping };
1731
- branchMap: { [key: string]: BranchMapping };
1732
- s: { [key: string]: number };
1733
- f: { [key: string]: number };
1734
- b: { [key: string]: number[] };
2020
+ * Called after the hook finished running.
2021
+ */
2022
+ onHookEnd?: (hook: ReportedHookContext) => Awaitable$1<void>;
2023
+ onCoverage?: (coverage: unknown) => Awaitable$1<void>;
1735
2024
  }
1736
2025
 
1737
- interface Totals {
1738
- total: number;
1739
- covered: number;
1740
- skipped: number;
1741
- pct: number;
2026
+ interface BaseOptions {
2027
+ isTTY?: boolean;
1742
2028
  }
1743
-
1744
- interface Coverage {
1745
- covered: number;
1746
- total: number;
1747
- coverage: number;
2029
+ declare abstract class BaseReporter implements Reporter {
2030
+ start: number;
2031
+ end: number;
2032
+ watchFilters?: string[];
2033
+ failedUnwatchedFiles: TestModule[];
2034
+ isTTY: boolean;
2035
+ ctx: Vitest;
2036
+ renderSucceed: boolean;
2037
+ protected verbose: boolean;
2038
+ private _filesInWatchMode;
2039
+ private _timeStart;
2040
+ constructor(options?: BaseOptions);
2041
+ onInit(ctx: Vitest): void;
2042
+ log(...messages: any): void;
2043
+ error(...messages: any): void;
2044
+ relative(path: string): string;
2045
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, _reason: TestRunEndReason): void;
2046
+ onTestCaseResult(testCase: TestCase): void;
2047
+ onTestSuiteResult(testSuite: TestSuite): void;
2048
+ onTestModuleEnd(testModule: TestModule): void;
2049
+ private logFailedTask;
2050
+ protected printTestModule(testModule: TestModule): void;
2051
+ protected printTestCase(moduleState: TestModuleState, test: TestCase): void;
2052
+ private getModuleLog;
2053
+ protected printTestSuite(_suite: TestSuite): void;
2054
+ protected getTestName(test: Task, separator?: string): string;
2055
+ protected getFullName(test: Task, separator?: string): string;
2056
+ protected formatShortError(error: TestError): string;
2057
+ protected getTestIndentation(_test: Task): string;
2058
+ protected printAnnotations(test: TestCase, console: "log" | "error", padding?: number): void;
2059
+ protected getDurationPrefix(task: Task): string;
2060
+ onWatcherStart(files?: File[], errors?: unknown[]): void;
2061
+ onWatcherRerun(files: string[], trigger?: string): void;
2062
+ onUserConsoleLog(log: UserConsoleLog, taskState?: TestResult["state"]): void;
2063
+ onTestRemoved(trigger?: string): void;
2064
+ shouldLog(log: UserConsoleLog, taskState?: TestResult["state"]): boolean;
2065
+ onServerRestart(reason?: string): void;
2066
+ reportSummary(files: File[], errors: unknown[]): void;
2067
+ reportTestSummary(files: File[], errors: unknown[]): void;
2068
+ private printErrorsSummary;
2069
+ reportBenchmarkSummary(files: File[]): void;
2070
+ private printTaskErrors;
1748
2071
  }
1749
2072
 
1750
- declare class FileCoverage implements FileCoverageData {
1751
- constructor(data: string | FileCoverage | FileCoverageData);
1752
- merge(other: FileCoverageData): void;
1753
- getBranchCoverageByLine(): { [line: number]: Coverage };
1754
- getLineCoverage(): { [line: number]: number };
1755
- getUncoveredLines(): number[];
1756
- resetHits(): void;
1757
- computeBranchTotals(): Totals;
1758
- computeSimpleTotals(): Totals;
1759
- toSummary(): CoverageSummary;
1760
- toJSON(): object;
2073
+ interface DefaultReporterOptions extends BaseOptions {
2074
+ summary?: boolean;
2075
+ }
2076
+ declare class DefaultReporter extends BaseReporter {
2077
+ private options;
2078
+ private summary?;
2079
+ constructor(options?: DefaultReporterOptions);
2080
+ onTestRunStart(specifications: ReadonlyArray<TestSpecification>): void;
2081
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): void;
2082
+ onTestModuleQueued(file: TestModule): void;
2083
+ onTestModuleCollected(module: TestModule): void;
2084
+ onTestModuleEnd(module: TestModule): void;
2085
+ onTestCaseReady(test: TestCase): void;
2086
+ onTestCaseResult(test: TestCase): void;
2087
+ onHookStart(hook: ReportedHookContext): void;
2088
+ onHookEnd(hook: ReportedHookContext): void;
2089
+ onInit(ctx: Vitest): void;
2090
+ }
1761
2091
 
1762
- data: FileCoverageData;
1763
- path: string;
1764
- statementMap: { [key: string]: Range };
1765
- fnMap: { [key: string]: FunctionMapping };
1766
- branchMap: { [key: string]: BranchMapping };
1767
- s: { [key: string]: number };
1768
- f: { [key: string]: number };
1769
- b: { [key: string]: number[] };
2092
+ interface HTMLOptions {
2093
+ outputFile?: string;
1770
2094
  }
1771
2095
 
1772
2096
  // for compatibility reasons, the reporter produces a JSON similar to the one produced by the Jest JSON reporter
@@ -1812,17 +2136,18 @@ interface JsonTestResults {
1812
2136
  snapshot: SnapshotSummary;
1813
2137
  coverageMap?: CoverageMap | null | undefined;
1814
2138
  }
1815
- interface JsonOptions$1 {
2139
+ interface JsonOptions {
1816
2140
  outputFile?: string;
1817
2141
  }
1818
2142
  declare class JsonReporter implements Reporter {
1819
2143
  start: number;
1820
2144
  ctx: Vitest;
1821
- options: JsonOptions$1;
1822
- constructor(options: JsonOptions$1);
2145
+ options: JsonOptions;
2146
+ coverageMap?: CoverageMap;
2147
+ constructor(options: JsonOptions);
1823
2148
  onInit(ctx: Vitest): void;
1824
- protected logTasks(files: File[], coverageMap?: CoverageMap | null): Promise<void>;
1825
- onFinished(files?: File[], _errors?: unknown[], coverageMap?: unknown): Promise<void>;
2149
+ onCoverage(coverageMap: unknown): void;
2150
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): Promise<void>;
1826
2151
  /**
1827
2152
  * Writes the report to an output file if specified in the config,
1828
2153
  * or logs it to the console otherwise.
@@ -1866,7 +2191,7 @@ declare class JUnitReporter implements Reporter {
1866
2191
  writeElement(name: string, attrs: Record<string, any>, children: () => Promise<void>): Promise<void>;
1867
2192
  writeLogs(task: Task, type: "err" | "out"): Promise<void>;
1868
2193
  writeTasks(tasks: Task[], filename: string): Promise<void>;
1869
- onFinished(files?: File[]): Promise<void>;
2194
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): Promise<void>;
1870
2195
  }
1871
2196
 
1872
2197
  declare class DotReporter extends BaseReporter {
@@ -1877,7 +2202,7 @@ declare class DotReporter extends BaseReporter {
1877
2202
  // Ignore default logging of base reporter
1878
2203
  printTestModule(): void;
1879
2204
  onWatcherRerun(files: string[], trigger?: string): void;
1880
- onFinished(files?: File[], errors?: unknown[]): void;
2205
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): void;
1881
2206
  onTestModuleCollected(module: TestModule): void;
1882
2207
  onTestCaseReady(test: TestCase): void;
1883
2208
  onTestCaseResult(test: TestCase): void;
@@ -1894,7 +2219,7 @@ declare class GithubActionsReporter implements Reporter {
1894
2219
  constructor(options?: GithubActionsReporterOptions);
1895
2220
  onInit(ctx: Vitest): void;
1896
2221
  onTestCaseAnnotate(testCase: TestCase, annotation: TestAnnotation): void;
1897
- onFinished(files?: File[], errors?: unknown[]): void;
2222
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): void;
1898
2223
  }
1899
2224
 
1900
2225
  declare class HangingProcessReporter implements Reporter {
@@ -1910,12 +2235,12 @@ declare class TapReporter implements Reporter {
1910
2235
  static getComment(task: Task): string;
1911
2236
  private logErrorDetails;
1912
2237
  protected logTasks(tasks: Task[]): void;
1913
- onFinished(files?: File[]): void;
2238
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): void;
1914
2239
  }
1915
2240
 
1916
2241
  declare class TapFlatReporter extends TapReporter {
1917
2242
  onInit(ctx: Vitest): void;
1918
- onFinished(files?: File[]): void;
2243
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>): void;
1919
2244
  }
1920
2245
 
1921
2246
  declare class VerboseReporter extends DefaultReporter {
@@ -1941,393 +2266,109 @@ declare function renderTable(options: {
1941
2266
  columns: number;
1942
2267
  slowTestThreshold: number;
1943
2268
  compare?: Record<Task["id"], FormattedBenchmarkResult>;
1944
- }): string;
1945
-
1946
- declare class BenchmarkReporter extends DefaultReporter {
1947
- compare?: Parameters<typeof renderTable>[0]["compare"];
1948
- onInit(ctx: Vitest): Promise<void>;
1949
- onTaskUpdate(packs: TaskResultPack[]): void;
1950
- onTestSuiteResult(testSuite: TestSuite): void;
1951
- protected printTestModule(testModule: TestModule): void;
1952
- private printSuiteTable;
1953
- onFinished(files?: File[], errors?: unknown[]): Promise<void>;
1954
- }
1955
-
1956
- declare class VerboseBenchmarkReporter extends BenchmarkReporter {
1957
- protected verbose: boolean;
1958
- }
1959
-
1960
- declare const BenchmarkReportsMap: {
1961
- default: typeof BenchmarkReporter;
1962
- verbose: typeof VerboseBenchmarkReporter;
1963
- };
1964
- type BenchmarkBuiltinReporters = keyof typeof BenchmarkReportsMap;
1965
-
1966
- declare const ReportersMap: {
1967
- default: typeof DefaultReporter;
1968
- blob: typeof BlobReporter;
1969
- verbose: typeof VerboseReporter;
1970
- dot: typeof DotReporter;
1971
- json: typeof JsonReporter;
1972
- tap: typeof TapReporter;
1973
- "tap-flat": typeof TapFlatReporter;
1974
- junit: typeof JUnitReporter;
1975
- "hanging-process": typeof HangingProcessReporter;
1976
- "github-actions": typeof GithubActionsReporter;
1977
- };
1978
- type BuiltinReporters = keyof typeof ReportersMap;
1979
- interface BuiltinReporterOptions {
1980
- "default": DefaultReporterOptions;
1981
- "verbose": DefaultReporterOptions;
1982
- "dot": BaseOptions;
1983
- "json": JsonOptions$1;
1984
- "blob": BlobOptions;
1985
- "tap": never;
1986
- "tap-flat": never;
1987
- "junit": JUnitOptions;
1988
- "hanging-process": never;
1989
- "html": HTMLOptions;
1990
- }
1991
-
1992
- interface TestSequencer {
1993
- /**
1994
- * Slicing tests into shards. Will be run before `sort`.
1995
- * Only run, if `shard` is defined.
1996
- */
1997
- shard: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
1998
- sort: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
1999
- }
2000
- interface TestSequencerConstructor {
2001
- new (ctx: Vitest): TestSequencer;
2002
- }
2003
-
2004
- interface WatcherTriggerPattern {
2005
- pattern: RegExp;
2006
- testsToRun: (file: string, match: RegExpMatchArray) => string[] | string | null | undefined | void;
2007
- }
2008
-
2009
- interface BenchmarkUserOptions {
2010
- /**
2011
- * Include globs for benchmark test files
2012
- *
2013
- * @default ['**\/*.{bench,benchmark}.?(c|m)[jt]s?(x)']
2014
- */
2015
- include?: string[];
2016
- /**
2017
- * Exclude globs for benchmark test files
2018
- * @default ['**\/node_modules/**', '**\/dist/**', '**\/cypress/**', '**\/.{idea,git,cache,output,temp}/**', '**\/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*']
2019
- */
2020
- exclude?: string[];
2021
- /**
2022
- * Include globs for in-source benchmark test files
2023
- *
2024
- * @default []
2025
- */
2026
- includeSource?: string[];
2027
- /**
2028
- * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
2029
- * and/or paths to custom reporters
2030
- *
2031
- * @default ['default']
2032
- */
2033
- reporters?: Arrayable<BenchmarkBuiltinReporters | Reporter>;
2034
- /**
2035
- * @deprecated Use `benchmark.outputJson` instead
2036
- */
2037
- outputFile?: string | (Partial<Record<BenchmarkBuiltinReporters, string>> & Record<string, string>);
2038
- /**
2039
- * benchmark output file to compare against
2040
- */
2041
- compare?: string;
2042
- /**
2043
- * benchmark output file
2044
- */
2045
- outputJson?: string;
2046
- /**
2047
- * Include `samples` array of benchmark results for API or custom reporter usages.
2048
- * This is disabled by default to reduce memory usage.
2049
- * @default false
2050
- */
2051
- includeSamples?: boolean;
2052
- }
2053
-
2054
- interface Node {
2055
- isRoot(): boolean;
2056
- visit(visitor: Visitor, state: any): void;
2057
- }
2058
-
2059
- interface Visitor<N extends Node = Node> {
2060
- onStart(root: N, state: any): void;
2061
- onSummary(root: N, state: any): void;
2062
- onDetail(root: N, state: any): void;
2063
- onSummaryEnd(root: N, state: any): void;
2064
- onEnd(root: N, state: any): void;
2065
- }
2066
-
2067
- interface FileOptions {
2068
- file: string;
2069
- }
2070
-
2071
- interface ProjectOptions {
2072
- projectRoot: string;
2073
- }
2074
-
2075
- interface ReportOptions {
2076
- clover: CloverOptions;
2077
- cobertura: CoberturaOptions;
2078
- "html-spa": HtmlSpaOptions;
2079
- html: HtmlOptions;
2080
- json: JsonOptions;
2081
- "json-summary": JsonSummaryOptions;
2082
- lcov: LcovOptions;
2083
- lcovonly: LcovOnlyOptions;
2084
- none: never;
2085
- teamcity: TeamcityOptions;
2086
- text: TextOptions;
2087
- "text-lcov": TextLcovOptions;
2088
- "text-summary": TextSummaryOptions;
2089
- }
2090
-
2091
- interface CloverOptions extends FileOptions, ProjectOptions {}
2092
-
2093
- interface CoberturaOptions extends FileOptions, ProjectOptions {}
2094
-
2095
- interface HtmlSpaOptions extends HtmlOptions {
2096
- metricsToShow: Array<"lines" | "branches" | "functions" | "statements">;
2097
- }
2098
- interface HtmlOptions {
2099
- verbose: boolean;
2100
- skipEmpty: boolean;
2101
- subdir: string;
2102
- linkMapper: LinkMapper;
2103
- }
2104
-
2105
- type JsonOptions = FileOptions;
2106
- type JsonSummaryOptions = FileOptions;
2107
-
2108
- interface LcovOptions extends FileOptions, ProjectOptions {}
2109
- interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
2269
+ }): string;
2110
2270
 
2111
- interface TeamcityOptions extends FileOptions {
2112
- blockName: string;
2271
+ declare class BenchmarkReporter extends DefaultReporter {
2272
+ compare?: Parameters<typeof renderTable>[0]["compare"];
2273
+ onInit(ctx: Vitest): Promise<void>;
2274
+ onTaskUpdate(packs: TaskResultPack[]): void;
2275
+ onTestSuiteResult(testSuite: TestSuite): void;
2276
+ protected printTestModule(testModule: TestModule): void;
2277
+ private printSuiteTable;
2278
+ onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): Promise<void>;
2113
2279
  }
2114
2280
 
2115
- interface TextOptions extends FileOptions {
2116
- maxCols: number;
2117
- skipEmpty: boolean;
2118
- skipFull: boolean;
2281
+ declare class VerboseBenchmarkReporter extends BenchmarkReporter {
2282
+ protected verbose: boolean;
2119
2283
  }
2120
- type TextLcovOptions = ProjectOptions;
2121
- type TextSummaryOptions = FileOptions;
2122
2284
 
2123
- interface LinkMapper {
2124
- getPath(node: string | Node): string;
2125
- relativePath(source: string | Node, target: string | Node): string;
2126
- assetPath(node: Node, name: string): string;
2127
- }
2285
+ declare const BenchmarkReportsMap: {
2286
+ default: typeof BenchmarkReporter;
2287
+ verbose: typeof VerboseBenchmarkReporter;
2288
+ };
2289
+ type BenchmarkBuiltinReporters = keyof typeof BenchmarkReportsMap;
2128
2290
 
2129
- type TransformResult = string | Partial<TransformResult$1> | undefined | null | void;
2130
- type CoverageResults = unknown;
2131
- interface CoverageProvider {
2132
- name: string;
2133
- /** Called when provider is being initialized before tests run */
2134
- initialize: (ctx: Vitest) => Promise<void> | void;
2135
- /** Called when setting coverage options for Vitest context (`ctx.config.coverage`) */
2136
- resolveOptions: () => ResolvedCoverageOptions;
2137
- /** Callback to clean previous reports */
2138
- clean: (clean?: boolean) => void | Promise<void>;
2139
- /** Called with coverage results after a single test file has been run */
2140
- onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void | Promise<void>;
2141
- /** Callback called when test run fails */
2142
- onTestFailure?: () => void | Promise<void>;
2143
- /** Callback to generate final coverage results */
2144
- generateCoverage: (reportContext: ReportContext) => CoverageResults | Promise<CoverageResults>;
2145
- /** Callback to convert coverage results to coverage reports. Called with results returned from `generateCoverage` */
2146
- reportCoverage: (coverage: CoverageResults, reportContext: ReportContext) => void | Promise<void>;
2147
- /** Callback for `--merge-reports` options. Called with multiple coverage results generated by `generateCoverage`. */
2148
- mergeReports?: (coverages: CoverageResults[]) => void | Promise<void>;
2149
- /** Callback called for instrumenting files with coverage counters. */
2150
- onFileTransform?: (sourceCode: string, id: string, pluginCtx: any) => TransformResult | Promise<TransformResult>;
2151
- }
2152
- interface ReportContext {
2153
- /** Indicates whether all tests were run. False when only specific tests were run. */
2154
- allTestsRun?: boolean;
2291
+ declare const ReportersMap: {
2292
+ default: typeof DefaultReporter;
2293
+ blob: typeof BlobReporter;
2294
+ verbose: typeof VerboseReporter;
2295
+ dot: typeof DotReporter;
2296
+ json: typeof JsonReporter;
2297
+ tap: typeof TapReporter;
2298
+ "tap-flat": typeof TapFlatReporter;
2299
+ junit: typeof JUnitReporter;
2300
+ "hanging-process": typeof HangingProcessReporter;
2301
+ "github-actions": typeof GithubActionsReporter;
2302
+ };
2303
+ type BuiltinReporters = keyof typeof ReportersMap;
2304
+ interface BuiltinReporterOptions {
2305
+ "default": DefaultReporterOptions;
2306
+ "verbose": DefaultReporterOptions;
2307
+ "dot": BaseOptions;
2308
+ "json": JsonOptions;
2309
+ "blob": BlobOptions;
2310
+ "tap": never;
2311
+ "tap-flat": never;
2312
+ "junit": JUnitOptions;
2313
+ "hanging-process": never;
2314
+ "html": HTMLOptions;
2155
2315
  }
2156
- interface CoverageProviderModule extends RuntimeCoverageProviderModule {
2316
+
2317
+ interface TestSequencer {
2157
2318
  /**
2158
- * Factory for creating a new coverage provider
2319
+ * Slicing tests into shards. Will be run before `sort`.
2320
+ * Only run, if `shard` is defined.
2159
2321
  */
2160
- getProvider: () => CoverageProvider | Promise<CoverageProvider>;
2322
+ shard: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
2323
+ sort: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
2161
2324
  }
2162
- type CoverageReporter = keyof ReportOptions | (string & {});
2163
- type CoverageReporterWithOptions<ReporterName extends CoverageReporter = CoverageReporter> = ReporterName extends keyof ReportOptions ? ReportOptions[ReporterName] extends never ? [ReporterName, object] : [ReporterName, Partial<ReportOptions[ReporterName]>] : [ReporterName, Record<string, unknown>];
2164
- type CoverageProviderName = "v8" | "istanbul" | "custom" | undefined;
2165
- type CoverageOptions<T extends CoverageProviderName = CoverageProviderName> = T extends "istanbul" ? {
2166
- provider: T;
2167
- } & CoverageIstanbulOptions : T extends "v8" ? {
2168
- /**
2169
- * Provider to use for coverage collection.
2170
- *
2171
- * @default 'v8'
2172
- */
2173
- provider: T;
2174
- } & CoverageV8Options : T extends "custom" ? {
2175
- provider: T;
2176
- } & CustomProviderOptions : {
2177
- provider?: T;
2178
- } & CoverageV8Options;
2179
- /** Fields that have default values. Internally these will always be defined. */
2180
- type FieldsWithDefaultValues = "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "exclude" | "reportOnFailure" | "allowExternal" | "processingConcurrency";
2181
- type ResolvedCoverageOptions<T extends CoverageProviderName = CoverageProviderName> = CoverageOptions<T> & Required<Pick<CoverageOptions<T>, FieldsWithDefaultValues>> & {
2182
- reporter: CoverageReporterWithOptions[];
2183
- };
2184
- interface BaseCoverageOptions {
2185
- /**
2186
- * Enables coverage collection. Can be overridden using `--coverage` CLI option.
2187
- *
2188
- * @default false
2189
- */
2190
- enabled?: boolean;
2325
+ interface TestSequencerConstructor {
2326
+ new (ctx: Vitest): TestSequencer;
2327
+ }
2328
+
2329
+ interface BenchmarkUserOptions {
2191
2330
  /**
2192
- * List of files included in coverage as glob patterns.
2193
- * By default only files covered by tests are included.
2331
+ * Include globs for benchmark test files
2194
2332
  *
2195
- * See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
2333
+ * @default ['**\/*.{bench,benchmark}.?(c|m)[jt]s?(x)']
2196
2334
  */
2197
2335
  include?: string[];
2198
2336
  /**
2199
- * List of files excluded from coverage as glob patterns.
2200
- * Files are first checked against `coverage.include`.
2201
- *
2202
- * See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
2337
+ * Exclude globs for benchmark test files
2338
+ * @default ['**\/node_modules/**', '**\/dist/**', '**\/cypress/**', '**\/.{idea,git,cache,output,temp}/**', '**\/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*']
2203
2339
  */
2204
2340
  exclude?: string[];
2205
2341
  /**
2206
- * Clean coverage results before running tests
2207
- *
2208
- * @default true
2209
- */
2210
- clean?: boolean;
2211
- /**
2212
- * Clean coverage report on watch rerun
2213
- *
2214
- * @default true
2215
- */
2216
- cleanOnRerun?: boolean;
2217
- /**
2218
- * Directory to write coverage report to
2219
- *
2220
- * @default './coverage'
2221
- */
2222
- reportsDirectory?: string;
2223
- /**
2224
- * Coverage reporters to use.
2225
- * See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters.
2226
- *
2227
- * @default ['text', 'html', 'clover', 'json']
2228
- */
2229
- reporter?: Arrayable$1<CoverageReporter> | (CoverageReporter | [CoverageReporter] | CoverageReporterWithOptions)[];
2230
- /**
2231
- * Do not show files with 100% statement, branch, and function coverage
2232
- *
2233
- * @default false
2234
- */
2235
- skipFull?: boolean;
2236
- /**
2237
- * Configurations for thresholds
2238
- *
2239
- * @example
2240
- *
2241
- * ```ts
2242
- * {
2243
- * // Thresholds for all files
2244
- * functions: 95,
2245
- * branches: 70,
2246
- * perFile: true,
2247
- * autoUpdate: true,
2248
- *
2249
- * // Thresholds for utilities
2250
- * 'src/utils/**.ts': {
2251
- * lines: 100,
2252
- * statements: 95,
2253
- * }
2254
- * }
2255
- * ```
2256
- */
2257
- thresholds?: Thresholds | ({
2258
- [glob: string]: Pick<Thresholds, 100 | "statements" | "functions" | "branches" | "lines">;
2259
- } & Thresholds);
2260
- /**
2261
- * Watermarks for statements, lines, branches and functions.
2262
- *
2263
- * Default value is `[50,80]` for each property.
2264
- */
2265
- watermarks?: {
2266
- statements?: [number, number];
2267
- functions?: [number, number];
2268
- branches?: [number, number];
2269
- lines?: [number, number];
2270
- };
2271
- /**
2272
- * Generate coverage report even when tests fail.
2342
+ * Include globs for in-source benchmark test files
2273
2343
  *
2274
- * @default false
2344
+ * @default []
2275
2345
  */
2276
- reportOnFailure?: boolean;
2346
+ includeSource?: string[];
2277
2347
  /**
2278
- * Collect coverage of files outside the project `root`.
2348
+ * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
2349
+ * and/or paths to custom reporters
2279
2350
  *
2280
- * @default false
2351
+ * @default ['default']
2281
2352
  */
2282
- allowExternal?: boolean;
2353
+ reporters?: Arrayable$1<BenchmarkBuiltinReporters | Reporter>;
2283
2354
  /**
2284
- * Apply exclusions again after coverage has been remapped to original sources.
2285
- * This is useful when your source files are transpiled and may contain source maps
2286
- * of non-source files.
2287
- *
2288
- * Use this option when you are seeing files that show up in report even if they
2289
- * match your `coverage.exclude` patterns.
2290
- *
2291
- * @default false
2355
+ * @deprecated Use `benchmark.outputJson` instead
2292
2356
  */
2293
- excludeAfterRemap?: boolean;
2357
+ outputFile?: string | (Partial<Record<BenchmarkBuiltinReporters, string>> & Record<string, string>);
2294
2358
  /**
2295
- * Concurrency limit used when processing the coverage results.
2296
- * Defaults to `Math.min(20, os.availableParallelism?.() ?? os.cpus().length)`
2359
+ * benchmark output file to compare against
2297
2360
  */
2298
- processingConcurrency?: number;
2361
+ compare?: string;
2299
2362
  /**
2300
- * Set to array of class method names to ignore for coverage
2301
- *
2302
- * @default []
2363
+ * benchmark output file
2303
2364
  */
2304
- ignoreClassMethods?: string[];
2305
- }
2306
- interface CoverageIstanbulOptions extends BaseCoverageOptions {}
2307
- interface CoverageV8Options extends BaseCoverageOptions {}
2308
- interface CustomProviderOptions extends Pick<BaseCoverageOptions, FieldsWithDefaultValues> {
2309
- /** Name of the module or path to a file to load the custom provider from */
2310
- customProviderModule: string;
2311
- }
2312
- interface Thresholds {
2313
- /** Set global thresholds to `100` */
2314
- 100?: boolean;
2315
- /** Check thresholds per file. */
2316
- perFile?: boolean;
2365
+ outputJson?: string;
2317
2366
  /**
2318
- * Update threshold values automatically when current coverage is higher than earlier thresholds
2319
- *
2367
+ * Include `samples` array of benchmark results for API or custom reporter usages.
2368
+ * This is disabled by default to reduce memory usage.
2320
2369
  * @default false
2321
2370
  */
2322
- autoUpdate?: boolean;
2323
- /** Thresholds for statements */
2324
- statements?: number;
2325
- /** Thresholds for functions */
2326
- functions?: number;
2327
- /** Thresholds for branches */
2328
- branches?: number;
2329
- /** Thresholds for lines */
2330
- lines?: number;
2371
+ includeSamples?: boolean;
2331
2372
  }
2332
2373
 
2333
2374
  type BuiltinEnvironment = "node" | "jsdom" | "happy-dom" | "edge-runtime";
@@ -2595,7 +2636,7 @@ interface InlineConfig {
2595
2636
  *
2596
2637
  * @default []
2597
2638
  */
2598
- reporters?: Arrayable$1<ReporterName | InlineReporter> | ((ReporterName | InlineReporter) | [ReporterName] | ReporterWithOptions)[];
2639
+ reporters?: Arrayable<ReporterName | InlineReporter> | ((ReporterName | InlineReporter) | [ReporterName] | ReporterWithOptions)[];
2599
2640
  /**
2600
2641
  * Write test results to a file when the --reporter=json` or `--reporter=junit` option is also specified.
2601
2642
  * Also definable individually per reporter by using an object instead.
@@ -3189,5 +3230,5 @@ type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
3189
3230
  });
3190
3231
  type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
3191
3232
 
3192
- export { CoverageMap as C, TestSuite as E, Logger as L, TestProject as T, Vitest as V, BenchmarkReporter as aA, BenchmarkReportsMap as aB, DefaultReporter as aC, DotReporter as aD, GithubActionsReporter as aE, HangingProcessReporter as aF, JsonReporter as aG, JUnitReporter as aH, ReportersMap as aI, TapFlatReporter as aJ, TapReporter as aK, VerboseBenchmarkReporter as aL, VerboseReporter as aM, BaseReporter as aN, TestSpecification as l, VitestPackageInstaller as n, getFilePoolName as p, TestCase as s, TestCollection as t, TestModule as v };
3193
- export type { BrowserOrchestrator as $, ApiConfig as A, TestResultSkipped as B, TestState as D, TestSuiteState as F, TestSequencerConstructor as G, HTMLOptions as H, InlineConfig as I, JsonOptions$1 as J, BenchmarkUserOptions as K, ModuleDiagnostic as M, BrowserBuiltinProvider as N, OnServerRestartHandler as O, ProcessPool as P, BrowserCommand as Q, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, BrowserCommandContext as X, BrowserConfigOptions as Y, BrowserInstanceOption as Z, BrowserModuleMocker as _, TestProjectConfiguration as a, BrowserProvider as a0, BrowserProviderInitializationOptions as a1, BrowserProviderModule as a2, BrowserProviderOptions as a3, BrowserScript as a4, BrowserServerState as a5, BrowserServerStateSession as a6, CDPSession as a7, ParentProjectBrowser as a8, ProjectBrowser as a9, BenchmarkBuiltinReporters as aO, BuiltinReporterOptions as aP, BuiltinReporters as aQ, JsonAssertionResult as aR, JsonTestResult as aS, JsonTestResults as aT, ResolvedBrowserOptions as aa, ToMatchScreenshotComparators as ab, ToMatchScreenshotOptions as ac, BuiltinEnvironment as ad, CSSModuleScopeStrategy as ae, DepsOptimizationOptions as af, EnvironmentOptions as ag, Pool as ah, PoolOptions as ai, ProjectConfig as aj, ResolvedProjectConfig as ak, ResolveSnapshotPathHandler as al, ResolveSnapshotPathHandlerContext as am, TypecheckConfig as an, VitestEnvironment as ao, BaseCoverageOptions as ap, CoverageIstanbulOptions as aq, CoverageOptions as ar, CoverageProvider as as, CoverageProviderModule as at, CoverageReporter as au, CustomProviderOptions as av, TestRunResult as aw, ReportedHookContext as ax, Reporter as ay, TestRunEndReason as az, ReportContext as b, CoverageV8Options as c, UserProjectConfigFn as d, UserProjectConfigExport as e, UserConfig as f, TestProjectInlineConfiguration as g, ResolvedConfig as h, VitestRunMode as i, VitestOptions as j, TestSequencer as k, OnTestsRerunHandler as m, WorkspaceSpec as o, JUnitOptions as q, TaskOptions as r, TestDiagnostic as u, TestModuleState as w, TestResult as x, TestResultFailed as y, TestResultPassed as z };
3233
+ export { CoverageMap as C, TestSuite as E, experimental_getRunnerTask as G, Logger as L, TestProject as T, Vitest as V, BenchmarkReporter as aB, BenchmarkReportsMap as aC, DefaultReporter as aD, DotReporter as aE, GithubActionsReporter as aF, HangingProcessReporter as aG, JsonReporter as aH, JUnitReporter as aI, ReportersMap as aJ, TapFlatReporter as aK, TapReporter as aL, VerboseBenchmarkReporter as aM, VerboseReporter as aN, BaseReporter as aO, TestSpecification as l, VitestPackageInstaller as n, getFilePoolName as p, TestCase as s, TestCollection as t, TestModule as v };
3234
+ export type { BrowserModuleMocker as $, ApiConfig as A, TestResultSkipped as B, TestState as D, TestSuiteState as F, HTMLOptions as H, InlineConfig as I, JsonOptions as J, TestSequencerConstructor as K, ModuleDiagnostic as M, BenchmarkUserOptions as N, OnServerRestartHandler as O, ProcessPool as P, BrowserBuiltinProvider as Q, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, BrowserCommand as X, BrowserCommandContext as Y, BrowserConfigOptions as Z, BrowserInstanceOption as _, TestProjectConfiguration as a, BrowserOrchestrator as a0, BrowserProvider as a1, BrowserProviderInitializationOptions as a2, BrowserProviderModule as a3, BrowserProviderOptions as a4, BrowserScript as a5, BrowserServerState as a6, BrowserServerStateSession as a7, CDPSession as a8, ParentProjectBrowser as a9, TestRunEndReason as aA, BenchmarkBuiltinReporters as aP, BuiltinReporterOptions as aQ, BuiltinReporters as aR, JsonAssertionResult as aS, JsonTestResult as aT, JsonTestResults as aU, ProjectBrowser as aa, ResolvedBrowserOptions as ab, ToMatchScreenshotComparators as ac, ToMatchScreenshotOptions as ad, BuiltinEnvironment as ae, CSSModuleScopeStrategy as af, DepsOptimizationOptions as ag, EnvironmentOptions as ah, Pool as ai, PoolOptions as aj, ProjectConfig as ak, ResolvedProjectConfig as al, ResolveSnapshotPathHandler as am, ResolveSnapshotPathHandlerContext as an, TypecheckConfig as ao, VitestEnvironment as ap, BaseCoverageOptions as aq, CoverageIstanbulOptions as ar, CoverageOptions as as, CoverageProvider as at, CoverageProviderModule as au, CoverageReporter as av, CustomProviderOptions as aw, TestRunResult as ax, ReportedHookContext as ay, Reporter as az, ReportContext as b, CoverageV8Options as c, UserProjectConfigFn as d, UserProjectConfigExport as e, UserConfig as f, TestProjectInlineConfiguration as g, ResolvedConfig as h, VitestRunMode as i, VitestOptions as j, TestSequencer as k, OnTestsRerunHandler as m, WorkspaceSpec as o, JUnitOptions as q, TaskOptions as r, TestDiagnostic as u, TestModuleState as w, TestResult as x, TestResultFailed as y, TestResultPassed as z };