vitest 4.1.12 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +192 -10
- package/browser/context.d.ts +7 -1
- package/browser/context.js +5 -5
- package/config.d.ts +0 -2
- package/dist/browser.d.ts +52 -21
- package/dist/browser.js +12 -13
- package/dist/chunks/{acorn.B2iPLyUM.js → acorn.C1kjbUFw.js} +30 -30
- package/dist/chunks/{base.B6Opl8PE.js → base.Cof-UHJf.js} +81 -52
- package/dist/chunks/{browser.d.BcoexmFG.d.ts → browser.d.C7tWgUvw.d.ts} +17 -14
- package/dist/chunks/{cac.DzDtg8hz.js → cac.BYbt0aJp.js} +143 -87
- package/dist/chunks/{cli-api.B0Pz1_R7.js → cli-api.COfZo8lK.js} +7160 -7189
- package/dist/chunks/config.d.B3YV4t0O.d.ts +3873 -0
- package/dist/chunks/{console.3WNpx0tS.js → console.CQZ877Hi.js} +69 -63
- package/dist/chunks/{constants.CPYnjOGj.js → constants.DLYM6cZY.js} +2 -2
- package/dist/chunks/coverage.9iqXE2gN.js +26 -0
- package/dist/chunks/{coverage.CTzCuANN.js → coverage.jGCktcGP.js} +7 -2
- package/dist/chunks/{creator.DgVhQm5q.js → creator.DHWmytIK.js} +65 -28
- package/dist/chunks/{defaults.9aQKnqFk.js → defaults.B1FCaFfh.js} +16 -9
- package/dist/chunks/display.BlTmubjj.js +194 -0
- package/dist/chunks/doctor.B-oPbwps.js +465 -0
- package/dist/chunks/{env.D4Lgay0q.js → env.BKKtU2WC.js} +2 -1
- package/dist/chunks/{environment.d.CrsxCzP1.d.ts → environment.d.BFQtFKdZ.d.ts} +9 -1
- package/dist/chunks/globals.ZKtKSkEf.js +29 -0
- package/dist/chunks/index.Bi0NXYPf.js +1708 -0
- package/dist/chunks/{index.CMESou6r.js → index.BoyTG_B7.js} +82 -81
- package/dist/chunks/index.CZzC1gGg.js +8501 -0
- package/dist/chunks/index.D0heQG4v.js +1318 -0
- package/dist/chunks/index.Di8au7q4.js +15665 -0
- package/dist/chunks/{index.Chj8NDwU.js → index.DmDMHCg8.js} +6 -12
- package/dist/chunks/{index.DXx9Dtk7.js → index.w_oBZ9N8.js} +25 -12
- package/dist/chunks/{init-forks.H5ZuobOQ.js → init-forks.BaDXQSD8.js} +7 -10
- package/dist/chunks/{init-threads.6kl1khcL.js → init-threads.ZX_Vov0z.js} +1 -1
- package/dist/chunks/{init.k9zZ9sLh.js → init.CO4AB7HZ.js} +113 -38
- package/dist/chunks/module-dependencies._2Eei3FO.js +71 -0
- package/dist/chunks/{native.DPzPHdi5.js → native.upB-V0CK.js} +50 -37
- package/dist/chunks/{nativeModuleMocker.BkNfQMkH.js → nativeModuleMocker.Dh5azSB4.js} +48 -19
- package/dist/chunks/{index.BCY_7LL2.js → nativeModuleRunner.9xPIMzi7.js} +110 -42
- package/dist/chunks/node.B9mkVmLH.js +47 -0
- package/dist/chunks/offset.Dy-5Fdfn.js +24 -0
- package/dist/chunks/pathe.M-eThtNZ.zq3TM4NT.js +492 -0
- package/dist/chunks/{reporters.d.DtoKVV2s.d.ts → plugin.d.LRFSN46m.d.ts} +2573 -1453
- package/dist/chunks/plugins.DPQHVT0p.js +37 -0
- package/dist/chunks/rawSnapshot.DqSiqIEx.js +356 -0
- package/dist/chunks/resolver.BzpmeQeT.js +48 -0
- package/dist/chunks/rpc.Uhkwr2NM.js +93 -0
- package/dist/chunks/rpc.d.3FOhdFx8.d.ts +75 -0
- package/dist/chunks/run.CjdgFZiW.js +4231 -0
- package/dist/chunks/setup-common.CqAQCXzx.js +36 -0
- package/dist/chunks/source-map.DakdQc29.js +1788 -0
- package/dist/chunks/source-map.d.BkG8YK_3.d.ts +89 -0
- package/dist/chunks/spy.DDMXghXv.js +509 -0
- package/dist/chunks/task-utils.d.D-gFPNFi.d.ts +144 -0
- package/dist/chunks/tinyrainbow.Do8I1XRG.js +88 -0
- package/dist/chunks/{utils.BS4fH3nR.js → utils.BBk_icFG.js} +50 -52
- package/dist/chunks/{utils.BX5Fg8C4.js → utils.DYj33du9.js} +1 -17
- package/dist/chunks/vm.b4MbCAJQ.js +1329 -0
- package/dist/chunks/{worker.d.ZpHpO4yb.d.ts → worker.d.CyJRpyfZ.d.ts} +34 -19
- package/dist/cli.js +5 -6
- package/dist/config.cjs +9 -6
- package/dist/config.d.ts +27 -25
- package/dist/config.js +3 -3
- package/dist/index.d.ts +471 -38
- package/dist/index.js +18 -19
- package/dist/module-evaluator.d.ts +64 -5
- package/dist/module-evaluator.js +122 -62
- package/dist/node.d.ts +355 -87
- package/dist/node.js +49 -73
- package/dist/runtime.d.ts +43 -6
- package/dist/runtime.js +7 -9
- package/dist/spy.js +1 -1
- package/dist/task-utils.js +290 -0
- package/dist/{chunks/traces.DT5aQ62U.js → traces.js} +3 -2
- package/dist/worker.d.ts +8 -10
- package/dist/worker.js +33 -43
- package/dist/workers/forks.js +30 -40
- package/dist/workers/runVmTests.js +66 -43
- package/dist/workers/threads.js +30 -40
- package/dist/workers/vmForks.js +19 -20
- package/dist/workers/vmThreads.js +19 -20
- package/globals.d.ts +19 -19
- package/index.cjs +3 -3
- package/optional-runtime-types.d.ts +1 -1
- package/optional-types.d.ts +1 -1
- package/package.json +59 -74
- package/suppress-warnings.cjs +1 -1
- package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +0 -6
- package/dist/chunks/benchmark.CX_oY03V.js +0 -40
- package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +0 -24
- package/dist/chunks/config.d.A1h_Y6Jt.d.ts +0 -232
- package/dist/chunks/coverage.DM_a_rWm.js +0 -1087
- package/dist/chunks/coverage.d.BZtK59WP.d.ts +0 -37
- package/dist/chunks/evaluatedModules.Dg1zASAC.js +0 -17
- package/dist/chunks/global.d.DVsSRdQ5.d.ts +0 -100
- package/dist/chunks/globals.Dj1TGiMC.js +0 -31
- package/dist/chunks/index.DC7d2Pf8.js +0 -729
- package/dist/chunks/index.DdgEv5B1.js +0 -42
- package/dist/chunks/index.UpGiHP7g.js +0 -4255
- package/dist/chunks/index.og1WyBLx.js +0 -6358
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +0 -36
- package/dist/chunks/node.COQbm6gK.js +0 -14
- package/dist/chunks/plugin.d.DwFIiJ7i.d.ts +0 -38
- package/dist/chunks/rpc.MzXet3jl.js +0 -144
- package/dist/chunks/rpc.d.B_8sPU0w.d.ts +0 -30
- package/dist/chunks/setup-common.DYx3LtFI.js +0 -60
- package/dist/chunks/startVitestModuleRunner.DB-7oCpn.js +0 -740
- package/dist/chunks/suite.d.udJtyAgw.d.ts +0 -10
- package/dist/chunks/test.DNmyFkvJ.js +0 -4430
- package/dist/chunks/traces.d.D2T_R8rx.d.ts +0 -60
- package/dist/chunks/vm.CXMd5FHa.js +0 -785
- package/dist/coverage.d.ts +0 -123
- package/dist/coverage.js +0 -27
- package/dist/environments.d.ts +0 -22
- package/dist/environments.js +0 -5
- package/dist/reporters.d.ts +0 -27
- package/dist/reporters.js +0 -26
- package/dist/runners.d.ts +0 -70
- package/dist/runners.js +0 -19
- package/dist/snapshot.d.ts +0 -9
- package/dist/snapshot.js +0 -6
- package/dist/suite.d.ts +0 -5
- package/dist/suite.js +0 -8
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TestError, SerializedError,
|
|
3
|
-
import { a as AfterSuiteRunMeta, U as UserConsoleLog, A as AsyncLeak, P as ProvidedContext, O as OTELCarrier, L as LabelColor } from './traces.d.D2T_R8rx.js';
|
|
1
|
+
import { DevEnvironment, IndexHtmlTransformContext, IndexHtmlTransformResult, ViteDevServer, UserConfig as UserConfig$1, Plugin, ResolvedConfig as ResolvedConfig$1, ESTree, TransformResult as TransformResult$1, InlineConfig as InlineConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
|
|
2
|
+
import { aW as TaskMeta, U as UserConsoleLog, Q as Suite, a as File, bk as SerializableRetry, T as TestError, h as TestAnnotation, j as TestArtifact, b2 as TestBenchmark, aL as SerializedError, a1 as ImportDuration, n as Test, A as Awaitable, Z as CancelReason, P as ParsedStack, bl as BrowserTraceViewMode, bm as BrowserTraceViewRecordingMode, a6 as BaselineData, p as ProvidedContext, b as SerializedConfig, bn as Arrayable, a3 as AfterSuiteRunMeta, aQ as SnapshotStateOptions, aR as SnapshotSummary, aO as SnapshotResult, Y as Task, bo as AsyncLeak, k as TaskResultPack, F as FileSpecification, m as SerializedRootConfig, L as LabelColor, c as SerializedDiffOptions, bi as SequenceSetupFiles, bh as SequenceHooks, bp as PrettyFormatOptions, e as FakeTimersConfig, g as TestTagDefinition } from './config.d.B3YV4t0O.js';
|
|
4
3
|
import { Writable } from 'node:stream';
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import { S as SerializedTestSpecification, c as SourceModuleDiagnostic, B as BrowserTesterOptions } from './browser.d.BcoexmFG.js';
|
|
8
|
-
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
9
|
-
import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
|
|
10
|
-
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
11
|
-
import { chai } from '@vitest/expect';
|
|
4
|
+
import { S as SerializedTestSpecification, B as BrowserTesterOptions, c as SourceModuleDiagnostic } from './browser.d.C7tWgUvw.js';
|
|
5
|
+
import * as chai from 'chai';
|
|
12
6
|
import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
7
|
+
import { a as ContextTestEnvironment, b as WorkerExecuteContext, c as WorkerTestEnvironment } from './worker.d.CyJRpyfZ.js';
|
|
8
|
+
import { O as OTELCarrier } from './rpc.d.3FOhdFx8.js';
|
|
15
9
|
import { MockedModule } from '@vitest/mocker';
|
|
16
|
-
import { StackTraceParserOptions } from '
|
|
17
|
-
import { CDPSession, BrowserCommands } from 'vitest/browser';
|
|
18
|
-
import
|
|
19
|
-
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
10
|
+
import { S as StackTraceParserOptions, a as RuntimeCoverageProviderModule } from './source-map.d.BkG8YK_3.js';
|
|
11
|
+
import { CDPSession, BrowserCommands, MarkOptions } from 'vitest/browser';
|
|
12
|
+
import path from 'node:path';
|
|
20
13
|
import { Console } from 'node:console';
|
|
21
|
-
import {
|
|
14
|
+
import { writeFile } from 'node:fs/promises';
|
|
22
15
|
|
|
23
16
|
type ChaiConfig = Omit<Partial<typeof chai.config>, "useProxy" | "proxyExcludedKeys" | "deepEqual">;
|
|
24
17
|
|
|
@@ -71,52 +64,6 @@ interface ConstructorOptionsOverride {
|
|
|
71
64
|
resources?: "usable";
|
|
72
65
|
}
|
|
73
66
|
|
|
74
|
-
interface TestSpecificationOptions {
|
|
75
|
-
testNamePattern?: RegExp;
|
|
76
|
-
testIds?: string[];
|
|
77
|
-
testLines?: number[];
|
|
78
|
-
testTagsFilter?: string[];
|
|
79
|
-
}
|
|
80
|
-
declare class TestSpecification {
|
|
81
|
-
/**
|
|
82
|
-
* The task id associated with the test module.
|
|
83
|
-
*/
|
|
84
|
-
readonly taskId: string;
|
|
85
|
-
/**
|
|
86
|
-
* The test project that the module belongs to.
|
|
87
|
-
*/
|
|
88
|
-
readonly project: TestProject;
|
|
89
|
-
/**
|
|
90
|
-
* The id of the module in the Vite module graph. It is usually an absolute file path.
|
|
91
|
-
*/
|
|
92
|
-
readonly moduleId: string;
|
|
93
|
-
/**
|
|
94
|
-
* The current test pool. It's possible to have multiple pools in a single test project with `typecheck.enabled`.
|
|
95
|
-
*/
|
|
96
|
-
readonly pool: Pool;
|
|
97
|
-
/**
|
|
98
|
-
* Line numbers of the test locations to run.
|
|
99
|
-
*/
|
|
100
|
-
testLines: number[] | undefined;
|
|
101
|
-
/**
|
|
102
|
-
* Regular expression pattern to filter test names.
|
|
103
|
-
*/
|
|
104
|
-
testNamePattern: RegExp | undefined;
|
|
105
|
-
/**
|
|
106
|
-
* The ids of tasks inside of this specification to run.
|
|
107
|
-
*/
|
|
108
|
-
testIds: string[] | undefined;
|
|
109
|
-
/**
|
|
110
|
-
* The tags of tests to run.
|
|
111
|
-
*/
|
|
112
|
-
testTagsFilter: string[] | undefined;
|
|
113
|
-
/**
|
|
114
|
-
* Test module associated with the specification. This will be `undefined` if tests have not been run yet.
|
|
115
|
-
*/
|
|
116
|
-
get testModule(): TestModule | undefined;
|
|
117
|
-
toJSON(): SerializedTestSpecification;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
67
|
declare class ReportedTaskImplementation {
|
|
121
68
|
/**
|
|
122
69
|
* The project associated with the test or suite.
|
|
@@ -144,6 +91,10 @@ declare class ReportedTaskImplementation {
|
|
|
144
91
|
* Custom metadata that was attached to the test during its execution.
|
|
145
92
|
*/
|
|
146
93
|
meta(): TaskMeta;
|
|
94
|
+
/**
|
|
95
|
+
* Console logs recorded during the test execution.
|
|
96
|
+
*/
|
|
97
|
+
logs(): ReadonlyArray<UserConsoleLog>;
|
|
147
98
|
}
|
|
148
99
|
declare class TestCase extends ReportedTaskImplementation {
|
|
149
100
|
#private;
|
|
@@ -181,6 +132,10 @@ declare class TestCase extends ReportedTaskImplementation {
|
|
|
181
132
|
*/
|
|
182
133
|
result(): TestResult;
|
|
183
134
|
/**
|
|
135
|
+
* Individual results for every retry and repeat attempt.
|
|
136
|
+
*/
|
|
137
|
+
attempts(): ReadonlyArray<TestAttempt>;
|
|
138
|
+
/**
|
|
184
139
|
* Test annotations added via the `task.annotate` API during the test execution.
|
|
185
140
|
*/
|
|
186
141
|
annotations(): ReadonlyArray<TestAnnotation>;
|
|
@@ -191,6 +146,12 @@ declare class TestCase extends ReportedTaskImplementation {
|
|
|
191
146
|
*/
|
|
192
147
|
artifacts(): ReadonlyArray<TestArtifact>;
|
|
193
148
|
/**
|
|
149
|
+
* @experimental
|
|
150
|
+
*
|
|
151
|
+
* A list of benchmarks performed during the test.
|
|
152
|
+
*/
|
|
153
|
+
benchmarks(): ReadonlyArray<TestBenchmark>;
|
|
154
|
+
/**
|
|
194
155
|
* Useful information about the test like duration, memory usage, etc.
|
|
195
156
|
* Diagnostic is only available after the test has finished.
|
|
196
157
|
*/
|
|
@@ -348,9 +309,27 @@ interface TaskOptions {
|
|
|
348
309
|
readonly timeout: number | undefined;
|
|
349
310
|
readonly mode: "run" | "only" | "skip" | "todo";
|
|
350
311
|
}
|
|
351
|
-
type
|
|
312
|
+
type TestAttemptState = "skipped" | "failed" | "passed";
|
|
313
|
+
type TestSuiteState = TestAttemptState | "pending";
|
|
352
314
|
type TestModuleState = TestSuiteState | "queued";
|
|
353
315
|
type TestState = TestResult["state"];
|
|
316
|
+
/**
|
|
317
|
+
* The result of an individual test attempt.
|
|
318
|
+
*/
|
|
319
|
+
interface TestAttempt {
|
|
320
|
+
/** The state after applying the test's expected failure option. */
|
|
321
|
+
readonly state: TestAttemptState;
|
|
322
|
+
/** Errors produced by this attempt. */
|
|
323
|
+
readonly errors: ReadonlyArray<TestError> | undefined;
|
|
324
|
+
/** How long in milliseconds the attempt took to run. */
|
|
325
|
+
readonly duration: number;
|
|
326
|
+
/** Time in milliseconds when the attempt started running. */
|
|
327
|
+
readonly startTime: number;
|
|
328
|
+
/** The zero-based retry index within the repeat. */
|
|
329
|
+
readonly retryIndex: number;
|
|
330
|
+
/** The zero-based repeat index. */
|
|
331
|
+
readonly repeatIndex: number;
|
|
332
|
+
}
|
|
354
333
|
type TestResult = TestResultPassed | TestResultFailed | TestResultSkipped | TestResultPending;
|
|
355
334
|
interface TestResultPending {
|
|
356
335
|
/**
|
|
@@ -462,1594 +441,2396 @@ interface ModuleDiagnostic {
|
|
|
462
441
|
* The time spent importing every non-externalized dependency that Vitest has processed.
|
|
463
442
|
*/
|
|
464
443
|
readonly importDurations: Record<string, ImportDuration>;
|
|
444
|
+
/**
|
|
445
|
+
* The id of the worker that ran this file. This value cannot be higher than `maxWorkers`.
|
|
446
|
+
* If file did not run yet, this will be 0.
|
|
447
|
+
*
|
|
448
|
+
* **Warning**: Node.js tests and browser tests run in different pools and do not share `concurrencyId`.
|
|
449
|
+
* It is possible to have multiple modules with the same `concurrencyId` because of that.
|
|
450
|
+
* Use `project.isBrowserEnabled()` to distinguish the concurrency.
|
|
451
|
+
* @since 5.0.0
|
|
452
|
+
*/
|
|
453
|
+
readonly concurrencyId: number;
|
|
454
|
+
/**
|
|
455
|
+
* Incremental number of the worker that ran this file. This number increases with each worker.
|
|
456
|
+
* If file did not run yet, this will be 0.
|
|
457
|
+
*
|
|
458
|
+
* **Warning**: Node.js tests and browser tests run in different pools and do not share `workerId`.
|
|
459
|
+
* It is possible to have multiple modules with the same `workerId` because of that.
|
|
460
|
+
* Use `project.isBrowserEnabled()` to distinguish the concurrency.
|
|
461
|
+
* @since 5.0.0
|
|
462
|
+
*/
|
|
463
|
+
readonly workerId: number;
|
|
465
464
|
}
|
|
466
465
|
declare function experimental_getRunnerTask(entity: TestCase): Test;
|
|
467
466
|
declare function experimental_getRunnerTask(entity: TestSuite): Suite;
|
|
468
467
|
declare function experimental_getRunnerTask(entity: TestModule): File;
|
|
469
468
|
declare function experimental_getRunnerTask(entity: TestCase | TestSuite | TestModule): Suite | File | Test;
|
|
470
469
|
|
|
471
|
-
interface
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
declare class CoverageSummary {
|
|
479
|
-
constructor(data: CoverageSummary | CoverageSummaryData);
|
|
480
|
-
merge(obj: CoverageSummary): CoverageSummary;
|
|
481
|
-
toJSON(): CoverageSummaryData;
|
|
482
|
-
isEmpty(): boolean;
|
|
483
|
-
data: CoverageSummaryData;
|
|
484
|
-
lines: Totals;
|
|
485
|
-
statements: Totals;
|
|
486
|
-
branches: Totals;
|
|
487
|
-
functions: Totals;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
interface CoverageMapData {
|
|
491
|
-
[key: string]: FileCoverage | FileCoverageData;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
declare class CoverageMap {
|
|
495
|
-
constructor(data: CoverageMapData | CoverageMap);
|
|
496
|
-
addFileCoverage(pathOrObject: string | FileCoverage | FileCoverageData): void;
|
|
497
|
-
files(): string[];
|
|
498
|
-
fileCoverageFor(filename: string): FileCoverage;
|
|
499
|
-
filter(callback: (key: string) => boolean): void;
|
|
500
|
-
getCoverageSummary(): CoverageSummary;
|
|
501
|
-
merge(data: CoverageMapData | CoverageMap): void;
|
|
502
|
-
toJSON(): CoverageMapData;
|
|
503
|
-
data: CoverageMapData;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
interface Location {
|
|
507
|
-
line: number;
|
|
508
|
-
column: number;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
interface Range {
|
|
512
|
-
start: Location;
|
|
513
|
-
end: Location;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
interface BranchMapping {
|
|
517
|
-
loc: Range;
|
|
518
|
-
type: string;
|
|
519
|
-
locations: Range[];
|
|
520
|
-
line: number;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
interface FunctionMapping {
|
|
524
|
-
name: string;
|
|
525
|
-
decl: Range;
|
|
526
|
-
loc: Range;
|
|
527
|
-
line: number;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
interface FileCoverageData {
|
|
531
|
-
path: string;
|
|
532
|
-
statementMap: { [key: string]: Range };
|
|
533
|
-
fnMap: { [key: string]: FunctionMapping };
|
|
534
|
-
branchMap: { [key: string]: BranchMapping };
|
|
535
|
-
s: { [key: string]: number };
|
|
536
|
-
f: { [key: string]: number };
|
|
537
|
-
b: { [key: string]: number[] };
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
interface Totals {
|
|
541
|
-
total: number;
|
|
542
|
-
covered: number;
|
|
543
|
-
skipped: number;
|
|
544
|
-
pct: number;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
interface Coverage {
|
|
548
|
-
covered: number;
|
|
549
|
-
total: number;
|
|
550
|
-
coverage: number;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
declare class FileCoverage implements FileCoverageData {
|
|
554
|
-
constructor(data: string | FileCoverage | FileCoverageData);
|
|
555
|
-
merge(other: FileCoverageData): void;
|
|
556
|
-
getBranchCoverageByLine(): { [line: number]: Coverage };
|
|
557
|
-
getLineCoverage(): { [line: number]: number };
|
|
558
|
-
getUncoveredLines(): number[];
|
|
559
|
-
resetHits(): void;
|
|
560
|
-
computeBranchTotals(): Totals;
|
|
561
|
-
computeSimpleTotals(): Totals;
|
|
562
|
-
toSummary(): CoverageSummary;
|
|
563
|
-
toJSON(): object;
|
|
564
|
-
|
|
565
|
-
data: FileCoverageData;
|
|
566
|
-
path: string;
|
|
567
|
-
statementMap: { [key: string]: Range };
|
|
568
|
-
fnMap: { [key: string]: FunctionMapping };
|
|
569
|
-
branchMap: { [key: string]: BranchMapping };
|
|
570
|
-
s: { [key: string]: number };
|
|
571
|
-
f: { [key: string]: number };
|
|
572
|
-
b: { [key: string]: number[] };
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
interface Node {
|
|
576
|
-
isRoot(): boolean;
|
|
577
|
-
visit(visitor: Visitor, state: any): void;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
interface Visitor<N extends Node = Node> {
|
|
581
|
-
onStart(root: N, state: any): void;
|
|
582
|
-
onSummary(root: N, state: any): void;
|
|
583
|
-
onDetail(root: N, state: any): void;
|
|
584
|
-
onSummaryEnd(root: N, state: any): void;
|
|
585
|
-
onEnd(root: N, state: any): void;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
interface FileOptions {
|
|
589
|
-
file: string;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
interface ProjectOptions {
|
|
593
|
-
projectRoot: string;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
interface ReportOptions {
|
|
597
|
-
clover: CloverOptions;
|
|
598
|
-
cobertura: CoberturaOptions;
|
|
599
|
-
"html-spa": HtmlSpaOptions;
|
|
600
|
-
html: HtmlOptions;
|
|
601
|
-
json: JsonOptions$1;
|
|
602
|
-
"json-summary": JsonSummaryOptions;
|
|
603
|
-
lcov: LcovOptions;
|
|
604
|
-
lcovonly: LcovOnlyOptions;
|
|
605
|
-
none: never;
|
|
606
|
-
teamcity: TeamcityOptions;
|
|
607
|
-
text: TextOptions;
|
|
608
|
-
"text-lcov": TextLcovOptions;
|
|
609
|
-
"text-summary": TextSummaryOptions;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
interface CloverOptions extends FileOptions, ProjectOptions {}
|
|
613
|
-
|
|
614
|
-
interface CoberturaOptions extends FileOptions, ProjectOptions {}
|
|
615
|
-
|
|
616
|
-
interface HtmlSpaOptions extends HtmlOptions {
|
|
617
|
-
metricsToShow: Array<"lines" | "branches" | "functions" | "statements">;
|
|
470
|
+
interface TestSpecificationOptions {
|
|
471
|
+
testNamePattern?: RegExp;
|
|
472
|
+
testIds?: string[];
|
|
473
|
+
testNames?: string[];
|
|
474
|
+
testLines?: number[];
|
|
475
|
+
testTagsFilter?: string[];
|
|
618
476
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
477
|
+
declare class TestSpecification {
|
|
478
|
+
/**
|
|
479
|
+
* The task id associated with the test module.
|
|
480
|
+
*/
|
|
481
|
+
readonly taskId: string;
|
|
482
|
+
/**
|
|
483
|
+
* The test project that the module belongs to.
|
|
484
|
+
*/
|
|
485
|
+
readonly project: TestProject;
|
|
486
|
+
/**
|
|
487
|
+
* The id of the module in the Vite module graph. It is usually an absolute file path.
|
|
488
|
+
*/
|
|
489
|
+
readonly moduleId: string;
|
|
490
|
+
/**
|
|
491
|
+
* The current test pool. It's possible to have multiple pools in a single test project with `typecheck.enabled`.
|
|
492
|
+
*/
|
|
493
|
+
readonly pool: Pool;
|
|
494
|
+
/**
|
|
495
|
+
* Line numbers of the test locations to run.
|
|
496
|
+
*/
|
|
497
|
+
testLines: number[] | undefined;
|
|
498
|
+
/**
|
|
499
|
+
* Regular expression pattern to filter test names.
|
|
500
|
+
*/
|
|
501
|
+
testNamePattern: RegExp | undefined;
|
|
502
|
+
/**
|
|
503
|
+
* The ids of tasks inside of this specification to run.
|
|
504
|
+
*/
|
|
505
|
+
testIds: string[] | undefined;
|
|
506
|
+
/**
|
|
507
|
+
* The full names of the tests inside of this specification to run, including the parent suites separated with `>`.
|
|
508
|
+
*/
|
|
509
|
+
testNames: string[] | undefined;
|
|
510
|
+
/**
|
|
511
|
+
* The tags of tests to run.
|
|
512
|
+
*/
|
|
513
|
+
testTagsFilter: string[] | undefined;
|
|
514
|
+
/**
|
|
515
|
+
* Test module associated with the specification. This will be `undefined` if tests have not been run yet.
|
|
516
|
+
*/
|
|
517
|
+
get testModule(): TestModule | undefined;
|
|
518
|
+
toJSON(): SerializedTestSpecification;
|
|
624
519
|
}
|
|
625
520
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
interface LcovOnlyOptions extends FileOptions, ProjectOptions {}
|
|
631
|
-
|
|
632
|
-
interface TeamcityOptions extends FileOptions {
|
|
633
|
-
blockName: string;
|
|
521
|
+
interface BrowserModuleMocker {
|
|
522
|
+
register: (sessionId: string, module: MockedModule) => Promise<void>;
|
|
523
|
+
delete: (sessionId: string, url: string) => Promise<void>;
|
|
524
|
+
clear: (sessionId: string) => Promise<void>;
|
|
634
525
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
526
|
+
interface BrowserProviderOption<Options extends object = object> {
|
|
527
|
+
name: string;
|
|
528
|
+
supportedBrowser?: ReadonlyArray<string>;
|
|
529
|
+
options: Options;
|
|
530
|
+
/**
|
|
531
|
+
* Called once for every resolved browser project right before its shared
|
|
532
|
+
* Vite server is created, so the provider can start preparing the browser
|
|
533
|
+
* (e.g. launching it) concurrently. Optional, fire-and-forget: errors must
|
|
534
|
+
* surface through the normal provider flow.
|
|
535
|
+
*/
|
|
536
|
+
prewarm?: (ctx: {
|
|
537
|
+
config: ResolvedConfig;
|
|
538
|
+
vitest: Vitest;
|
|
539
|
+
}) => void;
|
|
540
|
+
providerFactory: (project: TestProject) => BrowserProvider;
|
|
541
|
+
serverFactory: BrowserServerFactory;
|
|
640
542
|
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
interface LinkMapper {
|
|
645
|
-
getPath(node: string | Node): string;
|
|
646
|
-
relativePath(source: string | Node, target: string | Node): string;
|
|
647
|
-
assetPath(node: Node, name: string): string;
|
|
543
|
+
interface BrowserServerFactory {
|
|
544
|
+
(): Promise<BrowserServerContribution>;
|
|
648
545
|
}
|
|
649
|
-
|
|
650
|
-
type TransformResult = string | Partial<TransformResult$1> | undefined | null | void;
|
|
651
|
-
type CoverageResults = unknown;
|
|
652
|
-
interface CoverageProvider {
|
|
546
|
+
interface BrowserProvider {
|
|
653
547
|
name: string;
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
/** Called when setting coverage options for Vitest context (`ctx.config.coverage`) */
|
|
657
|
-
resolveOptions: () => ResolvedCoverageOptions;
|
|
658
|
-
/** Callback to clean previous reports */
|
|
659
|
-
clean: (clean?: boolean) => void | Promise<void>;
|
|
660
|
-
/** Called with coverage results after a single test file has been run */
|
|
661
|
-
onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void | Promise<void>;
|
|
662
|
-
/** Callback called when test run starts */
|
|
663
|
-
onTestRunStart?: () => void | Promise<void>;
|
|
664
|
-
/** Callback called when test run fails due to test failures */
|
|
665
|
-
onTestFailure?: () => void | Promise<void>;
|
|
666
|
-
/** Callback to generate final coverage results */
|
|
667
|
-
generateCoverage: (reportContext: ReportContext) => CoverageResults | Promise<CoverageResults>;
|
|
668
|
-
/** Callback to convert coverage results to coverage reports. Called with results returned from `generateCoverage` */
|
|
669
|
-
reportCoverage: (coverage: CoverageResults, reportContext: ReportContext) => void | Promise<void>;
|
|
670
|
-
/** Callback for `--merge-reports` options. Called with multiple coverage results generated by `generateCoverage`. */
|
|
671
|
-
mergeReports?: (coverages: CoverageResults[]) => void | Promise<void>;
|
|
672
|
-
/** Callback called for instrumenting files with coverage counters. */
|
|
673
|
-
onFileTransform?: (sourceCode: string, id: string, pluginCtx: any) => TransformResult | Promise<TransformResult>;
|
|
548
|
+
mocker?: BrowserModuleMocker;
|
|
549
|
+
readonly initScripts?: string[];
|
|
674
550
|
/**
|
|
675
|
-
*
|
|
676
|
-
* This is used to generate the persistent file hash by `fsModuleCache`
|
|
677
|
-
* @experimental
|
|
551
|
+
* @experimental opt-in into file parallelisation
|
|
678
552
|
*/
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
553
|
+
supportsParallelism: boolean;
|
|
554
|
+
getCommandsContext: (sessionId: string) => Record<string, unknown>;
|
|
555
|
+
openPage: (sessionId: string, url: string, options: {
|
|
556
|
+
parallel: boolean;
|
|
557
|
+
}) => Promise<void>;
|
|
558
|
+
getCDPSession?: (sessionId: string) => Promise<CDPSession>;
|
|
559
|
+
close: (options?: BrowserProviderCloseOptions) => Awaitable<void>;
|
|
686
560
|
}
|
|
687
|
-
interface
|
|
561
|
+
interface BrowserProviderCloseOptions {
|
|
688
562
|
/**
|
|
689
|
-
*
|
|
563
|
+
* The instance is closed to free a slot for another project and can be
|
|
564
|
+
* opened again later, so the provider may keep the browser process alive
|
|
565
|
+
* for the next instance instead of launching a new one.
|
|
566
|
+
* @default false
|
|
690
567
|
*/
|
|
691
|
-
|
|
568
|
+
keepWarm?: boolean;
|
|
692
569
|
}
|
|
693
|
-
type
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
type FieldsWithDefaultValues = "provider" | "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "exclude" | "reportOnFailure" | "allowExternal" | "processingConcurrency" | "reporter" | "excludeAfterRemap" | "ignoreClassMethods" | "skipFull" | "watermarks";
|
|
697
|
-
type ResolvedCoverageOptions = CoverageOptions & Required<Pick<CoverageOptions, FieldsWithDefaultValues>> & {
|
|
698
|
-
reporter: CoverageReporterWithOptions[];
|
|
699
|
-
htmlDir?: string;
|
|
700
|
-
};
|
|
701
|
-
interface CoverageOptions {
|
|
570
|
+
type BrowserBuiltinProvider = "webdriverio" | "playwright" | "preview";
|
|
571
|
+
interface _BrowserNames {}
|
|
572
|
+
interface BrowserTraceViewOptions {
|
|
702
573
|
/**
|
|
703
|
-
*
|
|
574
|
+
* @deprecated Use `mode` instead. `true` is the same as `mode: 'on'`.
|
|
575
|
+
*/
|
|
576
|
+
enabled?: boolean;
|
|
577
|
+
/**
|
|
578
|
+
* How trace view records tests.
|
|
704
579
|
*
|
|
705
|
-
*
|
|
580
|
+
* - `'on'`: every test gets a trace with a snapshot at every step, and Vitest UI shows steps live as tests run.
|
|
581
|
+
* - `'failure-only'`: only failed tests get a trace, with the full step timeline and a snapshot at the end.
|
|
582
|
+
* - `'off'`: no traces.
|
|
583
|
+
*
|
|
584
|
+
* Takes precedence over `enabled`.
|
|
585
|
+
*
|
|
586
|
+
* @default 'failure-only'
|
|
587
|
+
* @experimental
|
|
706
588
|
*/
|
|
707
|
-
|
|
589
|
+
mode?: BrowserTraceViewRecordingMode;
|
|
708
590
|
/**
|
|
709
|
-
*
|
|
591
|
+
* Capture canvas pixels in trace view snapshots.
|
|
592
|
+
*
|
|
593
|
+
* This uses rrweb's canvas snapshot support and can increase trace artifact size.
|
|
594
|
+
* In the trace viewer, this enables a weaker replay iframe sandbox because rrweb needs scripts to redraw canvas data.
|
|
710
595
|
*
|
|
711
596
|
* @default false
|
|
712
597
|
*/
|
|
713
|
-
|
|
598
|
+
recordCanvas?: boolean;
|
|
714
599
|
/**
|
|
715
|
-
*
|
|
716
|
-
* By default only files covered by tests are included.
|
|
600
|
+
* Inline loaded `<img>` element pixels in trace view snapshots.
|
|
717
601
|
*
|
|
718
|
-
*
|
|
602
|
+
* This uses rrweb's image inlining support. It improves offline replay for still images,
|
|
603
|
+
* but can increase trace artifact size and does not preserve original image resource bytes.
|
|
604
|
+
*
|
|
605
|
+
* @default false
|
|
719
606
|
*/
|
|
720
|
-
|
|
607
|
+
inlineImages?: boolean;
|
|
721
608
|
/**
|
|
722
|
-
*
|
|
723
|
-
* Files are first checked against `coverage.include`.
|
|
609
|
+
* Capture the accessibility tree alongside each trace view snapshot.
|
|
724
610
|
*
|
|
725
|
-
*
|
|
726
|
-
*/
|
|
727
|
-
exclude?: string[];
|
|
728
|
-
/**
|
|
729
|
-
* Clean coverage results before running tests
|
|
730
|
-
*
|
|
731
|
-
* @default true
|
|
732
|
-
*/
|
|
733
|
-
clean?: boolean;
|
|
734
|
-
/**
|
|
735
|
-
* Clean coverage report on watch rerun
|
|
611
|
+
* The trace viewer's snapshot pane can then switch between "DOM" and "Aria" views.
|
|
736
612
|
*
|
|
737
613
|
* @default true
|
|
614
|
+
* @experimental
|
|
738
615
|
*/
|
|
739
|
-
|
|
616
|
+
ariaSnapshot?: boolean;
|
|
617
|
+
}
|
|
618
|
+
type UnsupportedProperties = "browser" | "typecheck" | "alias" | "sequence" | "root" | "pool" | "runner" | "api" | "deps" | "environment" | "environmentOptions" | "server" | "benchmark" | "name";
|
|
619
|
+
interface BrowserInstanceOption extends Omit<ProjectConfig, UnsupportedProperties>, Pick<BrowserConfigOptions, "headless" | "locators" | "viewport" | "testerHtmlPath" | "screenshotDirectory" | "screenshotFailures"> {
|
|
740
620
|
/**
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
* @default './coverage'
|
|
621
|
+
* Name of the browser
|
|
744
622
|
*/
|
|
745
|
-
|
|
623
|
+
browser: keyof _BrowserNames extends never ? string : _BrowserNames[keyof _BrowserNames];
|
|
624
|
+
name?: string;
|
|
625
|
+
provider?: BrowserProviderOption;
|
|
626
|
+
}
|
|
627
|
+
interface BrowserConfigOptions {
|
|
746
628
|
/**
|
|
747
|
-
*
|
|
748
|
-
* See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters.
|
|
629
|
+
* if running tests in the browser should be the default
|
|
749
630
|
*
|
|
750
|
-
* @default
|
|
631
|
+
* @default false
|
|
751
632
|
*/
|
|
752
|
-
|
|
633
|
+
enabled?: boolean;
|
|
753
634
|
/**
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
* @default false
|
|
635
|
+
* Configurations for different browser setups
|
|
757
636
|
*/
|
|
758
|
-
|
|
637
|
+
instances?: BrowserInstanceOption[];
|
|
759
638
|
/**
|
|
760
|
-
*
|
|
761
|
-
*
|
|
639
|
+
* Browser provider
|
|
762
640
|
* @example
|
|
763
|
-
*
|
|
764
641
|
* ```ts
|
|
765
|
-
* {
|
|
766
|
-
*
|
|
767
|
-
*
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
*
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
* 'src/utils/**.ts': {
|
|
774
|
-
* lines: 100,
|
|
775
|
-
* statements: 95,
|
|
776
|
-
* }
|
|
777
|
-
* }
|
|
642
|
+
* import { playwright } from '@vitest/browser-playwright'
|
|
643
|
+
* export default defineConfig({
|
|
644
|
+
* test: {
|
|
645
|
+
* browser: {
|
|
646
|
+
* provider: playwright(),
|
|
647
|
+
* },
|
|
648
|
+
* },
|
|
649
|
+
* })
|
|
778
650
|
* ```
|
|
779
651
|
*/
|
|
780
|
-
|
|
781
|
-
[glob: string]: Pick<Thresholds, 100 | "statements" | "functions" | "branches" | "lines">;
|
|
782
|
-
} & Thresholds);
|
|
652
|
+
provider?: BrowserProviderOption;
|
|
783
653
|
/**
|
|
784
|
-
*
|
|
654
|
+
* enable headless mode
|
|
785
655
|
*
|
|
786
|
-
*
|
|
656
|
+
* @default process.env.CI
|
|
787
657
|
*/
|
|
788
|
-
|
|
789
|
-
statements?: [number, number];
|
|
790
|
-
functions?: [number, number];
|
|
791
|
-
branches?: [number, number];
|
|
792
|
-
lines?: [number, number];
|
|
793
|
-
};
|
|
658
|
+
headless?: boolean;
|
|
794
659
|
/**
|
|
795
|
-
*
|
|
660
|
+
* Show Vitest UI
|
|
796
661
|
*
|
|
797
|
-
* @default
|
|
662
|
+
* @default !process.env.CI
|
|
798
663
|
*/
|
|
799
|
-
|
|
664
|
+
ui?: boolean;
|
|
800
665
|
/**
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
666
|
+
* Default position for the details panel in browser mode
|
|
667
|
+
* 'right' shows the details panel on the right side (horizontal split)
|
|
668
|
+
* 'bottom' shows the details panel at the bottom (vertical split)
|
|
669
|
+
* @default 'right'
|
|
804
670
|
*/
|
|
805
|
-
|
|
671
|
+
detailsPanelPosition?: "right" | "bottom";
|
|
806
672
|
/**
|
|
807
|
-
*
|
|
808
|
-
* This is useful when your source files are transpiled and may contain source maps
|
|
809
|
-
* of non-source files.
|
|
810
|
-
*
|
|
811
|
-
* Use this option when you are seeing files that show up in report even if they
|
|
812
|
-
* match your `coverage.exclude` patterns.
|
|
813
|
-
*
|
|
814
|
-
* @default false
|
|
673
|
+
* Default viewport size
|
|
815
674
|
*/
|
|
816
|
-
|
|
675
|
+
viewport?: {
|
|
676
|
+
/**
|
|
677
|
+
* Width of the viewport
|
|
678
|
+
* @default 414
|
|
679
|
+
*/
|
|
680
|
+
width: number;
|
|
681
|
+
/**
|
|
682
|
+
* Height of the viewport
|
|
683
|
+
* @default 896
|
|
684
|
+
*/
|
|
685
|
+
height: number;
|
|
686
|
+
};
|
|
817
687
|
/**
|
|
818
|
-
*
|
|
819
|
-
* Defaults to `Math.min(20, os.availableParallelism?.() ?? os.cpus().length)`
|
|
688
|
+
* Locator options
|
|
820
689
|
*/
|
|
821
|
-
|
|
690
|
+
locators?: {
|
|
691
|
+
/**
|
|
692
|
+
* Attribute used to locate elements by test id
|
|
693
|
+
* @default 'data-testid'
|
|
694
|
+
*/
|
|
695
|
+
testIdAttribute?: string;
|
|
696
|
+
/**
|
|
697
|
+
* Should locators match the text exactly by default
|
|
698
|
+
* @default true
|
|
699
|
+
*/
|
|
700
|
+
exact?: boolean;
|
|
701
|
+
/**
|
|
702
|
+
* Format used for locator "Cannot find element" error details.
|
|
703
|
+
*
|
|
704
|
+
* @default 'all'
|
|
705
|
+
*/
|
|
706
|
+
errorFormat?: "html" | "aria" | "all";
|
|
707
|
+
};
|
|
822
708
|
/**
|
|
823
|
-
*
|
|
709
|
+
* Generate traces that can be viewed on https://trace.playwright.dev/
|
|
824
710
|
*
|
|
825
|
-
*
|
|
711
|
+
* This option is supported only by **playwright** provider.
|
|
826
712
|
*/
|
|
827
|
-
|
|
713
|
+
trace?: BrowserTraceViewMode | {
|
|
714
|
+
mode: BrowserTraceViewMode;
|
|
715
|
+
/**
|
|
716
|
+
* The directory where all traces will be stored. By default, Vitest
|
|
717
|
+
* stores all traces in `__traces__` folder close to the test file.
|
|
718
|
+
*/
|
|
719
|
+
tracesDir?: string;
|
|
720
|
+
/**
|
|
721
|
+
* Whether to capture screenshots during tracing. Screenshots are used to build a timeline preview.
|
|
722
|
+
* @default true
|
|
723
|
+
*/
|
|
724
|
+
screenshots?: boolean;
|
|
725
|
+
/**
|
|
726
|
+
* If this option is true tracing will
|
|
727
|
+
* - capture DOM snapshot on every action
|
|
728
|
+
* - record network activity
|
|
729
|
+
* @default true
|
|
730
|
+
*/
|
|
731
|
+
snapshots?: boolean;
|
|
732
|
+
};
|
|
828
733
|
/**
|
|
829
|
-
*
|
|
734
|
+
* Records the actions, assertions, and marks of browser tests with DOM snapshots for the trace viewer.
|
|
830
735
|
*
|
|
831
|
-
*
|
|
832
|
-
*
|
|
833
|
-
* `
|
|
736
|
+
* - `'failure-only'`: records only failed tests.
|
|
737
|
+
* - `true` or `'on'`: records every test.
|
|
738
|
+
* - `false` or `'off'`: turns trace view off.
|
|
834
739
|
*
|
|
835
|
-
*
|
|
836
|
-
*
|
|
740
|
+
* @default 'failure-only'
|
|
741
|
+
* @see {@link https://vitest.dev/guide/browser/trace-view}
|
|
742
|
+
*/
|
|
743
|
+
traceView?: boolean | BrowserTraceViewRecordingMode | BrowserTraceViewOptions;
|
|
744
|
+
/**
|
|
745
|
+
* Directory where screenshots will be saved when page.screenshot() is called
|
|
746
|
+
* If not set, all screenshots are saved to __screenshots__ directory in the same folder as the test file.
|
|
747
|
+
* If this is set, it will be resolved relative to the project root.
|
|
748
|
+
* @default __screenshots__
|
|
749
|
+
*/
|
|
750
|
+
screenshotDirectory?: string;
|
|
751
|
+
/**
|
|
752
|
+
* Should Vitest take screenshots if the test fails
|
|
753
|
+
* @default !browser.ui
|
|
754
|
+
*/
|
|
755
|
+
screenshotFailures?: boolean;
|
|
756
|
+
/**
|
|
757
|
+
* Serve sourcemaps of your dependencies (files in `node_modules`) to the
|
|
758
|
+
* browser during headless test runs.
|
|
837
759
|
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
840
|
-
*
|
|
841
|
-
*
|
|
760
|
+
* These sourcemaps are used by browser devtools: when disabled, pausing
|
|
761
|
+
* inside dependency code shows the compiled code the browser actually
|
|
762
|
+
* runs instead of the dependency's original sources. If you don't debug
|
|
763
|
+
* into your dependencies this way, disabling them makes test runs faster:
|
|
764
|
+
* the server doesn't generate and inline the maps, and every browser tab
|
|
765
|
+
* downloads several times fewer bytes.
|
|
842
766
|
*
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
*
|
|
846
|
-
* provider: 'istanbul',
|
|
847
|
-
* instrumenter: options => createOxcInstrumenter(options),
|
|
848
|
-
* }
|
|
849
|
-
* }
|
|
850
|
-
* })
|
|
767
|
+
* Reported test errors are not affected: stack frames pointing into a
|
|
768
|
+
* pre-bundled dependency are mapped using the sourcemaps stored on disk
|
|
769
|
+
* even when this option is disabled.
|
|
851
770
|
*
|
|
852
|
-
*
|
|
771
|
+
* Vitest never serves sourcemaps of its own pre-built modules in headless
|
|
772
|
+
* runs (unless `--inspect` is used) — their frames are hidden from stack
|
|
773
|
+
* traces anyway. Sourcemaps of your own source files are always served.
|
|
774
|
+
* @default true
|
|
853
775
|
*/
|
|
854
|
-
|
|
776
|
+
dependencySourcemaps?: boolean;
|
|
855
777
|
/**
|
|
856
|
-
*
|
|
857
|
-
* This is automatically configured for builtin reporter with html output (`html`, `html-spa`, and `lcov` reporters).
|
|
858
|
-
* Use this option to override with custom coverage reporting location.
|
|
778
|
+
* Path to the index.html file that will be used to run tests.
|
|
859
779
|
*/
|
|
860
|
-
|
|
780
|
+
testerHtmlPath?: string;
|
|
861
781
|
/**
|
|
862
|
-
*
|
|
863
|
-
* Inherits the default value from `test.changed`.
|
|
782
|
+
* Scripts injected into the main window.
|
|
864
783
|
*/
|
|
865
|
-
|
|
784
|
+
orchestratorScripts?: BrowserScript[];
|
|
866
785
|
/**
|
|
867
|
-
*
|
|
786
|
+
* Commands that will be executed on the server
|
|
787
|
+
* via the browser `import("vitest/browser").commands` API.
|
|
788
|
+
* @see {@link https://vitest.dev/api/browser/commands}
|
|
868
789
|
*/
|
|
869
|
-
|
|
870
|
-
}
|
|
871
|
-
interface Thresholds {
|
|
872
|
-
/** Set global thresholds to `100` */
|
|
873
|
-
100?: boolean;
|
|
874
|
-
/** Check thresholds per file. */
|
|
875
|
-
perFile?: boolean;
|
|
790
|
+
commands?: Record<string, BrowserCommand<any>>;
|
|
876
791
|
/**
|
|
877
|
-
*
|
|
878
|
-
*
|
|
792
|
+
* Timeout for connecting to the browser
|
|
793
|
+
* @default 60000
|
|
794
|
+
*/
|
|
795
|
+
connectTimeout?: number;
|
|
796
|
+
expect?: {
|
|
797
|
+
toMatchScreenshot?: { [ComparatorName in keyof ToMatchScreenshotComparators]: {
|
|
798
|
+
/**
|
|
799
|
+
* The name of the comparator to use for visual diffing.
|
|
800
|
+
*
|
|
801
|
+
* @defaultValue `'pixelmatch'`
|
|
802
|
+
*/
|
|
803
|
+
comparatorName?: ComparatorName;
|
|
804
|
+
comparatorOptions?: ToMatchScreenshotComparators[ComparatorName];
|
|
805
|
+
} }[keyof ToMatchScreenshotComparators] & ToMatchScreenshotOptions;
|
|
806
|
+
};
|
|
807
|
+
/**
|
|
808
|
+
* Enables tracking uncaught errors and exceptions so they can be reported by Vitest.
|
|
879
809
|
*
|
|
880
|
-
*
|
|
810
|
+
* If you need to hide certain errors, it is recommended to use [`onUnhandledError`](https://vitest.dev/config/onunhandlederror) option instead.
|
|
811
|
+
*
|
|
812
|
+
* Disabling this will completely remove all Vitest error handlers, which can help debugging with the "Pause on exceptions" checkbox turned on.
|
|
813
|
+
* @default true
|
|
881
814
|
*/
|
|
882
|
-
|
|
883
|
-
/**
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
815
|
+
trackUnhandledErrors?: boolean;
|
|
816
|
+
/**
|
|
817
|
+
* Serve module mocks through an import map in the tester document instead of
|
|
818
|
+
* intercepting network requests.
|
|
819
|
+
*
|
|
820
|
+
* By default, Vitest checks once per browser whether it accepts an import map
|
|
821
|
+
* after a module has loaded (Chromium 133+, Safari 18.4+, Firefox 150+ with
|
|
822
|
+
* `dom.multiple_import_maps.enabled`, which the Playwright provider sets) and
|
|
823
|
+
* falls back to request interception otherwise. `true` fails in a browser that
|
|
824
|
+
* cannot, `false` always intercepts.
|
|
825
|
+
*
|
|
826
|
+
* @experimental
|
|
827
|
+
*/
|
|
828
|
+
importMapMocks?: boolean;
|
|
891
829
|
}
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
coverageGlobalScope: string;
|
|
900
|
-
/** Whether the coverage global scope should be resolved through an evaluated function. */
|
|
901
|
-
coverageGlobalScopeFunc: boolean;
|
|
902
|
-
/** Class method names to exclude from function coverage. */
|
|
903
|
-
ignoreClassMethods: string[];
|
|
904
|
-
}
|
|
905
|
-
/**
|
|
906
|
-
* Interface for custom coverage instrumenters.
|
|
907
|
-
*
|
|
908
|
-
* Matches the subset of istanbul-lib-instrument's `Instrumenter` that Vitest
|
|
909
|
-
* actually uses. Implement this to plug in a faster instrumenter while keeping
|
|
910
|
-
* the Istanbul coverage pipeline for collection, merging, and reporting.
|
|
911
|
-
*/
|
|
912
|
-
interface CoverageInstrumenter {
|
|
913
|
-
/** Instrument source code synchronously. Returns the instrumented code string. */
|
|
914
|
-
instrumentSync: (code: string, filename: string, inputSourceMap?: any) => string;
|
|
915
|
-
/** Get the source map of the last instrumented file. */
|
|
916
|
-
lastSourceMap: () => any;
|
|
917
|
-
/** Get the Istanbul-compatible file coverage object of the last instrumented file. */
|
|
918
|
-
lastFileCoverage: () => any;
|
|
919
|
-
}
|
|
920
|
-
/** @deprecated Use `CoverageOptions` instead */
|
|
921
|
-
interface CoverageV8Options extends CoverageOptions {}
|
|
922
|
-
/** @deprecated Use `CoverageOptions` instead */
|
|
923
|
-
interface CoverageIstanbulOptions extends CoverageOptions {}
|
|
924
|
-
/** @deprecated Use `CoverageOptions` instead */
|
|
925
|
-
interface BaseCoverageOptions extends CoverageOptions {}
|
|
926
|
-
/** @deprecated Use `CoverageOptions` instead */
|
|
927
|
-
interface CustomProviderOptions extends CoverageOptions {}
|
|
928
|
-
|
|
929
|
-
interface TestRunResult {
|
|
930
|
-
testModules: TestModule[];
|
|
931
|
-
unhandledErrors: unknown[];
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
interface VCSProviderOptions {
|
|
935
|
-
root: string;
|
|
936
|
-
changedSince?: string | boolean;
|
|
937
|
-
}
|
|
938
|
-
interface VCSProvider {
|
|
939
|
-
findChangedFiles(options: VCSProviderOptions): Promise<string[]>;
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
declare class TypeCheckError extends Error {
|
|
943
|
-
message: string;
|
|
944
|
-
stacks: ParsedStack[];
|
|
945
|
-
name: string;
|
|
946
|
-
constructor(message: string, stacks: ParsedStack[]);
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
interface ErrorOptions {
|
|
950
|
-
type?: string;
|
|
951
|
-
fullStack?: boolean;
|
|
952
|
-
project?: TestProject;
|
|
953
|
-
verbose?: boolean;
|
|
954
|
-
screenshotPaths?: string[];
|
|
955
|
-
task?: Task;
|
|
956
|
-
showCodeFrame?: boolean;
|
|
957
|
-
}
|
|
958
|
-
type Listener = () => void;
|
|
959
|
-
declare class Logger {
|
|
960
|
-
ctx: Vitest;
|
|
961
|
-
outputStream: NodeJS.WriteStream | Writable;
|
|
962
|
-
errorStream: NodeJS.WriteStream | Writable;
|
|
963
|
-
private _clearScreenPending;
|
|
964
|
-
private _highlights;
|
|
965
|
-
private cleanupListeners;
|
|
966
|
-
console: Console;
|
|
967
|
-
constructor(ctx: Vitest, outputStream?: NodeJS.WriteStream | Writable, errorStream?: NodeJS.WriteStream | Writable);
|
|
968
|
-
log(...args: any[]): void;
|
|
969
|
-
error(...args: any[]): void;
|
|
970
|
-
warn(...args: any[]): void;
|
|
971
|
-
clearFullScreen(message?: string): void;
|
|
972
|
-
clearScreen(message: string, force?: boolean): void;
|
|
973
|
-
private _clearScreen;
|
|
974
|
-
printError(err: unknown, options?: ErrorOptions): void;
|
|
975
|
-
deprecate(message: string): void;
|
|
976
|
-
clearHighlightCache(filename?: string): void;
|
|
977
|
-
highlight(filename: string, source: string): string;
|
|
978
|
-
printNoTestTagsFound(): void;
|
|
979
|
-
printTags(): void;
|
|
980
|
-
printNoTestFound(filters?: string[]): void;
|
|
981
|
-
printBanner(): void;
|
|
982
|
-
printBrowserBanner(project: TestProject): void;
|
|
983
|
-
printUnhandledErrors(errors: ReadonlyArray<unknown>): void;
|
|
984
|
-
printSourceTypeErrors(errors: TypeCheckError[]): void;
|
|
985
|
-
getColumns(): number;
|
|
986
|
-
onTerminalCleanup(listener: Listener): void;
|
|
987
|
-
private addCleanupListeners;
|
|
988
|
-
private registerUnhandledRejection;
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
interface SuiteResultCache {
|
|
992
|
-
failed: boolean;
|
|
993
|
-
duration: number;
|
|
830
|
+
interface BrowserCommandContext {
|
|
831
|
+
testPath: string | undefined;
|
|
832
|
+
provider: BrowserProvider;
|
|
833
|
+
project: TestProject;
|
|
834
|
+
sessionId: string;
|
|
835
|
+
mark: (name: string, options?: MarkOptions) => Promise<void>;
|
|
836
|
+
triggerCommand: <K extends keyof BrowserCommands>(name: K, ...args: Parameters<BrowserCommands[K]>) => ReturnType<BrowserCommands[K]>;
|
|
994
837
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
constructor(logger: Logger);
|
|
1003
|
-
getCachePath(): string | null;
|
|
1004
|
-
setConfig(root: string, config: ResolvedConfig["cache"]): void;
|
|
1005
|
-
getResults(key: string): SuiteResultCache | undefined;
|
|
1006
|
-
clearCache(): Promise<void>;
|
|
1007
|
-
readFromCache(): Promise<void>;
|
|
1008
|
-
updateResults(files: File[]): void;
|
|
1009
|
-
removeFromCache(filepath: string): void;
|
|
1010
|
-
writeToCache(): Promise<void>;
|
|
838
|
+
interface BrowserServerStateSession {
|
|
839
|
+
project: TestProject;
|
|
840
|
+
otelCarrier?: OTELCarrier;
|
|
841
|
+
concurrencyId: number;
|
|
842
|
+
connected: () => void;
|
|
843
|
+
ready: () => void;
|
|
844
|
+
fail: (v: Error) => void;
|
|
1011
845
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
populateStats(root: string, specs: TestSpecification[]): Promise<void>;
|
|
1018
|
-
updateStats(fsPath: string, key: string): Promise<void>;
|
|
1019
|
-
removeStats(fsPath: string): void;
|
|
846
|
+
interface BrowserOrchestrator {
|
|
847
|
+
cleanupTesters: () => Promise<void>;
|
|
848
|
+
createTesters: (options: BrowserTesterOptions) => Promise<void>;
|
|
849
|
+
onCancel: (reason: CancelReason) => Promise<void>;
|
|
850
|
+
$close: () => void;
|
|
1020
851
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
results: ResultsCache;
|
|
1024
|
-
stats: FilesStatsCache;
|
|
1025
|
-
constructor(logger: Logger);
|
|
1026
|
-
getFileTestResults(key: string): SuiteResultCache | undefined;
|
|
1027
|
-
getFileStats(key: string): {
|
|
1028
|
-
size: number;
|
|
1029
|
-
} | undefined;
|
|
1030
|
-
static resolveCacheDir(root: string, dir?: string, projectName?: string): string;
|
|
852
|
+
interface BrowserServerState {
|
|
853
|
+
orchestrators: Map<string, BrowserOrchestrator>;
|
|
1031
854
|
}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
ensureInstalled(dependency: string, root: string, version?: string): Promise<boolean>;
|
|
855
|
+
interface ParentProjectBrowser {
|
|
856
|
+
spawn: (project: TestProject) => ProjectBrowser;
|
|
857
|
+
vite: ViteDevServer;
|
|
858
|
+
vitest: Vitest;
|
|
859
|
+
config: ResolvedConfig;
|
|
1038
860
|
}
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
onInit?: (vitest: Vitest) => void;
|
|
861
|
+
interface BrowserServerContribution {
|
|
862
|
+
transformIndexHtml: (ctx: IndexHtmlTransformContext) => Awaitable<IndexHtmlTransformResult | undefined>;
|
|
863
|
+
configureServer: (server: ViteDevServer) => Awaitable<void>;
|
|
1043
864
|
/**
|
|
1044
|
-
*
|
|
1045
|
-
*
|
|
865
|
+
* Browser-specific Vite config (`resolve.alias`, `define`, esbuild). Applied
|
|
866
|
+
* by the core loader plugin's `config` hook during the single project
|
|
867
|
+
* resolution, so other plugins observe it (e.g. alias must be baked at
|
|
868
|
+
* resolution time). The loader always forces `server.middlewareMode = false`
|
|
869
|
+
* on top. `harness` provides the package installer's `isPackageExists` (no
|
|
870
|
+
* `Vitest` instance is available during resolution).
|
|
1046
871
|
*/
|
|
1047
|
-
|
|
1048
|
-
onTestRemoved?: (trigger?: string) => Awaitable<void>;
|
|
1049
|
-
onWatcherStart?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
|
|
1050
|
-
onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
|
|
1051
|
-
onServerRestart?: (reason?: string) => Awaitable<void>;
|
|
1052
|
-
onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
|
|
1053
|
-
onProcessTimeout?: () => Awaitable<void>;
|
|
872
|
+
config: (config: UserConfig$1, harness: PluginHarness) => Awaitable<UserConfig$1>;
|
|
1054
873
|
/**
|
|
1055
|
-
*
|
|
874
|
+
* Browser `optimizeDeps`, aggregated across every project that shares the
|
|
875
|
+
* single browser Vite server (instance and benchmark variants). Called by core
|
|
876
|
+
* after all projects are resolved and before the server is created; the result
|
|
877
|
+
* is merged into the resolved Vite config's `client` environment
|
|
878
|
+
* `optimizeDeps`. `testFiles` is the aggregated, already-globbed set of test
|
|
879
|
+
* files for the server (globbing lives in the core package).
|
|
1056
880
|
*/
|
|
1057
|
-
|
|
881
|
+
resolveOptimizeDeps: (projectConfigs: ResolvedConfig[], testFiles: string[], harness: PluginHarness) => Awaitable<NonNullable<UserConfig$1["optimizeDeps"]>>;
|
|
1058
882
|
/**
|
|
1059
|
-
*
|
|
883
|
+
* Runtime plugins. Injected into the browser (`client`) environment by the
|
|
884
|
+
* loader's `applyToEnvironment`; their `configureServer`/`transformIndexHtml`
|
|
885
|
+
* are run by the loader. MUST NOT define `config`/`configResolved` hooks.
|
|
1060
886
|
*/
|
|
1061
|
-
|
|
887
|
+
plugins: Plugin[];
|
|
1062
888
|
/**
|
|
1063
|
-
*
|
|
889
|
+
* Constructs the `ParentBrowserProject`. Called by core at server creation,
|
|
890
|
+
* when the `Vitest` instance exists.
|
|
1064
891
|
*/
|
|
1065
|
-
|
|
892
|
+
createParent: (ctx: {
|
|
893
|
+
config: ResolvedConfig;
|
|
894
|
+
vitest: Vitest;
|
|
895
|
+
}) => ParentProjectBrowser;
|
|
896
|
+
/** Called by core once the server exists to wire up the browser RPC (the port may be bound later). */
|
|
897
|
+
setupRpc: (parent: ParentProjectBrowser) => void;
|
|
1066
898
|
/**
|
|
1067
|
-
*
|
|
899
|
+
* Mutable. Filled by core at server creation; the pushed `BrowserPlugin`
|
|
900
|
+
* closes over this same object and reads `.parent` in `configureServer`.
|
|
1068
901
|
*/
|
|
1069
|
-
|
|
902
|
+
parent?: ParentProjectBrowser;
|
|
903
|
+
}
|
|
904
|
+
interface ProjectBrowser {
|
|
905
|
+
vite: ViteDevServer;
|
|
906
|
+
state: BrowserServerState;
|
|
1070
907
|
/**
|
|
1071
|
-
*
|
|
908
|
+
* The provider of the open browser instance. It is `undefined` until the instance
|
|
909
|
+
* starts running tests and after the instance is closed to free a worker slot.
|
|
1072
910
|
*/
|
|
1073
|
-
|
|
911
|
+
provider: BrowserProvider | undefined;
|
|
912
|
+
close: () => Promise<void>;
|
|
913
|
+
initBrowserProvider: (project: TestProject) => Promise<void>;
|
|
914
|
+
closeBrowserProvider: (options?: BrowserProviderCloseOptions) => Promise<void>;
|
|
915
|
+
parseStacktrace: (stack: string, options?: StackTraceParserOptions) => ParsedStack[];
|
|
916
|
+
parseErrorStacktrace: (error: TestError, options?: StackTraceParserOptions) => ParsedStack[];
|
|
917
|
+
registerCommand: <K extends keyof BrowserCommands>(name: K, cb: BrowserCommand<Parameters<BrowserCommands[K]>, ReturnType<BrowserCommands[K]>>) => void;
|
|
918
|
+
triggerCommand: <K extends keyof BrowserCommands>(name: K, context: BrowserCommandContext, ...args: Parameters<BrowserCommands[K]>) => ReturnType<BrowserCommands[K]>;
|
|
919
|
+
}
|
|
920
|
+
interface BrowserCommand<
|
|
921
|
+
Payload extends unknown[] = [],
|
|
922
|
+
ReturnValue = any
|
|
923
|
+
> {
|
|
924
|
+
(context: BrowserCommandContext, ...payload: Payload): Awaitable<ReturnValue>;
|
|
925
|
+
}
|
|
926
|
+
interface BrowserScript {
|
|
1074
927
|
/**
|
|
1075
|
-
*
|
|
928
|
+
* If "content" is provided and type is "module", this will be its identifier.
|
|
929
|
+
*
|
|
930
|
+
* If you are using TypeScript, you can add `.ts` extension here for example.
|
|
931
|
+
* @default `injected-${index}.js`
|
|
1076
932
|
*/
|
|
1077
|
-
|
|
933
|
+
id?: string;
|
|
1078
934
|
/**
|
|
1079
|
-
*
|
|
1080
|
-
*
|
|
935
|
+
* JavaScript content to be injected. This string is processed by Vite plugins if type is "module".
|
|
936
|
+
*
|
|
937
|
+
* You can use `id` to give Vite a hint about the file extension.
|
|
1081
938
|
*/
|
|
1082
|
-
|
|
939
|
+
content?: string;
|
|
1083
940
|
/**
|
|
1084
|
-
*
|
|
1085
|
-
* The `result()` cannot be `pending`.
|
|
941
|
+
* Path to the script. This value is resolved by Vite so it can be a node module or a file path.
|
|
1086
942
|
*/
|
|
1087
|
-
|
|
943
|
+
src?: string;
|
|
1088
944
|
/**
|
|
1089
|
-
*
|
|
945
|
+
* If the script should be loaded asynchronously.
|
|
1090
946
|
*/
|
|
1091
|
-
|
|
947
|
+
async?: boolean;
|
|
1092
948
|
/**
|
|
1093
|
-
*
|
|
949
|
+
* Script type.
|
|
950
|
+
* @default 'module'
|
|
1094
951
|
*/
|
|
1095
|
-
|
|
952
|
+
type?: string;
|
|
953
|
+
}
|
|
954
|
+
interface ResolvedBrowserOptions extends BrowserConfigOptions {
|
|
955
|
+
name: string;
|
|
956
|
+
enabled: boolean;
|
|
957
|
+
headless: boolean;
|
|
958
|
+
ui: boolean;
|
|
959
|
+
viewport: {
|
|
960
|
+
width: number;
|
|
961
|
+
height: number;
|
|
962
|
+
};
|
|
963
|
+
screenshotFailures: boolean;
|
|
964
|
+
locators: {
|
|
965
|
+
testIdAttribute: string;
|
|
966
|
+
exact: boolean;
|
|
967
|
+
errorFormat: "html" | "aria" | "all";
|
|
968
|
+
};
|
|
969
|
+
trace: {
|
|
970
|
+
mode: BrowserTraceViewMode;
|
|
971
|
+
tracesDir?: string;
|
|
972
|
+
screenshots?: boolean;
|
|
973
|
+
snapshots?: boolean;
|
|
974
|
+
sources?: boolean;
|
|
975
|
+
};
|
|
976
|
+
traceView: Required<BrowserTraceViewOptions>;
|
|
977
|
+
}
|
|
978
|
+
type ToMatchScreenshotResolvePath = (data: {
|
|
1096
979
|
/**
|
|
1097
|
-
*
|
|
1098
|
-
*
|
|
980
|
+
* Path **without** extension, sanitized and relative to the test file.
|
|
981
|
+
*
|
|
982
|
+
* This comes from the arguments passed to `toMatchScreenshot`; if called
|
|
983
|
+
* without arguments this will be the auto-generated name.
|
|
984
|
+
*
|
|
985
|
+
* @example
|
|
986
|
+
* test('calls `onClick`', () => {
|
|
987
|
+
* expect(locator).toMatchScreenshot()
|
|
988
|
+
* // arg = "calls-onclick-1"
|
|
989
|
+
* })
|
|
990
|
+
*
|
|
991
|
+
* @example
|
|
992
|
+
* expect(locator).toMatchScreenshot('foo/bar/baz.png')
|
|
993
|
+
* // arg = "foo/bar/baz"
|
|
994
|
+
*
|
|
995
|
+
* @example
|
|
996
|
+
* expect(locator).toMatchScreenshot('../foo/bar/baz.png')
|
|
997
|
+
* // arg = "foo/bar/baz"
|
|
1099
998
|
*/
|
|
1100
|
-
|
|
999
|
+
arg: string;
|
|
1101
1000
|
/**
|
|
1102
|
-
*
|
|
1103
|
-
*
|
|
1001
|
+
* Screenshot extension, with leading dot.
|
|
1002
|
+
*
|
|
1003
|
+
* This can be set through the arguments passed to `toMatchScreenshot`, but
|
|
1004
|
+
* the value will fall back to `'.png'` if an unsupported extension is used.
|
|
1104
1005
|
*/
|
|
1105
|
-
|
|
1006
|
+
ext: string;
|
|
1106
1007
|
/**
|
|
1107
|
-
*
|
|
1008
|
+
* The instance's browser name.
|
|
1108
1009
|
*/
|
|
1109
|
-
|
|
1010
|
+
browserName: string;
|
|
1110
1011
|
/**
|
|
1111
|
-
*
|
|
1012
|
+
* The value of {@linkcode process.platform}.
|
|
1112
1013
|
*/
|
|
1113
|
-
|
|
1114
|
-
|
|
1014
|
+
platform: NodeJS.Platform;
|
|
1015
|
+
/**
|
|
1016
|
+
* The value provided to {@linkcode ToMatchScreenshotOptions.screenshotDirectory|browser.expect.toMatchScreenshot.screenshotDirectory}, if none is provided, its default value (`__screenshots__`).
|
|
1017
|
+
*/
|
|
1018
|
+
screenshotDirectory: string;
|
|
1019
|
+
/**
|
|
1020
|
+
* Absolute path to the project's
|
|
1021
|
+
* {@linkcode https://vitest.dev/config/root|root}.
|
|
1022
|
+
*/
|
|
1023
|
+
root: string;
|
|
1024
|
+
/**
|
|
1025
|
+
* Path to the test file, relative to the project's
|
|
1026
|
+
* {@linkcode https://vitest.dev/config/root|root}.
|
|
1027
|
+
*/
|
|
1028
|
+
testFileDirectory: string;
|
|
1029
|
+
/**
|
|
1030
|
+
* The test's filename.
|
|
1031
|
+
*/
|
|
1032
|
+
testFileName: string;
|
|
1033
|
+
/**
|
|
1034
|
+
* The {@linkcode https://vitest.dev/api/#test|test}'s name, including
|
|
1035
|
+
* parent {@linkcode https://vitest.dev/api/#describe|describe}, sanitized.
|
|
1036
|
+
*/
|
|
1037
|
+
testName: string;
|
|
1038
|
+
/**
|
|
1039
|
+
* The value provided to
|
|
1040
|
+
* {@linkcode https://vitest.dev/config/attachmentsdir|attachmentsDir},
|
|
1041
|
+
* if none is provided, its default value.
|
|
1042
|
+
*/
|
|
1043
|
+
attachmentsDir: string;
|
|
1044
|
+
/**
|
|
1045
|
+
* The {@linkcode https://vitest.dev/api/advanced/test-project|TestProject} the test belongs to.
|
|
1046
|
+
*
|
|
1047
|
+
* @experimental
|
|
1048
|
+
*/
|
|
1049
|
+
project: TestProject;
|
|
1050
|
+
}) => string;
|
|
1051
|
+
interface ToMatchScreenshotOptions {
|
|
1052
|
+
/**
|
|
1053
|
+
* The directory name used for storing reference screenshots.
|
|
1054
|
+
*
|
|
1055
|
+
* This value is passed as `screenshotDirectory` to {@linkcode resolveScreenshotPath|browser.expect.toMatchScreenshot.resolveScreenshotPath} and {@linkcode resolveDiffPath|browser.expect.toMatchScreenshot.resolveDiffPath}, and used in the default path resolution of `resolveScreenshotPath`.
|
|
1056
|
+
*
|
|
1057
|
+
* @default `__screenshots__`.
|
|
1058
|
+
*/
|
|
1059
|
+
screenshotDirectory?: string;
|
|
1060
|
+
/**
|
|
1061
|
+
* Overrides default reference screenshot path.
|
|
1062
|
+
*
|
|
1063
|
+
* @default path.resolve(root, testFileDirectory, screenshotDirectory, testFileName, `${arg}-${browserName}-${platform}${ext}`)
|
|
1064
|
+
*/
|
|
1065
|
+
resolveScreenshotPath?: ToMatchScreenshotResolvePath;
|
|
1066
|
+
/**
|
|
1067
|
+
* Overrides default screenshot path used for diffs.
|
|
1068
|
+
*
|
|
1069
|
+
* @default path.resolve(root, attachmentsDir, testFileDirectory, testFileName, `${arg}-${browserName}-${platform}${ext}`)
|
|
1070
|
+
*/
|
|
1071
|
+
resolveDiffPath?: ToMatchScreenshotResolvePath;
|
|
1072
|
+
}
|
|
1073
|
+
interface ToMatchScreenshotComparators {}
|
|
1074
|
+
|
|
1075
|
+
declare class BenchmarkManager {
|
|
1076
|
+
private project;
|
|
1077
|
+
constructor(project: TestProject);
|
|
1078
|
+
resolve(relativePath: string): string;
|
|
1079
|
+
readResult(relativePath: string): Promise<BaselineData | null>;
|
|
1080
|
+
writeResult(relativePath: string, data: BaselineData): Promise<void>;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
declare class TestProject {
|
|
1084
|
+
/**
|
|
1085
|
+
* The global Vitest instance.
|
|
1086
|
+
*/
|
|
1087
|
+
readonly vitest: Vitest;
|
|
1088
|
+
/**
|
|
1089
|
+
* Resolved global configuration. If there are no workspace projects, this will be the same as `config`.
|
|
1090
|
+
*/
|
|
1091
|
+
readonly globalConfig: ResolvedConfig;
|
|
1092
|
+
/**
|
|
1093
|
+
* Browser instance if the browser is enabled. This is initialized when the tests run for the first time.
|
|
1094
|
+
*/
|
|
1095
|
+
browser?: ProjectBrowser;
|
|
1096
|
+
/**
|
|
1097
|
+
* Temporary directory for the project. This is unique for each project. Vitest stores transformed content here.
|
|
1098
|
+
*/
|
|
1099
|
+
readonly tmpDir: string;
|
|
1100
|
+
readonly benchmark: BenchmarkManager;
|
|
1101
|
+
config: ResolvedConfig;
|
|
1102
|
+
viteConfig: ResolvedConfig$1;
|
|
1103
|
+
vite: ViteDevServer;
|
|
1104
|
+
hash: string;
|
|
1105
|
+
private runner;
|
|
1106
|
+
private closingPromise;
|
|
1107
|
+
private typecheckFilesList;
|
|
1108
|
+
private _globalSetups?;
|
|
1109
|
+
private _provided;
|
|
1110
|
+
constructor(vitest: Vitest, server: ViteDevServer, viteConfig: ResolvedConfig$1, projectConfig: ResolvedConfig);
|
|
1111
|
+
/**
|
|
1112
|
+
* Provide a value to the test context. This value will be available to all tests with `inject`.
|
|
1113
|
+
*/
|
|
1114
|
+
provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
|
|
1115
|
+
/**
|
|
1116
|
+
* Get the provided context. The project context is merged with the global context.
|
|
1117
|
+
*/
|
|
1118
|
+
getProvidedContext(): ProvidedContext;
|
|
1119
|
+
/**
|
|
1120
|
+
* Creates a new test specification. Specifications describe how to run tests.
|
|
1121
|
+
* @param moduleId The file path
|
|
1122
|
+
*/
|
|
1123
|
+
createSpecification(moduleId: string, locationsOrOptions?: number[] | TestSpecificationOptions | undefined, pool?: string, taskIdOverride?: string): TestSpecification;
|
|
1124
|
+
toJSON(): SerializedTestProject;
|
|
1125
|
+
/**
|
|
1126
|
+
* The name of the project or an empty string if not set.
|
|
1127
|
+
*/
|
|
1128
|
+
get name(): string;
|
|
1129
|
+
/**
|
|
1130
|
+
* The color used when reporting tasks of this project.
|
|
1131
|
+
*/
|
|
1132
|
+
get color(): ProjectName["color"];
|
|
1133
|
+
/**
|
|
1134
|
+
* Serialized project configuration. This is the config that tests receive.
|
|
1135
|
+
*/
|
|
1136
|
+
get serializedConfig(): SerializedConfig;
|
|
1137
|
+
/**
|
|
1138
|
+
* Check if this is the root project. The root project is the one that has the root config.
|
|
1139
|
+
*/
|
|
1140
|
+
isRootProject(): boolean;
|
|
1141
|
+
/**
|
|
1142
|
+
* Whether the project reuses the Vite server of the config that declared it
|
|
1143
|
+
* (see the `sharedViteServer` option). The project that owns the server
|
|
1144
|
+
* reports `false` even when other projects reuse it.
|
|
1145
|
+
*/
|
|
1146
|
+
get sharedViteServer(): boolean;
|
|
1147
|
+
onTestsRerun(cb: OnTestsRerunHandler): void;
|
|
1148
|
+
/**
|
|
1149
|
+
* Get all files in the project that match the globs in the config and the filters.
|
|
1150
|
+
* @param filters String filters to match the test files.
|
|
1151
|
+
*/
|
|
1152
|
+
globTestFiles(filters?: string[]): Promise<{
|
|
1153
|
+
/**
|
|
1154
|
+
* Test files that match the filters.
|
|
1155
|
+
*/
|
|
1156
|
+
testFiles: string[];
|
|
1157
|
+
/**
|
|
1158
|
+
* Typecheck test files that match the filters. This will be empty unless `typecheck.enabled` is `true`.
|
|
1159
|
+
*/
|
|
1160
|
+
typecheckTestFiles: string[];
|
|
1161
|
+
}>;
|
|
1162
|
+
private globAllTestFiles;
|
|
1163
|
+
isBrowserEnabled(): boolean;
|
|
1164
|
+
private markTestFile;
|
|
1165
|
+
/**
|
|
1166
|
+
* Test if a file matches the test globs. This does the actual glob matching if the test is not cached, unlike `isCachedTestFile`.
|
|
1167
|
+
*/
|
|
1168
|
+
matchesTestGlob(moduleId: string, source?: () => string): boolean;
|
|
1169
|
+
/**
|
|
1170
|
+
* Closes the project and all associated resources. This can only be called once; the closing promise is cached until the server restarts.
|
|
1171
|
+
* If the resources are needed again, create a new project.
|
|
1172
|
+
*/
|
|
1173
|
+
close(): Promise<void>;
|
|
1174
|
+
/**
|
|
1175
|
+
* Import a file using Vite module runner.
|
|
1176
|
+
* @param moduleId The ID of the module in Vite module graph
|
|
1177
|
+
*/
|
|
1178
|
+
import<T>(moduleId: string): Promise<T>;
|
|
1179
|
+
private _serializeOverriddenConfig;
|
|
1180
|
+
private clearTmpDir;
|
|
1181
|
+
private _provideObject;
|
|
1182
|
+
}
|
|
1183
|
+
interface SerializedTestProject {
|
|
1184
|
+
name: string;
|
|
1185
|
+
serializedConfig: SerializedConfig;
|
|
1186
|
+
context: ProvidedContext;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
declare class TypeCheckError extends Error {
|
|
1190
|
+
message: string;
|
|
1191
|
+
stacks: ParsedStack[];
|
|
1192
|
+
name: string;
|
|
1193
|
+
constructor(message: string, stacks: ParsedStack[]);
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
interface CapturePrintErrorResult {
|
|
1197
|
+
nearest: ParsedStack | undefined;
|
|
1198
|
+
output: string;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
interface ErrorOptions {
|
|
1202
|
+
type?: string;
|
|
1203
|
+
fullStack?: boolean;
|
|
1204
|
+
project?: TestProject;
|
|
1205
|
+
verbose?: boolean;
|
|
1206
|
+
screenshotPaths?: string[];
|
|
1207
|
+
showCodeFrame?: boolean;
|
|
1208
|
+
}
|
|
1209
|
+
type Listener = () => void;
|
|
1210
|
+
declare class Logger {
|
|
1211
|
+
outputStream: NodeJS.WriteStream | Writable;
|
|
1212
|
+
errorStream: NodeJS.WriteStream | Writable;
|
|
1213
|
+
private _clearScreenPending;
|
|
1214
|
+
private _highlights;
|
|
1215
|
+
private cleanupListeners;
|
|
1216
|
+
console: Console;
|
|
1217
|
+
private ctx;
|
|
1218
|
+
constructor(outputStream?: NodeJS.WriteStream | Writable, errorStream?: NodeJS.WriteStream | Writable);
|
|
1219
|
+
setVitest(vitest: Vitest): this;
|
|
1220
|
+
log(...args: any[]): void;
|
|
1221
|
+
error(...args: any[]): void;
|
|
1222
|
+
warn(...args: any[]): void;
|
|
1223
|
+
clearFullScreen(message?: string): void;
|
|
1224
|
+
clearScreen(message: string, force?: boolean): void;
|
|
1225
|
+
private _clearScreen;
|
|
1226
|
+
printError(err: unknown, options?: ErrorOptions): void;
|
|
1227
|
+
formatError(err: unknown, options?: ErrorOptions): CapturePrintErrorResult;
|
|
1228
|
+
deprecate(message: string): void;
|
|
1229
|
+
clearHighlightCache(filename?: string): void;
|
|
1230
|
+
highlight(filename: string, source: string): string;
|
|
1231
|
+
printNoTestTagsFound(): void;
|
|
1232
|
+
printTags(): void;
|
|
1233
|
+
printNoTestFound(filters?: string[]): void;
|
|
1234
|
+
printBanner(): void;
|
|
1235
|
+
printUnhandledErrors(errors: ReadonlyArray<unknown>): void;
|
|
1236
|
+
printSourceTypeErrors(errors: TypeCheckError[]): void;
|
|
1237
|
+
getColumns(): number;
|
|
1238
|
+
onTerminalCleanup(listener: Listener): void;
|
|
1239
|
+
private addCleanupListeners;
|
|
1240
|
+
private registerUnhandledRejection;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
declare class VitestPackageInstaller {
|
|
1244
|
+
isPackageExists(name: string, options?: {
|
|
1245
|
+
paths?: string[];
|
|
1246
|
+
}): boolean;
|
|
1247
|
+
ensureInstalled(dependency: string, root: string, version?: string): Promise<boolean>;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
declare class PluginHarness {
|
|
1251
|
+
logger: Logger;
|
|
1252
|
+
packageInstaller: VitestPackageInstaller;
|
|
1253
|
+
vitest?: Vitest;
|
|
1254
|
+
version: string;
|
|
1255
|
+
constructor(logger?: Logger, packageInstaller?: VitestPackageInstaller);
|
|
1256
|
+
setVitest(vitest: Vitest | undefined): this;
|
|
1257
|
+
getVitest(): Vitest;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
interface Report {
|
|
1261
|
+
/**
|
|
1262
|
+
* The root directory for this scope.
|
|
1263
|
+
*
|
|
1264
|
+
* ```ts
|
|
1265
|
+
* const report = vitest.createReport('my-json-reporter');
|
|
1266
|
+
*
|
|
1267
|
+
* // Is <project-root>/.vitest/my-json-reporter
|
|
1268
|
+
* const root = report.root
|
|
1269
|
+
* ```
|
|
1270
|
+
*/
|
|
1271
|
+
root: string;
|
|
1272
|
+
/**
|
|
1273
|
+
* Clean up the report directory for this scope.
|
|
1274
|
+
*
|
|
1275
|
+
* By default, if `--merge-reports` is used, this method will not delete existing reports.
|
|
1276
|
+
* To force deletion of existing reports, pass `true` as an argument.
|
|
1277
|
+
*
|
|
1278
|
+
* ```ts
|
|
1279
|
+
* const report = vitest.createReport('my-json-reporter');
|
|
1280
|
+
*
|
|
1281
|
+
* // Removes everything inside <project-root>/.vitest/my-json-reporter/
|
|
1282
|
+
* await report.clean()
|
|
1283
|
+
* ```
|
|
1284
|
+
*/
|
|
1285
|
+
clean: (force?: boolean) => Promise<void>;
|
|
1286
|
+
/**
|
|
1287
|
+
* Write a file to the report directory for this scope.
|
|
1288
|
+
* By default the file will be written with UTF-8 encoding.
|
|
1289
|
+
* The filename is relative to the scope directory.
|
|
1290
|
+
*
|
|
1291
|
+
* ```ts
|
|
1292
|
+
* const report = vitest.createReport('my-json-reporter');
|
|
1293
|
+
*
|
|
1294
|
+
* // Writes file to .vitest/my-json-reporter/test-report.json
|
|
1295
|
+
* await report.writeFile('test-report.json', JSON.stringify(results))
|
|
1296
|
+
* ```
|
|
1297
|
+
*/
|
|
1298
|
+
writeFile: (filename: string, content: Parameters<typeof writeFile>[1], encoding?: BufferEncoding) => Promise<void>;
|
|
1299
|
+
/**
|
|
1300
|
+
* Read a file from the report directory for this scope.
|
|
1301
|
+
*
|
|
1302
|
+
* ```ts
|
|
1303
|
+
* const report = vitest.createReport('my-json-reporter');
|
|
1304
|
+
*
|
|
1305
|
+
* // Reads file from .vitest/my-json-reporter/test-report.json
|
|
1306
|
+
* const content: string = await report.readFile('test-report.json')
|
|
1307
|
+
* ```
|
|
1308
|
+
*/
|
|
1309
|
+
readFile: (filename: string, encoding?: BufferEncoding) => Promise<string>;
|
|
1310
|
+
/**
|
|
1311
|
+
* Read contents of the report directory for this scope.
|
|
1312
|
+
*
|
|
1313
|
+
* ```ts
|
|
1314
|
+
* const report = vitest.createReport('my-json-reporter');
|
|
1315
|
+
*
|
|
1316
|
+
* // Reads contents from .vitest/my-json-reporter
|
|
1317
|
+
* const filenames: string[] = await report.readdir()
|
|
1318
|
+
* ```
|
|
1319
|
+
*/
|
|
1320
|
+
readdir: () => Promise<string[]>;
|
|
1321
|
+
/**
|
|
1322
|
+
* Delete a file from the report directory for this scope.
|
|
1323
|
+
*
|
|
1324
|
+
* ```ts
|
|
1325
|
+
* const report = vitest.createReport('my-json-reporter');
|
|
1326
|
+
*
|
|
1327
|
+
* // Deletes file from .vitest/my-json-reporter/test-report.json
|
|
1328
|
+
* await report.delete('test-report.json')
|
|
1329
|
+
* ```
|
|
1330
|
+
*/
|
|
1331
|
+
delete: (filename: string) => Promise<void>;
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
//#region src/tree.d.ts
|
|
1335
|
+
/**
|
|
1336
|
+
* A partial visitor only having the functions of interest to the caller.
|
|
1337
|
+
*
|
|
1338
|
+
* * `onStart(root, state)` - called before traversal begins
|
|
1339
|
+
* * `onSummary(node, state)` - called for every summary node
|
|
1340
|
+
* * `onDetail(node, state)` - called for every detail node
|
|
1341
|
+
* * `onSummaryEnd(node, state)` - called after all children have been visited for
|
|
1342
|
+
* a summary node.
|
|
1343
|
+
* * `onEnd(root, state)` - called after traversal ends
|
|
1344
|
+
*/
|
|
1345
|
+
interface PartialVisitor<N extends BaseNode = BaseNode> {
|
|
1346
|
+
onStart?(root: N, state?: any): void;
|
|
1347
|
+
onSummary?(node: N, state?: any): void;
|
|
1348
|
+
onDetail?(node: N, state?: any): void;
|
|
1349
|
+
onSummaryEnd?(node: N, state?: any): void;
|
|
1350
|
+
onEnd?(root: N, state?: any): void;
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* An object with methods that are called during the traversal of the coverage tree.
|
|
1354
|
+
* A visitor has the following methods that are called during tree traversal.
|
|
1355
|
+
*
|
|
1356
|
+
* * `onStart(root, state)` - called before traversal begins
|
|
1357
|
+
* * `onSummary(node, state)` - called for every summary node
|
|
1358
|
+
* * `onDetail(node, state)` - called for every detail node
|
|
1359
|
+
* * `onSummaryEnd(node, state)` - called after all children have been visited for
|
|
1360
|
+
* a summary node.
|
|
1361
|
+
* * `onEnd(root, state)` - called after traversal ends
|
|
1362
|
+
*
|
|
1363
|
+
* @param delegate - a partial visitor that only implements the methods of interest
|
|
1364
|
+
* The visitor object supplies the missing methods as noops. For example, reports
|
|
1365
|
+
* that only need the final coverage summary need implement `onStart` and nothing
|
|
1366
|
+
* else. Reports that use only detailed coverage information need implement `onDetail`
|
|
1367
|
+
* and nothing else.
|
|
1368
|
+
* @constructor
|
|
1369
|
+
*/
|
|
1370
|
+
declare class Visitor<N extends BaseNode = BaseNode> {
|
|
1371
|
+
delegate: PartialVisitor<N> | Visitor<N> | undefined;
|
|
1372
|
+
onStart: (root: N, state?: any) => void;
|
|
1373
|
+
onSummary: (node: N, state?: any) => void;
|
|
1374
|
+
onDetail: (node: N, state?: any) => void;
|
|
1375
|
+
onSummaryEnd: (node: N, state?: any) => void;
|
|
1376
|
+
onEnd: (root: N, state?: any) => void;
|
|
1377
|
+
constructor(delegate?: PartialVisitor<N> | Visitor<N>);
|
|
1378
|
+
}
|
|
1379
|
+
declare abstract class BaseNode {
|
|
1380
|
+
abstract getParent(): BaseNode | null;
|
|
1381
|
+
abstract getChildren(): BaseNode[];
|
|
1382
|
+
abstract isSummary(): boolean;
|
|
1383
|
+
isRoot(): boolean;
|
|
1384
|
+
/**
|
|
1385
|
+
* visit all nodes depth-first from this node down. Note that `onStart`
|
|
1386
|
+
* and `onEnd` are never called on the visitor even if the current
|
|
1387
|
+
* node is the root of the tree.
|
|
1388
|
+
* @param visitor a full visitor that is called during tree traversal
|
|
1389
|
+
* @param state optional state that is passed around
|
|
1390
|
+
*/
|
|
1391
|
+
visit(visitor: Visitor<any>, state?: any): void;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
//#region src/path.d.ts
|
|
1395
|
+
type PathParser = (path: string) => path.ParsedPath;
|
|
1396
|
+
declare class Path {
|
|
1397
|
+
v: string[];
|
|
1398
|
+
readonly length: number;
|
|
1399
|
+
push: (...items: string[]) => number;
|
|
1400
|
+
pop: () => string | undefined;
|
|
1401
|
+
shift: () => string | undefined;
|
|
1402
|
+
unshift: (...items: string[]) => number;
|
|
1403
|
+
splice: (start: number, deleteCount?: number, ...items: string[]) => string[];
|
|
1404
|
+
constructor(strOrArray: string | string[]);
|
|
1405
|
+
toString(): string;
|
|
1406
|
+
hasParent(): boolean;
|
|
1407
|
+
parent(): Path;
|
|
1408
|
+
elements(): string[];
|
|
1409
|
+
name(): string;
|
|
1410
|
+
contains(other: Path): boolean;
|
|
1411
|
+
ancestorOf(other: Path): boolean;
|
|
1412
|
+
descendantOf(other: Path): boolean;
|
|
1413
|
+
commonPrefixPath(other: Path): Path;
|
|
1414
|
+
static compare(a: Path, b: Path): number;
|
|
1415
|
+
static tester: {
|
|
1416
|
+
setParserAndSep(p: PathParser, sep: string): void;
|
|
1417
|
+
reset(): void;
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
//#region src/coverage-summary.d.ts
|
|
1422
|
+
/**
|
|
1423
|
+
* Totals for a single coverage metric (statements, lines, functions, branches).
|
|
1424
|
+
* `pct` is a percentage number (0-100), or the string `"Unknown"` for a blank
|
|
1425
|
+
* summary that has not yet been merged with any data.
|
|
1426
|
+
*/
|
|
1427
|
+
interface Totals {
|
|
1428
|
+
total: number;
|
|
1429
|
+
covered: number;
|
|
1430
|
+
skipped: number;
|
|
1431
|
+
pct: number | "Unknown";
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Raw, JSON-serializable data underlying a `CoverageSummary`.
|
|
1435
|
+
*/
|
|
1436
|
+
interface CoverageSummaryData {
|
|
1437
|
+
lines: Totals;
|
|
1438
|
+
statements: Totals;
|
|
1439
|
+
functions: Totals;
|
|
1440
|
+
branches: Totals;
|
|
1441
|
+
branchesTrue?: Totals;
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* CoverageSummary provides a summary of code coverage . It exposes 4 properties,
|
|
1445
|
+
* `lines`, `statements`, `branches`, and `functions`. Each of these properties
|
|
1446
|
+
* is an object that has 4 keys `total`, `covered`, `skipped` and `pct`.
|
|
1447
|
+
* `pct` is a percentage number (0-100).
|
|
1448
|
+
*/
|
|
1449
|
+
declare class CoverageSummary {
|
|
1450
|
+
data: CoverageSummaryData;
|
|
1451
|
+
readonly lines: Totals;
|
|
1452
|
+
readonly statements: Totals;
|
|
1453
|
+
readonly functions: Totals;
|
|
1454
|
+
readonly branches: Totals;
|
|
1455
|
+
readonly branchesTrue: Totals | undefined;
|
|
1456
|
+
/**
|
|
1457
|
+
* @constructor
|
|
1458
|
+
* @param obj an optional data object or
|
|
1459
|
+
* another coverage summary to initialize this object with.
|
|
1460
|
+
*/
|
|
1461
|
+
constructor(obj?: CoverageSummary | CoverageSummaryData);
|
|
1462
|
+
/**
|
|
1463
|
+
* merges a second summary coverage object into this one
|
|
1464
|
+
* @param obj - another coverage summary object
|
|
1465
|
+
*/
|
|
1466
|
+
merge(obj: CoverageSummary): this;
|
|
1467
|
+
/**
|
|
1468
|
+
* returns a POJO that is JSON serializable. May be used to get the raw
|
|
1469
|
+
* summary object.
|
|
1470
|
+
*/
|
|
1471
|
+
toJSON(): CoverageSummaryData;
|
|
1472
|
+
/**
|
|
1473
|
+
* return true if summary has no lines of code
|
|
1474
|
+
*/
|
|
1475
|
+
isEmpty(): boolean;
|
|
1476
|
+
}
|
|
1477
|
+
//#endregion
|
|
1478
|
+
//#region src/file-coverage.d.ts
|
|
1479
|
+
/** a single location in a source file: 1-based line, 0-based column */
|
|
1480
|
+
interface Location {
|
|
1481
|
+
line: number;
|
|
1482
|
+
column: number;
|
|
1483
|
+
}
|
|
1484
|
+
/** a source range delimited by a start and end location */
|
|
1485
|
+
interface Range {
|
|
1486
|
+
start: Location;
|
|
1487
|
+
end: Location;
|
|
1488
|
+
}
|
|
1489
|
+
/** metadata for a single function in the instrumented source */
|
|
1490
|
+
interface FunctionMapping {
|
|
1491
|
+
name: string;
|
|
1492
|
+
decl: Range;
|
|
1493
|
+
loc: Range;
|
|
1494
|
+
line: number;
|
|
1495
|
+
}
|
|
1496
|
+
/** metadata for a single branch in the instrumented source */
|
|
1497
|
+
interface BranchMapping {
|
|
1498
|
+
loc: Range;
|
|
1499
|
+
type: string;
|
|
1500
|
+
locations: Range[];
|
|
1501
|
+
line: number;
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Raw, JSON-serializable coverage data for a single file, as produced by the
|
|
1505
|
+
* istanbul instrumenter or coverage tooling.
|
|
1506
|
+
*/
|
|
1507
|
+
interface FileCoverageData {
|
|
1508
|
+
path: string;
|
|
1509
|
+
statementMap: Record<string, Range>;
|
|
1510
|
+
fnMap: Record<string, FunctionMapping>;
|
|
1511
|
+
branchMap: Record<string, BranchMapping>;
|
|
1512
|
+
s: Record<string, number>;
|
|
1513
|
+
f: Record<string, number>;
|
|
1514
|
+
b: Record<string, number[]>;
|
|
1515
|
+
/** hit counts for logical branch truthiness; only present when reportLogic is enabled */
|
|
1516
|
+
bT?: Record<string, number[]>;
|
|
1517
|
+
/** marks coverage produced by the `--all` option (empty placeholder coverage) */
|
|
1518
|
+
all?: boolean;
|
|
1519
|
+
}
|
|
1520
|
+
/** per-line branch coverage as returned by `FileCoverage#getBranchCoverageByLine` */
|
|
1521
|
+
interface Coverage {
|
|
1522
|
+
covered: number;
|
|
1523
|
+
total: number;
|
|
1524
|
+
coverage: number;
|
|
1525
|
+
}
|
|
1526
|
+
/**
|
|
1527
|
+
* provides a read-only view of coverage for a single file.
|
|
1528
|
+
* The deep structure of this object is documented elsewhere. It has the following
|
|
1529
|
+
* properties:
|
|
1530
|
+
*
|
|
1531
|
+
* * `path` - the file path for which coverage is being tracked
|
|
1532
|
+
* * `statementMap` - map of statement locations keyed by statement index
|
|
1533
|
+
* * `fnMap` - map of function metadata keyed by function index
|
|
1534
|
+
* * `branchMap` - map of branch metadata keyed by branch index
|
|
1535
|
+
* * `s` - hit counts for statements
|
|
1536
|
+
* * `f` - hit count for functions
|
|
1537
|
+
* * `b` - hit count for branches
|
|
1538
|
+
*/
|
|
1539
|
+
declare class FileCoverage {
|
|
1540
|
+
data: FileCoverageData;
|
|
1541
|
+
readonly path: string;
|
|
1542
|
+
readonly statementMap: Record<string, Range>;
|
|
1543
|
+
readonly fnMap: Record<string, FunctionMapping>;
|
|
1544
|
+
readonly branchMap: Record<string, BranchMapping>;
|
|
1545
|
+
readonly s: Record<string, number>;
|
|
1546
|
+
readonly f: Record<string, number>;
|
|
1547
|
+
readonly b: Record<string, number[]>;
|
|
1548
|
+
readonly bT: Record<string, number[]> | undefined;
|
|
1549
|
+
readonly all: boolean | undefined;
|
|
1550
|
+
/**
|
|
1551
|
+
* @constructor
|
|
1552
|
+
* @param pathOrObj is a string that initializes
|
|
1553
|
+
* and empty coverage object with the specified file path or a data object that
|
|
1554
|
+
* has all the required properties for a file coverage object.
|
|
1555
|
+
*/
|
|
1556
|
+
constructor(pathOrObj?: string | FileCoverage | FileCoverageData, reportLogic?: boolean);
|
|
1557
|
+
/**
|
|
1558
|
+
* returns computed line coverage from statement coverage.
|
|
1559
|
+
* This is a map of hits keyed by line number in the source.
|
|
1560
|
+
*/
|
|
1561
|
+
getLineCoverage(): Record<string, number>;
|
|
1562
|
+
/**
|
|
1563
|
+
* returns an array of uncovered line numbers.
|
|
1564
|
+
* @returns an array of line numbers for which no hits have been
|
|
1565
|
+
* collected.
|
|
1566
|
+
*/
|
|
1567
|
+
getUncoveredLines(): string[];
|
|
1568
|
+
/**
|
|
1569
|
+
* returns a map of branch coverage by source line number.
|
|
1570
|
+
* @returns an object keyed by line number. Each object
|
|
1571
|
+
* has a `covered`, `total` and `coverage` (percentage) property.
|
|
1572
|
+
*/
|
|
1573
|
+
getBranchCoverageByLine(): Record<string, Coverage>;
|
|
1574
|
+
/**
|
|
1575
|
+
* return a JSON-serializable POJO for this file coverage object
|
|
1576
|
+
*/
|
|
1577
|
+
toJSON(): FileCoverageData;
|
|
1578
|
+
/**
|
|
1579
|
+
* merges a second coverage object into this one, updating hit counts
|
|
1580
|
+
* @param other - the coverage object to be merged into this one.
|
|
1581
|
+
* Note that the other object should have the same structure as this one (same file).
|
|
1582
|
+
*/
|
|
1583
|
+
merge(other: FileCoverage): void;
|
|
1584
|
+
computeSimpleTotals(property: "getLineCoverage" | "s" | "f"): Totals;
|
|
1585
|
+
computeBranchTotals(property: "b" | "bT"): Totals;
|
|
1586
|
+
/**
|
|
1587
|
+
* resets hit counts for all statements, functions and branches
|
|
1588
|
+
* in this coverage object resulting in zero coverage.
|
|
1589
|
+
*/
|
|
1590
|
+
resetHits(): void;
|
|
1591
|
+
/**
|
|
1592
|
+
* returns a CoverageSummary for this file coverage object
|
|
1593
|
+
* @returns {CoverageSummary}
|
|
1594
|
+
*/
|
|
1595
|
+
toSummary(): CoverageSummary;
|
|
1596
|
+
}
|
|
1597
|
+
//#endregion
|
|
1598
|
+
//#region src/coverage-map.d.ts
|
|
1599
|
+
/**
|
|
1600
|
+
* Raw, JSON-serializable data underlying a `CoverageMap`: `FileCoverage`
|
|
1601
|
+
* objects or their raw data keyed by file path. This can be the raw global
|
|
1602
|
+
* coverage object.
|
|
1603
|
+
*/
|
|
1604
|
+
interface CoverageMapData {
|
|
1605
|
+
[path: string]: FileCoverage | FileCoverageData;
|
|
1606
|
+
}
|
|
1607
|
+
/** CoverageMap is a map of `FileCoverage` objects keyed by file paths. */
|
|
1608
|
+
declare class CoverageMap {
|
|
1609
|
+
data: Record<string, FileCoverage>;
|
|
1610
|
+
/**
|
|
1611
|
+
* @constructor
|
|
1612
|
+
* @param obj A coverage map from which to initialize this
|
|
1613
|
+
* map's contents. This can be the raw global coverage object.
|
|
1614
|
+
*/
|
|
1615
|
+
constructor(obj?: CoverageMap | CoverageMapData);
|
|
1616
|
+
/**
|
|
1617
|
+
* merges a second coverage map into this one
|
|
1618
|
+
* @param obj - a CoverageMap or its raw data. Coverage is merged
|
|
1619
|
+
* correctly for the same files and additional file coverage keys are created
|
|
1620
|
+
* as needed.
|
|
1621
|
+
*/
|
|
1622
|
+
merge(obj: CoverageMap | CoverageMapData): void;
|
|
1623
|
+
/**
|
|
1624
|
+
* filter the coveragemap based on the callback provided
|
|
1625
|
+
* @param callback - Returns true if the path
|
|
1626
|
+
* should be included in the coveragemap. False if it should be
|
|
1627
|
+
* removed.
|
|
1628
|
+
*/
|
|
1629
|
+
filter(callback: (path: string) => boolean): void;
|
|
1630
|
+
/**
|
|
1631
|
+
* returns a JSON-serializable POJO for this coverage map
|
|
1632
|
+
*/
|
|
1633
|
+
toJSON(): CoverageMapData;
|
|
1634
|
+
/**
|
|
1635
|
+
* returns an array for file paths for which this map has coverage
|
|
1636
|
+
* @returns array of files
|
|
1637
|
+
*/
|
|
1638
|
+
files(): string[];
|
|
1639
|
+
/**
|
|
1640
|
+
* returns the file coverage for the specified file.
|
|
1641
|
+
* @param file
|
|
1642
|
+
*/
|
|
1643
|
+
fileCoverageFor(file: string): FileCoverage;
|
|
1644
|
+
/**
|
|
1645
|
+
* adds a file coverage object to this map. If the path for the object,
|
|
1646
|
+
* already exists in the map, it is merged with the existing coverage
|
|
1647
|
+
* otherwise a new key is added to the map.
|
|
1648
|
+
* @param fc the file coverage to add
|
|
1649
|
+
*/
|
|
1650
|
+
addFileCoverage(fc: string | FileCoverage | FileCoverageData): void;
|
|
1651
|
+
/**
|
|
1652
|
+
* returns the coverage summary for all the file coverage objects in this map.
|
|
1653
|
+
* @returns {CoverageSummary}
|
|
1654
|
+
*/
|
|
1655
|
+
getCoverageSummary(): CoverageSummary;
|
|
1115
1656
|
}
|
|
1116
1657
|
|
|
1117
|
-
|
|
1118
|
-
|
|
1658
|
+
//#region src/summarizer-factory.d.ts
|
|
1659
|
+
/** names of the summarizer strategies supported by {@link SummarizerFactory} */
|
|
1660
|
+
type Summarizers = "flat" | "nested" | "pkg" | "defaultSummarizer";
|
|
1661
|
+
declare class ReportNode extends BaseNode {
|
|
1662
|
+
path: Path;
|
|
1663
|
+
parent: ReportNode | null;
|
|
1664
|
+
fileCoverage: FileCoverage | undefined;
|
|
1665
|
+
children: ReportNode[];
|
|
1666
|
+
c_files?: CoverageSummary | null;
|
|
1667
|
+
c_full?: CoverageSummary | null;
|
|
1668
|
+
constructor(path: Path, fileCoverage?: FileCoverage);
|
|
1669
|
+
static createRoot(children: ReportNode[]): ReportNode;
|
|
1670
|
+
addChild(child: ReportNode): void;
|
|
1671
|
+
asRelative(p: string): string;
|
|
1672
|
+
getQualifiedName(): string;
|
|
1673
|
+
getRelativeName(): string;
|
|
1674
|
+
getParent(): ReportNode | null;
|
|
1675
|
+
getChildren(): ReportNode[];
|
|
1676
|
+
isSummary(): boolean;
|
|
1677
|
+
getFileCoverage(): FileCoverage;
|
|
1678
|
+
getCoverageSummary(filesOnly?: boolean): CoverageSummary | null;
|
|
1119
1679
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
constructor(options: BlobOptions);
|
|
1126
|
-
onInit(ctx: Vitest): void;
|
|
1127
|
-
onCoverage(coverage: unknown): void;
|
|
1128
|
-
onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): Promise<void>;
|
|
1680
|
+
|
|
1681
|
+
/** options accepted by {@link ReportBase} */
|
|
1682
|
+
interface ReportBaseOptions {
|
|
1683
|
+
/** the summarizer strategy to use when executing the report */
|
|
1684
|
+
summarizer?: Summarizers;
|
|
1129
1685
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1686
|
+
|
|
1687
|
+
//#region src/reports/clover/index.d.ts
|
|
1688
|
+
/** options accepted by {@link CloverReport} */
|
|
1689
|
+
interface CloverOptions {
|
|
1690
|
+
/** the file to write the report to, defaults to `clover.xml` */
|
|
1691
|
+
file?: string;
|
|
1135
1692
|
}
|
|
1136
1693
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
transformTime: number;
|
|
1147
|
-
metadata: Record<string, {
|
|
1148
|
-
externalized: Record<string, string>;
|
|
1149
|
-
duration: Record<string, number[]>;
|
|
1150
|
-
tmps: Record<string, string>;
|
|
1151
|
-
dumpDir?: string;
|
|
1152
|
-
outline?: {
|
|
1153
|
-
externalized: number;
|
|
1154
|
-
inlined: number;
|
|
1155
|
-
};
|
|
1156
|
-
}>;
|
|
1157
|
-
onUnhandledError?: OnUnhandledErrorCallback;
|
|
1158
|
-
constructor(options: {
|
|
1159
|
-
onUnhandledError?: OnUnhandledErrorCallback;
|
|
1160
|
-
});
|
|
1161
|
-
catchError(error: unknown, type: string): void;
|
|
1162
|
-
catchLeaks(leaks: AsyncLeak[]): void;
|
|
1163
|
-
clearErrors(): void;
|
|
1164
|
-
getUnhandledErrors(): unknown[];
|
|
1165
|
-
getPaths(): string[];
|
|
1166
|
-
/**
|
|
1167
|
-
* Return files that were running or collected.
|
|
1168
|
-
*/
|
|
1169
|
-
getFiles(keys?: string[]): File[];
|
|
1170
|
-
getTestModules(keys?: string[]): TestModule[];
|
|
1171
|
-
getFilepaths(): string[];
|
|
1172
|
-
getFailedFilepaths(): string[];
|
|
1173
|
-
collectPaths(paths?: string[]): void;
|
|
1174
|
-
collectFiles(project: TestProject, files?: File[]): void;
|
|
1175
|
-
clearFiles(project: TestProject, paths?: string[]): void;
|
|
1176
|
-
updateId(task: Task, project: TestProject): void;
|
|
1177
|
-
getReportedEntity(task: Task): TestModule | TestCase | TestSuite | undefined;
|
|
1178
|
-
getReportedEntityById(taskId: string): TestModule | TestCase | TestSuite | undefined;
|
|
1179
|
-
updateTasks(packs: TaskResultPack[]): void;
|
|
1180
|
-
updateUserLog(log: UserConsoleLog): void;
|
|
1181
|
-
getCountOfFailedTests(): number;
|
|
1182
|
-
cancelFiles(files: FileSpecification[], project: TestProject): void;
|
|
1694
|
+
//#region src/reports/cobertura/index.d.ts
|
|
1695
|
+
/** options accepted by {@link CoberturaReport} */
|
|
1696
|
+
interface CoberturaOptions {
|
|
1697
|
+
/** the file to write the report to, defaults to `cobertura-coverage.xml` */
|
|
1698
|
+
file?: string;
|
|
1699
|
+
/** timestamp to embed in the report, defaults to `Date.now()` */
|
|
1700
|
+
timestamp?: string;
|
|
1701
|
+
/** the project root used to relativize file paths, defaults to `process.cwd()` */
|
|
1702
|
+
projectRoot?: string;
|
|
1183
1703
|
}
|
|
1184
1704
|
|
|
1185
|
-
|
|
1186
|
-
|
|
1705
|
+
//#region src/reports/html/index.d.ts
|
|
1706
|
+
/** maps report nodes to output paths, see the html report's `linkMapper` option */
|
|
1707
|
+
interface LinkMapper {
|
|
1708
|
+
getPath(node: ReportNode | string): string;
|
|
1709
|
+
relativePath(source: ReportNode | string, target: ReportNode | string): string;
|
|
1710
|
+
assetPath(node: ReportNode, name: string): string;
|
|
1711
|
+
}
|
|
1712
|
+
/** color themes of the html report, `legacy` being the classic istanbul colors */
|
|
1713
|
+
type HtmlTheme = "light" | "dark" | "legacy";
|
|
1714
|
+
/** options accepted by {@link HtmlReport} */
|
|
1715
|
+
interface HtmlOptions {
|
|
1716
|
+
/** show extra logging while the report is generated */
|
|
1717
|
+
verbose?: boolean;
|
|
1718
|
+
/** maps report nodes to output paths */
|
|
1719
|
+
linkMapper?: LinkMapper;
|
|
1720
|
+
/** subdirectory (under the report dir) to write the report to */
|
|
1721
|
+
subdir?: string;
|
|
1722
|
+
/** skip nodes with no coverage */
|
|
1723
|
+
skipEmpty?: boolean;
|
|
1724
|
+
/**
|
|
1725
|
+
* fixes the report's theme and hides the theme picker; when unset, viewers
|
|
1726
|
+
* pick a theme in the report, which otherwise follows their light/dark
|
|
1727
|
+
* preference, or the page embedding the report, like Vitest UI
|
|
1728
|
+
*/
|
|
1729
|
+
theme?: HtmlTheme;
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
//#region src/reports/html-spa/index.d.ts
|
|
1733
|
+
/** options accepted by {@link HtmlSpaReport} */
|
|
1734
|
+
interface HtmlSpaOptions extends Omit<HtmlOptions, "theme"> {
|
|
1735
|
+
/** the metrics to show in the report UI, defaults to lines, branches and functions */
|
|
1736
|
+
metricsToShow?: ("lines" | "branches" | "functions" | "statements")[];
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
//#region src/reports/json-summary/index.d.ts
|
|
1740
|
+
/** options accepted by {@link JsonSummaryReport} */
|
|
1741
|
+
interface JsonSummaryOptions {
|
|
1742
|
+
/** the file to write the report to, defaults to `coverage-summary.json` */
|
|
1743
|
+
file?: string;
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
//#region src/reports/json/index.d.ts
|
|
1747
|
+
/** options accepted by {@link JsonReport} */
|
|
1748
|
+
interface JsonOptions$1 {
|
|
1749
|
+
/** the file to write the report to, defaults to `coverage-final.json` */
|
|
1750
|
+
file?: string;
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
//#region src/reports/lcovonly/index.d.ts
|
|
1754
|
+
/** options accepted by {@link LcovOnlyReport} */
|
|
1755
|
+
interface LcovOnlyOptions {
|
|
1756
|
+
/** the file to write the report to, defaults to `lcov.info` */
|
|
1757
|
+
file?: string;
|
|
1758
|
+
/** the project root used to relativize file paths, defaults to `process.cwd()` */
|
|
1759
|
+
projectRoot?: string;
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
//#region src/reports/lcov/index.d.ts
|
|
1763
|
+
/** options accepted by {@link LcovReport}, passed through to the lcovonly report */
|
|
1764
|
+
interface LcovOptions extends LcovOnlyOptions {}
|
|
1765
|
+
|
|
1766
|
+
//#region src/reports/teamcity/index.d.ts
|
|
1767
|
+
/** options accepted by {@link TeamcityReport} */
|
|
1768
|
+
interface TeamcityOptions {
|
|
1769
|
+
/** the file to write the report to, defaults to the console */
|
|
1770
|
+
file?: string | null;
|
|
1771
|
+
/** the teamcity block name to wrap the output in, defaults to `Code Coverage Summary` */
|
|
1772
|
+
blockName?: string;
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
//#region src/reports/text-lcov/index.d.ts
|
|
1776
|
+
/** options accepted by {@link TextLcov}, `file` is always the console */
|
|
1777
|
+
interface TextLcovOptions {
|
|
1778
|
+
/** the project root used to relativize file paths, defaults to `process.cwd()` */
|
|
1779
|
+
projectRoot?: string;
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
//#region src/reports/text-summary/index.d.ts
|
|
1783
|
+
/** options accepted by {@link TextSummaryReport} */
|
|
1784
|
+
interface TextSummaryOptions {
|
|
1785
|
+
/** the file to write the report to, defaults to the console */
|
|
1786
|
+
file?: string | null;
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
//#region src/reports/text/index.d.ts
|
|
1790
|
+
/** options accepted by {@link TextReport} */
|
|
1791
|
+
interface TextOptions extends ReportBaseOptions {
|
|
1792
|
+
/** the file to write the report to, defaults to the console */
|
|
1793
|
+
file?: string | null;
|
|
1794
|
+
/** maximum column width of the table, defaults to the terminal width */
|
|
1795
|
+
maxCols?: number;
|
|
1796
|
+
/** skip rows with no coverage */
|
|
1797
|
+
skipEmpty?: boolean;
|
|
1798
|
+
/** skip rows with full coverage */
|
|
1799
|
+
skipFull?: boolean;
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
/** options accepted by each built-in report, keyed by report name */
|
|
1803
|
+
interface ReportOptions {
|
|
1804
|
+
clover: CloverOptions;
|
|
1805
|
+
cobertura: CoberturaOptions;
|
|
1806
|
+
html: HtmlOptions;
|
|
1807
|
+
"html-spa": HtmlSpaOptions;
|
|
1808
|
+
json: JsonOptions$1;
|
|
1809
|
+
"json-summary": JsonSummaryOptions;
|
|
1810
|
+
lcov: LcovOptions;
|
|
1811
|
+
lcovonly: LcovOnlyOptions;
|
|
1812
|
+
none: never;
|
|
1813
|
+
teamcity: TeamcityOptions;
|
|
1814
|
+
text: TextOptions;
|
|
1815
|
+
"text-lcov": TextLcovOptions;
|
|
1816
|
+
"text-summary": TextSummaryOptions;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
type TransformResult = string | Partial<TransformResult$1> | undefined | null | void;
|
|
1820
|
+
type CoverageResults = unknown;
|
|
1821
|
+
interface CoverageProvider {
|
|
1822
|
+
name: string;
|
|
1823
|
+
/** Called when provider is being initialized before tests run */
|
|
1824
|
+
initialize: (ctx: Vitest) => Promise<void> | void;
|
|
1825
|
+
/** Called when setting coverage options for Vitest context (`ctx.config.coverage`) */
|
|
1826
|
+
resolveOptions: () => ResolvedCoverageOptions;
|
|
1827
|
+
/** Callback to clean previous reports */
|
|
1828
|
+
clean: (clean?: boolean) => void | Promise<void>;
|
|
1829
|
+
/** Called with coverage results after a single test file has been run */
|
|
1830
|
+
onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void | Promise<void>;
|
|
1831
|
+
/** Callback called when test run starts */
|
|
1832
|
+
onTestRunStart?: (specifications: ReadonlyArray<TestSpecification>) => void | Promise<void>;
|
|
1833
|
+
/** Callback called when test run fails due to test failures */
|
|
1834
|
+
onTestFailure?: () => void | Promise<void>;
|
|
1835
|
+
/** Callback to generate final coverage results */
|
|
1836
|
+
generateCoverage: (reportContext: ReportContext) => CoverageResults | Promise<CoverageResults>;
|
|
1837
|
+
/** Callback to convert coverage results to coverage reports. Called with results returned from `generateCoverage` */
|
|
1838
|
+
reportCoverage: (coverage: CoverageResults, reportContext: ReportContext) => void | Promise<void>;
|
|
1839
|
+
/** Callback for `--merge-reports` options. Called with multiple coverage results generated by `generateCoverage`. */
|
|
1840
|
+
mergeReports?: (coverages: CoverageResults[]) => void | Promise<void>;
|
|
1841
|
+
/** Callback called for instrumenting files with coverage counters. */
|
|
1842
|
+
onFileTransform?: (sourceCode: string, id: string, pluginCtx: any) => TransformResult | Promise<TransformResult>;
|
|
1187
1843
|
/**
|
|
1188
|
-
*
|
|
1844
|
+
* Return `true` if this file is transformed by the coverage provider.
|
|
1845
|
+
* This is used to generate the persistent file hash by `fsModuleCache`
|
|
1846
|
+
* @experimental
|
|
1189
1847
|
*/
|
|
1190
|
-
|
|
1848
|
+
requiresTransform?: (id: string) => boolean;
|
|
1191
1849
|
/**
|
|
1192
|
-
*
|
|
1850
|
+
* Version of the coverage provider. Can be used as cache key in various caching mechanisms.
|
|
1851
|
+
* @experimental
|
|
1193
1852
|
*/
|
|
1194
|
-
|
|
1195
|
-
private readonly _onRerun;
|
|
1196
|
-
constructor(vitest: Vitest);
|
|
1197
|
-
close(): void;
|
|
1198
|
-
unregisterWatcher: () => void;
|
|
1199
|
-
registerWatcher(): this;
|
|
1200
|
-
private scheduleRerun;
|
|
1201
|
-
private getTestFilesFromWatcherTrigger;
|
|
1202
|
-
onFileChange: (id: string) => void;
|
|
1203
|
-
onFileDelete: (id: string) => void;
|
|
1204
|
-
onFileCreate: (id: string) => void;
|
|
1205
|
-
private handleSetupFile;
|
|
1853
|
+
version?: string;
|
|
1206
1854
|
/**
|
|
1207
|
-
*
|
|
1855
|
+
* Return data that should be stored with the transformed module in `fsModuleCache`,
|
|
1856
|
+
* e.g. data collected in `onFileTransform`. The data must be JSON serializable.
|
|
1857
|
+
* When the module is later loaded from `fsModuleCache`, `onFileTransform` is not called.
|
|
1858
|
+
* The data is passed to `restoreModuleCacheData` instead.
|
|
1859
|
+
* @experimental
|
|
1208
1860
|
*/
|
|
1209
|
-
|
|
1861
|
+
getModuleCacheData?: (environment: DevEnvironment, id: string) => unknown;
|
|
1862
|
+
/**
|
|
1863
|
+
* Called with the data returned by `getModuleCacheData` when the module is loaded from `fsModuleCache`.
|
|
1864
|
+
* @experimental
|
|
1865
|
+
*/
|
|
1866
|
+
restoreModuleCacheData?: (environment: DevEnvironment, id: string, data: unknown) => void;
|
|
1867
|
+
/** Callback that's called when the coverage is enabled via a programmatic `enableCoverage` API. */
|
|
1868
|
+
onEnabled?: () => void | Promise<void>;
|
|
1210
1869
|
}
|
|
1211
|
-
interface
|
|
1212
|
-
|
|
1213
|
-
|
|
1870
|
+
interface ReportContext {
|
|
1871
|
+
/** Indicates whether all tests were run. False when only specific tests were run. */
|
|
1872
|
+
allTestsRun?: boolean;
|
|
1214
1873
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
stderr?: NodeJS.WriteStream | Writable;
|
|
1874
|
+
interface CoverageProviderModule extends RuntimeCoverageProviderModule {
|
|
1875
|
+
/**
|
|
1876
|
+
* Factory for creating a new coverage provider
|
|
1877
|
+
*/
|
|
1878
|
+
getProvider: () => CoverageProvider | Promise<CoverageProvider>;
|
|
1221
1879
|
}
|
|
1222
|
-
|
|
1223
|
-
|
|
1880
|
+
type CoverageReporter = keyof ReportOptions | (string & {});
|
|
1881
|
+
type CoverageReporterWithOptions<ReporterName extends CoverageReporter = CoverageReporter> = ReporterName extends keyof ReportOptions ? ReportOptions[ReporterName] extends never ? [ReporterName, object] : [ReporterName, Partial<ReportOptions[ReporterName]>] : [ReporterName, Record<string, unknown>];
|
|
1882
|
+
/** Fields that have default values. Internally these will always be defined. */
|
|
1883
|
+
type FieldsWithDefaultValues = "provider" | "enabled" | "clean" | "cleanOnRerun" | "reportsDirectory" | "exclude" | "reportOnFailure" | "allowExternal" | "processingConcurrency" | "reporter" | "excludeAfterRemap" | "ignoreClassMethods" | "skipFull" | "watermarks" | "autoAttachSubprocess";
|
|
1884
|
+
type ResolvedCoverageOptions = CoverageOptions & Required<Pick<CoverageOptions, FieldsWithDefaultValues>> & {
|
|
1885
|
+
reporter: CoverageReporterWithOptions[];
|
|
1886
|
+
htmlDir?: string;
|
|
1887
|
+
};
|
|
1888
|
+
interface CoverageOptions {
|
|
1224
1889
|
/**
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1890
|
+
* Coverage provider to use.
|
|
1891
|
+
*
|
|
1892
|
+
* @default 'v8'
|
|
1227
1893
|
*/
|
|
1228
|
-
|
|
1229
|
-
static readonly version: string;
|
|
1894
|
+
provider?: "v8" | "istanbul" | "custom";
|
|
1230
1895
|
/**
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1896
|
+
* Enables coverage collection. Can be overridden using `--coverage` CLI option.
|
|
1897
|
+
*
|
|
1898
|
+
* @default false
|
|
1899
|
+
*/
|
|
1900
|
+
enabled?: boolean;
|
|
1901
|
+
/**
|
|
1902
|
+
* List of files included in coverage as glob patterns.
|
|
1903
|
+
* By default only files covered by tests are included.
|
|
1904
|
+
*
|
|
1905
|
+
* See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
|
|
1906
|
+
*/
|
|
1907
|
+
include?: string[];
|
|
1908
|
+
/**
|
|
1909
|
+
* List of files excluded from coverage as glob patterns.
|
|
1910
|
+
* Files are first checked against `coverage.include`.
|
|
1911
|
+
*
|
|
1912
|
+
* See [Including and excluding files from coverage report](https://vitest.dev/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.
|
|
1913
|
+
*/
|
|
1914
|
+
exclude?: string[];
|
|
1915
|
+
/**
|
|
1916
|
+
* Clean coverage results before running tests
|
|
1917
|
+
*
|
|
1918
|
+
* @default true
|
|
1919
|
+
*/
|
|
1920
|
+
clean?: boolean;
|
|
1921
|
+
/**
|
|
1922
|
+
* Clean coverage report on watch rerun
|
|
1923
|
+
*
|
|
1924
|
+
* @default true
|
|
1925
|
+
*/
|
|
1926
|
+
cleanOnRerun?: boolean;
|
|
1927
|
+
/**
|
|
1928
|
+
* Directory to write coverage report to
|
|
1929
|
+
*
|
|
1930
|
+
* @default './coverage'
|
|
1931
|
+
*/
|
|
1932
|
+
reportsDirectory?: string;
|
|
1933
|
+
/**
|
|
1934
|
+
* Coverage reporters to use.
|
|
1935
|
+
* See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters.
|
|
1936
|
+
*
|
|
1937
|
+
* @default ['text', 'html', 'clover', 'json']
|
|
1938
|
+
*/
|
|
1939
|
+
reporter?: Arrayable<CoverageReporter> | (CoverageReporter | [CoverageReporter] | CoverageReporterWithOptions)[];
|
|
1940
|
+
/**
|
|
1941
|
+
* Do not show files with 100% statement, branch, and function coverage
|
|
1942
|
+
*
|
|
1943
|
+
* @default false
|
|
1944
|
+
*/
|
|
1945
|
+
skipFull?: boolean;
|
|
1946
|
+
/**
|
|
1947
|
+
* Configurations for thresholds
|
|
1948
|
+
*
|
|
1233
1949
|
* @example
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1950
|
+
*
|
|
1951
|
+
* ```ts
|
|
1952
|
+
* {
|
|
1953
|
+
* // Thresholds for all files
|
|
1954
|
+
* functions: 95,
|
|
1955
|
+
* branches: 70,
|
|
1956
|
+
* perFile: true,
|
|
1957
|
+
* autoUpdate: true,
|
|
1958
|
+
*
|
|
1959
|
+
* // Thresholds for utilities
|
|
1960
|
+
* 'src/utils/**.ts': {
|
|
1961
|
+
* lines: 100,
|
|
1962
|
+
* statements: 95,
|
|
1963
|
+
* }
|
|
1964
|
+
* }
|
|
1965
|
+
* ```
|
|
1237
1966
|
*/
|
|
1238
|
-
|
|
1967
|
+
thresholds?: Thresholds | ({
|
|
1968
|
+
[glob: string]: Pick<Thresholds, 100 | "statements" | "functions" | "branches" | "lines" | "perFile">;
|
|
1969
|
+
} & Thresholds);
|
|
1239
1970
|
/**
|
|
1240
|
-
*
|
|
1241
|
-
*
|
|
1242
|
-
*
|
|
1971
|
+
* Watermarks for statements, lines, branches and functions.
|
|
1972
|
+
*
|
|
1973
|
+
* Default value is `[50,80]` for each property.
|
|
1243
1974
|
*/
|
|
1244
|
-
|
|
1975
|
+
watermarks?: {
|
|
1976
|
+
statements?: [number, number];
|
|
1977
|
+
functions?: [number, number];
|
|
1978
|
+
branches?: [number, number];
|
|
1979
|
+
lines?: [number, number];
|
|
1980
|
+
};
|
|
1245
1981
|
/**
|
|
1246
|
-
*
|
|
1982
|
+
* Generate coverage report even when tests fail.
|
|
1983
|
+
*
|
|
1984
|
+
* @default false
|
|
1247
1985
|
*/
|
|
1248
|
-
|
|
1986
|
+
reportOnFailure?: boolean;
|
|
1249
1987
|
/**
|
|
1250
|
-
*
|
|
1251
|
-
*
|
|
1988
|
+
* Collect coverage of files outside the project `root`.
|
|
1989
|
+
*
|
|
1990
|
+
* @default false
|
|
1252
1991
|
*/
|
|
1253
|
-
|
|
1992
|
+
allowExternal?: boolean;
|
|
1254
1993
|
/**
|
|
1255
|
-
*
|
|
1256
|
-
*
|
|
1994
|
+
* Apply exclusions again after coverage has been remapped to original sources.
|
|
1995
|
+
* This is useful when your source files are transpiled and may contain source maps
|
|
1996
|
+
* of non-source files.
|
|
1257
1997
|
*
|
|
1258
|
-
*
|
|
1259
|
-
*
|
|
1998
|
+
* Use this option when you are seeing files that show up in report even if they
|
|
1999
|
+
* match your `coverage.exclude` patterns.
|
|
2000
|
+
*
|
|
2001
|
+
* @default false
|
|
1260
2002
|
*/
|
|
1261
|
-
|
|
2003
|
+
excludeAfterRemap?: boolean;
|
|
1262
2004
|
/**
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1265
|
-
* By default, Vitest uses Git. You can provide a custom implementation via
|
|
1266
|
-
* `experimental.vcsProvider` in your config.
|
|
2005
|
+
* Concurrency limit used when processing the coverage results.
|
|
2006
|
+
* Defaults to `Math.min(20, os.availableParallelism())`
|
|
1267
2007
|
*/
|
|
1268
|
-
|
|
1269
|
-
private isFirstRun;
|
|
1270
|
-
private restartsCount;
|
|
1271
|
-
private readonly specifications;
|
|
1272
|
-
private pool;
|
|
1273
|
-
private _vite?;
|
|
1274
|
-
private _state?;
|
|
1275
|
-
private _cache?;
|
|
1276
|
-
private _snapshot?;
|
|
1277
|
-
private _coverageProvider?;
|
|
1278
|
-
constructor(mode: VitestRunMode, cliOptions: UserConfig, options?: VitestOptions);
|
|
1279
|
-
private _onRestartListeners;
|
|
1280
|
-
private _onClose;
|
|
1281
|
-
private _onSetServer;
|
|
1282
|
-
private _onCancelListeners;
|
|
1283
|
-
private _onUserTestsRerun;
|
|
1284
|
-
private _onFilterWatchedSpecification;
|
|
2008
|
+
processingConcurrency?: number;
|
|
1285
2009
|
/**
|
|
1286
|
-
*
|
|
2010
|
+
* Track coverage of the `node:child_process` and `node:worker_threads` spawned during test run.
|
|
2011
|
+
* Supported only by `v8` provider.
|
|
2012
|
+
*
|
|
2013
|
+
* @default false
|
|
1287
2014
|
*/
|
|
1288
|
-
|
|
2015
|
+
autoAttachSubprocess?: boolean;
|
|
1289
2016
|
/**
|
|
1290
|
-
*
|
|
2017
|
+
* Set to array of class method names to ignore for coverage
|
|
2018
|
+
*
|
|
2019
|
+
* @default []
|
|
1291
2020
|
*/
|
|
1292
|
-
|
|
2021
|
+
ignoreClassMethods?: string[];
|
|
1293
2022
|
/**
|
|
1294
|
-
*
|
|
1295
|
-
*
|
|
2023
|
+
* Filter to ignore code from coverage based on its AST node.
|
|
2024
|
+
* Called only for nodes that Vitest's built-in filters don't already ignore.
|
|
2025
|
+
* Return `'ignore-this-and-nested-nodes'` to also ignore all nodes inside the given node.
|
|
2026
|
+
* Supported only by `v8` provider.
|
|
2027
|
+
*
|
|
2028
|
+
* @example
|
|
2029
|
+
* ```ts
|
|
2030
|
+
* ignoreNode: (node, type) => type === 'statement' && node.type === 'DebuggerStatement'
|
|
2031
|
+
* ```
|
|
1296
2032
|
*/
|
|
1297
|
-
|
|
2033
|
+
ignoreNode?: (node: ESTree.Node, type: "function" | "statement" | "branch") => boolean | "ignore-this-and-nested-nodes" | void;
|
|
1298
2034
|
/**
|
|
1299
|
-
*
|
|
2035
|
+
* Custom instrumenter factory to use instead of the default `@vitest/istanbul-lib-instrument`.
|
|
2036
|
+
*
|
|
2037
|
+
* The factory receives the same runtime coverage options Vitest passes to its
|
|
2038
|
+
* built-in Istanbul instrumenter and must return an object implementing the
|
|
2039
|
+
* `CoverageInstrumenter` interface.
|
|
2040
|
+
*
|
|
2041
|
+
* This allows using faster instrumenters (e.g., oxc-coverage-instrument, SWC) while
|
|
2042
|
+
* keeping the Istanbul coverage pipeline for collection, merging, and reporting.
|
|
2043
|
+
*
|
|
2044
|
+
* @example
|
|
2045
|
+
* ```ts
|
|
2046
|
+
* import { defineConfig } from 'vitest/config'
|
|
2047
|
+
* import { createOxcInstrumenter } from 'oxc-coverage-instrument/vitest'
|
|
2048
|
+
*
|
|
2049
|
+
* export default defineConfig({
|
|
2050
|
+
* test: {
|
|
2051
|
+
* coverage: {
|
|
2052
|
+
* provider: 'istanbul',
|
|
2053
|
+
* instrumenter: options => createOxcInstrumenter(options),
|
|
2054
|
+
* }
|
|
2055
|
+
* }
|
|
2056
|
+
* })
|
|
2057
|
+
*
|
|
2058
|
+
* @experimental
|
|
1300
2059
|
*/
|
|
1301
|
-
|
|
2060
|
+
instrumenter?: (options: InstrumenterOptions) => CoverageInstrumenter;
|
|
1302
2061
|
/**
|
|
1303
|
-
*
|
|
2062
|
+
* Directory of HTML coverage output to be served in UI mode and HTML reporter.
|
|
2063
|
+
* This is automatically configured for builtin reporter with html output (`html`, `html-spa`, and `lcov` reporters).
|
|
2064
|
+
* Use this option to override with custom coverage reporting location.
|
|
1304
2065
|
*/
|
|
1305
|
-
|
|
1306
|
-
listTags(): Promise<void>;
|
|
1307
|
-
enableCoverage(): Promise<void>;
|
|
1308
|
-
disableCoverage(): void;
|
|
1309
|
-
private clearAllCachePaths;
|
|
1310
|
-
private _coverageOverrideCache;
|
|
2066
|
+
htmlDir?: string;
|
|
1311
2067
|
/**
|
|
1312
|
-
*
|
|
1313
|
-
*
|
|
1314
|
-
* @returns An array of new test projects. Can be empty if the name was filtered out.
|
|
2068
|
+
* Collect coverage only for files changed since a specified commit or branch.
|
|
2069
|
+
* Inherits the default value from `test.changed`.
|
|
1315
2070
|
*/
|
|
1316
|
-
|
|
2071
|
+
changed?: boolean | string;
|
|
1317
2072
|
/**
|
|
1318
|
-
*
|
|
2073
|
+
* Name of the module or path to a file to load the custom provider from
|
|
1319
2074
|
*/
|
|
1320
|
-
|
|
2075
|
+
customProviderModule?: string;
|
|
2076
|
+
}
|
|
2077
|
+
interface Thresholds {
|
|
2078
|
+
/** Set global thresholds to `100` */
|
|
2079
|
+
100?: boolean;
|
|
1321
2080
|
/**
|
|
1322
|
-
*
|
|
2081
|
+
* Check thresholds per file. When set to an object, the top-level thresholds
|
|
2082
|
+
* still apply to the aggregate and every file must additionally meet these
|
|
2083
|
+
* per-file minimums.
|
|
2084
|
+
*
|
|
2085
|
+
* Can also be set per glob pattern via `thresholds['<glob>'].perFile`. Glob
|
|
2086
|
+
* patterns do not inherit this top-level `perFile`; set it on each glob
|
|
2087
|
+
* explicitly.
|
|
2088
|
+
*
|
|
2089
|
+
* @default false
|
|
1323
2090
|
*/
|
|
1324
|
-
|
|
2091
|
+
perFile?: boolean | Pick<Thresholds, 100 | "statements" | "functions" | "branches" | "lines">;
|
|
1325
2092
|
/**
|
|
1326
|
-
*
|
|
2093
|
+
* Update threshold values automatically when current coverage is higher than earlier thresholds
|
|
2094
|
+
* Also can accept a function to format the new threshold values
|
|
2095
|
+
*
|
|
2096
|
+
* @default false
|
|
1327
2097
|
*/
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
2098
|
+
autoUpdate?: boolean | ((newThreshold: number, previousThreshold: number) => number);
|
|
2099
|
+
/** Thresholds for statements */
|
|
2100
|
+
statements?: number;
|
|
2101
|
+
/** Thresholds for functions */
|
|
2102
|
+
functions?: number;
|
|
2103
|
+
/** Thresholds for branches */
|
|
2104
|
+
branches?: number;
|
|
2105
|
+
/** Thresholds for lines */
|
|
2106
|
+
lines?: number;
|
|
2107
|
+
}
|
|
2108
|
+
/**
|
|
2109
|
+
* Options passed to the custom instrumenter factory.
|
|
2110
|
+
*/
|
|
2111
|
+
interface InstrumenterOptions {
|
|
2112
|
+
/** Global variable name that Vitest uses to store coverage data at runtime. */
|
|
2113
|
+
coverageVariable: string;
|
|
2114
|
+
/** Global scope where the coverage variable is attached at runtime. */
|
|
2115
|
+
coverageGlobalScope: string;
|
|
2116
|
+
/** Whether the coverage global scope should be resolved through an evaluated function. */
|
|
2117
|
+
coverageGlobalScopeFunc: boolean;
|
|
2118
|
+
/** Class method names to exclude from function coverage. */
|
|
2119
|
+
ignoreClassMethods: string[];
|
|
2120
|
+
}
|
|
2121
|
+
/**
|
|
2122
|
+
* Interface for custom coverage instrumenters.
|
|
2123
|
+
*
|
|
2124
|
+
* Matches the subset of istanbul-lib-instrument's `Instrumenter` that Vitest
|
|
2125
|
+
* actually uses. Implement this to plug in a faster instrumenter while keeping
|
|
2126
|
+
* the Istanbul coverage pipeline for collection, merging, and reporting.
|
|
2127
|
+
*/
|
|
2128
|
+
interface CoverageInstrumenter {
|
|
2129
|
+
/** Instrument source code synchronously. Returns the instrumented code string. */
|
|
2130
|
+
instrumentSync: (code: string, filename: string, inputSourceMap?: any) => string;
|
|
2131
|
+
/** Get the source map of the last instrumented file. */
|
|
2132
|
+
lastSourceMap: () => any;
|
|
2133
|
+
/** Get the Istanbul-compatible file coverage object of the last instrumented file. */
|
|
2134
|
+
lastFileCoverage: () => any;
|
|
2135
|
+
}
|
|
2136
|
+
/** @deprecated Use `CoverageOptions` instead */
|
|
2137
|
+
interface CoverageV8Options extends CoverageOptions {}
|
|
2138
|
+
/** @deprecated Use `CoverageOptions` instead */
|
|
2139
|
+
interface CoverageIstanbulOptions extends CoverageOptions {}
|
|
2140
|
+
/** @deprecated Use `CoverageOptions` instead */
|
|
2141
|
+
interface BaseCoverageOptions extends CoverageOptions {}
|
|
2142
|
+
/** @deprecated Use `CoverageOptions` instead */
|
|
2143
|
+
interface CustomProviderOptions extends CoverageOptions {}
|
|
2144
|
+
|
|
2145
|
+
interface TestRunResult {
|
|
2146
|
+
testModules: TestModule[];
|
|
2147
|
+
unhandledErrors: unknown[];
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
interface ModuleDependency {
|
|
1331
2151
|
/**
|
|
1332
|
-
*
|
|
1333
|
-
* @param moduleId The ID of the module in Vite module graph
|
|
2152
|
+
* Absolute path of the file.
|
|
1334
2153
|
*/
|
|
1335
|
-
|
|
2154
|
+
file: string;
|
|
1336
2155
|
/**
|
|
1337
|
-
*
|
|
2156
|
+
* Start time of the oldest run that recorded the file, in milliseconds since the epoch.
|
|
2157
|
+
* A change after this time was not seen by every test file that depends on the file.
|
|
2158
|
+
* It is not set when the dependency comes from the static module graph.
|
|
1338
2159
|
*/
|
|
1339
|
-
|
|
1340
|
-
|
|
2160
|
+
recordedAt?: number;
|
|
2161
|
+
}
|
|
2162
|
+
interface ModulesResolver {
|
|
1341
2163
|
/**
|
|
1342
|
-
*
|
|
1343
|
-
* @param filters String filters to match the test files.
|
|
2164
|
+
* Every file whose change can affect the test files of the run.
|
|
1344
2165
|
*/
|
|
1345
|
-
|
|
1346
|
-
|
|
2166
|
+
getDependencies(): Promise<ModuleDependency[]>;
|
|
2167
|
+
}
|
|
2168
|
+
interface VCSProviderOptions {
|
|
2169
|
+
root: string;
|
|
2170
|
+
changedSince?: string | boolean;
|
|
1347
2171
|
/**
|
|
1348
|
-
*
|
|
1349
|
-
* @experimental
|
|
2172
|
+
* Resolves the dependencies of the test files of the run.
|
|
1350
2173
|
*/
|
|
1351
|
-
|
|
2174
|
+
resolver: ModulesResolver;
|
|
2175
|
+
}
|
|
2176
|
+
interface VCSProvider {
|
|
2177
|
+
findChangedFiles(options: VCSProviderOptions): Promise<string[]>;
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
declare class SnapshotManager {
|
|
2181
|
+
options: Omit<SnapshotStateOptions, "snapshotEnvironment">;
|
|
2182
|
+
summary: SnapshotSummary;
|
|
2183
|
+
extension: string;
|
|
2184
|
+
constructor(options: Omit<SnapshotStateOptions, "snapshotEnvironment">);
|
|
2185
|
+
clear(): void;
|
|
2186
|
+
add(result: SnapshotResult): void;
|
|
2187
|
+
resolvePath<T = any>(testPath: string, context?: T): string;
|
|
2188
|
+
resolveRawPath(testPath: string, rawPath: string): string;
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
interface CachedTestFileResult {
|
|
1352
2192
|
/**
|
|
1353
|
-
*
|
|
2193
|
+
* The file has a known failure.
|
|
2194
|
+
* A complete run of the file clears it, or a run in which every known failed test passes.
|
|
1354
2195
|
*/
|
|
1355
|
-
|
|
2196
|
+
failed: boolean;
|
|
1356
2197
|
/**
|
|
1357
|
-
*
|
|
2198
|
+
* Duration of the last complete run in milliseconds.
|
|
2199
|
+
* A file that never ran completely keeps the duration of its first recorded run.
|
|
1358
2200
|
*/
|
|
1359
|
-
|
|
1360
|
-
collect(filters?: string[], options?: {
|
|
1361
|
-
staticParse?: boolean;
|
|
1362
|
-
staticParseConcurrency?: number;
|
|
1363
|
-
}): Promise<TestRunResult>;
|
|
2201
|
+
duration: number;
|
|
1364
2202
|
/**
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
2203
|
+
* Unix timestamp in milliseconds of the start of the last complete run.
|
|
2204
|
+
* It is not set if the file never ran completely.
|
|
1367
2205
|
*/
|
|
1368
|
-
|
|
2206
|
+
lastRun?: number;
|
|
1369
2207
|
/**
|
|
1370
|
-
*
|
|
1371
|
-
*
|
|
1372
|
-
* - `FilesNotFoundError` if no tests are found
|
|
1373
|
-
* - `GitNotFoundError` if `--related` flag is used, but git repository is not initialized
|
|
1374
|
-
* - `Error` from the user reporters
|
|
1375
|
-
* @param filters String filters to match the test files
|
|
2208
|
+
* Full names of the tests that failed in the last run of the file. `--last-failed` runs only these tests.
|
|
2209
|
+
* It is not set if the failure happened outside of tests, for example in a hook or during collection.
|
|
1376
2210
|
*/
|
|
1377
|
-
|
|
2211
|
+
failedTests?: string[];
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
declare class VitestCache {
|
|
2215
|
+
private fileStats;
|
|
2216
|
+
private warnedMethods;
|
|
1378
2217
|
/**
|
|
1379
|
-
*
|
|
2218
|
+
* Returns the result of the test file from the previous test runs.
|
|
1380
2219
|
*/
|
|
1381
|
-
|
|
2220
|
+
getTestSpecificationResult(specification: TestSpecification): CachedTestFileResult | undefined;
|
|
1382
2221
|
/**
|
|
1383
|
-
*
|
|
1384
|
-
* If the `--watch` flag is provided, Vitest will still run changed tests even if this method was not called.
|
|
2222
|
+
* @deprecated Use `getTestSpecificationResult(specification)` instead.
|
|
1385
2223
|
*/
|
|
1386
|
-
|
|
2224
|
+
getFileTestResults(key: string): CachedTestFileResult | undefined;
|
|
1387
2225
|
/**
|
|
1388
|
-
*
|
|
1389
|
-
* resolve when the test run is finished.
|
|
2226
|
+
* @deprecated Vitest does not cache file sizes anymore. Read the size from the file system instead.
|
|
1390
2227
|
*/
|
|
1391
|
-
|
|
2228
|
+
getFileStats(key: string): {
|
|
2229
|
+
size: number;
|
|
2230
|
+
} | undefined;
|
|
2231
|
+
private readFileStats;
|
|
2232
|
+
private deprecate;
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
type TestRunEndReason = "passed" | "interrupted" | "failed";
|
|
2236
|
+
interface Reporter {
|
|
2237
|
+
onInit?: (vitest: Vitest) => void;
|
|
1392
2238
|
/**
|
|
1393
|
-
*
|
|
1394
|
-
*
|
|
1395
|
-
* **Note:** this method relies on a cache generated by `globTestSpecifications`. If the file was not processed yet, use `project.matchesGlobPattern` instead.
|
|
1396
|
-
* @param moduleId The module ID to get test specifications for.
|
|
2239
|
+
* Called when the project initiated the browser instance.
|
|
2240
|
+
* project.browser will always be defined.
|
|
1397
2241
|
*/
|
|
1398
|
-
|
|
2242
|
+
onBrowserInit?: (project: TestProject) => Awaitable<void>;
|
|
2243
|
+
onTestRemoved?: (trigger?: string) => Awaitable<void>;
|
|
2244
|
+
onWatcherStart?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
|
|
2245
|
+
onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
|
|
2246
|
+
onServerRestart?: (reason?: string) => Awaitable<void>;
|
|
2247
|
+
onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
|
|
2248
|
+
onProcessTimeout?: () => Awaitable<void>;
|
|
1399
2249
|
/**
|
|
1400
|
-
*
|
|
2250
|
+
* Called when the new test run starts.
|
|
1401
2251
|
*/
|
|
1402
|
-
|
|
2252
|
+
onTestRunStart?: (specifications: ReadonlyArray<TestSpecification>) => Awaitable<void>;
|
|
1403
2253
|
/**
|
|
1404
|
-
*
|
|
1405
|
-
* @param specifications A list of specifications to run.
|
|
1406
|
-
* @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
|
|
2254
|
+
* Called when the test run is finished.
|
|
1407
2255
|
*/
|
|
1408
|
-
|
|
2256
|
+
onTestRunEnd?: (testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason) => Awaitable<void>;
|
|
1409
2257
|
/**
|
|
1410
|
-
*
|
|
1411
|
-
* @param filepaths A list of file paths to run tests for.
|
|
1412
|
-
* @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
|
|
2258
|
+
* Called when the module is enqueued for testing. The file itself is not loaded yet.
|
|
1413
2259
|
*/
|
|
1414
|
-
|
|
2260
|
+
onTestModuleQueued?: (testModule: TestModule) => Awaitable<void>;
|
|
1415
2261
|
/**
|
|
1416
|
-
*
|
|
1417
|
-
* @param specifications A list of specifications to run.
|
|
1418
|
-
* @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
|
|
2262
|
+
* Called when the test file is loaded and the module is ready to run tests.
|
|
1419
2263
|
*/
|
|
1420
|
-
|
|
1421
|
-
private runFiles;
|
|
2264
|
+
onTestModuleCollected?: (testModule: TestModule) => Awaitable<void>;
|
|
1422
2265
|
/**
|
|
1423
|
-
*
|
|
1424
|
-
*
|
|
1425
|
-
* If the module was not transformed or executed, the diagnostic will be empty.
|
|
1426
|
-
* @experimental
|
|
1427
|
-
* @see {@link https://vitest.dev/api/advanced/vitest#getsourcemodulediagnostic}
|
|
2266
|
+
* Called when starting to run tests of the test file
|
|
1428
2267
|
*/
|
|
1429
|
-
|
|
1430
|
-
experimental_parseSpecifications(specifications: TestSpecification[], options?: {
|
|
1431
|
-
/** @default os.availableParallelism() */
|
|
1432
|
-
concurrency?: number;
|
|
1433
|
-
}): Promise<TestModule[]>;
|
|
1434
|
-
experimental_parseSpecification(specification: TestSpecification): Promise<TestModule>;
|
|
2268
|
+
onTestModuleStart?: (testModule: TestModule) => Awaitable<void>;
|
|
1435
2269
|
/**
|
|
1436
|
-
*
|
|
1437
|
-
* @param specifications A list of specifications to run.
|
|
2270
|
+
* Called when all tests of the test file have finished running.
|
|
1438
2271
|
*/
|
|
1439
|
-
|
|
2272
|
+
onTestModuleEnd?: (testModule: TestModule) => Awaitable<void>;
|
|
1440
2273
|
/**
|
|
1441
|
-
*
|
|
2274
|
+
* Called when test case is ready to run.
|
|
2275
|
+
* Called before the `beforeEach` hooks for the test are run.
|
|
1442
2276
|
*/
|
|
1443
|
-
|
|
1444
|
-
private initializeGlobalSetup;
|
|
2277
|
+
onTestCaseReady?: (testCase: TestCase) => Awaitable<void>;
|
|
1445
2278
|
/**
|
|
1446
|
-
*
|
|
1447
|
-
*
|
|
2279
|
+
* Called after the test and its hooks are finished running.
|
|
2280
|
+
* The `result()` cannot be `pending`.
|
|
1448
2281
|
*/
|
|
1449
|
-
|
|
2282
|
+
onTestCaseResult?: (testCase: TestCase) => Awaitable<void>;
|
|
1450
2283
|
/**
|
|
1451
|
-
*
|
|
1452
|
-
* This method doesn't run any tests.
|
|
1453
|
-
*
|
|
1454
|
-
* Every test that runs after this method is called will update snapshots.
|
|
1455
|
-
* To disable the mode, call `resetSnapshotUpdate`.
|
|
2284
|
+
* Called when annotation is added via the `task.annotate` API.
|
|
1456
2285
|
*/
|
|
1457
|
-
|
|
2286
|
+
onTestCaseAnnotate?: (testCase: TestCase, annotation: TestAnnotation) => Awaitable<void>;
|
|
1458
2287
|
/**
|
|
1459
|
-
*
|
|
2288
|
+
* Called when artifacts are recorded on tests via the `recordArtifact` utility.
|
|
1460
2289
|
*/
|
|
1461
|
-
|
|
2290
|
+
onTestCaseArtifactRecord?: (testCase: TestCase, artifact: TestArtifact) => Awaitable<void>;
|
|
1462
2291
|
/**
|
|
1463
|
-
*
|
|
1464
|
-
*
|
|
2292
|
+
* Called when test suite is ready to run.
|
|
2293
|
+
* Called before the `beforeAll` hooks for the test are run.
|
|
1465
2294
|
*/
|
|
1466
|
-
|
|
2295
|
+
onTestSuiteReady?: (testSuite: TestSuite) => Awaitable<void>;
|
|
1467
2296
|
/**
|
|
1468
|
-
*
|
|
2297
|
+
* Called after the test suite and its hooks are finished running.
|
|
2298
|
+
* The `state` cannot be `pending`.
|
|
1469
2299
|
*/
|
|
1470
|
-
|
|
2300
|
+
onTestSuiteResult?: (testSuite: TestSuite) => Awaitable<void>;
|
|
1471
2301
|
/**
|
|
1472
|
-
*
|
|
2302
|
+
* Called before the hook starts to run.
|
|
1473
2303
|
*/
|
|
1474
|
-
|
|
1475
|
-
private _rerunTimer;
|
|
1476
|
-
private scheduleRerun;
|
|
2304
|
+
onHookStart?: (hook: ReportedHookContext) => Awaitable<void>;
|
|
1477
2305
|
/**
|
|
1478
|
-
*
|
|
2306
|
+
* Called after the hook finished running.
|
|
1479
2307
|
*/
|
|
1480
|
-
|
|
1481
|
-
|
|
2308
|
+
onHookEnd?: (hook: ReportedHookContext) => Awaitable<void>;
|
|
2309
|
+
onCoverage?: (coverage: unknown) => Awaitable<void>;
|
|
1482
2310
|
/**
|
|
1483
|
-
*
|
|
1484
|
-
*
|
|
2311
|
+
* @experimental
|
|
2312
|
+
* Called after the benchmark is finished.
|
|
1485
2313
|
*/
|
|
1486
|
-
|
|
2314
|
+
onTestCaseBenchmark?: (testCase: TestCase, benchmark: TestBenchmark) => Awaitable<void>;
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
interface BlobOptions {
|
|
2318
|
+
outputFile?: string;
|
|
2319
|
+
label?: string;
|
|
2320
|
+
}
|
|
2321
|
+
declare class BlobReporter implements Reporter {
|
|
2322
|
+
start: number;
|
|
2323
|
+
ctx: Vitest;
|
|
2324
|
+
options: BlobOptions;
|
|
2325
|
+
coverage: unknown | undefined;
|
|
2326
|
+
constructor(options: BlobOptions);
|
|
2327
|
+
onInit(ctx: Vitest): void;
|
|
2328
|
+
onCoverage(coverage: unknown): void;
|
|
2329
|
+
onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): Promise<void>;
|
|
2330
|
+
}
|
|
2331
|
+
interface MergedBlobs {
|
|
2332
|
+
files: File[];
|
|
2333
|
+
errors: unknown[];
|
|
2334
|
+
coverages: unknown[];
|
|
2335
|
+
executionTimes: number[];
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
declare class StateManager {
|
|
2339
|
+
filesMap: Map<string, File[]>;
|
|
2340
|
+
pathsSet: Set<string>;
|
|
2341
|
+
idMap: Map<string, Task>;
|
|
2342
|
+
taskFileMap: WeakMap<Task, File>;
|
|
2343
|
+
errorsSet: Set<unknown>;
|
|
2344
|
+
leakSet: Set<AsyncLeak>;
|
|
2345
|
+
reportedTasksMap: WeakMap<Task, TestModule | TestCase | TestSuite>;
|
|
2346
|
+
blobs?: MergedBlobs;
|
|
1487
2347
|
/**
|
|
1488
|
-
*
|
|
1489
|
-
*
|
|
2348
|
+
* Total time spent starting test workers (spawning the process/thread, loading
|
|
2349
|
+
* the worker bundle and setting up the test environment). Used to surface the
|
|
2350
|
+
* cost of `isolate: true`, which spawns a fresh worker per test file.
|
|
1490
2351
|
*/
|
|
1491
|
-
|
|
2352
|
+
startupTime: number;
|
|
2353
|
+
/** Number of test workers that were started during the run. */
|
|
2354
|
+
workersSpawned: number;
|
|
2355
|
+
metadata: Record<string, {
|
|
2356
|
+
externalized: Record<string, string>;
|
|
2357
|
+
duration: Record<string, number[]>;
|
|
2358
|
+
tmps: Record<string, string>;
|
|
2359
|
+
dumpDir?: string;
|
|
2360
|
+
outline?: {
|
|
2361
|
+
externalized: number;
|
|
2362
|
+
inlined: number;
|
|
2363
|
+
};
|
|
2364
|
+
}>;
|
|
2365
|
+
onUnhandledError?: OnUnhandledErrorCallback;
|
|
2366
|
+
constructor(options: {
|
|
2367
|
+
onUnhandledError?: OnUnhandledErrorCallback;
|
|
2368
|
+
});
|
|
2369
|
+
catchError(error: unknown, type: string): void;
|
|
2370
|
+
catchLeaks(leaks: AsyncLeak[]): void;
|
|
2371
|
+
clearErrors(): void;
|
|
2372
|
+
getUnhandledErrors(): unknown[];
|
|
2373
|
+
getPaths(): string[];
|
|
1492
2374
|
/**
|
|
1493
|
-
*
|
|
2375
|
+
* Return files that were running or collected.
|
|
1494
2376
|
*/
|
|
1495
|
-
|
|
2377
|
+
getFiles(keys?: string[]): File[];
|
|
2378
|
+
getTestModules(keys?: string[]): TestModule[];
|
|
2379
|
+
getFilepaths(): string[];
|
|
2380
|
+
getFailedFilepaths(): string[];
|
|
2381
|
+
collectPaths(paths?: string[]): void;
|
|
2382
|
+
collectFiles(project: TestProject, files?: File[]): void;
|
|
2383
|
+
clearFiles(project: TestProject, paths?: string[]): void;
|
|
2384
|
+
updateId(task: Task, project: TestProject): void;
|
|
2385
|
+
getReportedEntity(task: Task): TestModule | TestCase | TestSuite | undefined;
|
|
2386
|
+
getReportedEntityById(taskId: string): TestModule | TestCase | TestSuite | undefined;
|
|
2387
|
+
updateTasks(packs: TaskResultPack[]): void;
|
|
2388
|
+
updateUserLog(log: UserConsoleLog): void;
|
|
2389
|
+
getCountOfFailedTests(): number;
|
|
2390
|
+
cancelFiles(files: FileSpecification[], project: TestProject): void;
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2393
|
+
type EventName = "add" | "addDir" | "change" | "unlink" | "unlinkDir";
|
|
2394
|
+
type TrackEventName = EventName | "any";
|
|
2395
|
+
type Track = (filepath: string, options?: {
|
|
2396
|
+
timeout?: number;
|
|
2397
|
+
type?: TrackEventName;
|
|
2398
|
+
}) => Promise<void>;
|
|
2399
|
+
declare class VitestWatcher {
|
|
2400
|
+
private vitest;
|
|
1496
2401
|
/**
|
|
1497
|
-
*
|
|
2402
|
+
* Modules that will be invalidated on the next run.
|
|
1498
2403
|
*/
|
|
1499
|
-
|
|
2404
|
+
readonly invalidates: Set<string>;
|
|
1500
2405
|
/**
|
|
1501
|
-
*
|
|
2406
|
+
* Test files that have changed and need to be rerun.
|
|
1502
2407
|
*/
|
|
1503
|
-
|
|
2408
|
+
readonly changedTests: Set<string>;
|
|
2409
|
+
private readonly _onRerun;
|
|
2410
|
+
private trackers;
|
|
2411
|
+
constructor(vitest: Vitest);
|
|
2412
|
+
close(): void;
|
|
2413
|
+
unregisterWatcher: () => void;
|
|
2414
|
+
registerWatcher(): this;
|
|
2415
|
+
private scheduleRerun;
|
|
2416
|
+
private getTestFilesFromWatcherTrigger;
|
|
2417
|
+
onFileChange: (id: string) => void;
|
|
2418
|
+
onFileDelete: (id: string) => void;
|
|
2419
|
+
onFileCreate: (id: string) => void;
|
|
2420
|
+
private handleProjectFile;
|
|
1504
2421
|
/**
|
|
1505
|
-
*
|
|
2422
|
+
* @returns A value indicating whether rerun is needed (changedTests was mutated)
|
|
1506
2423
|
*/
|
|
1507
|
-
|
|
2424
|
+
private handleFileChanged;
|
|
2425
|
+
createTracker(): {
|
|
2426
|
+
track: Track;
|
|
2427
|
+
stop: () => void;
|
|
2428
|
+
};
|
|
2429
|
+
private track;
|
|
2430
|
+
private handleTrackEvent;
|
|
2431
|
+
private resolveTrackEvent;
|
|
2432
|
+
}
|
|
2433
|
+
interface WatcherTriggerPattern {
|
|
2434
|
+
pattern: RegExp;
|
|
2435
|
+
testsToRun: (file: string, match: RegExpMatchArray) => string[] | string | null | undefined | void;
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2438
|
+
interface VitestOptions {
|
|
2439
|
+
packageInstaller?: VitestPackageInstaller;
|
|
2440
|
+
stdin?: NodeJS.ReadStream;
|
|
2441
|
+
stdout?: NodeJS.WriteStream | Writable;
|
|
2442
|
+
stderr?: NodeJS.WriteStream | Writable;
|
|
2443
|
+
}
|
|
2444
|
+
declare class Vitest {
|
|
1508
2445
|
/**
|
|
1509
|
-
*
|
|
2446
|
+
* Current Vitest version.
|
|
2447
|
+
* @example '2.0.0'
|
|
1510
2448
|
*/
|
|
1511
|
-
|
|
2449
|
+
readonly version: string;
|
|
2450
|
+
static readonly version: string;
|
|
1512
2451
|
/**
|
|
1513
|
-
*
|
|
1514
|
-
*
|
|
2452
|
+
* The logger instance used to log messages. It's recommended to use this logger instead of `console`.
|
|
2453
|
+
* It's possible to override stdout and stderr streams when initiating Vitest.
|
|
1515
2454
|
* @example
|
|
1516
|
-
*
|
|
1517
|
-
*
|
|
2455
|
+
* new Vitest({
|
|
2456
|
+
* stdout: new Writable(),
|
|
2457
|
+
* })
|
|
1518
2458
|
*/
|
|
1519
|
-
|
|
2459
|
+
readonly logger: Logger;
|
|
1520
2460
|
/**
|
|
1521
|
-
*
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
type OnTestsRerunHandler = (testFiles: TestSpecification[]) => Promise<void> | void;
|
|
1527
|
-
|
|
1528
|
-
interface BrowserModuleMocker {
|
|
1529
|
-
register: (sessionId: string, module: MockedModule) => Promise<void>;
|
|
1530
|
-
delete: (sessionId: string, url: string) => Promise<void>;
|
|
1531
|
-
clear: (sessionId: string) => Promise<void>;
|
|
1532
|
-
}
|
|
1533
|
-
interface BrowserProviderOption<Options extends object = object> {
|
|
1534
|
-
name: string;
|
|
1535
|
-
supportedBrowser?: ReadonlyArray<string>;
|
|
1536
|
-
options: Options;
|
|
1537
|
-
providerFactory: (project: TestProject) => BrowserProvider;
|
|
1538
|
-
serverFactory: BrowserServerFactory;
|
|
1539
|
-
}
|
|
1540
|
-
interface BrowserServerOptions {
|
|
1541
|
-
project: TestProject;
|
|
1542
|
-
coveragePlugin: () => Plugin;
|
|
1543
|
-
mocksPlugins: (options: {
|
|
1544
|
-
filter: (id: string) => boolean;
|
|
1545
|
-
}) => Plugin[];
|
|
1546
|
-
metaEnvReplacer: () => Plugin;
|
|
1547
|
-
}
|
|
1548
|
-
interface BrowserServerFactory {
|
|
1549
|
-
(options: BrowserServerOptions): Promise<ParentProjectBrowser>;
|
|
1550
|
-
}
|
|
1551
|
-
interface BrowserProvider {
|
|
1552
|
-
name: string;
|
|
1553
|
-
mocker?: BrowserModuleMocker;
|
|
1554
|
-
readonly initScripts?: string[];
|
|
2461
|
+
* The package installer instance used to install Vitest packages.
|
|
2462
|
+
* @example
|
|
2463
|
+
* await vitest.packageInstaller.ensureInstalled('@vitest/browser', process.cwd())
|
|
2464
|
+
*/
|
|
2465
|
+
readonly packageInstaller: VitestPackageInstaller;
|
|
1555
2466
|
/**
|
|
1556
|
-
*
|
|
2467
|
+
* A path to the built Vitest directory. This is usually a folder in `node_modules`.
|
|
1557
2468
|
*/
|
|
1558
|
-
|
|
1559
|
-
getCommandsContext: (sessionId: string) => Record<string, unknown>;
|
|
1560
|
-
openPage: (sessionId: string, url: string, options: {
|
|
1561
|
-
parallel: boolean;
|
|
1562
|
-
}) => Promise<void>;
|
|
1563
|
-
getCDPSession?: (sessionId: string) => Promise<CDPSession>;
|
|
1564
|
-
close: () => Awaitable<void>;
|
|
1565
|
-
}
|
|
1566
|
-
type BrowserBuiltinProvider = "webdriverio" | "playwright" | "preview";
|
|
1567
|
-
interface _BrowserNames {}
|
|
1568
|
-
type UnsupportedProperties = "browser" | "typecheck" | "alias" | "sequence" | "root" | "pool" | "runner" | "api" | "deps" | "environment" | "environmentOptions" | "server" | "benchmark" | "name";
|
|
1569
|
-
interface BrowserInstanceOption extends Omit<ProjectConfig, UnsupportedProperties>, Pick<BrowserConfigOptions, "headless" | "locators" | "viewport" | "testerHtmlPath" | "screenshotDirectory" | "screenshotFailures"> {
|
|
2469
|
+
readonly distPath: string;
|
|
1570
2470
|
/**
|
|
1571
|
-
*
|
|
2471
|
+
* A list of projects that are currently running.
|
|
2472
|
+
* If projects were filtered with `--project` flag, they won't appear here.
|
|
1572
2473
|
*/
|
|
1573
|
-
|
|
1574
|
-
name?: string;
|
|
1575
|
-
provider?: BrowserProviderOption;
|
|
1576
|
-
}
|
|
1577
|
-
interface BrowserConfigOptions {
|
|
2474
|
+
projects: TestProject[];
|
|
1578
2475
|
/**
|
|
1579
|
-
*
|
|
2476
|
+
* A watcher handler. This is not the file system watcher. The handler only
|
|
2477
|
+
* exposes methods to handle changed files.
|
|
1580
2478
|
*
|
|
1581
|
-
*
|
|
2479
|
+
* If you have your own watcher, you can use these methods to replicate
|
|
2480
|
+
* Vitest behaviour.
|
|
1582
2481
|
*/
|
|
1583
|
-
|
|
2482
|
+
readonly watcher: VitestWatcher;
|
|
1584
2483
|
/**
|
|
1585
|
-
*
|
|
2484
|
+
* The version control system provider used to detect changed files.
|
|
2485
|
+
* This is used with the `--changed` flag to determine which test files to run.
|
|
2486
|
+
* By default, Vitest uses Git. You can provide a custom implementation via
|
|
2487
|
+
* `experimental.vcsProvider` in your config.
|
|
1586
2488
|
*/
|
|
1587
|
-
|
|
2489
|
+
vcs: VCSProvider;
|
|
1588
2490
|
/**
|
|
1589
|
-
*
|
|
1590
|
-
* @example
|
|
1591
|
-
* ```ts
|
|
1592
|
-
* import { playwright } from '@vitest/browser-playwright'
|
|
1593
|
-
* export default defineConfig({
|
|
1594
|
-
* test: {
|
|
1595
|
-
* browser: {
|
|
1596
|
-
* provider: playwright(),
|
|
1597
|
-
* },
|
|
1598
|
-
* },
|
|
1599
|
-
* })
|
|
1600
|
-
* ```
|
|
2491
|
+
* The global config.
|
|
1601
2492
|
*/
|
|
1602
|
-
|
|
2493
|
+
config: ResolvedConfig;
|
|
1603
2494
|
/**
|
|
1604
|
-
*
|
|
1605
|
-
*
|
|
1606
|
-
* @default process.env.CI
|
|
2495
|
+
* Resolved global vite config.
|
|
1607
2496
|
*/
|
|
1608
|
-
|
|
2497
|
+
viteConfig: ResolvedConfig$1;
|
|
1609
2498
|
/**
|
|
1610
|
-
*
|
|
1611
|
-
*
|
|
1612
|
-
* The default port is 63315.
|
|
2499
|
+
* Global Vite's dev server instance.
|
|
1613
2500
|
*/
|
|
1614
|
-
|
|
2501
|
+
vite: ViteDevServer;
|
|
1615
2502
|
/**
|
|
1616
|
-
*
|
|
1617
|
-
*
|
|
1618
|
-
* @default true
|
|
1619
|
-
* @deprecated use top-level `isolate` instead
|
|
2503
|
+
* The global test state manager.
|
|
2504
|
+
* @experimental The State API is experimental and not subject to semver.
|
|
1620
2505
|
*/
|
|
1621
|
-
|
|
2506
|
+
state: StateManager;
|
|
1622
2507
|
/**
|
|
1623
|
-
*
|
|
1624
|
-
* This option only has effect in headless mode (enabled in CI by default)
|
|
1625
|
-
*
|
|
1626
|
-
* @default // Same as "test.fileParallelism"
|
|
1627
|
-
* @deprecated use top-level `fileParallelism` instead
|
|
2508
|
+
* The global snapshot manager. You can access the current state on `snapshot.summary`.
|
|
1628
2509
|
*/
|
|
1629
|
-
|
|
2510
|
+
snapshot: SnapshotManager;
|
|
1630
2511
|
/**
|
|
1631
|
-
*
|
|
1632
|
-
*
|
|
1633
|
-
* @default !process.env.CI
|
|
2512
|
+
* The cache of the previous test runs. Primarily used by the sequencer to sort tests.
|
|
1634
2513
|
*/
|
|
1635
|
-
|
|
2514
|
+
cache: VitestCache;
|
|
2515
|
+
private _warnedExperimentalCacheKeyGenerator;
|
|
2516
|
+
private isFirstRun;
|
|
2517
|
+
private restartsCount;
|
|
2518
|
+
private readonly specifications;
|
|
2519
|
+
private pool;
|
|
2520
|
+
private _coverageProvider?;
|
|
1636
2521
|
/**
|
|
1637
|
-
*
|
|
1638
|
-
* 'right' shows the details panel on the right side (horizontal split)
|
|
1639
|
-
* 'bottom' shows the details panel at the bottom (vertical split)
|
|
1640
|
-
* @default 'right'
|
|
2522
|
+
* @deprecated Do not rely on this property, it's always `test`. Scheduled to be removed in the next major.
|
|
1641
2523
|
*/
|
|
1642
|
-
|
|
2524
|
+
readonly mode = "test";
|
|
2525
|
+
constructor(harness: PluginHarness, viteConfig: ResolvedConfig$1);
|
|
2526
|
+
private _onRestartListeners;
|
|
2527
|
+
private _onClose;
|
|
2528
|
+
private _onSetServer;
|
|
2529
|
+
private _onCancelListeners;
|
|
2530
|
+
private _onUserTestsRerun;
|
|
2531
|
+
private _onFilterWatchedSpecification;
|
|
2532
|
+
private _restartPromise?;
|
|
2533
|
+
private _restartQueued;
|
|
2534
|
+
private _restart;
|
|
2535
|
+
private _restartNow;
|
|
2536
|
+
listTags(): Promise<void>;
|
|
2537
|
+
enableCoverage(): Promise<void>;
|
|
2538
|
+
disableCoverage(): void;
|
|
2539
|
+
private clearAllCachePaths;
|
|
2540
|
+
private _coverageOverrideCache;
|
|
1643
2541
|
/**
|
|
1644
|
-
*
|
|
2542
|
+
* Inject new test projects into the workspace.
|
|
2543
|
+
* @param config Glob, config path or a custom config options.
|
|
2544
|
+
* @returns An array of new test projects. Can be empty if the name was filtered out.
|
|
1645
2545
|
*/
|
|
1646
|
-
|
|
1647
|
-
/**
|
|
1648
|
-
* Width of the viewport
|
|
1649
|
-
* @default 414
|
|
1650
|
-
*/
|
|
1651
|
-
width: number;
|
|
1652
|
-
/**
|
|
1653
|
-
* Height of the viewport
|
|
1654
|
-
* @default 896
|
|
1655
|
-
*/
|
|
1656
|
-
height: number;
|
|
1657
|
-
};
|
|
2546
|
+
private injectTestProject;
|
|
1658
2547
|
/**
|
|
1659
|
-
*
|
|
2548
|
+
* Provide a value to the test context. This value will be available to all tests with `inject`.
|
|
1660
2549
|
*/
|
|
1661
|
-
|
|
1662
|
-
/**
|
|
1663
|
-
* Attribute used to locate elements by test id
|
|
1664
|
-
* @default 'data-testid'
|
|
1665
|
-
*/
|
|
1666
|
-
testIdAttribute?: string;
|
|
1667
|
-
/**
|
|
1668
|
-
* Should locators match the text exactly by default
|
|
1669
|
-
* @default false
|
|
1670
|
-
*/
|
|
1671
|
-
exact?: boolean;
|
|
1672
|
-
};
|
|
2550
|
+
provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
|
|
1673
2551
|
/**
|
|
1674
|
-
*
|
|
1675
|
-
*
|
|
1676
|
-
* This option is supported only by **playwright** provider.
|
|
2552
|
+
* Get global provided context.
|
|
1677
2553
|
*/
|
|
1678
|
-
|
|
1679
|
-
mode: BrowserTraceViewMode;
|
|
1680
|
-
/**
|
|
1681
|
-
* The directory where all traces will be stored. By default, Vitest
|
|
1682
|
-
* stores all traces in `__traces__` folder close to the test file.
|
|
1683
|
-
*/
|
|
1684
|
-
tracesDir?: string;
|
|
1685
|
-
/**
|
|
1686
|
-
* Whether to capture screenshots during tracing. Screenshots are used to build a timeline preview.
|
|
1687
|
-
* @default true
|
|
1688
|
-
*/
|
|
1689
|
-
screenshots?: boolean;
|
|
1690
|
-
/**
|
|
1691
|
-
* If this option is true tracing will
|
|
1692
|
-
* - capture DOM snapshot on every action
|
|
1693
|
-
* - record network activity
|
|
1694
|
-
* @default true
|
|
1695
|
-
*/
|
|
1696
|
-
snapshots?: boolean;
|
|
1697
|
-
};
|
|
2554
|
+
getProvidedContext(): ProvidedContext;
|
|
1698
2555
|
/**
|
|
1699
|
-
*
|
|
1700
|
-
* If not set, all screenshots are saved to __screenshots__ directory in the same folder as the test file.
|
|
1701
|
-
* If this is set, it will be resolved relative to the project root.
|
|
1702
|
-
* @default __screenshots__
|
|
2556
|
+
* Return project that has the root (or "global") config.
|
|
1703
2557
|
*/
|
|
1704
|
-
|
|
2558
|
+
getRootProject(): TestProject;
|
|
2559
|
+
get serializedRootConfig(): SerializedRootConfig;
|
|
2560
|
+
getProjectByName(name: string): TestProject;
|
|
1705
2561
|
/**
|
|
1706
|
-
*
|
|
1707
|
-
* @
|
|
2562
|
+
* Import a file using Vite module runner. The file will be transformed by Vite and executed in a separate context.
|
|
2563
|
+
* @param moduleId The ID of the module in Vite module graph
|
|
1708
2564
|
*/
|
|
1709
|
-
|
|
2565
|
+
import<T>(moduleId: string): Promise<T>;
|
|
1710
2566
|
/**
|
|
1711
|
-
*
|
|
2567
|
+
* Creates a coverage provider if `coverage` is enabled in the config.
|
|
1712
2568
|
*/
|
|
1713
|
-
|
|
2569
|
+
createCoverageProvider(): Promise<CoverageProvider | null>;
|
|
1714
2570
|
/**
|
|
1715
|
-
*
|
|
2571
|
+
* Glob test files in every project and create a TestSpecification for each file and pool.
|
|
2572
|
+
* @param filters String filters to match the test files.
|
|
1716
2573
|
*/
|
|
1717
|
-
|
|
2574
|
+
globTestSpecifications(filters?: string[]): Promise<TestSpecification[]>;
|
|
2575
|
+
private initCoverageProvider;
|
|
1718
2576
|
/**
|
|
1719
|
-
*
|
|
1720
|
-
* via the browser `import("vitest/browser").commands` API.
|
|
1721
|
-
* @see {@link https://vitest.dev/api/browser/commands}
|
|
2577
|
+
* @deprecated Use `clearCache` instead.
|
|
1722
2578
|
*/
|
|
1723
|
-
|
|
2579
|
+
experimental_clearCache(): Promise<void>;
|
|
1724
2580
|
/**
|
|
1725
|
-
*
|
|
1726
|
-
* @default 30000
|
|
2581
|
+
* Deletes all Vitest caches, including the `fsModuleCache`.
|
|
1727
2582
|
*/
|
|
1728
|
-
|
|
1729
|
-
expect?: {
|
|
1730
|
-
toMatchScreenshot?: { [ComparatorName in keyof ToMatchScreenshotComparators] : {
|
|
1731
|
-
/**
|
|
1732
|
-
* The name of the comparator to use for visual diffing.
|
|
1733
|
-
*
|
|
1734
|
-
* @defaultValue `'pixelmatch'`
|
|
1735
|
-
*/
|
|
1736
|
-
comparatorName?: ComparatorName;
|
|
1737
|
-
comparatorOptions?: ToMatchScreenshotComparators[ComparatorName];
|
|
1738
|
-
} }[keyof ToMatchScreenshotComparators] & ToMatchScreenshotOptions;
|
|
1739
|
-
};
|
|
2583
|
+
clearCache(): Promise<void>;
|
|
1740
2584
|
/**
|
|
1741
|
-
*
|
|
1742
|
-
*
|
|
1743
|
-
* If you need to hide certain errors, it is recommended to use [`onUnhandledError`](https://vitest.dev/config/onunhandlederror) option instead.
|
|
1744
|
-
*
|
|
1745
|
-
* Disabling this will completely remove all Vitest error handlers, which can help debugging with the "Pause on exceptions" checkbox turned on.
|
|
1746
|
-
* @default true
|
|
2585
|
+
* Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified).
|
|
1747
2586
|
*/
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
}
|
|
1757
|
-
interface BrowserServerStateSession {
|
|
1758
|
-
project: TestProject;
|
|
1759
|
-
otelCarrier?: OTELCarrier;
|
|
1760
|
-
connected: () => void;
|
|
1761
|
-
ready: () => void;
|
|
1762
|
-
fail: (v: Error) => void;
|
|
1763
|
-
}
|
|
1764
|
-
interface BrowserOrchestrator {
|
|
1765
|
-
cleanupTesters: () => Promise<void>;
|
|
1766
|
-
createTesters: (options: BrowserTesterOptions) => Promise<void>;
|
|
1767
|
-
onCancel: (reason: CancelReason) => Promise<void>;
|
|
1768
|
-
$close: () => void;
|
|
1769
|
-
}
|
|
1770
|
-
interface BrowserServerState {
|
|
1771
|
-
orchestrators: Map<string, BrowserOrchestrator>;
|
|
1772
|
-
}
|
|
1773
|
-
interface ParentProjectBrowser {
|
|
1774
|
-
spawn: (project: TestProject) => ProjectBrowser;
|
|
1775
|
-
vite: ViteDevServer;
|
|
1776
|
-
}
|
|
1777
|
-
interface ProjectBrowser {
|
|
1778
|
-
vite: ViteDevServer;
|
|
1779
|
-
state: BrowserServerState;
|
|
1780
|
-
provider: BrowserProvider;
|
|
1781
|
-
close: () => Promise<void>;
|
|
1782
|
-
initBrowserProvider: (project: TestProject) => Promise<void>;
|
|
1783
|
-
parseStacktrace: (stack: string) => ParsedStack[];
|
|
1784
|
-
parseErrorStacktrace: (error: TestError, options?: StackTraceParserOptions) => ParsedStack[];
|
|
1785
|
-
registerCommand: <K extends keyof BrowserCommands>(name: K, cb: BrowserCommand<Parameters<BrowserCommands[K]>, ReturnType<BrowserCommands[K]>>) => void;
|
|
1786
|
-
triggerCommand: <K extends keyof BrowserCommands>(name: K, context: BrowserCommandContext, ...args: Parameters<BrowserCommands[K]>) => ReturnType<BrowserCommands[K]>;
|
|
1787
|
-
}
|
|
1788
|
-
interface BrowserCommand<
|
|
1789
|
-
Payload extends unknown[] = [],
|
|
1790
|
-
ReturnValue = any
|
|
1791
|
-
> {
|
|
1792
|
-
(context: BrowserCommandContext, ...payload: Payload): Awaitable<ReturnValue>;
|
|
1793
|
-
}
|
|
1794
|
-
interface BrowserScript {
|
|
2587
|
+
mergeReports(directory?: string): Promise<TestRunResult>;
|
|
2588
|
+
/**
|
|
2589
|
+
* Returns the seed, if tests are running in a random order.
|
|
2590
|
+
*/
|
|
2591
|
+
getSeed(): number | null;
|
|
2592
|
+
collect(filters?: string[], options?: {
|
|
2593
|
+
staticParse?: boolean;
|
|
2594
|
+
staticParseConcurrency?: number;
|
|
2595
|
+
}): Promise<TestRunResult>;
|
|
1795
2596
|
/**
|
|
1796
|
-
*
|
|
1797
|
-
*
|
|
1798
|
-
* If you are using TypeScript, you can add `.ts` extension here for example.
|
|
1799
|
-
* @default `injected-${index}.js`
|
|
2597
|
+
* Returns the list of test files that match the config and filters.
|
|
2598
|
+
* @param filters String filters to match the test files
|
|
1800
2599
|
*/
|
|
1801
|
-
|
|
2600
|
+
getRelevantTestSpecifications(filters?: string[]): Promise<TestSpecification[]>;
|
|
1802
2601
|
/**
|
|
1803
|
-
*
|
|
1804
|
-
*
|
|
1805
|
-
*
|
|
2602
|
+
* Initialize reporters, the coverage provider, and run tests.
|
|
2603
|
+
* This method can throw an error:
|
|
2604
|
+
* - `FilesNotFoundError` if no tests are found
|
|
2605
|
+
* - `GitNotFoundError` if `--related` flag is used, but git repository is not initialized
|
|
2606
|
+
* - `Error` from the user reporters
|
|
2607
|
+
* @param filters String filters to match the test files
|
|
1806
2608
|
*/
|
|
1807
|
-
|
|
2609
|
+
start(filters?: string[]): Promise<TestRunResult>;
|
|
1808
2610
|
/**
|
|
1809
|
-
*
|
|
2611
|
+
* @deprecated use `standalone()` instead
|
|
1810
2612
|
*/
|
|
1811
|
-
|
|
2613
|
+
init(): Promise<void>;
|
|
1812
2614
|
/**
|
|
1813
|
-
*
|
|
2615
|
+
* Initialize reporters and the coverage provider. This method doesn't run any tests.
|
|
2616
|
+
* If the `--watch` flag is provided, Vitest will still run changed tests even if this method was not called.
|
|
1814
2617
|
*/
|
|
1815
|
-
|
|
2618
|
+
standalone(): Promise<void>;
|
|
1816
2619
|
/**
|
|
1817
|
-
*
|
|
1818
|
-
*
|
|
2620
|
+
* If there is a test run happening, returns a promise that will
|
|
2621
|
+
* resolve when the test run is finished.
|
|
1819
2622
|
*/
|
|
1820
|
-
|
|
1821
|
-
}
|
|
1822
|
-
interface ResolvedBrowserOptions extends BrowserConfigOptions {
|
|
1823
|
-
name: string;
|
|
1824
|
-
enabled: boolean;
|
|
1825
|
-
headless: boolean;
|
|
1826
|
-
isolate: boolean;
|
|
1827
|
-
fileParallelism: boolean;
|
|
1828
|
-
api: ApiConfig;
|
|
1829
|
-
ui: boolean;
|
|
1830
|
-
viewport: {
|
|
1831
|
-
width: number;
|
|
1832
|
-
height: number;
|
|
1833
|
-
};
|
|
1834
|
-
screenshotFailures: boolean;
|
|
1835
|
-
locators: {
|
|
1836
|
-
testIdAttribute: string;
|
|
1837
|
-
exact: boolean;
|
|
1838
|
-
};
|
|
1839
|
-
trace: {
|
|
1840
|
-
mode: BrowserTraceViewMode;
|
|
1841
|
-
tracesDir?: string;
|
|
1842
|
-
screenshots?: boolean;
|
|
1843
|
-
snapshots?: boolean;
|
|
1844
|
-
sources?: boolean;
|
|
1845
|
-
};
|
|
1846
|
-
}
|
|
1847
|
-
type ToMatchScreenshotResolvePath = (data: {
|
|
2623
|
+
waitForTestRunEnd(): Promise<void>;
|
|
1848
2624
|
/**
|
|
1849
|
-
*
|
|
1850
|
-
*
|
|
1851
|
-
* This comes from the arguments passed to `toMatchScreenshot`; if called
|
|
1852
|
-
* without arguments this will be the auto-generated name.
|
|
1853
|
-
*
|
|
1854
|
-
* @example
|
|
1855
|
-
* test('calls `onClick`', () => {
|
|
1856
|
-
* expect(locator).toMatchScreenshot()
|
|
1857
|
-
* // arg = "calls-onclick-1"
|
|
1858
|
-
* })
|
|
1859
|
-
*
|
|
1860
|
-
* @example
|
|
1861
|
-
* expect(locator).toMatchScreenshot('foo/bar/baz.png')
|
|
1862
|
-
* // arg = "foo/bar/baz"
|
|
2625
|
+
* Get test specifications associated with the given module. If module is not a test file, an empty array is returned.
|
|
1863
2626
|
*
|
|
1864
|
-
*
|
|
1865
|
-
*
|
|
1866
|
-
* // arg = "foo/bar/baz"
|
|
2627
|
+
* **Note:** this method relies on a cache generated by `globTestSpecifications`. If the file was not processed yet, use `project.matchesGlobPattern` instead.
|
|
2628
|
+
* @param moduleId The module ID to get test specifications for.
|
|
1867
2629
|
*/
|
|
1868
|
-
|
|
2630
|
+
getModuleSpecifications(moduleId: string): TestSpecification[];
|
|
1869
2631
|
/**
|
|
1870
|
-
*
|
|
1871
|
-
*
|
|
1872
|
-
* This can be set through the arguments passed to `toMatchScreenshot`, but
|
|
1873
|
-
* the value will fall back to `'.png'` if an unsupported extension is used.
|
|
2632
|
+
* Vitest automatically caches test specifications for each file. This method clears the cache for the given file or the whole cache altogether.
|
|
1874
2633
|
*/
|
|
1875
|
-
|
|
2634
|
+
clearSpecificationsCache(moduleId?: string): void;
|
|
1876
2635
|
/**
|
|
1877
|
-
*
|
|
2636
|
+
* Run tests for the given test specifications. This does not trigger `onWatcher*` events.
|
|
2637
|
+
* @param specifications A list of specifications to run.
|
|
2638
|
+
* @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
|
|
1878
2639
|
*/
|
|
1879
|
-
|
|
2640
|
+
runTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
|
|
1880
2641
|
/**
|
|
1881
|
-
*
|
|
2642
|
+
* Runs tests for the given file paths. This does not trigger `onWatcher*` events.
|
|
2643
|
+
* @param filepaths A list of file paths to run tests for.
|
|
2644
|
+
* @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
|
|
1882
2645
|
*/
|
|
1883
|
-
|
|
2646
|
+
runTestFiles(filepaths: string[], allTestsRun?: boolean): Promise<TestRunResult>;
|
|
1884
2647
|
/**
|
|
1885
|
-
*
|
|
1886
|
-
*
|
|
1887
|
-
*
|
|
2648
|
+
* Rerun files and trigger `onWatcherRerun`, `onWatcherStart` and `onTestsRerun` events.
|
|
2649
|
+
* @param specifications A list of specifications to run.
|
|
2650
|
+
* @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
|
|
1888
2651
|
*/
|
|
1889
|
-
|
|
2652
|
+
rerunTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
|
|
2653
|
+
private runFiles;
|
|
1890
2654
|
/**
|
|
1891
|
-
*
|
|
1892
|
-
*
|
|
2655
|
+
* Returns module's diagnostic. If `testModule` is not provided, `selfTime` and `totalTime` will be aggregated across all tests.
|
|
2656
|
+
*
|
|
2657
|
+
* If the module was not transformed or executed, the diagnostic will be empty.
|
|
2658
|
+
* @experimental
|
|
2659
|
+
* @see {@link https://vitest.dev/api/advanced/vitest#getsourcemodulediagnostic}
|
|
1893
2660
|
*/
|
|
1894
|
-
|
|
2661
|
+
experimental_getSourceModuleDiagnostic(moduleId: string, testModule?: TestModule): Promise<SourceModuleDiagnostic>;
|
|
1895
2662
|
/**
|
|
1896
|
-
*
|
|
1897
|
-
* {@linkcode https://vitest.dev/config/root|root}.
|
|
2663
|
+
* @deprecated Use `parseSpecifications` instead
|
|
1898
2664
|
*/
|
|
1899
|
-
|
|
2665
|
+
experimental_parseSpecifications(specifications: TestSpecification[], options?: {
|
|
2666
|
+
/** @default os.availableParallelism() */
|
|
2667
|
+
concurrency?: number;
|
|
2668
|
+
}): Promise<TestModule[]>;
|
|
2669
|
+
parseSpecifications(specifications: TestSpecification[], options?: {
|
|
2670
|
+
/** @default os.availableParallelism() */
|
|
2671
|
+
concurrency?: number;
|
|
2672
|
+
}): Promise<TestModule[]>;
|
|
2673
|
+
experimental_parseSpecification(specification: TestSpecification): Promise<TestModule>;
|
|
1900
2674
|
/**
|
|
1901
|
-
*
|
|
2675
|
+
* Collect tests in specified modules. Vitest will run the files to collect tests.
|
|
2676
|
+
* @param specifications A list of specifications to run.
|
|
1902
2677
|
*/
|
|
1903
|
-
|
|
2678
|
+
collectTests(specifications: TestSpecification[]): Promise<TestRunResult>;
|
|
1904
2679
|
/**
|
|
1905
|
-
*
|
|
1906
|
-
* parent {@linkcode https://vitest.dev/api/#describe|describe}, sanitized.
|
|
2680
|
+
* Gracefully cancel the current test run. Vitest will wait until all running tests are finished before cancelling.
|
|
1907
2681
|
*/
|
|
1908
|
-
|
|
2682
|
+
cancelCurrentRun(reason: CancelReason): Promise<void>;
|
|
2683
|
+
private initializeGlobalSetup;
|
|
1909
2684
|
/**
|
|
1910
|
-
*
|
|
1911
|
-
*
|
|
1912
|
-
* if none is provided, its default value.
|
|
2685
|
+
* Update snapshots in specified files. If no files are provided, it will update files with failed tests and obsolete snapshots.
|
|
2686
|
+
* @param files The list of files on the file system
|
|
1913
2687
|
*/
|
|
1914
|
-
|
|
2688
|
+
updateSnapshot(files?: string[]): Promise<TestRunResult>;
|
|
1915
2689
|
/**
|
|
1916
|
-
*
|
|
2690
|
+
* Enable the mode that allows updating snapshots when running tests.
|
|
2691
|
+
* This method doesn't run any tests.
|
|
1917
2692
|
*
|
|
1918
|
-
*
|
|
2693
|
+
* Every test that runs after this method is called will update snapshots.
|
|
2694
|
+
* To disable the mode, call `resetSnapshotUpdate`.
|
|
1919
2695
|
*/
|
|
1920
|
-
|
|
1921
|
-
}) => string;
|
|
1922
|
-
interface ToMatchScreenshotOptions {
|
|
2696
|
+
enableSnapshotUpdate(): void;
|
|
1923
2697
|
/**
|
|
1924
|
-
*
|
|
1925
|
-
*
|
|
1926
|
-
* @default `${root}/${testFileDirectory}/${screenshotDirectory}/${testFileName}/${arg}-${browserName}-${platform}${ext}`
|
|
2698
|
+
* Disable the mode that allows updating snapshots when running tests.
|
|
1927
2699
|
*/
|
|
1928
|
-
|
|
2700
|
+
resetSnapshotUpdate(): void;
|
|
1929
2701
|
/**
|
|
1930
|
-
*
|
|
1931
|
-
*
|
|
1932
|
-
* @default `${root}/${attachmentsDir}/${testFileDirectory}/${testFileName}/${arg}-${browserName}-${platform}${ext}`
|
|
2702
|
+
* Set the global test name pattern to a regexp.
|
|
2703
|
+
* This method doesn't run any tests.
|
|
1933
2704
|
*/
|
|
1934
|
-
|
|
1935
|
-
}
|
|
1936
|
-
interface ToMatchScreenshotComparators {}
|
|
1937
|
-
|
|
1938
|
-
declare class TestProject {
|
|
1939
|
-
options?: InitializeProjectOptions | undefined;
|
|
2705
|
+
setGlobalTestNamePattern(pattern: string | RegExp): void;
|
|
1940
2706
|
/**
|
|
1941
|
-
*
|
|
2707
|
+
* Returns the regexp used for the global test name pattern.
|
|
1942
2708
|
*/
|
|
1943
|
-
|
|
2709
|
+
getGlobalTestNamePattern(): RegExp | undefined;
|
|
1944
2710
|
/**
|
|
1945
|
-
*
|
|
2711
|
+
* Resets the global test name pattern. This method doesn't run any tests.
|
|
1946
2712
|
*/
|
|
1947
|
-
|
|
2713
|
+
resetGlobalTestNamePattern(): void;
|
|
2714
|
+
private _rerunTimer;
|
|
2715
|
+
private scheduleRerun;
|
|
1948
2716
|
/**
|
|
1949
|
-
*
|
|
2717
|
+
* Invalidate a file in all projects.
|
|
1950
2718
|
*/
|
|
1951
|
-
|
|
2719
|
+
invalidateFile(filepath: string): void;
|
|
2720
|
+
private reportCoverage;
|
|
1952
2721
|
/**
|
|
1953
|
-
*
|
|
2722
|
+
* Closes all projects and their associated resources.
|
|
2723
|
+
* This can only be called once; the closing promise is cached until the server restarts.
|
|
1954
2724
|
*/
|
|
1955
|
-
|
|
1956
|
-
private runner;
|
|
1957
|
-
private closingPromise;
|
|
1958
|
-
private typecheckFilesList;
|
|
1959
|
-
private _globalSetups?;
|
|
1960
|
-
private _provided;
|
|
1961
|
-
constructor(vitest: Vitest, options?: InitializeProjectOptions | undefined, tmpDir?: string);
|
|
2725
|
+
close(): Promise<void>;
|
|
1962
2726
|
/**
|
|
1963
|
-
*
|
|
1964
|
-
*
|
|
1965
|
-
*
|
|
2727
|
+
* Removes the root temp directory with the tmp module copies,
|
|
2728
|
+
* mirroring `TestProject.clearTmpDir()`. The reference is cleared before
|
|
2729
|
+
* the removal so a repeated close is a no-op.
|
|
1966
2730
|
*/
|
|
1967
|
-
|
|
2731
|
+
private _clearTmpDir;
|
|
1968
2732
|
/**
|
|
1969
|
-
*
|
|
2733
|
+
* Closes all projects and exit the process
|
|
2734
|
+
* @param force If true, the process will exit immediately after closing the projects.
|
|
1970
2735
|
*/
|
|
1971
|
-
|
|
2736
|
+
exit(force?: boolean): Promise<void>;
|
|
1972
2737
|
/**
|
|
1973
|
-
*
|
|
2738
|
+
* Should the server be kept running after the tests are done.
|
|
1974
2739
|
*/
|
|
1975
|
-
|
|
2740
|
+
shouldKeepServer(): boolean;
|
|
1976
2741
|
/**
|
|
1977
|
-
*
|
|
1978
|
-
* @param moduleId The file path
|
|
2742
|
+
* Register a handler that will be called when the server is restarted due to a config change.
|
|
1979
2743
|
*/
|
|
1980
|
-
|
|
1981
|
-
toJSON(): SerializedTestProject;
|
|
2744
|
+
onServerRestart(fn: OnServerRestartHandler): void;
|
|
1982
2745
|
/**
|
|
1983
|
-
*
|
|
2746
|
+
* Register a handler that will be called when the test run is cancelled with `vitest.cancelCurrentRun`.
|
|
1984
2747
|
*/
|
|
1985
|
-
|
|
2748
|
+
onCancel(fn: (reason: CancelReason) => Awaitable<void>): () => void;
|
|
1986
2749
|
/**
|
|
1987
|
-
*
|
|
2750
|
+
* Register a handler that will be called when the server is closed.
|
|
1988
2751
|
*/
|
|
1989
|
-
|
|
2752
|
+
onClose(fn: () => Awaitable<void>): void;
|
|
1990
2753
|
/**
|
|
1991
|
-
*
|
|
2754
|
+
* Register a handler that will be called when the tests are rerunning.
|
|
1992
2755
|
*/
|
|
1993
|
-
|
|
2756
|
+
onTestsRerun(fn: OnTestsRerunHandler): void;
|
|
1994
2757
|
/**
|
|
1995
|
-
*
|
|
2758
|
+
* Register a handler that will be called when a file is changed.
|
|
2759
|
+
* This callback should return `true` of `false` indicating whether the test file needs to be rerun.
|
|
2760
|
+
* @example
|
|
2761
|
+
* const testsToRun = [resolve('./test.spec.ts')]
|
|
2762
|
+
* vitest.onFilterWatchedSpecification(specification => testsToRun.includes(specification.moduleId))
|
|
1996
2763
|
*/
|
|
1997
|
-
|
|
2764
|
+
onFilterWatchedSpecification(fn: (specification: TestSpecification) => boolean): void;
|
|
1998
2765
|
/**
|
|
1999
|
-
*
|
|
2766
|
+
* Check if the project with a given name should be included.
|
|
2000
2767
|
*/
|
|
2001
|
-
|
|
2768
|
+
matchesProjectFilter(name: string): boolean;
|
|
2002
2769
|
/**
|
|
2003
|
-
*
|
|
2770
|
+
* Create a report that's scoped to a specific reporter directory.
|
|
2004
2771
|
*/
|
|
2005
|
-
|
|
2006
|
-
|
|
2772
|
+
createReport(scope: string): Report;
|
|
2773
|
+
}
|
|
2774
|
+
type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
|
|
2775
|
+
type OnTestsRerunHandler = (testFiles: TestSpecification[]) => Promise<void> | void;
|
|
2776
|
+
|
|
2777
|
+
interface CliOptions extends UserConfig {
|
|
2007
2778
|
/**
|
|
2008
|
-
*
|
|
2009
|
-
* @param filters String filters to match the test files.
|
|
2779
|
+
* Override the watch mode
|
|
2010
2780
|
*/
|
|
2011
|
-
|
|
2012
|
-
/**
|
|
2013
|
-
* Test files that match the filters.
|
|
2014
|
-
*/
|
|
2015
|
-
testFiles: string[];
|
|
2016
|
-
/**
|
|
2017
|
-
* Typecheck test files that match the filters. This will be empty unless `typecheck.enabled` is `true`.
|
|
2018
|
-
*/
|
|
2019
|
-
typecheckTestFiles: string[];
|
|
2020
|
-
}>;
|
|
2021
|
-
private globAllTestFiles;
|
|
2022
|
-
isBrowserEnabled(): boolean;
|
|
2023
|
-
private markTestFile;
|
|
2781
|
+
run?: boolean;
|
|
2024
2782
|
/**
|
|
2025
|
-
*
|
|
2783
|
+
* Run only the tests that failed in the last run
|
|
2026
2784
|
*/
|
|
2027
|
-
|
|
2028
|
-
private isInSourceTestCode;
|
|
2029
|
-
private filterFiles;
|
|
2030
|
-
private _parentBrowser?;
|
|
2785
|
+
lastFailed?: boolean;
|
|
2031
2786
|
/**
|
|
2032
|
-
*
|
|
2033
|
-
* If the resources are needed again, create a new project.
|
|
2787
|
+
* Removes colors from the console output
|
|
2034
2788
|
*/
|
|
2035
|
-
|
|
2789
|
+
color?: boolean;
|
|
2036
2790
|
/**
|
|
2037
|
-
*
|
|
2038
|
-
* @param moduleId The ID of the module in Vite module graph
|
|
2791
|
+
* Output collected tests as JSON or to a file
|
|
2039
2792
|
*/
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2793
|
+
json?: string | boolean;
|
|
2794
|
+
/**
|
|
2795
|
+
* Output collected test files only
|
|
2796
|
+
*/
|
|
2797
|
+
filesOnly?: boolean;
|
|
2798
|
+
/**
|
|
2799
|
+
* Parse files statically instead of running them to collect tests
|
|
2800
|
+
* @default true
|
|
2801
|
+
*/
|
|
2802
|
+
staticParse?: boolean;
|
|
2803
|
+
/**
|
|
2804
|
+
* How many tests to process at the same time
|
|
2805
|
+
* @default os.availableParallelism()
|
|
2806
|
+
*/
|
|
2807
|
+
staticParseConcurrency?: number;
|
|
2808
|
+
/**
|
|
2809
|
+
* Override vite config's configLoader from CLI.
|
|
2810
|
+
* Use `bundle` to bundle the config with esbuild or `runner` (experimental) to process it on the fly (default: `bundle`).
|
|
2811
|
+
* This is only available with **vite version 6.1.0** and above.
|
|
2812
|
+
* @experimental
|
|
2813
|
+
*/
|
|
2814
|
+
configLoader?: InlineConfig$1 extends {
|
|
2815
|
+
configLoader?: infer T;
|
|
2816
|
+
} ? T : never;
|
|
2817
|
+
/**
|
|
2818
|
+
* Run only the tests whose recorded dependencies were modified since the last run of the test,
|
|
2819
|
+
* and the tests that failed in their last run. Requires `cache`.
|
|
2820
|
+
* @experimental
|
|
2821
|
+
*/
|
|
2822
|
+
sinceLastRun?: boolean;
|
|
2052
2823
|
}
|
|
2824
|
+
/**
|
|
2825
|
+
* Start Vitest programmatically
|
|
2826
|
+
*
|
|
2827
|
+
* Returns a Vitest instance if initialized successfully.
|
|
2828
|
+
*/
|
|
2829
|
+
declare function startVitest(cliFilters?: string[], options?: CliOptions, viteOverrides?: UserConfig$1, vitestOptions?: VitestOptions): Promise<Vitest>;
|
|
2830
|
+
/**
|
|
2831
|
+
* @deprecated The `mode` argument is no longer used. Use `startVitest(cliFilters?, options?, viteOverrides?, vitestOptions?)` instead.
|
|
2832
|
+
*/
|
|
2833
|
+
declare function startVitest(mode: VitestRunMode, cliFilters?: string[], options?: CliOptions, viteOverrides?: UserConfig$1, vitestOptions?: VitestOptions): Promise<Vitest>;
|
|
2053
2834
|
|
|
2054
2835
|
interface PoolRunnerInitializer {
|
|
2055
2836
|
readonly name: string;
|
|
@@ -2068,8 +2849,8 @@ interface PoolWorker {
|
|
|
2068
2849
|
readonly name: string;
|
|
2069
2850
|
readonly reportMemory?: boolean;
|
|
2070
2851
|
readonly cacheFs?: boolean;
|
|
2071
|
-
on: (event: string, callback: (
|
|
2072
|
-
off: (event: string, callback: (
|
|
2852
|
+
on: (event: string, callback: (...args: any[]) => void) => void;
|
|
2853
|
+
off: (event: string, callback: (...args: any[]) => void) => void;
|
|
2073
2854
|
send: (message: WorkerRequest) => void;
|
|
2074
2855
|
deserialize: (data: unknown) => unknown;
|
|
2075
2856
|
start: () => Promise<void>;
|
|
@@ -2161,6 +2942,8 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
2161
2942
|
protected silent?: boolean | "passed-only";
|
|
2162
2943
|
private _filesInWatchMode;
|
|
2163
2944
|
private _timeStart;
|
|
2945
|
+
private _perProjectBenchmarks;
|
|
2946
|
+
private _printedSuites;
|
|
2164
2947
|
constructor(options?: BaseOptions);
|
|
2165
2948
|
onInit(ctx: Vitest): void;
|
|
2166
2949
|
log(...messages: any): void;
|
|
@@ -2169,6 +2952,7 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
2169
2952
|
onTestRunStart(_specifications: ReadonlyArray<TestSpecification>): void;
|
|
2170
2953
|
onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, _reason: TestRunEndReason): void;
|
|
2171
2954
|
onTestCaseResult(testCase: TestCase): void;
|
|
2955
|
+
onTestCaseBenchmark(testCase: TestCase, benchmark: TestBenchmark): void;
|
|
2172
2956
|
onTestSuiteResult(testSuite: TestSuite): void;
|
|
2173
2957
|
onTestModuleEnd(testModule: TestModule): void;
|
|
2174
2958
|
protected logFailedTask(task: Task): void;
|
|
@@ -2176,6 +2960,8 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
2176
2960
|
protected printTestCase(moduleState: TestModuleState, test: TestCase): void;
|
|
2177
2961
|
private getModuleLog;
|
|
2178
2962
|
protected printTestSuite(testSuite: TestSuite): void;
|
|
2963
|
+
private printSuiteEntry;
|
|
2964
|
+
private printAncestorSuites;
|
|
2179
2965
|
protected getTestName(test: Task, _separator?: string): string;
|
|
2180
2966
|
protected getFullName(test: Task, separator?: string): string;
|
|
2181
2967
|
protected getTestIndentation(test: Task): string;
|
|
@@ -2191,13 +2977,45 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
2191
2977
|
shouldLog(log: UserConsoleLog, taskState?: TestResult["state"]): boolean;
|
|
2192
2978
|
onServerRestart(reason?: string): void;
|
|
2193
2979
|
reportSummary(files: File[], errors: unknown[]): void;
|
|
2980
|
+
private printSourceFilterSummary;
|
|
2981
|
+
private printLastFailedSummary;
|
|
2194
2982
|
reportTestSummary(files: File[], errors: unknown[], leakCount: number): void;
|
|
2983
|
+
/**
|
|
2984
|
+
* Surfaces the cost of re-creating a DOM environment for every test file:
|
|
2985
|
+
* with an isolating pool, `jsdom`/`happy-dom` are imported and set up once
|
|
2986
|
+
* per file. When that repeated setup dominates the run, hint that a `vm`
|
|
2987
|
+
* pool sets the environment up once per worker while keeping per-file
|
|
2988
|
+
* isolation, and that `isolate: false` shares it across files.
|
|
2989
|
+
*/
|
|
2990
|
+
private reportEnvironmentDiagnostic;
|
|
2991
|
+
/**
|
|
2992
|
+
* Surfaces repeated evaluation of the same module graph: with `isolate: true`
|
|
2993
|
+
* every test file re-imports its whole graph, so suites where files share
|
|
2994
|
+
* most of their modules (typically through barrel files) pay the graph cost
|
|
2995
|
+
* once per file. The duplication is measured from server-side fetch counts,
|
|
2996
|
+
* so suites with disjoint per-file graphs stay quiet.
|
|
2997
|
+
*/
|
|
2998
|
+
private reportImportDiagnostic;
|
|
2999
|
+
/**
|
|
3000
|
+
* Surfaces transform-dominated runs: without the fs module cache every
|
|
3001
|
+
* `vitest run` transforms the whole module graph from scratch. Enabling
|
|
3002
|
+
* `fsModuleCache` persists the results so the next run skips them.
|
|
3003
|
+
*/
|
|
3004
|
+
private reportTransformDiagnostic;
|
|
3005
|
+
/**
|
|
3006
|
+
* Surfaces the cost of `isolate: true`: with isolation enabled Vitest spawns a
|
|
3007
|
+
* fresh worker (and re-creates the test environment) for every test file. When
|
|
3008
|
+
* that repeated startup cost is significant, hint that `isolate: false` would
|
|
3009
|
+
* reuse workers across files.
|
|
3010
|
+
*/
|
|
3011
|
+
private reportIsolateDiagnostic;
|
|
2195
3012
|
private reportImportDurations;
|
|
2196
3013
|
private importDurationTime;
|
|
2197
3014
|
private ellipsisPath;
|
|
2198
3015
|
private printErrorsSummary;
|
|
2199
3016
|
private printLeaksSummary;
|
|
2200
|
-
|
|
3017
|
+
protected printPerProjectBenchmarks(): void;
|
|
3018
|
+
protected printBenchmarkTable(benchmarks: readonly TestBenchmark[], basePadding: string, columnName?: string): void;
|
|
2201
3019
|
private printTaskErrors;
|
|
2202
3020
|
}
|
|
2203
3021
|
|
|
@@ -2234,6 +3052,12 @@ interface GithubActionsReporterOptions {
|
|
|
2234
3052
|
jobSummary?: Partial<JobSummaryOptions>;
|
|
2235
3053
|
}
|
|
2236
3054
|
interface JobSummaryOptions {
|
|
3055
|
+
/**
|
|
3056
|
+
* Title of the summary.
|
|
3057
|
+
*
|
|
3058
|
+
* @default 'Vitest Test Report'
|
|
3059
|
+
*/
|
|
3060
|
+
title: string;
|
|
2237
3061
|
/**
|
|
2238
3062
|
* Whether to generate the summary.
|
|
2239
3063
|
*
|
|
@@ -2285,7 +3109,22 @@ declare class GithubActionsReporter implements Reporter {
|
|
|
2285
3109
|
}
|
|
2286
3110
|
|
|
2287
3111
|
interface HTMLOptions {
|
|
2288
|
-
|
|
3112
|
+
/**
|
|
3113
|
+
* Directory used as the report artifact root.
|
|
3114
|
+
*
|
|
3115
|
+
* The report entry is written to `<outputDir>/index.html` and the UI
|
|
3116
|
+
* implementation files live under `<outputDir>/ui/`. By default this is the
|
|
3117
|
+
* shared `.vitest` artifact directory.
|
|
3118
|
+
*
|
|
3119
|
+
* @default '.vitest'
|
|
3120
|
+
*/
|
|
3121
|
+
outputDir?: string;
|
|
3122
|
+
/**
|
|
3123
|
+
* Inline report assets, metadata, and attachments into the generated HTML file.
|
|
3124
|
+
*
|
|
3125
|
+
* @default false
|
|
3126
|
+
*/
|
|
3127
|
+
singleFile?: boolean;
|
|
2289
3128
|
}
|
|
2290
3129
|
|
|
2291
3130
|
type Status = "passed" | "failed" | "skipped" | "pending" | "todo" | "disabled";
|
|
@@ -2304,6 +3143,7 @@ interface JsonAssertionResult {
|
|
|
2304
3143
|
failureMessages: Array<string> | null;
|
|
2305
3144
|
location?: Callsite | null;
|
|
2306
3145
|
tags: string[];
|
|
3146
|
+
benchmarks: TestBenchmark[];
|
|
2307
3147
|
}
|
|
2308
3148
|
interface JsonTestResult {
|
|
2309
3149
|
message: string;
|
|
@@ -2331,6 +3171,12 @@ interface JsonTestResults {
|
|
|
2331
3171
|
}
|
|
2332
3172
|
interface JsonOptions {
|
|
2333
3173
|
outputFile?: string;
|
|
3174
|
+
/**
|
|
3175
|
+
* Print the report to stdout instead of writing it to a file.
|
|
3176
|
+
* Ignored when {@link outputFile} is set.
|
|
3177
|
+
* @default false
|
|
3178
|
+
*/
|
|
3179
|
+
stdout?: boolean;
|
|
2334
3180
|
/** @experimental */
|
|
2335
3181
|
filterMeta?: (key: string, value: unknown) => unknown;
|
|
2336
3182
|
}
|
|
@@ -2343,24 +3189,97 @@ declare class JsonReporter implements Reporter {
|
|
|
2343
3189
|
onInit(ctx: Vitest): void;
|
|
2344
3190
|
onCoverage(coverageMap: unknown): void;
|
|
2345
3191
|
onTestRunEnd(testModules: ReadonlyArray<TestModule>): Promise<void>;
|
|
2346
|
-
/**
|
|
2347
|
-
* Writes the report to an output file if specified in the config,
|
|
2348
|
-
* or logs it to the console otherwise.
|
|
2349
|
-
* @param report
|
|
2350
|
-
*/
|
|
2351
|
-
writeReport(report: string): Promise<void>;
|
|
2352
3192
|
}
|
|
2353
3193
|
|
|
2354
3194
|
interface ClassnameTemplateVariables {
|
|
3195
|
+
/** Relative path from the root (e.g. `src/foo.test.ts`) */
|
|
2355
3196
|
filename: string;
|
|
3197
|
+
/** Absolute file path */
|
|
2356
3198
|
filepath: string;
|
|
3199
|
+
/** File basename without directory (e.g. `foo.test.ts`) */
|
|
3200
|
+
basename: string;
|
|
3201
|
+
/** Ancestor describe block names joined by {@link JUnitOptions.ancestorSeparator} */
|
|
3202
|
+
classname: string;
|
|
3203
|
+
/** Leaf test title (the string passed to `it`/`test`) */
|
|
3204
|
+
title: string;
|
|
3205
|
+
/** Top-level describe block name, or empty string when the test has no enclosing describe */
|
|
3206
|
+
suitename: string;
|
|
3207
|
+
/** Vitest project name */
|
|
3208
|
+
displayName: string;
|
|
3209
|
+
}
|
|
3210
|
+
interface SuiteNameTemplateVariables {
|
|
3211
|
+
/** Absolute file path */
|
|
3212
|
+
filepath: string;
|
|
3213
|
+
/** Relative path from the root (e.g. `src/foo.test.ts`) */
|
|
3214
|
+
filename: string;
|
|
3215
|
+
/** File basename without directory (e.g. `foo.test.ts`) */
|
|
3216
|
+
basename: string;
|
|
3217
|
+
/** Vitest project name */
|
|
3218
|
+
displayName: string;
|
|
3219
|
+
/**
|
|
3220
|
+
* The name of the first top-level `describe` block in the file.
|
|
3221
|
+
* Falls back to the file basename when the file has no top-level describe.
|
|
3222
|
+
*/
|
|
3223
|
+
title: string;
|
|
2357
3224
|
}
|
|
2358
3225
|
interface JUnitOptions {
|
|
2359
3226
|
outputFile?: string;
|
|
2360
3227
|
/**
|
|
2361
|
-
*
|
|
3228
|
+
* Print the report to stdout instead of writing it to a file.
|
|
3229
|
+
* Ignored when {@link outputFile} is set.
|
|
3230
|
+
* @default false
|
|
3231
|
+
*/
|
|
3232
|
+
stdout?: boolean;
|
|
3233
|
+
/**
|
|
3234
|
+
* Template for the `classname` attribute of `<testcase>`.
|
|
3235
|
+
*
|
|
3236
|
+
* Can be a template string or a function.
|
|
3237
|
+
*
|
|
3238
|
+
* Supported placeholders:
|
|
3239
|
+
* - `{filename}` – relative path from root (e.g. `src/foo.test.ts`)
|
|
3240
|
+
* - `{filepath}` – absolute file path
|
|
3241
|
+
* - `{basename}` – file name without directory (e.g. `foo.test.ts`)
|
|
3242
|
+
* - `{classname}` – ancestor describe names joined by {@link ancestorSeparator}
|
|
3243
|
+
* - `{title}` – leaf test title
|
|
3244
|
+
* - `{suitename}` – top-level describe block name
|
|
3245
|
+
* - `{displayName}` – Vitest project name
|
|
3246
|
+
*
|
|
3247
|
+
* @default relative file path from root
|
|
2362
3248
|
*/
|
|
2363
3249
|
classnameTemplate?: string | ((classnameVariables: ClassnameTemplateVariables) => string);
|
|
3250
|
+
/**
|
|
3251
|
+
* Template for the `name` attribute of `<testcase>`.
|
|
3252
|
+
*
|
|
3253
|
+
* Can be a template string or a function. Supports the same placeholders as
|
|
3254
|
+
* {@link classnameTemplate}.
|
|
3255
|
+
*
|
|
3256
|
+
* When not set the full test title including ancestor describe hierarchy is used
|
|
3257
|
+
* (current default behaviour, e.g. `outer > inner > test name`).
|
|
3258
|
+
*/
|
|
3259
|
+
titleTemplate?: string | ((titleVariables: ClassnameTemplateVariables) => string);
|
|
3260
|
+
/**
|
|
3261
|
+
* Template for the `name` attribute of `<testsuite>`.
|
|
3262
|
+
*
|
|
3263
|
+
* Can be a template string or a function.
|
|
3264
|
+
*
|
|
3265
|
+
* Supported placeholders:
|
|
3266
|
+
* - `{title}` – first top-level describe name (falls back to file basename)
|
|
3267
|
+
* - `{filename}` – relative path from root
|
|
3268
|
+
* - `{filepath}` – absolute file path
|
|
3269
|
+
* - `{basename}` – file basename
|
|
3270
|
+
* - `{displayName}` – Vitest project name
|
|
3271
|
+
*
|
|
3272
|
+
* When not set the relative file path from root is used (current default behaviour).
|
|
3273
|
+
*/
|
|
3274
|
+
suiteNameTemplate?: string | ((suiteNameVariables: SuiteNameTemplateVariables) => string);
|
|
3275
|
+
/**
|
|
3276
|
+
* Separator used to join ancestor describe block names when building the
|
|
3277
|
+
* `{classname}` template variable (and the default testcase name when
|
|
3278
|
+
* {@link titleTemplate} is not set).
|
|
3279
|
+
*
|
|
3280
|
+
* @default ' > '
|
|
3281
|
+
*/
|
|
3282
|
+
ancestorSeparator?: string;
|
|
2364
3283
|
suiteName?: string;
|
|
2365
3284
|
/**
|
|
2366
3285
|
* Write <system-out> and <system-err> for console output
|
|
@@ -2376,7 +3295,34 @@ interface JUnitOptions {
|
|
|
2376
3295
|
* Hostname to use in the report. By default, it uses os.hostname()
|
|
2377
3296
|
*/
|
|
2378
3297
|
hostname?: string;
|
|
3298
|
+
/**
|
|
3299
|
+
* Include stack traces in test failure reports.
|
|
3300
|
+
* @default true
|
|
3301
|
+
*/
|
|
3302
|
+
stackTrace?: boolean;
|
|
2379
3303
|
}
|
|
3304
|
+
/**
|
|
3305
|
+
* Internal task type that carries pre-computed template metadata.
|
|
3306
|
+
* The three underscore-prefixed fields are set by {@link flattenTasks} and
|
|
3307
|
+
* consumed only within the reporter. They are deliberately not part of the
|
|
3308
|
+
* public `Task` interface.
|
|
3309
|
+
*/
|
|
3310
|
+
type TaskWithMeta = Task & {
|
|
3311
|
+
/** Original leaf test title before hierarchy prefix was prepended */
|
|
3312
|
+
_leafName?: string;
|
|
3313
|
+
/** Ancestor describe names joined by the active separator */
|
|
3314
|
+
_classname?: string;
|
|
3315
|
+
/** Top-level describe block name */
|
|
3316
|
+
_suitename?: string;
|
|
3317
|
+
};
|
|
3318
|
+
/**
|
|
3319
|
+
* Runtime additions on top of {@link SerializedError}: `type` is set by
|
|
3320
|
+
* {@link state.catchError}, `VITEST_TEST_PATH` by the runtime error catcher.
|
|
3321
|
+
*/
|
|
3322
|
+
type UnhandledError = SerializedError & {
|
|
3323
|
+
type?: string;
|
|
3324
|
+
VITEST_TEST_PATH?: string;
|
|
3325
|
+
};
|
|
2380
3326
|
declare class JUnitReporter implements Reporter {
|
|
2381
3327
|
private ctx;
|
|
2382
3328
|
private reportFile?;
|
|
@@ -2389,8 +3335,13 @@ declare class JUnitReporter implements Reporter {
|
|
|
2389
3335
|
onInit(ctx: Vitest): Promise<void>;
|
|
2390
3336
|
writeElement(name: string, attrs: Record<string, any>, children: () => Promise<void>): Promise<void>;
|
|
2391
3337
|
writeLogs(task: Task, type: "err" | "out"): Promise<void>;
|
|
2392
|
-
|
|
2393
|
-
|
|
3338
|
+
writeSystemOut(task: Task): Promise<void>;
|
|
3339
|
+
private applyTemplate;
|
|
3340
|
+
writeTasks(tasks: TaskWithMeta[], filename: string, fileAbsPath: string): Promise<void>;
|
|
3341
|
+
private resolveSuiteNameTemplate;
|
|
3342
|
+
private writeErrorElement;
|
|
3343
|
+
private writeUnhandledErrorsTestsuite;
|
|
3344
|
+
onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors?: ReadonlyArray<UnhandledError>): Promise<void>;
|
|
2394
3345
|
}
|
|
2395
3346
|
|
|
2396
3347
|
declare class DotReporter extends BaseReporter {
|
|
@@ -2411,13 +3362,14 @@ declare class DotReporter extends BaseReporter {
|
|
|
2411
3362
|
|
|
2412
3363
|
declare class HangingProcessReporter implements Reporter {
|
|
2413
3364
|
whyRunning: (() => void) | undefined;
|
|
2414
|
-
onInit(): void
|
|
3365
|
+
onInit(): Promise<void>;
|
|
2415
3366
|
onProcessTimeout(): void;
|
|
2416
3367
|
}
|
|
2417
3368
|
|
|
2418
3369
|
declare class MinimalReporter extends DefaultReporter {
|
|
2419
3370
|
renderSucceed: boolean;
|
|
2420
3371
|
constructor(options?: DefaultReporterOptions);
|
|
3372
|
+
onInit(ctx: Vitest): void;
|
|
2421
3373
|
onTestRunStart(specifications: ReadonlyArray<TestSpecification>): void;
|
|
2422
3374
|
protected printTestModule(testModule: TestModule): void;
|
|
2423
3375
|
protected printTestCase(moduleState: TestModuleState, test: TestCase): void;
|
|
@@ -2450,40 +3402,6 @@ declare class VerboseReporter extends DefaultReporter {
|
|
|
2450
3402
|
onTestCaseResult(test: TestCase): void;
|
|
2451
3403
|
}
|
|
2452
3404
|
|
|
2453
|
-
type FormattedBenchmarkResult = BenchmarkResult & {
|
|
2454
|
-
id: string;
|
|
2455
|
-
};
|
|
2456
|
-
|
|
2457
|
-
declare function renderTable(options: {
|
|
2458
|
-
tasks: Task[];
|
|
2459
|
-
level: number;
|
|
2460
|
-
shallow?: boolean;
|
|
2461
|
-
showHeap: boolean;
|
|
2462
|
-
columns: number;
|
|
2463
|
-
slowTestThreshold: number;
|
|
2464
|
-
compare?: Record<Task["id"], FormattedBenchmarkResult>;
|
|
2465
|
-
}): string;
|
|
2466
|
-
|
|
2467
|
-
declare class BenchmarkReporter extends DefaultReporter {
|
|
2468
|
-
compare?: Parameters<typeof renderTable>[0]["compare"];
|
|
2469
|
-
onInit(ctx: Vitest): Promise<void>;
|
|
2470
|
-
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
2471
|
-
onTestSuiteResult(testSuite: TestSuite): void;
|
|
2472
|
-
protected printTestModule(testModule: TestModule): void;
|
|
2473
|
-
private printSuiteTable;
|
|
2474
|
-
onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason): Promise<void>;
|
|
2475
|
-
}
|
|
2476
|
-
|
|
2477
|
-
declare class VerboseBenchmarkReporter extends BenchmarkReporter {
|
|
2478
|
-
protected verbose: boolean;
|
|
2479
|
-
}
|
|
2480
|
-
|
|
2481
|
-
declare const BenchmarkReportsMap: {
|
|
2482
|
-
default: typeof BenchmarkReporter;
|
|
2483
|
-
verbose: typeof VerboseBenchmarkReporter;
|
|
2484
|
-
};
|
|
2485
|
-
type BenchmarkBuiltinReporters = keyof typeof BenchmarkReportsMap;
|
|
2486
|
-
|
|
2487
3405
|
declare const ReportersMap: {
|
|
2488
3406
|
default: typeof DefaultReporter;
|
|
2489
3407
|
agent: typeof MinimalReporter;
|
|
@@ -2501,19 +3419,19 @@ declare const ReportersMap: {
|
|
|
2501
3419
|
};
|
|
2502
3420
|
type BuiltinReporters = keyof typeof ReportersMap;
|
|
2503
3421
|
interface BuiltinReporterOptions {
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
3422
|
+
default: DefaultReporterOptions;
|
|
3423
|
+
minimal: DefaultReporterOptions;
|
|
3424
|
+
agent: DefaultReporterOptions;
|
|
3425
|
+
verbose: DefaultReporterOptions;
|
|
3426
|
+
dot: BaseOptions;
|
|
3427
|
+
tree: BaseOptions;
|
|
3428
|
+
json: JsonOptions;
|
|
3429
|
+
blob: BlobOptions;
|
|
3430
|
+
tap: never;
|
|
2513
3431
|
"tap-flat": never;
|
|
2514
|
-
|
|
3432
|
+
junit: JUnitOptions;
|
|
2515
3433
|
"hanging-process": never;
|
|
2516
|
-
|
|
3434
|
+
html: HTMLOptions;
|
|
2517
3435
|
"github-actions": GithubActionsReporterOptions;
|
|
2518
3436
|
}
|
|
2519
3437
|
|
|
@@ -2530,6 +3448,7 @@ interface TestSequencerConstructor {
|
|
|
2530
3448
|
}
|
|
2531
3449
|
|
|
2532
3450
|
interface BenchmarkUserOptions {
|
|
3451
|
+
enabled?: boolean;
|
|
2533
3452
|
/**
|
|
2534
3453
|
* Include globs for benchmark test files
|
|
2535
3454
|
*
|
|
@@ -2538,7 +3457,8 @@ interface BenchmarkUserOptions {
|
|
|
2538
3457
|
include?: string[];
|
|
2539
3458
|
/**
|
|
2540
3459
|
* Exclude globs for benchmark test files
|
|
2541
|
-
*
|
|
3460
|
+
*
|
|
3461
|
+
* @default ['**\/node_modules/**', '**\/.git/**']
|
|
2542
3462
|
*/
|
|
2543
3463
|
exclude?: string[];
|
|
2544
3464
|
/**
|
|
@@ -2548,31 +3468,29 @@ interface BenchmarkUserOptions {
|
|
|
2548
3468
|
*/
|
|
2549
3469
|
includeSource?: string[];
|
|
2550
3470
|
/**
|
|
2551
|
-
*
|
|
2552
|
-
*
|
|
2553
|
-
*
|
|
2554
|
-
* @default ['default']
|
|
2555
|
-
*/
|
|
2556
|
-
reporters?: Arrayable<BenchmarkBuiltinReporters | Reporter | (string & {})>;
|
|
2557
|
-
/**
|
|
2558
|
-
* @deprecated Use `benchmark.outputJson` instead
|
|
2559
|
-
*/
|
|
2560
|
-
outputFile?: string | (Partial<Record<BenchmarkBuiltinReporters, string>> & Record<string, string>);
|
|
2561
|
-
/**
|
|
2562
|
-
* benchmark output file to compare against
|
|
3471
|
+
* Include `samples` array of benchmark results for API or custom reporter usages.
|
|
3472
|
+
* This is disabled by default to reduce memory usage.
|
|
3473
|
+
* @default false
|
|
2563
3474
|
*/
|
|
2564
|
-
|
|
3475
|
+
retainSamples?: boolean;
|
|
2565
3476
|
/**
|
|
2566
|
-
* benchmark
|
|
3477
|
+
* The benchmark provider that executes registered benchmarks and produces
|
|
3478
|
+
* their results. Provide a path to a module whose default export implements
|
|
3479
|
+
* `BenchmarkProvider`. The path is resolved relative to the project
|
|
3480
|
+
* root. If not specified, the built-in provider is used.
|
|
3481
|
+
*
|
|
3482
|
+
* @experimental
|
|
2567
3483
|
*/
|
|
2568
|
-
|
|
3484
|
+
provider?: string;
|
|
2569
3485
|
/**
|
|
2570
|
-
*
|
|
2571
|
-
* This is disabled by default to reduce memory usage.
|
|
3486
|
+
* Disable warnings when a benchmark accesses module export getters too many times.
|
|
2572
3487
|
* @default false
|
|
2573
3488
|
*/
|
|
2574
|
-
|
|
3489
|
+
suppressExportGetterWarnings?: boolean;
|
|
2575
3490
|
}
|
|
3491
|
+
type ResolvedBenchmarkOptions = Omit<Required<BenchmarkUserOptions>, "provider"> & {
|
|
3492
|
+
provider?: string;
|
|
3493
|
+
};
|
|
2576
3494
|
|
|
2577
3495
|
type BuiltinEnvironment = "node" | "jsdom" | "happy-dom" | "edge-runtime";
|
|
2578
3496
|
type VitestEnvironment = BuiltinEnvironment | (string & Record<never, never>);
|
|
@@ -2581,7 +3499,7 @@ type ApiConfig = Pick<ServerOptions, "port" | "strictPort" | "host" | "middlewar
|
|
|
2581
3499
|
/**
|
|
2582
3500
|
* Allow any write operations from the API server.
|
|
2583
3501
|
*
|
|
2584
|
-
* @default
|
|
3502
|
+
* @default false if `api.host` is exposed to network, true otherwise
|
|
2585
3503
|
*/
|
|
2586
3504
|
allowWrite?: boolean;
|
|
2587
3505
|
/**
|
|
@@ -2589,10 +3507,29 @@ type ApiConfig = Pick<ServerOptions, "port" | "strictPort" | "host" | "middlewar
|
|
|
2589
3507
|
* If `api.host` is exposed to network and `allowWrite` is true,
|
|
2590
3508
|
* anyone connected to the API server can run arbitrary code on your machine.
|
|
2591
3509
|
*
|
|
2592
|
-
* @default
|
|
3510
|
+
* @default false if `api.host` is exposed to network, true otherwise
|
|
2593
3511
|
*/
|
|
2594
3512
|
allowExec?: boolean;
|
|
2595
3513
|
};
|
|
3514
|
+
type ResolvedApiConfig = ApiConfig & {
|
|
3515
|
+
token: string;
|
|
3516
|
+
tokenCreated: boolean;
|
|
3517
|
+
};
|
|
3518
|
+
interface UIOptions {
|
|
3519
|
+
/**
|
|
3520
|
+
* Enable Vitest UI
|
|
3521
|
+
*
|
|
3522
|
+
* @default false
|
|
3523
|
+
*/
|
|
3524
|
+
enabled?: boolean;
|
|
3525
|
+
/**
|
|
3526
|
+
* Color theme of Vitest UI and the browser mode UI. `auto` follows the system preference
|
|
3527
|
+
* and remembers the theme toggled in the UI. `dark` and `light` are applied on every page load.
|
|
3528
|
+
*
|
|
3529
|
+
* @default 'auto'
|
|
3530
|
+
*/
|
|
3531
|
+
theme?: "dark" | "light" | "auto";
|
|
3532
|
+
}
|
|
2596
3533
|
interface EnvironmentOptions {
|
|
2597
3534
|
/**
|
|
2598
3535
|
* jsdom options.
|
|
@@ -2601,8 +3538,10 @@ interface EnvironmentOptions {
|
|
|
2601
3538
|
happyDOM?: HappyDOMOptions;
|
|
2602
3539
|
[x: string]: unknown;
|
|
2603
3540
|
}
|
|
2604
|
-
|
|
2605
|
-
|
|
3541
|
+
/**
|
|
3542
|
+
* @deprecated
|
|
3543
|
+
*/
|
|
3544
|
+
type VitestRunMode = "test";
|
|
2606
3545
|
interface ProjectName {
|
|
2607
3546
|
label: string;
|
|
2608
3547
|
color?: LabelColor;
|
|
@@ -2650,7 +3589,7 @@ interface SequenceOptions {
|
|
|
2650
3589
|
* Defines how setup files should be ordered
|
|
2651
3590
|
* - 'parallel' will run all setup files in parallel
|
|
2652
3591
|
* - 'list' will run all setup files in the order they are defined in the config file
|
|
2653
|
-
* @default '
|
|
3592
|
+
* @default 'list'
|
|
2654
3593
|
*/
|
|
2655
3594
|
setupFiles?: SequenceSetupFiles;
|
|
2656
3595
|
/**
|
|
@@ -2714,7 +3653,8 @@ interface DepsOptions {
|
|
|
2714
3653
|
*/
|
|
2715
3654
|
interopDefault?: boolean;
|
|
2716
3655
|
/**
|
|
2717
|
-
* A list of directories
|
|
3656
|
+
* A list of directories that contain dependencies. A file is a dependency if its path includes `/<directory>/`.
|
|
3657
|
+
* `node_modules` is always included.
|
|
2718
3658
|
*
|
|
2719
3659
|
* @default ['node_modules']
|
|
2720
3660
|
*/
|
|
@@ -2796,6 +3736,23 @@ interface InlineConfig {
|
|
|
2796
3736
|
*/
|
|
2797
3737
|
globals?: boolean;
|
|
2798
3738
|
/**
|
|
3739
|
+
* Inject CommonJS module variables (`module`, `exports`, `require`,
|
|
3740
|
+
* `__filename`, `__dirname`) into every module processed by Vitest.
|
|
3741
|
+
*
|
|
3742
|
+
* When disabled, ES modules no longer have access to CommonJS variables,
|
|
3743
|
+
* matching how the code runs outside of Vitest. Modules detected to be
|
|
3744
|
+
* CommonJS keep these variables because they are part of the module scope.
|
|
3745
|
+
* The module type is detected the same way Node.js does it: the file
|
|
3746
|
+
* extension wins, then the `type` field in the nearest package.json,
|
|
3747
|
+
* then the presence of ESM syntax in the file.
|
|
3748
|
+
*
|
|
3749
|
+
* This option doesn't affect externalized modules which are always
|
|
3750
|
+
* executed by the native runtime.
|
|
3751
|
+
*
|
|
3752
|
+
* @default true
|
|
3753
|
+
*/
|
|
3754
|
+
injectCjsGlobals?: boolean;
|
|
3755
|
+
/**
|
|
2799
3756
|
* Running environment
|
|
2800
3757
|
*
|
|
2801
3758
|
* Supports 'node', 'jsdom', 'happy-dom', 'edge-runtime'
|
|
@@ -2854,10 +3811,31 @@ interface InlineConfig {
|
|
|
2854
3811
|
*/
|
|
2855
3812
|
fileParallelism?: boolean;
|
|
2856
3813
|
/**
|
|
2857
|
-
* Options for projects
|
|
3814
|
+
* Options for projects.
|
|
3815
|
+
*
|
|
3816
|
+
* When a project is referenced as a config file (or a directory with one) and
|
|
3817
|
+
* that config declares `projects` itself, it becomes a container: it doesn't
|
|
3818
|
+
* run tests, only provides the projects it declares. Inline configurations
|
|
3819
|
+
* cannot declare `projects`.
|
|
2858
3820
|
*/
|
|
2859
3821
|
projects?: TestProjectConfiguration[];
|
|
2860
3822
|
/**
|
|
3823
|
+
* Let inline projects that don't modify the Vite config reuse the Vite
|
|
3824
|
+
* server of the config that declares them. Instead of resolving a new
|
|
3825
|
+
* Vite config and creating a new server per project, such projects share
|
|
3826
|
+
* the server and its transform cache.
|
|
3827
|
+
*
|
|
3828
|
+
* A project still gets its own server when it defines Vite-level options
|
|
3829
|
+
* (`plugins`, `resolve`, ...) or test options that affect the
|
|
3830
|
+
* Vite config: `alias`, `browser`, `css`, `deps.moduleDirectories`,
|
|
3831
|
+
* `deps.optimizer`, `mode`, `root`,
|
|
3832
|
+
* or when `extends` doesn't point to the declaring config.
|
|
3833
|
+
*
|
|
3834
|
+
* This option is only respected in the root configuration.
|
|
3835
|
+
* @default true
|
|
3836
|
+
*/
|
|
3837
|
+
sharedViteServer?: boolean;
|
|
3838
|
+
/**
|
|
2861
3839
|
* Update snapshot
|
|
2862
3840
|
*
|
|
2863
3841
|
* @default false
|
|
@@ -2866,7 +3844,7 @@ interface InlineConfig {
|
|
|
2866
3844
|
/**
|
|
2867
3845
|
* Watch mode
|
|
2868
3846
|
*
|
|
2869
|
-
* @default !process.env.CI
|
|
3847
|
+
* @default !process.env.CI && process.stdin.isTTY && !isAgent
|
|
2870
3848
|
*/
|
|
2871
3849
|
watch?: boolean;
|
|
2872
3850
|
/**
|
|
@@ -2950,7 +3928,7 @@ interface InlineConfig {
|
|
|
2950
3928
|
testNamePattern?: string | RegExp;
|
|
2951
3929
|
/**
|
|
2952
3930
|
* Will call `.mockClear()` on all spies before each test
|
|
2953
|
-
* @default
|
|
3931
|
+
* @default true
|
|
2954
3932
|
*/
|
|
2955
3933
|
clearMocks?: boolean;
|
|
2956
3934
|
/**
|
|
@@ -2986,7 +3964,7 @@ interface InlineConfig {
|
|
|
2986
3964
|
*
|
|
2987
3965
|
* @default false
|
|
2988
3966
|
*/
|
|
2989
|
-
ui?: boolean;
|
|
3967
|
+
ui?: boolean | UIOptions;
|
|
2990
3968
|
/**
|
|
2991
3969
|
* options for test in a browser environment
|
|
2992
3970
|
*
|
|
@@ -3054,7 +4032,7 @@ interface InlineConfig {
|
|
|
3054
4032
|
/**
|
|
3055
4033
|
* Options for @sinon/fake-timers
|
|
3056
4034
|
*/
|
|
3057
|
-
fakeTimers?:
|
|
4035
|
+
fakeTimers?: FakeTimersConfig;
|
|
3058
4036
|
/**
|
|
3059
4037
|
* Custom handler for console.log in tests.
|
|
3060
4038
|
*
|
|
@@ -3092,20 +4070,43 @@ interface InlineConfig {
|
|
|
3092
4070
|
*/
|
|
3093
4071
|
maxConcurrency?: number;
|
|
3094
4072
|
/**
|
|
3095
|
-
*
|
|
3096
|
-
*
|
|
4073
|
+
* Store the results of test runs on the file system to run failed
|
|
4074
|
+
* and longer test files first. The cache is stored in Vite's "cacheDir".
|
|
4075
|
+
* @default true
|
|
3097
4076
|
*/
|
|
3098
|
-
cache?:
|
|
4077
|
+
cache?: boolean | {
|
|
3099
4078
|
/**
|
|
3100
|
-
* @deprecated Use Vite's "cacheDir" instead if you want to change the cache
|
|
4079
|
+
* @deprecated This option has no effect. Use Vite's "cacheDir" instead if you want to change the cache directory.
|
|
3101
4080
|
*/
|
|
3102
4081
|
dir: string;
|
|
3103
4082
|
};
|
|
3104
4083
|
/**
|
|
4084
|
+
* Cache transformed modules on the file system and reuse them between reruns
|
|
4085
|
+
* and separate Vitest processes, which can significantly speed up cold starts.
|
|
4086
|
+
*
|
|
4087
|
+
* @default true
|
|
4088
|
+
*/
|
|
4089
|
+
fsModuleCache?: boolean;
|
|
4090
|
+
/**
|
|
4091
|
+
* Directory where the {@link fsModuleCache} is stored. Can be set per project;
|
|
4092
|
+
* projects that don't override it fall back to the root's cache directory.
|
|
4093
|
+
*
|
|
4094
|
+
* By default the cache is stored inside `node_modules` at the workspace root, so
|
|
4095
|
+
* that it is naturally invalidated when dependencies are reinstalled.
|
|
4096
|
+
*
|
|
4097
|
+
* @default 'node_modules/.vitest-cache'
|
|
4098
|
+
*/
|
|
4099
|
+
fsModuleCachePath?: string;
|
|
4100
|
+
/**
|
|
3105
4101
|
* Options for configuring the order of running tests.
|
|
3106
4102
|
*/
|
|
3107
4103
|
sequence?: SequenceOptions;
|
|
3108
4104
|
/**
|
|
4105
|
+
* Overrides Vite mode
|
|
4106
|
+
* @default 'test'
|
|
4107
|
+
*/
|
|
4108
|
+
mode?: string;
|
|
4109
|
+
/**
|
|
3109
4110
|
* Specifies an `Object`, or an `Array` of `Object`,
|
|
3110
4111
|
* which defines aliases used to replace values in `import` or `require` statements.
|
|
3111
4112
|
* Will be merged with the default aliases inside `resolve.alias`.
|
|
@@ -3216,6 +4217,14 @@ interface InlineConfig {
|
|
|
3216
4217
|
*/
|
|
3217
4218
|
chaiConfig?: ChaiConfig;
|
|
3218
4219
|
/**
|
|
4220
|
+
* Sets length limit for formatted values interpolated into generated task titles.
|
|
4221
|
+
*
|
|
4222
|
+
* This affects values inserted by APIs like `test.each` and `test.for`.
|
|
4223
|
+
*
|
|
4224
|
+
* @default 40
|
|
4225
|
+
*/
|
|
4226
|
+
taskTitleValueFormatTruncate?: number;
|
|
4227
|
+
/**
|
|
3219
4228
|
* Stop test execution when given number of tests have failed.
|
|
3220
4229
|
*/
|
|
3221
4230
|
bail?: number;
|
|
@@ -3232,15 +4241,20 @@ interface InlineConfig {
|
|
|
3232
4241
|
*/
|
|
3233
4242
|
retry?: SerializableRetry;
|
|
3234
4243
|
/**
|
|
4244
|
+
* Repeat every test a specific number of times regardless of the result.
|
|
4245
|
+
*
|
|
4246
|
+
* @default 0 // Don't repeat
|
|
4247
|
+
*/
|
|
4248
|
+
repeats?: number;
|
|
4249
|
+
/**
|
|
3235
4250
|
* Show full diff when snapshot fails instead of a patch.
|
|
3236
4251
|
*/
|
|
3237
4252
|
expandSnapshotDiff?: boolean;
|
|
3238
4253
|
/**
|
|
3239
|
-
* By default, Vitest
|
|
3240
|
-
*
|
|
3241
|
-
*
|
|
3242
|
-
*
|
|
3243
|
-
* This option has no effect on browser pool since Vitest preserves original logging on browser devtools.
|
|
4254
|
+
* By default, Vitest intercepts console output during tests to add context such as the test file and test title.
|
|
4255
|
+
* In browser mode, this interception is required to forward logs from the browser DevTools to the terminal.
|
|
4256
|
+
* It is also required for console log previews in the Vitest UI.
|
|
4257
|
+
* Disabling console interception can be useful when you want to debug code with normal synchronous terminal logging.
|
|
3244
4258
|
*
|
|
3245
4259
|
* @default false
|
|
3246
4260
|
*/
|
|
@@ -3260,7 +4274,7 @@ interface InlineConfig {
|
|
|
3260
4274
|
/**
|
|
3261
4275
|
* Directory path for storing attachments created by `context.annotate`
|
|
3262
4276
|
*
|
|
3263
|
-
* @default '.vitest
|
|
4277
|
+
* @default '.vitest/attachments'
|
|
3264
4278
|
*/
|
|
3265
4279
|
attachmentsDir?: string;
|
|
3266
4280
|
/**
|
|
@@ -3269,15 +4283,6 @@ interface InlineConfig {
|
|
|
3269
4283
|
* @experimental
|
|
3270
4284
|
*/
|
|
3271
4285
|
experimental?: {
|
|
3272
|
-
/**
|
|
3273
|
-
* Enable caching of modules on the file system between reruns.
|
|
3274
|
-
*/
|
|
3275
|
-
fsModuleCache?: boolean;
|
|
3276
|
-
/**
|
|
3277
|
-
* Path relative to the root of the project where the fs module cache will be stored.
|
|
3278
|
-
* @default node_modules/.experimental-vitest-cache
|
|
3279
|
-
*/
|
|
3280
|
-
fsModuleCachePath?: string;
|
|
3281
4286
|
/**
|
|
3282
4287
|
* {@link https://vitest.dev/guide/open-telemetry}
|
|
3283
4288
|
*/
|
|
@@ -3346,18 +4351,66 @@ interface InlineConfig {
|
|
|
3346
4351
|
*/
|
|
3347
4352
|
nodeLoader?: boolean;
|
|
3348
4353
|
/**
|
|
3349
|
-
*
|
|
4354
|
+
* Record `expect.poll`, `vi.waitFor`, and `vi.waitUntil` steps of each test and print them as a timeline when the test fails.
|
|
4355
|
+
* Steps of passing tests are dropped without being reported.
|
|
4356
|
+
*
|
|
4357
|
+
* This has no effect in browser mode, which records its steps with `browser.traceView`.
|
|
4358
|
+
* @default false
|
|
4359
|
+
*/
|
|
4360
|
+
traceTimeline?: boolean;
|
|
4361
|
+
/**
|
|
4362
|
+
* Provider for detecting changed files. Used with the `--changed` flag
|
|
3350
4363
|
* to determine which files have been modified.
|
|
3351
4364
|
*
|
|
3352
|
-
*
|
|
3353
|
-
*
|
|
4365
|
+
* - `'git'` (default) compares the working tree with the `--changed` reference.
|
|
4366
|
+
* - `'mtime'` compares the modification time of every recorded dependency with the run
|
|
4367
|
+
* that recorded it. It requires `experimental.recordDependencies`. The test files that
|
|
4368
|
+
* failed in their last run also run.
|
|
4369
|
+
*
|
|
4370
|
+
* You can also provide a custom implementation of the `VCSProvider` interface.
|
|
4371
|
+
*/
|
|
4372
|
+
vcsProvider?: "git" | "mtime" | VCSProvider | (string & {});
|
|
4373
|
+
/**
|
|
4374
|
+
* Record the modules that every test file loads in the cache and use the records
|
|
4375
|
+
* with `--changed` and `--related` instead of walking the module graph statically.
|
|
4376
|
+
*
|
|
4377
|
+
* A test file without a record always runs.
|
|
4378
|
+
* @default false
|
|
3354
4379
|
*/
|
|
3355
|
-
|
|
4380
|
+
recordDependencies?: boolean;
|
|
3356
4381
|
/**
|
|
3357
4382
|
* Parse test specifications before running them.
|
|
3358
4383
|
* This will apply `.only` flag and test name pattern across all files without running them.
|
|
3359
4384
|
*/
|
|
3360
4385
|
preParse?: boolean;
|
|
4386
|
+
/**
|
|
4387
|
+
* Print performance hints after the run when the collected timings show
|
|
4388
|
+
* that a configuration change would make the run significantly faster.
|
|
4389
|
+
* Hints are never printed for options that were set explicitly.
|
|
4390
|
+
*
|
|
4391
|
+
* Set to `false` to disable all hints, or disable them individually:
|
|
4392
|
+
* - `isolate`: hint when `isolate: true` spends a significant amount of
|
|
4393
|
+
* time spawning a fresh worker (and re-creating the environment) for
|
|
4394
|
+
* every test file, estimating how much `isolate: false` could save.
|
|
4395
|
+
* - `environment`: hint when re-creating a DOM environment for every test
|
|
4396
|
+
* file dominates the run and a `vm` pool would set it up once per worker.
|
|
4397
|
+
* - `import`: hint when test files repeatedly evaluate the same module
|
|
4398
|
+
* graph (typical for barrel-file imports) and `isolate: false` would
|
|
4399
|
+
* evaluate it once per worker.
|
|
4400
|
+
* - `transform`: hint when transforming modules dominates the run and
|
|
4401
|
+
* `fsModuleCache` would persist the results across runs.
|
|
4402
|
+
* @default true
|
|
4403
|
+
*/
|
|
4404
|
+
diagnostics?: boolean | {
|
|
4405
|
+
/** @default true */
|
|
4406
|
+
isolate?: boolean;
|
|
4407
|
+
/** @default true */
|
|
4408
|
+
environment?: boolean;
|
|
4409
|
+
/** @default true */
|
|
4410
|
+
import?: boolean;
|
|
4411
|
+
/** @default true */
|
|
4412
|
+
transform?: boolean;
|
|
4413
|
+
};
|
|
3361
4414
|
};
|
|
3362
4415
|
/**
|
|
3363
4416
|
* Define tags available in your test files.
|
|
@@ -3370,6 +4423,12 @@ interface InlineConfig {
|
|
|
3370
4423
|
* @default true
|
|
3371
4424
|
*/
|
|
3372
4425
|
strictTags?: boolean;
|
|
4426
|
+
/**
|
|
4427
|
+
* Runs tests that are affected by the changes in the repository, or between specified branch or commit hash
|
|
4428
|
+
* Requires initialized git repository
|
|
4429
|
+
* @default false
|
|
4430
|
+
*/
|
|
4431
|
+
changed?: boolean | string;
|
|
3373
4432
|
}
|
|
3374
4433
|
interface TypecheckConfig {
|
|
3375
4434
|
/**
|
|
@@ -3395,7 +4454,7 @@ interface TypecheckConfig {
|
|
|
3395
4454
|
/**
|
|
3396
4455
|
* Pattern for files that should not be treated as test files
|
|
3397
4456
|
*
|
|
3398
|
-
* @default ['**\/node_modules/**', '
|
|
4457
|
+
* @default ['**\/node_modules/**', '**\/.git/**']
|
|
3399
4458
|
*/
|
|
3400
4459
|
exclude: string[];
|
|
3401
4460
|
/**
|
|
@@ -3408,6 +4467,10 @@ interface TypecheckConfig {
|
|
|
3408
4467
|
*/
|
|
3409
4468
|
ignoreSourceErrors?: boolean;
|
|
3410
4469
|
/**
|
|
4470
|
+
* Use TypeScript build mode.
|
|
4471
|
+
*/
|
|
4472
|
+
build?: boolean;
|
|
4473
|
+
/**
|
|
3411
4474
|
* Path to tsconfig, relative to the project root.
|
|
3412
4475
|
*/
|
|
3413
4476
|
tsconfig?: string;
|
|
@@ -3443,17 +4506,6 @@ interface UserConfig extends InlineConfig {
|
|
|
3443
4506
|
*/
|
|
3444
4507
|
related?: string[] | string;
|
|
3445
4508
|
/**
|
|
3446
|
-
* Overrides Vite mode
|
|
3447
|
-
* @default 'test'
|
|
3448
|
-
*/
|
|
3449
|
-
mode?: string;
|
|
3450
|
-
/**
|
|
3451
|
-
* Runs tests that are affected by the changes in the repository, or between specified branch or commit hash
|
|
3452
|
-
* Requires initialized git repository
|
|
3453
|
-
* @default false
|
|
3454
|
-
*/
|
|
3455
|
-
changed?: boolean | string;
|
|
3456
|
-
/**
|
|
3457
4509
|
* Test suite shard to execute in a format of <index>/<count>.
|
|
3458
4510
|
* Will divide tests into a `count` numbers, and run only the `indexed` part.
|
|
3459
4511
|
* Cannot be used with enabled watch.
|
|
@@ -3473,20 +4525,12 @@ interface UserConfig extends InlineConfig {
|
|
|
3473
4525
|
*/
|
|
3474
4526
|
clearScreen?: boolean;
|
|
3475
4527
|
/**
|
|
3476
|
-
* benchmark.compare option exposed at the top level for cli
|
|
3477
|
-
*/
|
|
3478
|
-
compare?: string;
|
|
3479
|
-
/**
|
|
3480
|
-
* benchmark.outputJson option exposed at the top level for cli
|
|
3481
|
-
*/
|
|
3482
|
-
outputJson?: string;
|
|
3483
|
-
/**
|
|
3484
4528
|
* Directory of blob reports to merge
|
|
3485
|
-
* @default '.vitest
|
|
4529
|
+
* @default '.vitest/blob'
|
|
3486
4530
|
*/
|
|
3487
4531
|
mergeReports?: string;
|
|
3488
4532
|
/**
|
|
3489
|
-
* Delete all Vitest caches, including `
|
|
4533
|
+
* Delete all Vitest caches, including the `fsModuleCache`.
|
|
3490
4534
|
* @experimental
|
|
3491
4535
|
*/
|
|
3492
4536
|
clearCache?: boolean;
|
|
@@ -3499,12 +4543,16 @@ interface UserConfig extends InlineConfig {
|
|
|
3499
4543
|
* Log all available tags instead of running tests.
|
|
3500
4544
|
*/
|
|
3501
4545
|
listTags?: boolean | "json";
|
|
4546
|
+
configLoader?: "bundle" | "runner" | "native";
|
|
4547
|
+
/**
|
|
4548
|
+
* The `--reporter` argument from the CLI
|
|
4549
|
+
*/
|
|
4550
|
+
reporter?: string | string[];
|
|
3502
4551
|
}
|
|
3503
4552
|
type OnUnhandledErrorCallback = (error: (TestError | Error) & {
|
|
3504
4553
|
type: string;
|
|
3505
4554
|
}) => boolean | void;
|
|
3506
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config" | "filters" | "browser" | "coverage" | "testNamePattern" | "related" | "api" | "reporters" | "resolveSnapshotPath" | "benchmark" | "shard" | "cache" | "sequence" | "typecheck" | "runner" | "pool" | "cliExclude" | "diff" | "setupFiles" | "snapshotEnvironment" | "bail" | "name" | "vmMemoryLimit" | "fileParallelism" | "tagsFilter"> {
|
|
3507
|
-
mode: VitestRunMode;
|
|
4555
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config" | "filters" | "browser" | "coverage" | "testNamePattern" | "related" | "api" | "reporters" | "resolveSnapshotPath" | "benchmark" | "shard" | "cache" | "sequence" | "typecheck" | "runner" | "pool" | "cliExclude" | "diff" | "setupFiles" | "snapshotEnvironment" | "bail" | "name" | "vmMemoryLimit" | "fileParallelism" | "tagsFilter" | "reporter" | "ui"> {
|
|
3508
4556
|
name: ProjectName["label"];
|
|
3509
4557
|
color?: ProjectName["color"];
|
|
3510
4558
|
base?: string;
|
|
@@ -3523,13 +4571,12 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config"
|
|
|
3523
4571
|
poolRunner?: PoolRunnerInitializer;
|
|
3524
4572
|
reporters: (InlineReporter | ReporterWithOptions)[];
|
|
3525
4573
|
defines: Record<string, any>;
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
};
|
|
4574
|
+
api: ResolvedApiConfig;
|
|
4575
|
+
ui: boolean;
|
|
4576
|
+
uiOptions: Required<Omit<UIOptions, "enabled">>;
|
|
3530
4577
|
cliExclude?: string[];
|
|
3531
4578
|
project: string[];
|
|
3532
|
-
benchmark
|
|
4579
|
+
benchmark: ResolvedBenchmarkOptions;
|
|
3533
4580
|
shard?: {
|
|
3534
4581
|
index: number;
|
|
3535
4582
|
count: number;
|
|
@@ -3554,10 +4601,11 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config"
|
|
|
3554
4601
|
};
|
|
3555
4602
|
runner?: string;
|
|
3556
4603
|
maxWorkers: number;
|
|
3557
|
-
vmMemoryLimit?:
|
|
4604
|
+
vmMemoryLimit?: string | number;
|
|
3558
4605
|
dumpDir?: string;
|
|
3559
4606
|
tagsFilter?: string[];
|
|
3560
|
-
|
|
4607
|
+
mergeReportsLabel?: string;
|
|
4608
|
+
experimental: Omit<Required<UserConfig>["experimental"], "importDurations" | "diagnostics"> & {
|
|
3561
4609
|
importDurations: {
|
|
3562
4610
|
print: boolean | "on-warn";
|
|
3563
4611
|
limit: number;
|
|
@@ -3567,9 +4615,40 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config"
|
|
|
3567
4615
|
danger: number;
|
|
3568
4616
|
};
|
|
3569
4617
|
};
|
|
4618
|
+
diagnostics: {
|
|
4619
|
+
isolate: boolean;
|
|
4620
|
+
environment: boolean;
|
|
4621
|
+
import: boolean;
|
|
4622
|
+
transform: boolean;
|
|
4623
|
+
};
|
|
3570
4624
|
};
|
|
4625
|
+
cliOptions: CliOptions;
|
|
4626
|
+
viteOverrides: UserConfig$1;
|
|
4627
|
+
resolvedProjects: ResolvedProjectEntry[];
|
|
4628
|
+
}
|
|
4629
|
+
/**
|
|
4630
|
+
* A resolved project entry. `viteConfig` may be shared by reference across multiple
|
|
4631
|
+
* entries (e.g. browser instances or benchmark variants of the same parent), while
|
|
4632
|
+
* `projectConfig` is always a distinct object per entry.
|
|
4633
|
+
*/
|
|
4634
|
+
interface ResolvedProjectEntry {
|
|
4635
|
+
viteConfig: ResolvedConfig$1;
|
|
4636
|
+
projectConfig: ResolvedConfig;
|
|
4637
|
+
/**
|
|
4638
|
+
* When set, this entry exists only so browser-instance siblings can attach
|
|
4639
|
+
* to a parent that owns the Vite server and (later) the browser provider.
|
|
4640
|
+
* The resulting `TestProject` is created and kept alive (so siblings can
|
|
4641
|
+
* reference it via `_parent`) but is NOT pushed to `vitest.projects`.
|
|
4642
|
+
*/
|
|
4643
|
+
hidden?: boolean;
|
|
4644
|
+
/**
|
|
4645
|
+
* The project was declared as an inline configuration. Its
|
|
4646
|
+
* `viteConfig.configFile` is the config it extends (the root config file
|
|
4647
|
+
* by default), not a file of its own.
|
|
4648
|
+
*/
|
|
4649
|
+
inline?: boolean;
|
|
3571
4650
|
}
|
|
3572
|
-
type NonProjectOptions = "shard" | "watch" | "run" | "cache" | "update" | "reporters" | "outputFile" | "teardownTimeout" | "silent" | "forceRerunTriggers" | "testNamePattern" | "ui" | "open" | "uiBase" | "snapshotFormat" | "resolveSnapshotPath" | "passWithNoTests" | "onConsoleLog" | "onStackTrace" | "dangerouslyIgnoreUnhandledErrors" | "slowTestThreshold" | "inspect" | "inspectBrk" | "coverage" | "watchTriggerPatterns" | "tagsFilter";
|
|
4651
|
+
type NonProjectOptions = "shard" | "watch" | "run" | "cache" | "update" | "reporters" | "outputFile" | "teardownTimeout" | "silent" | "forceRerunTriggers" | "testNamePattern" | "ui" | "open" | "uiBase" | "snapshotFormat" | "resolveSnapshotPath" | "passWithNoTests" | "onConsoleLog" | "onStackTrace" | "dangerouslyIgnoreUnhandledErrors" | "slowTestThreshold" | "inspect" | "inspectBrk" | "coverage" | "watchTriggerPatterns" | "tagsFilter" | "sharedViteServer";
|
|
3573
4652
|
interface ServerDepsOptions {
|
|
3574
4653
|
/**
|
|
3575
4654
|
* Externalize means that Vite will bpass the package to native Node.
|
|
@@ -3594,26 +4673,67 @@ interface ServerDepsOptions {
|
|
|
3594
4673
|
*/
|
|
3595
4674
|
fallbackCJS?: boolean;
|
|
3596
4675
|
}
|
|
3597
|
-
type ProjectConfig = Omit<InlineConfig, NonProjectOptions | "
|
|
4676
|
+
type ProjectConfig = Omit<InlineConfig, NonProjectOptions | "projects" | "sequence" | "deps"> & {
|
|
3598
4677
|
mode?: string;
|
|
3599
|
-
|
|
3600
|
-
|
|
4678
|
+
sequence?: Omit<SequenceOptions, "sequencer" | "seed" | "shuffle"> & {
|
|
4679
|
+
shuffle?: boolean | {
|
|
4680
|
+
tests?: boolean;
|
|
4681
|
+
};
|
|
4682
|
+
};
|
|
4683
|
+
deps?: DepsOptions;
|
|
3601
4684
|
};
|
|
3602
4685
|
type ResolvedProjectConfig = Omit<ResolvedConfig, Exclude<NonProjectOptions, "coverage" | "watch">>;
|
|
3603
4686
|
interface UserWorkspaceConfig extends UserConfig$1 {
|
|
3604
|
-
test?: ProjectConfig
|
|
4687
|
+
test?: ProjectConfig & {
|
|
4688
|
+
projects?: TestProjectConfiguration[];
|
|
4689
|
+
};
|
|
3605
4690
|
}
|
|
3606
4691
|
type UserProjectConfigFn = (env: ConfigEnv) => UserWorkspaceConfig | Promise<UserWorkspaceConfig>;
|
|
3607
4692
|
type UserProjectConfigExport = UserWorkspaceConfig | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
|
|
3608
|
-
type TestProjectInlineConfiguration =
|
|
4693
|
+
type TestProjectInlineConfiguration = UserWorkspaceConfig & {
|
|
3609
4694
|
/**
|
|
3610
4695
|
* Relative path to the extendable config. All other options will be merged with this config.
|
|
3611
4696
|
* If `true`, the project will inherit all options from the root config.
|
|
4697
|
+
* Set to `false` to keep the project configuration completely separate from the root config.
|
|
4698
|
+
* @default true
|
|
3612
4699
|
* @example '../vite.config.ts'
|
|
3613
4700
|
*/
|
|
3614
|
-
extends?: string |
|
|
3615
|
-
}
|
|
4701
|
+
extends?: string | boolean;
|
|
4702
|
+
};
|
|
3616
4703
|
type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
|
|
3617
4704
|
|
|
3618
|
-
|
|
3619
|
-
|
|
4705
|
+
/**
|
|
4706
|
+
* Generate a unique cache identifier.
|
|
4707
|
+
*
|
|
4708
|
+
* Return `false` to disable caching of the file.
|
|
4709
|
+
*/
|
|
4710
|
+
interface CacheKeyIdGenerator {
|
|
4711
|
+
(context: CacheKeyIdGeneratorContext): string | undefined | null | false;
|
|
4712
|
+
}
|
|
4713
|
+
interface CacheKeyIdGeneratorContext {
|
|
4714
|
+
environment: DevEnvironment;
|
|
4715
|
+
id: string;
|
|
4716
|
+
sourceCode: string;
|
|
4717
|
+
}
|
|
4718
|
+
|
|
4719
|
+
interface VitestPluginContext {
|
|
4720
|
+
vitest: Vitest;
|
|
4721
|
+
project: TestProject;
|
|
4722
|
+
injectTestProjects: (config: TestProjectConfiguration | TestProjectConfiguration[]) => Promise<TestProject[]>;
|
|
4723
|
+
/**
|
|
4724
|
+
* Define a generator that will be applied before hashing this project's cache key.
|
|
4725
|
+
*
|
|
4726
|
+
* Use this to make sure Vitest generates correct hash. It is a good idea
|
|
4727
|
+
* to define this function if your plugin can be registered with different options.
|
|
4728
|
+
*
|
|
4729
|
+
* This is called only if `fsModuleCache` is enabled.
|
|
4730
|
+
*/
|
|
4731
|
+
defineCacheKeyGenerator: (callback: CacheKeyIdGenerator) => void;
|
|
4732
|
+
/**
|
|
4733
|
+
* @deprecated Use {@link defineCacheKeyGenerator} instead.
|
|
4734
|
+
*/
|
|
4735
|
+
experimental_defineCacheKeyGenerator: (callback: CacheKeyIdGenerator) => void;
|
|
4736
|
+
}
|
|
4737
|
+
|
|
4738
|
+
export { Logger as L, MinimalReporter as M, PluginHarness as P, ReportersMap as aD, TapFlatReporter as aK, TapReporter as aL, TestCase as aP, TestCollection as aQ, TestModule as aS, DefaultReporter as aa, DotReporter as ac, GithubActionsReporter as ae, HangingProcessReporter as ag, JUnitReporter as aj, JsonReporter as am, TestSuite as b2, VerboseReporter as b8, VitestPackageInstaller as ba, experimental_getRunnerTask as bd, startVitest as be, Vitest as f, CoverageMap as h, TestSpecification as i, TestProject as k, BaseReporter as t };
|
|
4739
|
+
export type { CSSModuleScopeStrategy as $, ApiConfig as A, BaseCoverageOptions as B, CoverageOptions as C, BrowserModuleMocker as D, BrowserOrchestrator as E, FieldsWithDefaultValues as F, BrowserProvider as G, BrowserProviderCloseOptions as H, InlineConfig as I, BrowserProviderOption as J, BrowserScript as K, BrowserServerContribution as N, BrowserServerFactory as O, BrowserServerState as Q, ResolvedConfig as R, BrowserServerStateSession as S, TestProjectConfiguration as T, UserWorkspaceConfig as U, VitestPluginContext as V, WatcherTriggerPattern as W, BrowserTraceViewOptions as X, BuiltinEnvironment as Y, BuiltinReporterOptions as Z, BuiltinReporters as _, UserProjectConfigFn as a, TestSequencerConstructor as a$, CacheKeyIdGenerator as a0, CacheKeyIdGeneratorContext as a1, CachedTestFileResult as a2, CoverageInstrumenter as a3, CoverageIstanbulOptions as a4, CoverageProvider as a5, CoverageProviderModule as a6, CoverageReporter as a7, CoverageV8Options as a8, CustomProviderOptions as a9, Report as aA, ReportedHookContext as aB, Reporter as aC, ResolveSnapshotPathHandler as aE, ResolveSnapshotPathHandlerContext as aF, ResolvedBrowserOptions as aG, ResolvedProjectConfig as aH, SerializedTestProject as aI, SuiteNameTemplateVariables as aJ, TaskOptions as aM, TestAttempt as aN, TestAttemptState as aO, TestDiagnostic as aR, TestModuleState as aT, TestResult as aU, TestResultFailed as aV, TestResultPassed as aW, TestResultPending as aX, TestResultSkipped as aY, TestRunEndReason as aZ, TestRunResult as a_, DepsOptimizationOptions as ab, EnvironmentOptions as ad, HTMLOptions as af, InstrumenterOptions as ah, JUnitOptions as ai, JsonAssertionResult as ak, JsonOptions as al, JsonTestResult as an, JsonTestResults as ao, ModuleDependency as ap, ModuleDiagnostic as aq, ModulesResolver as ar, OnServerRestartHandler as as, OnTestsRerunHandler as at, ParentProjectBrowser as au, Pool as av, PoolRunnerInitializer as aw, PoolTask as ax, ProjectBrowser as ay, ProjectConfig as az, UserProjectConfigExport as b, TestSpecificationOptions as b0, TestState as b1, TestSuiteState as b3, ToMatchScreenshotComparators as b4, ToMatchScreenshotOptions as b5, TypecheckConfig as b6, UIOptions as b7, VitestEnvironment as b9, WorkerResponse as bb, _BrowserNames as bc, TestProjectInlineConfiguration as c, UserConfig as d, CliOptions as e, ResolvedCoverageOptions as g, ReportContext as j, VitestOptions as l, VitestRunMode as m, VCSProvider as n, VCSProviderOptions as o, PoolWorker as p, PoolOptions as q, WorkerRequest as r, TestSequencer as s, BenchmarkUserOptions as u, BrowserBuiltinProvider as v, BrowserCommand as w, BrowserCommandContext as x, BrowserConfigOptions as y, BrowserInstanceOption as z };
|