vitest 3.0.0-beta.1 → 3.0.0-beta.2
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/dist/browser.d.ts +12 -9
- package/dist/browser.js +2 -2
- package/dist/chunks/{base.CkcgFVQd.js → base.CUgXReRN.js} +1 -1
- package/dist/chunks/{cac.CWCZimpS.js → cac.Xzv7eNWw.js} +18 -13
- package/dist/chunks/{cli-api.BKUOv0Nc.js → cli-api.CETCDGgZ.js} +915 -531
- package/dist/chunks/{coverage.BoMDb1ip.js → coverage.BWeNbfBa.js} +4 -4
- package/dist/chunks/{environment.CT0jpO-1.d.ts → environment.d8YfPkTm.d.ts} +1 -3
- package/dist/chunks/{globals.DJTzb7B3.js → globals.BFncSRNA.js} +2 -2
- package/dist/chunks/{index.DKe7vK-G.js → index.9ZEBV_TJ.js} +635 -606
- package/dist/chunks/{index.BqHViJW9.js → index.CkWmZCXU.js} +1 -1
- package/dist/chunks/{index.CkOJwybT.js → index.DoV7W5gc.js} +2 -2
- package/dist/chunks/{reporters.BZbwTvrM.d.ts → reporters.DTtxC3KQ.d.ts} +447 -374
- package/dist/chunks/{resolveConfig.3rGGWga5.js → resolveConfig.BA-_OKEx.js} +5529 -5532
- package/dist/chunks/{runBaseTests.C6huCAng.js → runBaseTests.D0dWpzZV.js} +11 -10
- package/dist/chunks/{setup-common.B5ClyS48.js → setup-common.Cp_bu5q3.js} +1 -1
- package/dist/chunks/types.BOjykUpq.d.ts +27 -0
- package/dist/chunks/{vi.CZKezqeD.js → vi.S4Fq8wSo.js} +2 -1
- package/dist/chunks/{vite.DIfmneq0.d.ts → vite.CXaetSK3.d.ts} +1 -1
- package/dist/chunks/{worker.umPNbBNk.d.ts → worker.ClntunZp.d.ts} +1 -1
- package/dist/chunks/{worker.CmzGeuVD.d.ts → worker.o1PBoDdo.d.ts} +3 -3
- package/dist/cli.js +1 -1
- package/dist/config.d.ts +6 -8
- package/dist/coverage.d.ts +4 -6
- package/dist/coverage.js +1 -1
- package/dist/environments.d.ts +2 -2
- package/dist/execute.d.ts +2 -2
- package/dist/index.d.ts +11 -14
- package/dist/index.js +2 -2
- package/dist/node.d.ts +22 -17
- package/dist/node.js +65 -31
- package/dist/reporters.d.ts +4 -6
- package/dist/reporters.js +1 -1
- package/dist/runners.d.ts +2 -2
- package/dist/runners.js +1 -1
- package/dist/suite.d.ts +1 -1
- package/dist/workers/forks.js +1 -1
- package/dist/workers/runVmTests.js +7 -7
- package/dist/workers/threads.js +1 -1
- package/dist/workers.d.ts +3 -3
- package/dist/workers.js +1 -1
- package/package.json +13 -13
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import * as _vitest_runner from '@vitest/runner';
|
|
2
|
-
import { File, TaskResultPack, Task,
|
|
3
|
-
import { b as Awaitable, U as UserConsoleLog, A as AfterSuiteRunMeta, c as Arrayable$1, f as EnvironmentOptions, P as ProvidedContext
|
|
2
|
+
import { File, TaskResultPack, Task, TaskMeta, Suite, SequenceHooks, SequenceSetupFiles, CancelReason } from '@vitest/runner';
|
|
3
|
+
import { b as Awaitable, U as UserConsoleLog, A as AfterSuiteRunMeta, c as Arrayable$1, f as EnvironmentOptions, P as ProvidedContext } from './environment.d8YfPkTm.js';
|
|
4
|
+
import { TestError, ParsedStack, Arrayable, ErrorWithDiff, Awaitable as Awaitable$1 } from '@vitest/utils';
|
|
4
5
|
import { Writable } from 'node:stream';
|
|
5
6
|
import { TransformResult as TransformResult$1, ServerOptions, DepOptimizationConfig, AliasOptions, UserConfig as UserConfig$1, ConfigEnv, ViteDevServer, ModuleNode } from 'vite';
|
|
6
|
-
import { TestError, ParsedStack, Arrayable, ErrorWithDiff, Awaitable as Awaitable$1 } from '@vitest/utils';
|
|
7
|
-
import { RawSourceMap, ViteNodeServerOptions } from 'vite-node';
|
|
8
7
|
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
9
8
|
import { S as SerializedConfig, F as FakeTimerInstallOpts } from './config.BTPBhmK5.js';
|
|
10
9
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
11
10
|
import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
|
|
12
11
|
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
12
|
+
import { ViteNodeServerOptions } from 'vite-node';
|
|
13
13
|
import * as chai from 'chai';
|
|
14
14
|
import { B as BenchmarkResult } from './benchmark.CFFwLv-O.js';
|
|
15
|
-
import { ViteNodeRunner } from 'vite-node/client';
|
|
16
|
-
import { ViteNodeServer } from 'vite-node/server';
|
|
17
15
|
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
18
16
|
import { Stats } from 'node:fs';
|
|
19
17
|
|
|
@@ -25,6 +23,7 @@ type SerializedTestSpecification = [
|
|
|
25
23
|
file: string,
|
|
26
24
|
options: {
|
|
27
25
|
pool: string;
|
|
26
|
+
testLines?: number[] | undefined;
|
|
28
27
|
}
|
|
29
28
|
];
|
|
30
29
|
|
|
@@ -109,11 +108,6 @@ interface HTMLOptions {
|
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
declare class ReportedTaskImplementation {
|
|
112
|
-
/**
|
|
113
|
-
* Task instance.
|
|
114
|
-
* @experimental Public runner task API is experimental and does not follow semver.
|
|
115
|
-
*/
|
|
116
|
-
readonly task: Task;
|
|
117
111
|
/**
|
|
118
112
|
* The project assosiacted with the test or suite.
|
|
119
113
|
*/
|
|
@@ -121,7 +115,7 @@ declare class ReportedTaskImplementation {
|
|
|
121
115
|
/**
|
|
122
116
|
* Unique identifier.
|
|
123
117
|
* This ID is deterministic and will be the same for the same test across multiple runs.
|
|
124
|
-
* The ID is based on the project name, module url and test
|
|
118
|
+
* The ID is based on the project name, module url and test order.
|
|
125
119
|
*/
|
|
126
120
|
readonly id: string;
|
|
127
121
|
/**
|
|
@@ -131,15 +125,14 @@ declare class ReportedTaskImplementation {
|
|
|
131
125
|
line: number;
|
|
132
126
|
column: number;
|
|
133
127
|
} | undefined;
|
|
134
|
-
protected constructor(task: Task, project: TestProject);
|
|
135
128
|
/**
|
|
136
|
-
*
|
|
129
|
+
* Checks if the test did not fail the suite.
|
|
130
|
+
* If the test is not finished yet or was skipped, it will return `true`.
|
|
137
131
|
*/
|
|
138
|
-
|
|
132
|
+
ok(): boolean;
|
|
139
133
|
}
|
|
140
134
|
declare class TestCase extends ReportedTaskImplementation {
|
|
141
135
|
#private;
|
|
142
|
-
readonly task: Test;
|
|
143
136
|
readonly type = "test";
|
|
144
137
|
/**
|
|
145
138
|
* Direct reference to the test module where the test or suite is defined.
|
|
@@ -157,20 +150,18 @@ declare class TestCase extends ReportedTaskImplementation {
|
|
|
157
150
|
* Parent suite. If the test was called directly inside the module, the parent will be the module itself.
|
|
158
151
|
*/
|
|
159
152
|
readonly parent: TestSuite | TestModule;
|
|
160
|
-
protected constructor(task: Test, project: TestProject);
|
|
161
153
|
/**
|
|
162
154
|
* Full name of the test including all parent suites separated with `>`.
|
|
163
155
|
*/
|
|
164
156
|
get fullName(): string;
|
|
165
157
|
/**
|
|
166
|
-
* Test results. Will be `undefined` if test is not finished yet or was just collected.
|
|
158
|
+
* Test results. Will be `undefined` if test is skipped, not finished yet or was just collected.
|
|
167
159
|
*/
|
|
168
160
|
result(): TestResult | undefined;
|
|
169
161
|
/**
|
|
170
|
-
* Checks if the test
|
|
171
|
-
* If the test is not finished yet or was skipped, it will return `true`.
|
|
162
|
+
* Checks if the test was skipped during collection or dynamically with `ctx.skip()`.
|
|
172
163
|
*/
|
|
173
|
-
|
|
164
|
+
skipped(): boolean;
|
|
174
165
|
/**
|
|
175
166
|
* Custom metadata that was attached to the test during its execution.
|
|
176
167
|
*/
|
|
@@ -185,7 +176,7 @@ declare class TestCollection {
|
|
|
185
176
|
#private;
|
|
186
177
|
constructor(task: Suite | File, project: TestProject);
|
|
187
178
|
/**
|
|
188
|
-
* Returns the test or suite at a specific index
|
|
179
|
+
* Returns the test or suite at a specific index.
|
|
189
180
|
*/
|
|
190
181
|
at(index: number): TestCase | TestSuite | undefined;
|
|
191
182
|
/**
|
|
@@ -216,16 +207,21 @@ declare class TestCollection {
|
|
|
216
207
|
}
|
|
217
208
|
|
|
218
209
|
declare abstract class SuiteImplementation extends ReportedTaskImplementation {
|
|
219
|
-
readonly task: Suite | File;
|
|
220
210
|
/**
|
|
221
211
|
* Collection of suites and tests that are part of this suite.
|
|
222
212
|
*/
|
|
223
213
|
readonly children: TestCollection;
|
|
224
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Checks if the suite was skipped during collection.
|
|
216
|
+
*/
|
|
217
|
+
skipped(): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Errors that happened outside of the test run during collection, like syntax errors.
|
|
220
|
+
*/
|
|
221
|
+
errors(): TestError[];
|
|
225
222
|
}
|
|
226
223
|
declare class TestSuite extends SuiteImplementation {
|
|
227
224
|
#private;
|
|
228
|
-
readonly task: Suite;
|
|
229
225
|
readonly type = "suite";
|
|
230
226
|
/**
|
|
231
227
|
* Name of the test or the suite.
|
|
@@ -243,14 +239,17 @@ declare class TestSuite extends SuiteImplementation {
|
|
|
243
239
|
* Options that suite was initiated with.
|
|
244
240
|
*/
|
|
245
241
|
readonly options: TaskOptions;
|
|
246
|
-
|
|
242
|
+
/**
|
|
243
|
+
* Checks if the suite has any failed tests.
|
|
244
|
+
* This will also return `false` if suite failed during collection.
|
|
245
|
+
*/
|
|
246
|
+
ok: () => boolean;
|
|
247
247
|
/**
|
|
248
248
|
* Full name of the suite including all parent suites separated with `>`.
|
|
249
249
|
*/
|
|
250
250
|
get fullName(): string;
|
|
251
251
|
}
|
|
252
252
|
declare class TestModule extends SuiteImplementation {
|
|
253
|
-
readonly task: File;
|
|
254
253
|
readonly location: undefined;
|
|
255
254
|
readonly type = "module";
|
|
256
255
|
/**
|
|
@@ -259,7 +258,15 @@ declare class TestModule extends SuiteImplementation {
|
|
|
259
258
|
* This value corresponds to Vite's `ModuleGraph` id.
|
|
260
259
|
*/
|
|
261
260
|
readonly moduleId: string;
|
|
262
|
-
|
|
261
|
+
/**
|
|
262
|
+
* Checks if the module has any failed tests.
|
|
263
|
+
* This will also return `false` if module failed during collection.
|
|
264
|
+
*/
|
|
265
|
+
ok: () => boolean;
|
|
266
|
+
/**
|
|
267
|
+
* Checks if the module was skipped and didn't run.
|
|
268
|
+
*/
|
|
269
|
+
skipped: () => boolean;
|
|
263
270
|
/**
|
|
264
271
|
* Useful information about the module like duration, memory usage, etc.
|
|
265
272
|
* If the module was not executed yet, all diagnostic values will return `0`.
|
|
@@ -299,8 +306,8 @@ interface TestResultFailed {
|
|
|
299
306
|
}
|
|
300
307
|
interface TestResultSkipped {
|
|
301
308
|
/**
|
|
302
|
-
* The test was skipped with `only
|
|
303
|
-
* You can see which one was used in the `mode` option.
|
|
309
|
+
* The test was skipped with `only` (on another test), `skip` or `todo` flag.
|
|
310
|
+
* You can see which one was used in the `options.mode` option.
|
|
304
311
|
*/
|
|
305
312
|
state: 'skipped';
|
|
306
313
|
/**
|
|
@@ -308,7 +315,7 @@ interface TestResultSkipped {
|
|
|
308
315
|
*/
|
|
309
316
|
errors: undefined;
|
|
310
317
|
/**
|
|
311
|
-
* A custom note.
|
|
318
|
+
* A custom note passed down to `ctx.skip(note)`.
|
|
312
319
|
*/
|
|
313
320
|
note: string | undefined;
|
|
314
321
|
}
|
|
@@ -618,114 +625,12 @@ declare class VerboseReporter extends DefaultReporter {
|
|
|
618
625
|
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
619
626
|
}
|
|
620
627
|
|
|
621
|
-
interface ParsedFile extends File {
|
|
622
|
-
start: number;
|
|
623
|
-
end: number;
|
|
624
|
-
}
|
|
625
|
-
interface ParsedTest extends Test {
|
|
626
|
-
start: number;
|
|
627
|
-
end: number;
|
|
628
|
-
}
|
|
629
|
-
interface ParsedSuite extends Suite {
|
|
630
|
-
start: number;
|
|
631
|
-
end: number;
|
|
632
|
-
}
|
|
633
|
-
interface LocalCallDefinition {
|
|
634
|
-
start: number;
|
|
635
|
-
end: number;
|
|
636
|
-
name: string;
|
|
637
|
-
type: 'suite' | 'test';
|
|
638
|
-
mode: 'run' | 'skip' | 'only' | 'todo';
|
|
639
|
-
task: ParsedSuite | ParsedFile | ParsedTest;
|
|
640
|
-
}
|
|
641
|
-
interface FileInformation {
|
|
642
|
-
file: File;
|
|
643
|
-
filepath: string;
|
|
644
|
-
parsed: string;
|
|
645
|
-
map: RawSourceMap | null;
|
|
646
|
-
definitions: LocalCallDefinition[];
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
type RawErrsMap = Map<string, TscErrorInfo[]>;
|
|
650
|
-
interface TscErrorInfo {
|
|
651
|
-
filePath: string;
|
|
652
|
-
errCode: number;
|
|
653
|
-
errMsg: string;
|
|
654
|
-
line: number;
|
|
655
|
-
column: number;
|
|
656
|
-
}
|
|
657
|
-
interface CollectLineNumbers {
|
|
658
|
-
target: number;
|
|
659
|
-
next: number;
|
|
660
|
-
prev?: number;
|
|
661
|
-
}
|
|
662
|
-
type CollectLines = {
|
|
663
|
-
[key in keyof CollectLineNumbers]: string;
|
|
664
|
-
};
|
|
665
|
-
interface RootAndTarget {
|
|
666
|
-
root: string;
|
|
667
|
-
targetAbsPath: string;
|
|
668
|
-
}
|
|
669
|
-
type Context = RootAndTarget & {
|
|
670
|
-
rawErrsMap: RawErrsMap;
|
|
671
|
-
openedDirs: Set<string>;
|
|
672
|
-
lastActivePath?: string;
|
|
673
|
-
};
|
|
674
|
-
|
|
675
628
|
declare class TypeCheckError extends Error {
|
|
676
629
|
message: string;
|
|
677
630
|
stacks: ParsedStack[];
|
|
678
631
|
name: string;
|
|
679
632
|
constructor(message: string, stacks: ParsedStack[]);
|
|
680
633
|
}
|
|
681
|
-
interface TypecheckResults {
|
|
682
|
-
files: File[];
|
|
683
|
-
sourceErrors: TypeCheckError[];
|
|
684
|
-
time: number;
|
|
685
|
-
}
|
|
686
|
-
type Callback<Args extends Array<any> = []> = (...args: Args) => Awaitable<void>;
|
|
687
|
-
declare class Typechecker {
|
|
688
|
-
protected ctx: TestProject;
|
|
689
|
-
private _onParseStart?;
|
|
690
|
-
private _onParseEnd?;
|
|
691
|
-
private _onWatcherRerun?;
|
|
692
|
-
private _result;
|
|
693
|
-
private _startTime;
|
|
694
|
-
private _output;
|
|
695
|
-
private _tests;
|
|
696
|
-
private tempConfigPath?;
|
|
697
|
-
private allowJs?;
|
|
698
|
-
private process?;
|
|
699
|
-
protected files: string[];
|
|
700
|
-
constructor(ctx: TestProject);
|
|
701
|
-
setFiles(files: string[]): void;
|
|
702
|
-
onParseStart(fn: Callback): void;
|
|
703
|
-
onParseEnd(fn: Callback<[TypecheckResults]>): void;
|
|
704
|
-
onWatcherRerun(fn: Callback): void;
|
|
705
|
-
protected collectFileTests(filepath: string): Promise<FileInformation | null>;
|
|
706
|
-
protected getFiles(): string[];
|
|
707
|
-
collectTests(): Promise<Record<string, FileInformation>>;
|
|
708
|
-
protected markPassed(file: File): void;
|
|
709
|
-
protected prepareResults(output: string): Promise<{
|
|
710
|
-
files: File[];
|
|
711
|
-
sourceErrors: TypeCheckError[];
|
|
712
|
-
time: number;
|
|
713
|
-
}>;
|
|
714
|
-
protected parseTscLikeOutput(output: string): Promise<Map<string, {
|
|
715
|
-
error: TypeCheckError;
|
|
716
|
-
originalError: TscErrorInfo;
|
|
717
|
-
}[]>>;
|
|
718
|
-
clear(): Promise<void>;
|
|
719
|
-
stop(): Promise<void>;
|
|
720
|
-
protected ensurePackageInstalled(ctx: Vitest, checker: string): Promise<void>;
|
|
721
|
-
prepare(): Promise<void>;
|
|
722
|
-
getExitCode(): number | false;
|
|
723
|
-
getOutput(): string;
|
|
724
|
-
start(): Promise<void>;
|
|
725
|
-
getResult(): TypecheckResults;
|
|
726
|
-
getTestFiles(): File[];
|
|
727
|
-
getTestPacks(): TaskResultPack[];
|
|
728
|
-
}
|
|
729
634
|
|
|
730
635
|
interface PrintErrorResult {
|
|
731
636
|
nearest?: ParsedStack;
|
|
@@ -920,13 +825,175 @@ interface BuiltinReporterOptions {
|
|
|
920
825
|
|
|
921
826
|
type ChaiConfig = Omit<Partial<typeof chai.config>, 'useProxy' | 'proxyExcludedKeys'>;
|
|
922
827
|
|
|
828
|
+
type BuiltinPool = 'browser' | 'threads' | 'forks' | 'vmThreads' | 'vmForks' | 'typescript';
|
|
829
|
+
type Pool = BuiltinPool | (string & {});
|
|
830
|
+
interface PoolOptions extends Record<string, unknown> {
|
|
831
|
+
/**
|
|
832
|
+
* Run tests in `node:worker_threads`.
|
|
833
|
+
*
|
|
834
|
+
* Test isolation (when enabled) is done by spawning a new thread for each test file.
|
|
835
|
+
*
|
|
836
|
+
* This pool is used by default.
|
|
837
|
+
*/
|
|
838
|
+
threads?: ThreadsOptions & WorkerContextOptions;
|
|
839
|
+
/**
|
|
840
|
+
* Run tests in `node:child_process` using [`fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
|
|
841
|
+
*
|
|
842
|
+
* Test isolation (when enabled) is done by spawning a new child process for each test file.
|
|
843
|
+
*/
|
|
844
|
+
forks?: ForksOptions & WorkerContextOptions;
|
|
845
|
+
/**
|
|
846
|
+
* Run tests in isolated `node:vm`.
|
|
847
|
+
* Test files are run parallel using `node:worker_threads`.
|
|
848
|
+
*
|
|
849
|
+
* This makes tests run faster, but VM module is unstable. Your tests might leak memory.
|
|
850
|
+
*/
|
|
851
|
+
vmThreads?: ThreadsOptions & VmOptions;
|
|
852
|
+
/**
|
|
853
|
+
* Run tests in isolated `node:vm`.
|
|
854
|
+
*
|
|
855
|
+
* Test files are run parallel using `node:child_process` [`fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
|
|
856
|
+
*
|
|
857
|
+
* This makes tests run faster, but VM module is unstable. Your tests might leak memory.
|
|
858
|
+
*/
|
|
859
|
+
vmForks?: ForksOptions & VmOptions;
|
|
860
|
+
}
|
|
861
|
+
interface ResolvedPoolOptions extends PoolOptions {
|
|
862
|
+
threads?: ResolvedThreadsOptions & WorkerContextOptions;
|
|
863
|
+
forks?: ResolvedForksOptions & WorkerContextOptions;
|
|
864
|
+
vmThreads?: ResolvedThreadsOptions & VmOptions;
|
|
865
|
+
vmForks?: ResolvedForksOptions & VmOptions;
|
|
866
|
+
}
|
|
867
|
+
interface ThreadsOptions {
|
|
868
|
+
/** Minimum amount of threads to use */
|
|
869
|
+
minThreads?: number | string;
|
|
870
|
+
/** Maximum amount of threads to use */
|
|
871
|
+
maxThreads?: number | string;
|
|
872
|
+
/**
|
|
873
|
+
* Run tests inside a single thread.
|
|
874
|
+
*
|
|
875
|
+
* @default false
|
|
876
|
+
*/
|
|
877
|
+
singleThread?: boolean;
|
|
878
|
+
/**
|
|
879
|
+
* Use Atomics to synchronize threads
|
|
880
|
+
*
|
|
881
|
+
* This can improve performance in some cases, but might cause segfault in older Node versions.
|
|
882
|
+
*
|
|
883
|
+
* @default false
|
|
884
|
+
*/
|
|
885
|
+
useAtomics?: boolean;
|
|
886
|
+
}
|
|
887
|
+
interface ResolvedThreadsOptions extends ThreadsOptions {
|
|
888
|
+
minThreads?: number;
|
|
889
|
+
maxThreads?: number;
|
|
890
|
+
}
|
|
891
|
+
interface ForksOptions {
|
|
892
|
+
/** Minimum amount of child processes to use */
|
|
893
|
+
minForks?: number | string;
|
|
894
|
+
/** Maximum amount of child processes to use */
|
|
895
|
+
maxForks?: number | string;
|
|
896
|
+
/**
|
|
897
|
+
* Run tests inside a single fork.
|
|
898
|
+
*
|
|
899
|
+
* @default false
|
|
900
|
+
*/
|
|
901
|
+
singleFork?: boolean;
|
|
902
|
+
}
|
|
903
|
+
interface ResolvedForksOptions extends ForksOptions {
|
|
904
|
+
minForks?: number;
|
|
905
|
+
maxForks?: number;
|
|
906
|
+
}
|
|
907
|
+
interface WorkerContextOptions {
|
|
908
|
+
/**
|
|
909
|
+
* Isolate test environment by recycling `worker_threads` or `child_process` after each test
|
|
910
|
+
*
|
|
911
|
+
* @default true
|
|
912
|
+
*/
|
|
913
|
+
isolate?: boolean;
|
|
914
|
+
/**
|
|
915
|
+
* Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
|
|
916
|
+
*
|
|
917
|
+
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
|
918
|
+
*
|
|
919
|
+
* Set to `process.execArgv` to pass all arguments of the current process.
|
|
920
|
+
*
|
|
921
|
+
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
|
922
|
+
*
|
|
923
|
+
* @default [] // no execution arguments are passed
|
|
924
|
+
*/
|
|
925
|
+
execArgv?: string[];
|
|
926
|
+
}
|
|
927
|
+
interface VmOptions {
|
|
928
|
+
/**
|
|
929
|
+
* Specifies the memory limit for `worker_thread` or `child_process` before they are recycled.
|
|
930
|
+
* If you see memory leaks, try to tinker this value.
|
|
931
|
+
*/
|
|
932
|
+
memoryLimit?: string | number;
|
|
933
|
+
/** Isolation is always enabled */
|
|
934
|
+
isolate?: true;
|
|
935
|
+
/**
|
|
936
|
+
* Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
|
|
937
|
+
*
|
|
938
|
+
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
|
939
|
+
*
|
|
940
|
+
* Set to `process.execArgv` to pass all arguments of the current process.
|
|
941
|
+
*
|
|
942
|
+
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
|
943
|
+
*
|
|
944
|
+
* @default [] // no execution arguments are passed
|
|
945
|
+
*/
|
|
946
|
+
execArgv?: string[];
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
declare class TestSpecification {
|
|
950
|
+
/**
|
|
951
|
+
* @deprecated use `project` instead
|
|
952
|
+
*/
|
|
953
|
+
readonly 0: TestProject;
|
|
954
|
+
/**
|
|
955
|
+
* @deprecated use `moduleId` instead
|
|
956
|
+
*/
|
|
957
|
+
readonly 1: string;
|
|
958
|
+
/**
|
|
959
|
+
* @deprecated use `pool` instead
|
|
960
|
+
*/
|
|
961
|
+
readonly 2: {
|
|
962
|
+
pool: Pool;
|
|
963
|
+
};
|
|
964
|
+
/**
|
|
965
|
+
* The test project that the module belongs to.
|
|
966
|
+
*/
|
|
967
|
+
readonly project: TestProject;
|
|
968
|
+
/**
|
|
969
|
+
* The ID of the module in the Vite module graph. It is usually an absolute file path.
|
|
970
|
+
*/
|
|
971
|
+
readonly moduleId: string;
|
|
972
|
+
/**
|
|
973
|
+
* The current test pool. It's possible to have multiple pools in a single test project with `poolMatchGlob` and `typecheck.enabled`.
|
|
974
|
+
* @experimental In Vitest 4, the project will only support a single pool and this property will be removed.
|
|
975
|
+
*/
|
|
976
|
+
readonly pool: Pool;
|
|
977
|
+
/**
|
|
978
|
+
* Line numbers of the test locations to run.
|
|
979
|
+
*/
|
|
980
|
+
readonly testLines: number[] | undefined;
|
|
981
|
+
constructor(project: TestProject, moduleId: string, pool: Pool, testLines?: number[] | undefined);
|
|
982
|
+
toJSON(): SerializedTestSpecification;
|
|
983
|
+
/**
|
|
984
|
+
* for backwards compatibility
|
|
985
|
+
* @deprecated
|
|
986
|
+
*/
|
|
987
|
+
[Symbol.iterator](): Generator<string | TestProject, void, unknown>;
|
|
988
|
+
}
|
|
989
|
+
|
|
923
990
|
interface TestSequencer {
|
|
924
991
|
/**
|
|
925
992
|
* Slicing tests into shards. Will be run before `sort`.
|
|
926
993
|
* Only run, if `shard` is defined.
|
|
927
994
|
*/
|
|
928
|
-
shard: (files:
|
|
929
|
-
sort: (files:
|
|
995
|
+
shard: (files: TestSpecification[]) => Awaitable<TestSpecification[]>;
|
|
996
|
+
sort: (files: TestSpecification[]) => Awaitable<TestSpecification[]>;
|
|
930
997
|
}
|
|
931
998
|
interface TestSequencerConstructor {
|
|
932
999
|
new (ctx: Vitest): TestSequencer;
|
|
@@ -1087,7 +1154,9 @@ interface CoverageProviderModule {
|
|
|
1087
1154
|
/**
|
|
1088
1155
|
* Executed before tests are run in the worker thread.
|
|
1089
1156
|
*/
|
|
1090
|
-
startCoverage?: (
|
|
1157
|
+
startCoverage?: (runtimeOptions: {
|
|
1158
|
+
isolate: boolean;
|
|
1159
|
+
}) => unknown | Promise<unknown>;
|
|
1091
1160
|
/**
|
|
1092
1161
|
* Executed on after each run in the worker thread. Possible to return a payload passed to the provider
|
|
1093
1162
|
*/
|
|
@@ -1095,7 +1164,9 @@ interface CoverageProviderModule {
|
|
|
1095
1164
|
/**
|
|
1096
1165
|
* Executed after all tests have been run in the worker thread.
|
|
1097
1166
|
*/
|
|
1098
|
-
stopCoverage?: (
|
|
1167
|
+
stopCoverage?: (runtimeOptions: {
|
|
1168
|
+
isolate: boolean;
|
|
1169
|
+
}) => unknown | Promise<unknown>;
|
|
1099
1170
|
}
|
|
1100
1171
|
type CoverageReporter = keyof ReportOptions | (string & {});
|
|
1101
1172
|
type CoverageReporterWithOptions<ReporterName extends CoverageReporter = CoverageReporter> = ReporterName extends keyof ReportOptions ? ReportOptions[ReporterName] extends never ? [ReporterName, object] : [ReporterName, Partial<ReportOptions[ReporterName]>] : [ReporterName, Record<string, unknown>];
|
|
@@ -1284,127 +1355,6 @@ interface Thresholds {
|
|
|
1284
1355
|
lines?: number;
|
|
1285
1356
|
}
|
|
1286
1357
|
|
|
1287
|
-
type BuiltinPool = 'browser' | 'threads' | 'forks' | 'vmThreads' | 'vmForks' | 'typescript';
|
|
1288
|
-
type Pool = BuiltinPool | (string & {});
|
|
1289
|
-
interface PoolOptions extends Record<string, unknown> {
|
|
1290
|
-
/**
|
|
1291
|
-
* Run tests in `node:worker_threads`.
|
|
1292
|
-
*
|
|
1293
|
-
* Test isolation (when enabled) is done by spawning a new thread for each test file.
|
|
1294
|
-
*
|
|
1295
|
-
* This pool is used by default.
|
|
1296
|
-
*/
|
|
1297
|
-
threads?: ThreadsOptions & WorkerContextOptions;
|
|
1298
|
-
/**
|
|
1299
|
-
* Run tests in `node:child_process` using [`fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
|
|
1300
|
-
*
|
|
1301
|
-
* Test isolation (when enabled) is done by spawning a new child process for each test file.
|
|
1302
|
-
*/
|
|
1303
|
-
forks?: ForksOptions & WorkerContextOptions;
|
|
1304
|
-
/**
|
|
1305
|
-
* Run tests in isolated `node:vm`.
|
|
1306
|
-
* Test files are run parallel using `node:worker_threads`.
|
|
1307
|
-
*
|
|
1308
|
-
* This makes tests run faster, but VM module is unstable. Your tests might leak memory.
|
|
1309
|
-
*/
|
|
1310
|
-
vmThreads?: ThreadsOptions & VmOptions;
|
|
1311
|
-
/**
|
|
1312
|
-
* Run tests in isolated `node:vm`.
|
|
1313
|
-
*
|
|
1314
|
-
* Test files are run parallel using `node:child_process` [`fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
|
|
1315
|
-
*
|
|
1316
|
-
* This makes tests run faster, but VM module is unstable. Your tests might leak memory.
|
|
1317
|
-
*/
|
|
1318
|
-
vmForks?: ForksOptions & VmOptions;
|
|
1319
|
-
}
|
|
1320
|
-
interface ResolvedPoolOptions extends PoolOptions {
|
|
1321
|
-
threads?: ResolvedThreadsOptions & WorkerContextOptions;
|
|
1322
|
-
forks?: ResolvedForksOptions & WorkerContextOptions;
|
|
1323
|
-
vmThreads?: ResolvedThreadsOptions & VmOptions;
|
|
1324
|
-
vmForks?: ResolvedForksOptions & VmOptions;
|
|
1325
|
-
}
|
|
1326
|
-
interface ThreadsOptions {
|
|
1327
|
-
/** Minimum amount of threads to use */
|
|
1328
|
-
minThreads?: number | string;
|
|
1329
|
-
/** Maximum amount of threads to use */
|
|
1330
|
-
maxThreads?: number | string;
|
|
1331
|
-
/**
|
|
1332
|
-
* Run tests inside a single thread.
|
|
1333
|
-
*
|
|
1334
|
-
* @default false
|
|
1335
|
-
*/
|
|
1336
|
-
singleThread?: boolean;
|
|
1337
|
-
/**
|
|
1338
|
-
* Use Atomics to synchronize threads
|
|
1339
|
-
*
|
|
1340
|
-
* This can improve performance in some cases, but might cause segfault in older Node versions.
|
|
1341
|
-
*
|
|
1342
|
-
* @default false
|
|
1343
|
-
*/
|
|
1344
|
-
useAtomics?: boolean;
|
|
1345
|
-
}
|
|
1346
|
-
interface ResolvedThreadsOptions extends ThreadsOptions {
|
|
1347
|
-
minThreads?: number;
|
|
1348
|
-
maxThreads?: number;
|
|
1349
|
-
}
|
|
1350
|
-
interface ForksOptions {
|
|
1351
|
-
/** Minimum amount of child processes to use */
|
|
1352
|
-
minForks?: number | string;
|
|
1353
|
-
/** Maximum amount of child processes to use */
|
|
1354
|
-
maxForks?: number | string;
|
|
1355
|
-
/**
|
|
1356
|
-
* Run tests inside a single fork.
|
|
1357
|
-
*
|
|
1358
|
-
* @default false
|
|
1359
|
-
*/
|
|
1360
|
-
singleFork?: boolean;
|
|
1361
|
-
}
|
|
1362
|
-
interface ResolvedForksOptions extends ForksOptions {
|
|
1363
|
-
minForks?: number;
|
|
1364
|
-
maxForks?: number;
|
|
1365
|
-
}
|
|
1366
|
-
interface WorkerContextOptions {
|
|
1367
|
-
/**
|
|
1368
|
-
* Isolate test environment by recycling `worker_threads` or `child_process` after each test
|
|
1369
|
-
*
|
|
1370
|
-
* @default true
|
|
1371
|
-
*/
|
|
1372
|
-
isolate?: boolean;
|
|
1373
|
-
/**
|
|
1374
|
-
* Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
|
|
1375
|
-
*
|
|
1376
|
-
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
|
1377
|
-
*
|
|
1378
|
-
* Set to `process.execArgv` to pass all arguments of the current process.
|
|
1379
|
-
*
|
|
1380
|
-
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
|
1381
|
-
*
|
|
1382
|
-
* @default [] // no execution arguments are passed
|
|
1383
|
-
*/
|
|
1384
|
-
execArgv?: string[];
|
|
1385
|
-
}
|
|
1386
|
-
interface VmOptions {
|
|
1387
|
-
/**
|
|
1388
|
-
* Specifies the memory limit for `worker_thread` or `child_process` before they are recycled.
|
|
1389
|
-
* If you see memory leaks, try to tinker this value.
|
|
1390
|
-
*/
|
|
1391
|
-
memoryLimit?: string | number;
|
|
1392
|
-
/** Isolation is always enabled */
|
|
1393
|
-
isolate?: true;
|
|
1394
|
-
/**
|
|
1395
|
-
* Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
|
|
1396
|
-
*
|
|
1397
|
-
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
|
1398
|
-
*
|
|
1399
|
-
* Set to `process.execArgv` to pass all arguments of the current process.
|
|
1400
|
-
*
|
|
1401
|
-
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
|
1402
|
-
*
|
|
1403
|
-
* @default [] // no execution arguments are passed
|
|
1404
|
-
*/
|
|
1405
|
-
execArgv?: string[];
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
1358
|
type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime';
|
|
1409
1359
|
type VitestEnvironment = BuiltinEnvironment | (string & Record<never, never>);
|
|
1410
1360
|
|
|
@@ -2498,35 +2448,6 @@ interface ResolvedBrowserOptions extends BrowserConfigOptions {
|
|
|
2498
2448
|
};
|
|
2499
2449
|
}
|
|
2500
2450
|
|
|
2501
|
-
declare class TestSpecification {
|
|
2502
|
-
/**
|
|
2503
|
-
* @deprecated use `project` instead
|
|
2504
|
-
*/
|
|
2505
|
-
readonly 0: TestProject;
|
|
2506
|
-
/**
|
|
2507
|
-
* @deprecated use `moduleId` instead
|
|
2508
|
-
*/
|
|
2509
|
-
readonly 1: string;
|
|
2510
|
-
/**
|
|
2511
|
-
* @deprecated use `pool` instead
|
|
2512
|
-
*/
|
|
2513
|
-
readonly 2: {
|
|
2514
|
-
pool: Pool;
|
|
2515
|
-
};
|
|
2516
|
-
readonly project: TestProject;
|
|
2517
|
-
readonly moduleId: string;
|
|
2518
|
-
readonly pool: Pool;
|
|
2519
|
-
/** @private */
|
|
2520
|
-
readonly testLocations: number[] | undefined;
|
|
2521
|
-
constructor(project: TestProject, moduleId: string, pool: Pool, testLocations?: number[] | undefined);
|
|
2522
|
-
toJSON(): SerializedTestSpecification;
|
|
2523
|
-
/**
|
|
2524
|
-
* for backwards compatibility
|
|
2525
|
-
* @deprecated
|
|
2526
|
-
*/
|
|
2527
|
-
[Symbol.iterator](): Generator<string | TestProject, void, unknown>;
|
|
2528
|
-
}
|
|
2529
|
-
|
|
2530
2451
|
declare class TestProject {
|
|
2531
2452
|
/** @deprecated */
|
|
2532
2453
|
path: string | number;
|
|
@@ -2551,9 +2472,7 @@ declare class TestProject {
|
|
|
2551
2472
|
* Temporary directory for the project. This is unique for each project. Vitest stores transformed content here.
|
|
2552
2473
|
*/
|
|
2553
2474
|
readonly tmpDir: string;
|
|
2554
|
-
|
|
2555
|
-
runner: ViteNodeRunner;
|
|
2556
|
-
typechecker?: Typechecker;
|
|
2475
|
+
private runner;
|
|
2557
2476
|
private closingPromise;
|
|
2558
2477
|
private testFilesList;
|
|
2559
2478
|
private typecheckFilesList;
|
|
@@ -2578,7 +2497,9 @@ declare class TestProject {
|
|
|
2578
2497
|
* Creates a new test specification. Specifications describe how to run tests.
|
|
2579
2498
|
* @param moduleId The file path
|
|
2580
2499
|
*/
|
|
2581
|
-
createSpecification(moduleId: string,
|
|
2500
|
+
createSpecification(moduleId: string, locations?: number[] | undefined,
|
|
2501
|
+
/** @internal */
|
|
2502
|
+
pool?: string): TestSpecification;
|
|
2582
2503
|
toJSON(): SerializedTestProject;
|
|
2583
2504
|
/**
|
|
2584
2505
|
* Vite's dev server instance. Every workspace project has its own server.
|
|
@@ -2637,12 +2558,13 @@ declare class TestProject {
|
|
|
2637
2558
|
}>;
|
|
2638
2559
|
private globAllTestFiles;
|
|
2639
2560
|
isBrowserEnabled(): boolean;
|
|
2561
|
+
private markTestFile;
|
|
2640
2562
|
/** @deprecated use `serializedConfig` instead */
|
|
2641
2563
|
getSerializableConfig(): SerializedConfig;
|
|
2642
2564
|
/**
|
|
2643
|
-
* Test if a file matches the test globs. This does the actual glob matching unlike `
|
|
2565
|
+
* Test if a file matches the test globs. This does the actual glob matching if the test is not cached, unlike `isCachedTestFile`.
|
|
2644
2566
|
*/
|
|
2645
|
-
matchesTestGlob(
|
|
2567
|
+
matchesTestGlob(moduleId: string, source?: () => string): boolean;
|
|
2646
2568
|
/** @deprecated use `matchesTestGlob` instead */
|
|
2647
2569
|
isTargetFile(id: string, source?: string): Promise<boolean>;
|
|
2648
2570
|
private isInSourceTestCode;
|
|
@@ -2652,6 +2574,11 @@ declare class TestProject {
|
|
|
2652
2574
|
* If the resources are needed again, create a new project.
|
|
2653
2575
|
*/
|
|
2654
2576
|
close(): Promise<void>;
|
|
2577
|
+
/**
|
|
2578
|
+
* Import a file using Vite module runner.
|
|
2579
|
+
* @param moduleId The ID of the module in Vite module graph
|
|
2580
|
+
*/
|
|
2581
|
+
import<T>(moduleId: string): Promise<T>;
|
|
2655
2582
|
/** @deprecated use `name` instead */
|
|
2656
2583
|
getName(): string;
|
|
2657
2584
|
/** @deprecated internal */
|
|
@@ -2691,7 +2618,7 @@ type WorkspaceSpec = TestSpecification & [
|
|
|
2691
2618
|
pool: Pool;
|
|
2692
2619
|
}
|
|
2693
2620
|
];
|
|
2694
|
-
type RunWithFiles = (files:
|
|
2621
|
+
type RunWithFiles = (files: TestSpecification[], invalidates?: string[]) => Awaitable$1<void>;
|
|
2695
2622
|
interface ProcessPool {
|
|
2696
2623
|
name: string;
|
|
2697
2624
|
runTests: RunWithFiles;
|
|
@@ -2700,6 +2627,11 @@ interface ProcessPool {
|
|
|
2700
2627
|
}
|
|
2701
2628
|
declare function getFilePoolName(project: TestProject, file: string): Pool;
|
|
2702
2629
|
|
|
2630
|
+
interface TestRunResult {
|
|
2631
|
+
testModules: TestModule[];
|
|
2632
|
+
unhandledErrors: unknown[];
|
|
2633
|
+
}
|
|
2634
|
+
|
|
2703
2635
|
interface SuiteResultCache {
|
|
2704
2636
|
failed: boolean;
|
|
2705
2637
|
duration: number;
|
|
@@ -2724,7 +2656,7 @@ type FileStatsCache = Pick<Stats, 'size'>;
|
|
|
2724
2656
|
declare class FilesStatsCache {
|
|
2725
2657
|
cache: Map<string, FileStatsCache>;
|
|
2726
2658
|
getStats(key: string): FileStatsCache | undefined;
|
|
2727
|
-
populateStats(root: string, specs:
|
|
2659
|
+
populateStats(root: string, specs: TestSpecification[]): Promise<void>;
|
|
2728
2660
|
updateStats(fsPath: string, key: string): Promise<void>;
|
|
2729
2661
|
removeStats(fsPath: string): void;
|
|
2730
2662
|
}
|
|
@@ -2787,120 +2719,261 @@ interface VitestOptions {
|
|
|
2787
2719
|
}
|
|
2788
2720
|
declare class Vitest {
|
|
2789
2721
|
readonly mode: VitestRunMode;
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2722
|
+
/**
|
|
2723
|
+
* Current Vitest version.
|
|
2724
|
+
* @example '2.0.0'
|
|
2725
|
+
*/
|
|
2726
|
+
readonly version: string;
|
|
2727
|
+
static readonly version: string;
|
|
2728
|
+
/**
|
|
2729
|
+
* The logger instance used to log messages. It's recommended to use this logger instead of `console`.
|
|
2730
|
+
* It's possible to override stdout and stderr streams when initiating Vitest.
|
|
2731
|
+
* @example
|
|
2732
|
+
* new Vitest('test', {
|
|
2733
|
+
* stdout: new Writable(),
|
|
2734
|
+
* })
|
|
2735
|
+
*/
|
|
2736
|
+
readonly logger: Logger;
|
|
2737
|
+
/**
|
|
2738
|
+
* The package installer instance used to install Vitest packages.
|
|
2739
|
+
* @example
|
|
2740
|
+
* await vitest.packageInstaller.ensureInstalled('@vitest/browser', process.cwd())
|
|
2741
|
+
*/
|
|
2742
|
+
readonly packageInstaller: VitestPackageInstaller;
|
|
2743
|
+
/**
|
|
2744
|
+
* A path to the built Vitest directory. This is usually a folder in `node_modules`.
|
|
2745
|
+
*/
|
|
2746
|
+
readonly distPath: string;
|
|
2747
|
+
/**
|
|
2748
|
+
* A list of projects that are currently running.
|
|
2749
|
+
* If projects were filtered with `--project` flag, they won't appear here.
|
|
2750
|
+
*/
|
|
2815
2751
|
projects: TestProject[];
|
|
2816
|
-
|
|
2817
|
-
private
|
|
2752
|
+
private isFirstRun;
|
|
2753
|
+
private restartsCount;
|
|
2754
|
+
private readonly specifications;
|
|
2755
|
+
private readonly watcher;
|
|
2756
|
+
private pool;
|
|
2757
|
+
private _config?;
|
|
2758
|
+
private _vite?;
|
|
2759
|
+
private _state?;
|
|
2760
|
+
private _cache?;
|
|
2761
|
+
private _snapshot?;
|
|
2818
2762
|
private _workspaceConfigPath?;
|
|
2819
|
-
/** @deprecated use `_cachedSpecs` */
|
|
2820
|
-
projectTestFiles: Map<string, TestSpecification[]>;
|
|
2821
2763
|
constructor(mode: VitestRunMode, options?: VitestOptions);
|
|
2822
2764
|
private _onRestartListeners;
|
|
2823
2765
|
private _onClose;
|
|
2824
2766
|
private _onSetServer;
|
|
2825
2767
|
private _onCancelListeners;
|
|
2826
2768
|
private _onUserTestsRerun;
|
|
2769
|
+
private _onFilterWatchedSpecification;
|
|
2770
|
+
/** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
|
|
2771
|
+
get invalidates(): Set<string>;
|
|
2772
|
+
/** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
|
|
2773
|
+
get changedTests(): Set<string>;
|
|
2774
|
+
/**
|
|
2775
|
+
* The global config.
|
|
2776
|
+
*/
|
|
2777
|
+
get config(): ResolvedConfig;
|
|
2778
|
+
/** @deprecated use `vitest.vite` instead */
|
|
2779
|
+
get server(): ViteDevServer;
|
|
2780
|
+
/**
|
|
2781
|
+
* Global Vite's dev server instance.
|
|
2782
|
+
*/
|
|
2783
|
+
get vite(): ViteDevServer;
|
|
2784
|
+
/**
|
|
2785
|
+
* The global test state manager.
|
|
2786
|
+
* @experimental The State API is experimental and not subject to semver.
|
|
2787
|
+
*/
|
|
2788
|
+
get state(): StateManager;
|
|
2789
|
+
/**
|
|
2790
|
+
* The global snapshot manager. You can access the current state on `snapshot.summary`.
|
|
2791
|
+
*/
|
|
2792
|
+
get snapshot(): SnapshotManager;
|
|
2793
|
+
/**
|
|
2794
|
+
* Test results and test file stats cache. Primarily used by the sequencer to sort tests.
|
|
2795
|
+
*/
|
|
2796
|
+
get cache(): VitestCache;
|
|
2797
|
+
/** @deprecated internal */
|
|
2827
2798
|
setServer(options: UserConfig, server: ViteDevServer, cliOptions: UserConfig): Promise<void>;
|
|
2828
|
-
|
|
2829
|
-
|
|
2799
|
+
/**
|
|
2800
|
+
* Provide a value to the test context. This value will be available to all tests with `inject`.
|
|
2801
|
+
*/
|
|
2802
|
+
provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
|
|
2803
|
+
/**
|
|
2804
|
+
* Get global provided context.
|
|
2805
|
+
*/
|
|
2806
|
+
getProvidedContext(): ProvidedContext;
|
|
2807
|
+
/** @deprecated use `getRootProject` instead */
|
|
2808
|
+
getCoreWorkspaceProject(): TestProject;
|
|
2809
|
+
/**
|
|
2810
|
+
* Return project that has the root (or "global") config.
|
|
2811
|
+
*/
|
|
2812
|
+
getRootProject(): TestProject;
|
|
2830
2813
|
/**
|
|
2831
2814
|
* @deprecated use Reported Task API instead
|
|
2832
2815
|
*/
|
|
2833
2816
|
getProjectByTaskId(taskId: string): TestProject;
|
|
2834
|
-
getProjectByName(name
|
|
2817
|
+
getProjectByName(name: string): TestProject;
|
|
2818
|
+
/**
|
|
2819
|
+
* Import a file using Vite module runner. The file will be transformed by Vite and executed in a separate context.
|
|
2820
|
+
* @param moduleId The ID of the module in Vite module graph
|
|
2821
|
+
*/
|
|
2822
|
+
import<T>(moduleId: string): Promise<T>;
|
|
2835
2823
|
private resolveWorkspaceConfigPath;
|
|
2836
2824
|
private resolveWorkspace;
|
|
2825
|
+
/**
|
|
2826
|
+
* Glob test files in every project and create a TestSpecification for each file and pool.
|
|
2827
|
+
* @param filters String filters to match the test files.
|
|
2828
|
+
*/
|
|
2829
|
+
globTestSpecifications(filters?: string[]): Promise<TestSpecification[]>;
|
|
2837
2830
|
private initCoverageProvider;
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2831
|
+
/**
|
|
2832
|
+
* Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified).
|
|
2833
|
+
*/
|
|
2834
|
+
mergeReports(directory?: string): Promise<TestRunResult>;
|
|
2835
|
+
collect(filters?: string[]): Promise<TestRunResult>;
|
|
2836
|
+
/** @deprecated use `getRelevantTestSpecifications` instead */
|
|
2837
|
+
listFiles(filters?: string[]): Promise<TestSpecification[]>;
|
|
2838
|
+
/**
|
|
2839
|
+
* Returns the list of test files that match the config and filters.
|
|
2840
|
+
* @param filters String filters to match the test files
|
|
2841
|
+
*/
|
|
2842
|
+
getRelevantTestSpecifications(filters?: string[]): Promise<TestSpecification[]>;
|
|
2843
|
+
/**
|
|
2844
|
+
* Initialize reporters, the coverage provider, and run tests.
|
|
2845
|
+
* This method can throw an error:
|
|
2846
|
+
* - `FilesNotFoundError` if no tests are found
|
|
2847
|
+
* - `GitNotFoundError` if `--related` flag is used, but git repository is not initialized
|
|
2848
|
+
* - `Error` from the user reporters
|
|
2849
|
+
* @param filters String filters to match the test files
|
|
2850
|
+
*/
|
|
2851
|
+
start(filters?: string[]): Promise<TestRunResult>;
|
|
2852
|
+
/**
|
|
2853
|
+
* Initialize reporters and the coverage provider. This method doesn't run any tests.
|
|
2854
|
+
* If the `--watch` flag is provided, Vitest will still run changed tests even if this method was not called.
|
|
2855
|
+
*/
|
|
2845
2856
|
init(): Promise<void>;
|
|
2846
|
-
private getTestDependencies;
|
|
2847
|
-
filterTestsBySource(specs: WorkspaceSpec[]): Promise<WorkspaceSpec[]>;
|
|
2848
2857
|
/**
|
|
2849
|
-
* @deprecated remove when vscode extension supports "
|
|
2858
|
+
* @deprecated remove when vscode extension supports "getModuleSpecifications"
|
|
2850
2859
|
*/
|
|
2851
2860
|
getProjectsByTestFile(file: string): WorkspaceSpec[];
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2861
|
+
/** @deprecated */
|
|
2862
|
+
getFileWorkspaceSpecs(file: string): WorkspaceSpec[];
|
|
2863
|
+
/**
|
|
2864
|
+
* Get test specifications assosiated with the given module. If module is not a test file, an empty array is returned.
|
|
2865
|
+
*
|
|
2866
|
+
* **Note:** this method relies on a cache generated by `globTestSpecifications`. If the file was not processed yet, use `project.matchesGlobPattern` instead.
|
|
2867
|
+
* @param moduleId The module ID to get test specifications for.
|
|
2868
|
+
*/
|
|
2869
|
+
getModuleSpecifications(moduleId: string): TestSpecification[];
|
|
2870
|
+
/**
|
|
2871
|
+
* Vitest automatically caches test specifications for each file. This method clears the cache for the given file or the whole cache alltogether.
|
|
2872
|
+
*/
|
|
2873
|
+
clearSpecificationsCache(moduleId?: string): void;
|
|
2874
|
+
/**
|
|
2875
|
+
* Run tests for the given test specifications. This does not trigger `onWatcher*` events.
|
|
2876
|
+
* @param specifications A list of specifications to run.
|
|
2877
|
+
* @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
|
|
2878
|
+
*/
|
|
2879
|
+
runTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
|
|
2880
|
+
/**
|
|
2881
|
+
* Rerun files and trigger `onWatcherRerun`, `onWatcherStart` and `onTestsRerun` events.
|
|
2882
|
+
* @param specifications A list of specifications to run.
|
|
2883
|
+
* @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
|
|
2884
|
+
*/
|
|
2885
|
+
rerunTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
|
|
2886
|
+
private runFiles;
|
|
2887
|
+
/**
|
|
2888
|
+
* Collect tests in specified modules. Vitest will run the files to collect tests.
|
|
2889
|
+
* @param specifications A list of specifications to run.
|
|
2890
|
+
*/
|
|
2891
|
+
collectTests(specifications: TestSpecification[]): Promise<TestRunResult>;
|
|
2892
|
+
/**
|
|
2893
|
+
* Gracefully cancel the current test run. Vitest will wait until all running tests are finished before cancelling.
|
|
2894
|
+
*/
|
|
2856
2895
|
cancelCurrentRun(reason: CancelReason): Promise<void>;
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2896
|
+
private initializeGlobalSetup;
|
|
2897
|
+
/**
|
|
2898
|
+
* Enable the mode that allows updating snapshots when running tests.
|
|
2899
|
+
* This method doesn't run any tests.
|
|
2900
|
+
*
|
|
2901
|
+
* Every test that runs after this method is called will update snapshots.
|
|
2902
|
+
* To disable the mode, call `resetSnapshotUpdate`.
|
|
2903
|
+
*/
|
|
2904
|
+
enableSnapshotUpdate(): void;
|
|
2905
|
+
/**
|
|
2906
|
+
* Disable the mode that allows updating snapshots when running tests.
|
|
2907
|
+
*/
|
|
2908
|
+
resetSnapshotUpdate(): void;
|
|
2909
|
+
/**
|
|
2910
|
+
* Set the global test name pattern to a regexp.
|
|
2911
|
+
* This method doesn't run any tests.
|
|
2912
|
+
*/
|
|
2913
|
+
setGlobalTestNamePattern(pattern: string | RegExp): void;
|
|
2914
|
+
/**
|
|
2915
|
+
* Resets the global test name pattern. This method doesn't run any tests.
|
|
2916
|
+
*/
|
|
2917
|
+
resetGlobalTestNamePattern(): void;
|
|
2866
2918
|
private _rerunTimer;
|
|
2867
2919
|
private scheduleRerun;
|
|
2868
|
-
getModuleProjects(filepath: string): TestProject[];
|
|
2869
2920
|
/**
|
|
2870
|
-
*
|
|
2921
|
+
* Invalidate a file in all projects.
|
|
2871
2922
|
*/
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
onAdd: (id: string) => Promise<void>;
|
|
2877
|
-
checkUnhandledErrors(errors: unknown[]): void;
|
|
2878
|
-
private unregisterWatcher;
|
|
2879
|
-
private registerWatcher;
|
|
2923
|
+
invalidateFile(filepath: string): void;
|
|
2924
|
+
/** @deprecated use `invalidateFile` */
|
|
2925
|
+
updateLastChanged(filepath: string): void;
|
|
2926
|
+
private reportCoverage;
|
|
2880
2927
|
/**
|
|
2881
|
-
*
|
|
2928
|
+
* Closes all projects and their associated resources.
|
|
2929
|
+
* This can only be called once; the closing promise is cached until the server restarts.
|
|
2882
2930
|
*/
|
|
2883
|
-
private handleFileChanged;
|
|
2884
|
-
private reportCoverage;
|
|
2885
2931
|
close(): Promise<void>;
|
|
2886
2932
|
/**
|
|
2887
|
-
*
|
|
2933
|
+
* Closes all projects and exit the process
|
|
2934
|
+
* @param force If true, the process will exit immediately after closing the projects.
|
|
2888
2935
|
*/
|
|
2889
2936
|
exit(force?: boolean): Promise<void>;
|
|
2890
|
-
report<T extends keyof Reporter>(name: T, ...args: ArgumentsType<Reporter[T]>): Promise<void>;
|
|
2891
|
-
getTestFilepaths(): Promise<string[]>;
|
|
2892
|
-
globTestSpecs(filters?: string[]): Promise<WorkspaceSpec[]>;
|
|
2893
2937
|
/**
|
|
2894
|
-
* @deprecated use `
|
|
2938
|
+
* @deprecated use `globTestSpecifications` instead
|
|
2939
|
+
*/
|
|
2940
|
+
globTestSpecs(filters?: string[]): Promise<TestSpecification[]>;
|
|
2941
|
+
/**
|
|
2942
|
+
* @deprecated use `globTestSpecifications` instead
|
|
2943
|
+
*/
|
|
2944
|
+
globTestFiles(filters?: string[]): Promise<TestSpecification[]>;
|
|
2945
|
+
/** @deprecated filter by `this.projects` yourself */
|
|
2946
|
+
getModuleProjects(filepath: string): TestProject[];
|
|
2947
|
+
/**
|
|
2948
|
+
* Should the server be kept running after the tests are done.
|
|
2895
2949
|
*/
|
|
2896
|
-
globTestFiles(filters?: string[]): Promise<WorkspaceSpec[]>;
|
|
2897
|
-
private ensureSpecCached;
|
|
2898
2950
|
shouldKeepServer(): boolean;
|
|
2951
|
+
/**
|
|
2952
|
+
* Register a handler that will be called when the server is restarted due to a config change.
|
|
2953
|
+
*/
|
|
2899
2954
|
onServerRestart(fn: OnServerRestartHandler): void;
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2955
|
+
/**
|
|
2956
|
+
* Register a handler that will be called when the test run is cancelled with `vitest.cancelCurrentRun`.
|
|
2957
|
+
*/
|
|
2958
|
+
onCancel(fn: (reason: CancelReason) => Awaitable$1<void>): void;
|
|
2959
|
+
/**
|
|
2960
|
+
* Register a handler that will be called when the server is closed.
|
|
2961
|
+
*/
|
|
2962
|
+
onClose(fn: () => Awaitable$1<void>): void;
|
|
2963
|
+
/**
|
|
2964
|
+
* Register a handler that will be called when the tests are rerunning.
|
|
2965
|
+
*/
|
|
2903
2966
|
onTestsRerun(fn: OnTestsRerunHandler): void;
|
|
2967
|
+
/**
|
|
2968
|
+
* Register a handler that will be called when a file is changed.
|
|
2969
|
+
* This callback should return `true` of `false` indicating whether the test file needs to be rerun.
|
|
2970
|
+
* @example
|
|
2971
|
+
* const testsToRun = [resolve('./test.spec.ts')]
|
|
2972
|
+
* vitest.onFilterWatchedSpecification(specification => testsToRun.includes(specification.moduleId))
|
|
2973
|
+
*/
|
|
2974
|
+
onFilterWatchedSpecification(fn: (specification: TestSpecification) => boolean): void;
|
|
2904
2975
|
}
|
|
2976
|
+
type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
|
|
2977
|
+
type OnTestsRerunHandler = (testFiles: TestSpecification[]) => Promise<void> | void;
|
|
2905
2978
|
|
|
2906
|
-
export { type
|
|
2979
|
+
export { type JUnitOptions as $, type ApiConfig as A, type BaseCoverageOptions as B, CoverageMap as C, type DepsOptimizationOptions as D, TestProject as E, type TestSequencer as F, TestSpecification as G, TestModule as H, type InlineConfig as I, type OnTestsRerunHandler as J, VitestPackageInstaller as K, Logger as L, type ModuleDiagnostic as M, type ProcessPool as N, type OnServerRestartHandler as O, type Pool as P, type WorkspaceSpec as Q, type ResolvedCoverageOptions as R, type SerializedTestSpecification as S, type TestProjectConfiguration as T, type UserWorkspaceConfig as U, Vitest as V, type WorkspaceProjectConfiguration as W, getFilePoolName as X, type SerializedTestProject as Y, type HTMLOptions as Z, type JsonOptions$1 as _, type ReportContext as a, type TaskOptions as a0, TestCase as a1, TestCollection as a2, type TestDiagnostic as a3, type TestResult as a4, type TestResultFailed as a5, type TestResultPassed as a6, type TestResultSkipped as a7, TestSuite as a8, type TestSequencerConstructor as a9, VerboseReporter as aA, BaseReporter as aB, TestFile as aC, type FileDiagnostic as aD, ReportersMap as aE, type BuiltinReporters as aF, type BuiltinReporterOptions as aG, type JsonAssertionResult as aH, type JsonTestResult as aI, type JsonTestResults as aJ, BenchmarkReportsMap as aK, type BenchmarkBuiltinReporters as aL, type BrowserBuiltinProvider as aa, type BrowserCommand as ab, type BrowserCommandContext as ac, type BrowserOrchestrator as ad, type BrowserProvider as ae, type BrowserProviderInitializationOptions as af, type BrowserProviderModule as ag, type BrowserProviderOptions as ah, type BrowserServer as ai, type BrowserServerState as aj, type BrowserServerStateContext as ak, type CDPSession as al, type ResolvedBrowserOptions as am, type ResolvedProjectConfig as an, type ResolveSnapshotPathHandler as ao, type ResolveSnapshotPathHandlerContext as ap, type TestRunResult as aq, BasicReporter as ar, DefaultReporter as as, DotReporter as at, GithubActionsReporter as au, HangingProcessReporter as av, JsonReporter as aw, JUnitReporter as ax, TapFlatReporter as ay, TapReporter as az, type CoverageProvider as b, type CoverageProviderModule as c, type CoverageV8Options as d, type UserProjectConfigFn as e, type UserProjectConfigExport as f, type CoverageReporter as g, type CoverageProviderName as h, type CoverageOptions as i, type CoverageIstanbulOptions as j, type CustomProviderOptions as k, type Reporter as l, type BrowserScript as m, type BrowserConfigOptions as n, type BuiltinEnvironment as o, type VitestEnvironment as p, type PoolOptions as q, type CSSModuleScopeStrategy as r, type VitestRunMode as s, type TransformModePatterns as t, type TypecheckConfig as u, type UserConfig as v, type ResolvedConfig as w, type ProjectConfig as x, type BenchmarkUserOptions as y, type VitestOptions as z };
|