vitest 4.0.0-beta.7 → 4.0.0-beta.8
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/chunks/{cac.Dsn7ixFt.js → cac.By1HvRIk.js} +6 -7
- package/dist/chunks/{cli-api.DfGJyldU.js → cli-api.C-JHgQgp.js} +52 -182
- package/dist/chunks/{coverage.Dvxug1RM.js → coverage.DarITf6U.js} +6 -6
- package/dist/chunks/{index.C3EbxYwt.js → index.AzwzFtyi.js} +6 -2
- package/dist/chunks/{index.D2B6d2vv.js → index.BuwjkI-q.js} +1 -1
- package/dist/chunks/{plugin.d.vcD4xbMS.d.ts → plugin.d.CHe6slQs.d.ts} +1 -1
- package/dist/chunks/{reporters.d.BC86JJdB.d.ts → reporters.d.37tJQ2uV.d.ts} +449 -552
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +6 -6
- package/dist/coverage.d.ts +4 -4
- package/dist/coverage.js +1 -1
- package/dist/node.d.ts +18 -8
- package/dist/node.js +7 -7
- package/dist/reporters.d.ts +4 -4
- package/dist/reporters.js +2 -2
- package/package.json +10 -11
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CancelReason, TaskMeta, Suite, File, TestAnnotation, ImportDuration, Test, Task, TaskResultPack, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
|
|
2
|
+
import { Awaitable, ParsedStack, TestError, SerializedError, Arrayable as Arrayable$1 } from '@vitest/utils';
|
|
3
3
|
import { P as ProvidedContext, c as Arrayable, A as AfterSuiteRunMeta, U as UserConsoleLog, b as Awaitable$1, L as LabelColor } from './environment.d.2fYMoz3o.js';
|
|
4
4
|
import { Writable } from 'node:stream';
|
|
5
|
-
import { ViteDevServer,
|
|
6
|
-
import { Console } from 'node:console';
|
|
7
|
-
import { B as BrowserTesterOptions, S as SerializedTestSpecification } from './browser.d.DOMmqJQx.js';
|
|
5
|
+
import { ViteDevServer, TransformResult as TransformResult$1, DepOptimizationConfig, ServerOptions, UserConfig as UserConfig$1, ConfigEnv, AliasOptions } from 'vite';
|
|
8
6
|
import { MockedModule } from '@vitest/mocker';
|
|
9
7
|
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
8
|
+
import { B as BrowserTesterOptions, S as SerializedTestSpecification } from './browser.d.DOMmqJQx.js';
|
|
10
9
|
import { a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d._GBBbReY.js';
|
|
11
10
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
12
11
|
import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
|
|
@@ -17,6 +16,7 @@ import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
|
|
|
17
16
|
import { a as RuntimeCoverageProviderModule } from './coverage.d.BZtK59WP.js';
|
|
18
17
|
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
19
18
|
import { Stats } from 'node:fs';
|
|
19
|
+
import { Console } from 'node:console';
|
|
20
20
|
|
|
21
21
|
type ChaiConfig = Omit<Partial<typeof chai.config>, "useProxy" | "proxyExcludedKeys">;
|
|
22
22
|
|
|
@@ -69,53 +69,6 @@ interface ConstructorOptionsOverride {
|
|
|
69
69
|
resources?: "usable";
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
declare class TypeCheckError extends Error {
|
|
73
|
-
message: string;
|
|
74
|
-
stacks: ParsedStack[];
|
|
75
|
-
name: string;
|
|
76
|
-
constructor(message: string, stacks: ParsedStack[]);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
interface ErrorOptions {
|
|
80
|
-
type?: string;
|
|
81
|
-
fullStack?: boolean;
|
|
82
|
-
project?: TestProject;
|
|
83
|
-
verbose?: boolean;
|
|
84
|
-
screenshotPaths?: string[];
|
|
85
|
-
task?: Task;
|
|
86
|
-
showCodeFrame?: boolean;
|
|
87
|
-
}
|
|
88
|
-
type Listener = () => void;
|
|
89
|
-
declare class Logger {
|
|
90
|
-
ctx: Vitest;
|
|
91
|
-
outputStream: NodeJS.WriteStream | Writable;
|
|
92
|
-
errorStream: NodeJS.WriteStream | Writable;
|
|
93
|
-
private _clearScreenPending;
|
|
94
|
-
private _highlights;
|
|
95
|
-
private cleanupListeners;
|
|
96
|
-
console: Console;
|
|
97
|
-
constructor(ctx: Vitest, outputStream?: NodeJS.WriteStream | Writable, errorStream?: NodeJS.WriteStream | Writable);
|
|
98
|
-
log(...args: any[]): void;
|
|
99
|
-
error(...args: any[]): void;
|
|
100
|
-
warn(...args: any[]): void;
|
|
101
|
-
clearFullScreen(message?: string): void;
|
|
102
|
-
clearScreen(message: string, force?: boolean): void;
|
|
103
|
-
private _clearScreen;
|
|
104
|
-
printError(err: unknown, options?: ErrorOptions): void;
|
|
105
|
-
deprecate(message: string): void;
|
|
106
|
-
clearHighlightCache(filename?: string): void;
|
|
107
|
-
highlight(filename: string, source: string): string;
|
|
108
|
-
printNoTestFound(filters?: string[]): void;
|
|
109
|
-
printBanner(): void;
|
|
110
|
-
printBrowserBanner(project: TestProject): void;
|
|
111
|
-
printUnhandledErrors(errors: ReadonlyArray<unknown>): void;
|
|
112
|
-
printSourceTypeErrors(errors: TypeCheckError[]): void;
|
|
113
|
-
getColumns(): number;
|
|
114
|
-
onTerminalCleanup(listener: Listener): void;
|
|
115
|
-
private addCleanupListeners;
|
|
116
|
-
private registerUnhandledRejection;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
72
|
interface BrowserProviderInitializationOptions {
|
|
120
73
|
browser: string;
|
|
121
74
|
options?: BrowserProviderOptions;
|
|
@@ -262,11 +215,6 @@ interface BrowserConfigOptions {
|
|
|
262
215
|
*/
|
|
263
216
|
screenshotFailures?: boolean;
|
|
264
217
|
/**
|
|
265
|
-
* Scripts injected into the tester iframe.
|
|
266
|
-
* @deprecated Will be removed in the future, use `testerHtmlPath` instead.
|
|
267
|
-
*/
|
|
268
|
-
testerScripts?: BrowserScript[];
|
|
269
|
-
/**
|
|
270
218
|
* Path to the index.html file that will be used to run tests.
|
|
271
219
|
*/
|
|
272
220
|
testerHtmlPath?: string;
|
|
@@ -472,660 +420,590 @@ interface ToMatchScreenshotOptions {
|
|
|
472
420
|
}
|
|
473
421
|
interface ToMatchScreenshotComparators {}
|
|
474
422
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
*/
|
|
479
|
-
readonly project: TestProject;
|
|
423
|
+
type BuiltinPool = "browser" | "threads" | "forks" | "vmThreads" | "vmForks" | "typescript";
|
|
424
|
+
type Pool = BuiltinPool | (string & {});
|
|
425
|
+
interface PoolOptions extends Record<string, unknown> {
|
|
480
426
|
/**
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
427
|
+
* Run tests in `node:worker_threads`.
|
|
428
|
+
*
|
|
429
|
+
* Test isolation (when enabled) is done by spawning a new thread for each test file.
|
|
430
|
+
*
|
|
431
|
+
* This pool is used by default.
|
|
484
432
|
*/
|
|
485
|
-
|
|
433
|
+
threads?: ThreadsOptions & WorkerContextOptions;
|
|
486
434
|
/**
|
|
487
|
-
*
|
|
435
|
+
* Run tests in `node:child_process` using [`fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
|
|
436
|
+
*
|
|
437
|
+
* Test isolation (when enabled) is done by spawning a new child process for each test file.
|
|
488
438
|
*/
|
|
489
|
-
|
|
490
|
-
line: number;
|
|
491
|
-
column: number;
|
|
492
|
-
} | undefined;
|
|
439
|
+
forks?: ForksOptions & WorkerContextOptions;
|
|
493
440
|
/**
|
|
494
|
-
*
|
|
495
|
-
*
|
|
441
|
+
* Run tests in isolated `node:vm`.
|
|
442
|
+
* Test files are run parallel using `node:worker_threads`.
|
|
443
|
+
*
|
|
444
|
+
* This makes tests run faster, but VM module is unstable. Your tests might leak memory.
|
|
496
445
|
*/
|
|
497
|
-
|
|
446
|
+
vmThreads?: ThreadsOptions & VmOptions;
|
|
498
447
|
/**
|
|
499
|
-
*
|
|
448
|
+
* Run tests in isolated `node:vm`.
|
|
449
|
+
*
|
|
450
|
+
* Test files are run parallel using `node:child_process` [`fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
|
|
451
|
+
*
|
|
452
|
+
* This makes tests run faster, but VM module is unstable. Your tests might leak memory.
|
|
500
453
|
*/
|
|
501
|
-
|
|
454
|
+
vmForks?: ForksOptions & VmOptions;
|
|
502
455
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
456
|
+
interface ResolvedPoolOptions extends PoolOptions {
|
|
457
|
+
threads?: ResolvedThreadsOptions & WorkerContextOptions;
|
|
458
|
+
forks?: ResolvedForksOptions & WorkerContextOptions;
|
|
459
|
+
vmThreads?: ResolvedThreadsOptions & VmOptions;
|
|
460
|
+
vmForks?: ResolvedForksOptions & VmOptions;
|
|
461
|
+
}
|
|
462
|
+
interface ThreadsOptions {
|
|
463
|
+
/** Minimum amount of threads to use */
|
|
464
|
+
minThreads?: number | string;
|
|
465
|
+
/** Maximum amount of threads to use */
|
|
466
|
+
maxThreads?: number | string;
|
|
510
467
|
/**
|
|
511
|
-
*
|
|
468
|
+
* Run tests inside a single thread.
|
|
469
|
+
*
|
|
470
|
+
* @default false
|
|
512
471
|
*/
|
|
513
|
-
|
|
472
|
+
singleThread?: boolean;
|
|
514
473
|
/**
|
|
515
|
-
*
|
|
474
|
+
* Use Atomics to synchronize threads
|
|
475
|
+
*
|
|
476
|
+
* This can improve performance in some cases, but might cause segfault in older Node versions.
|
|
477
|
+
*
|
|
478
|
+
* @default false
|
|
516
479
|
*/
|
|
517
|
-
|
|
480
|
+
useAtomics?: boolean;
|
|
481
|
+
}
|
|
482
|
+
interface ResolvedThreadsOptions extends ThreadsOptions {
|
|
483
|
+
minThreads?: number;
|
|
484
|
+
maxThreads?: number;
|
|
485
|
+
}
|
|
486
|
+
interface ForksOptions {
|
|
487
|
+
/** Minimum amount of child processes to use */
|
|
488
|
+
minForks?: number | string;
|
|
489
|
+
/** Maximum amount of child processes to use */
|
|
490
|
+
maxForks?: number | string;
|
|
518
491
|
/**
|
|
519
|
-
*
|
|
492
|
+
* Run tests inside a single fork.
|
|
493
|
+
*
|
|
494
|
+
* @default false
|
|
520
495
|
*/
|
|
521
|
-
|
|
496
|
+
singleFork?: boolean;
|
|
497
|
+
}
|
|
498
|
+
interface ResolvedForksOptions extends ForksOptions {
|
|
499
|
+
minForks?: number;
|
|
500
|
+
maxForks?: number;
|
|
501
|
+
}
|
|
502
|
+
interface WorkerContextOptions {
|
|
522
503
|
/**
|
|
523
|
-
*
|
|
504
|
+
* Isolate test environment by recycling `worker_threads` or `child_process` after each test
|
|
505
|
+
*
|
|
506
|
+
* @default true
|
|
524
507
|
*/
|
|
525
|
-
|
|
508
|
+
isolate?: boolean;
|
|
526
509
|
/**
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
* -
|
|
530
|
-
*
|
|
531
|
-
*
|
|
510
|
+
* Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
|
|
511
|
+
*
|
|
512
|
+
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
|
513
|
+
*
|
|
514
|
+
* Set to `process.execArgv` to pass all arguments of the current process.
|
|
515
|
+
*
|
|
516
|
+
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
|
517
|
+
*
|
|
518
|
+
* @default [] // no execution arguments are passed
|
|
532
519
|
*/
|
|
533
|
-
|
|
520
|
+
execArgv?: string[];
|
|
521
|
+
}
|
|
522
|
+
interface VmOptions {
|
|
534
523
|
/**
|
|
535
|
-
*
|
|
524
|
+
* Specifies the memory limit for `worker_thread` or `child_process` before they are recycled.
|
|
525
|
+
* If you see memory leaks, try to tinker this value.
|
|
536
526
|
*/
|
|
537
|
-
|
|
527
|
+
memoryLimit?: string | number;
|
|
528
|
+
/** Isolation is always enabled */
|
|
529
|
+
isolate?: true;
|
|
538
530
|
/**
|
|
539
|
-
*
|
|
540
|
-
*
|
|
531
|
+
* Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
|
|
532
|
+
*
|
|
533
|
+
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
|
534
|
+
*
|
|
535
|
+
* Set to `process.execArgv` to pass all arguments of the current process.
|
|
536
|
+
*
|
|
537
|
+
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
|
538
|
+
*
|
|
539
|
+
* @default [] // no execution arguments are passed
|
|
541
540
|
*/
|
|
542
|
-
|
|
541
|
+
execArgv?: string[];
|
|
543
542
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
constructor(task: Suite | File, project: TestProject);
|
|
547
|
-
/**
|
|
548
|
-
* Returns the test or suite at a specific index.
|
|
549
|
-
*/
|
|
550
|
-
at(index: number): TestCase | TestSuite | undefined;
|
|
543
|
+
|
|
544
|
+
declare class TestSpecification {
|
|
551
545
|
/**
|
|
552
|
-
* The
|
|
546
|
+
* The task ID associated with the test module.
|
|
553
547
|
*/
|
|
554
|
-
|
|
548
|
+
readonly taskId: string;
|
|
555
549
|
/**
|
|
556
|
-
*
|
|
550
|
+
* The test project that the module belongs to.
|
|
557
551
|
*/
|
|
558
|
-
|
|
552
|
+
readonly project: TestProject;
|
|
559
553
|
/**
|
|
560
|
-
*
|
|
554
|
+
* The ID of the module in the Vite module graph. It is usually an absolute file path.
|
|
561
555
|
*/
|
|
562
|
-
|
|
556
|
+
readonly moduleId: string;
|
|
563
557
|
/**
|
|
564
|
-
*
|
|
558
|
+
* The current test pool. It's possible to have multiple pools in a single test project with `poolMatchGlob` and `typecheck.enabled`.
|
|
559
|
+
* @experimental In Vitest 4, the project will only support a single pool and this property will be removed.
|
|
565
560
|
*/
|
|
566
|
-
|
|
561
|
+
readonly pool: Pool;
|
|
567
562
|
/**
|
|
568
|
-
*
|
|
563
|
+
* Line numbers of the test locations to run.
|
|
569
564
|
*/
|
|
570
|
-
|
|
565
|
+
readonly testLines: number[] | undefined;
|
|
566
|
+
constructor(project: TestProject, moduleId: string, pool: Pool, testLines?: number[] | undefined);
|
|
571
567
|
/**
|
|
572
|
-
*
|
|
568
|
+
* Test module associated with the specification.
|
|
573
569
|
*/
|
|
574
|
-
|
|
575
|
-
|
|
570
|
+
get testModule(): TestModule | undefined;
|
|
571
|
+
toJSON(): SerializedTestSpecification;
|
|
576
572
|
}
|
|
577
573
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
readonly entity: TestSuite | TestModule;
|
|
581
|
-
} | {
|
|
582
|
-
readonly name: "beforeEach" | "afterEach";
|
|
583
|
-
readonly entity: TestCase;
|
|
584
|
-
};
|
|
585
|
-
declare abstract class SuiteImplementation extends ReportedTaskImplementation {
|
|
574
|
+
declare class TestProject {
|
|
575
|
+
options?: Vitest;
|
|
586
576
|
/**
|
|
587
|
-
*
|
|
577
|
+
* The global Vitest instance.
|
|
578
|
+
* @experimental The public Vitest API is experimental and does not follow semver.
|
|
588
579
|
*/
|
|
589
|
-
readonly
|
|
580
|
+
readonly vitest: Vitest;
|
|
590
581
|
/**
|
|
591
|
-
*
|
|
582
|
+
* Resolved global configuration. If there are no workspace projects, this will be the same as `config`.
|
|
592
583
|
*/
|
|
593
|
-
|
|
594
|
-
}
|
|
595
|
-
declare class TestSuite extends SuiteImplementation {
|
|
596
|
-
#private;
|
|
597
|
-
readonly type = "suite";
|
|
584
|
+
readonly globalConfig: ResolvedConfig;
|
|
598
585
|
/**
|
|
599
|
-
*
|
|
586
|
+
* Browser instance if the browser is enabled. This is initialized when the tests run for the first time.
|
|
600
587
|
*/
|
|
601
|
-
|
|
602
|
-
/**
|
|
603
|
-
* Direct reference to the test module where the test or suite is defined.
|
|
604
|
-
*/
|
|
605
|
-
readonly module: TestModule;
|
|
588
|
+
browser?: ProjectBrowser;
|
|
606
589
|
/**
|
|
607
|
-
*
|
|
590
|
+
* Temporary directory for the project. This is unique for each project. Vitest stores transformed content here.
|
|
608
591
|
*/
|
|
609
|
-
readonly
|
|
592
|
+
readonly tmpDir: string;
|
|
593
|
+
/** @inetrnal */ testFilesList: string[] | null;
|
|
594
|
+
private runner;
|
|
595
|
+
private closingPromise;
|
|
596
|
+
private typecheckFilesList;
|
|
597
|
+
private _globalSetups?;
|
|
598
|
+
private _provided;
|
|
599
|
+
constructor(vitest: Vitest, options?: InitializeProjectOptions | undefined);
|
|
610
600
|
/**
|
|
611
|
-
*
|
|
601
|
+
* The unique hash of this project. This value is consistent between the reruns.
|
|
602
|
+
*
|
|
603
|
+
* It is based on the root of the project (not consistent between OS) and its name.
|
|
612
604
|
*/
|
|
613
|
-
|
|
605
|
+
get hash(): string;
|
|
606
|
+
// "provide" is a property, not a method to keep the context when destructed in the global setup,
|
|
607
|
+
// making it a method would be a breaking change, and can be done in Vitest 3 at minimum
|
|
614
608
|
/**
|
|
615
|
-
*
|
|
616
|
-
* This will also return `false` if suite failed during collection.
|
|
609
|
+
* Provide a value to the test context. This value will be available to all tests with `inject`.
|
|
617
610
|
*/
|
|
618
|
-
|
|
611
|
+
provide: <T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) => void;
|
|
619
612
|
/**
|
|
620
|
-
*
|
|
613
|
+
* Get the provided context. The project context is merged with the global context.
|
|
621
614
|
*/
|
|
622
|
-
|
|
615
|
+
getProvidedContext(): ProvidedContext;
|
|
623
616
|
/**
|
|
624
|
-
*
|
|
617
|
+
* Creates a new test specification. Specifications describe how to run tests.
|
|
618
|
+
* @param moduleId The file path
|
|
625
619
|
*/
|
|
626
|
-
|
|
620
|
+
createSpecification(moduleId: string, locations?: number[] | undefined, pool?: string): TestSpecification;
|
|
621
|
+
toJSON(): SerializedTestProject;
|
|
627
622
|
/**
|
|
628
|
-
*
|
|
623
|
+
* Vite's dev server instance. Every workspace project has its own server.
|
|
629
624
|
*/
|
|
630
|
-
get
|
|
631
|
-
}
|
|
632
|
-
declare class TestModule extends SuiteImplementation {
|
|
633
|
-
readonly location: undefined;
|
|
634
|
-
readonly type = "module";
|
|
625
|
+
get vite(): ViteDevServer;
|
|
635
626
|
/**
|
|
636
|
-
*
|
|
637
|
-
* It can be a virtual ID if the file is not on the disk.
|
|
638
|
-
* This value corresponds to the ID in the Vite's module graph.
|
|
627
|
+
* Resolved project configuration.
|
|
639
628
|
*/
|
|
640
|
-
|
|
629
|
+
get config(): ResolvedConfig;
|
|
641
630
|
/**
|
|
642
|
-
*
|
|
631
|
+
* The name of the project or an empty string if not set.
|
|
643
632
|
*/
|
|
644
|
-
|
|
633
|
+
get name(): string;
|
|
645
634
|
/**
|
|
646
|
-
*
|
|
647
|
-
* This will also return `false` if module failed during collection.
|
|
635
|
+
* The color used when reporting tasks of this project.
|
|
648
636
|
*/
|
|
649
|
-
|
|
637
|
+
get color(): ProjectName["color"];
|
|
650
638
|
/**
|
|
651
|
-
*
|
|
639
|
+
* Serialized project configuration. This is the config that tests receive.
|
|
652
640
|
*/
|
|
653
|
-
|
|
641
|
+
get serializedConfig(): SerializedConfig;
|
|
654
642
|
/**
|
|
655
|
-
*
|
|
656
|
-
* If the module was not executed yet, all diagnostic values will return `0`.
|
|
643
|
+
* Check if this is the root project. The root project is the one that has the root config.
|
|
657
644
|
*/
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
interface TaskOptions {
|
|
661
|
-
readonly each: boolean | undefined;
|
|
662
|
-
readonly fails: boolean | undefined;
|
|
663
|
-
readonly concurrent: boolean | undefined;
|
|
664
|
-
readonly shuffle: boolean | undefined;
|
|
665
|
-
readonly retry: number | undefined;
|
|
666
|
-
readonly repeats: number | undefined;
|
|
667
|
-
readonly mode: "run" | "only" | "skip" | "todo";
|
|
668
|
-
}
|
|
669
|
-
type TestSuiteState = "skipped" | "pending" | "failed" | "passed";
|
|
670
|
-
type TestModuleState = TestSuiteState | "queued";
|
|
671
|
-
type TestState = TestResult["state"];
|
|
672
|
-
type TestResult = TestResultPassed | TestResultFailed | TestResultSkipped | TestResultPending;
|
|
673
|
-
interface TestResultPending {
|
|
645
|
+
isRootProject(): boolean;
|
|
646
|
+
onTestsRerun(cb: OnTestsRerunHandler): void;
|
|
674
647
|
/**
|
|
675
|
-
*
|
|
648
|
+
* Get all files in the project that match the globs in the config and the filters.
|
|
649
|
+
* @param filters String filters to match the test files.
|
|
676
650
|
*/
|
|
677
|
-
|
|
651
|
+
globTestFiles(filters?: string[]): Promise<{
|
|
652
|
+
/**
|
|
653
|
+
* Test files that match the filters.
|
|
654
|
+
*/
|
|
655
|
+
testFiles: string[];
|
|
656
|
+
/**
|
|
657
|
+
* Typecheck test files that match the filters. This will be empty unless `typecheck.enabled` is `true`.
|
|
658
|
+
*/
|
|
659
|
+
typecheckTestFiles: string[];
|
|
660
|
+
}>;
|
|
661
|
+
private globAllTestFiles;
|
|
662
|
+
isBrowserEnabled(): boolean;
|
|
663
|
+
private markTestFile;
|
|
678
664
|
/**
|
|
679
|
-
*
|
|
665
|
+
* Test if a file matches the test globs. This does the actual glob matching if the test is not cached, unlike `isCachedTestFile`.
|
|
680
666
|
*/
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
667
|
+
matchesTestGlob(moduleId: string, source?: () => string): boolean;
|
|
668
|
+
private isInSourceTestCode;
|
|
669
|
+
private filterFiles;
|
|
670
|
+
private _parentBrowser?;
|
|
684
671
|
/**
|
|
685
|
-
*
|
|
672
|
+
* Closes the project and all associated resources. This can only be called once; the closing promise is cached until the server restarts.
|
|
673
|
+
* If the resources are needed again, create a new project.
|
|
686
674
|
*/
|
|
687
|
-
|
|
675
|
+
close(): Promise<void>;
|
|
688
676
|
/**
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
* **Note**: If test was retried successfully, errors will still be reported.
|
|
677
|
+
* Import a file using Vite module runner.
|
|
678
|
+
* @param moduleId The ID of the module in Vite module graph
|
|
692
679
|
*/
|
|
693
|
-
|
|
680
|
+
import<T>(moduleId: string): Promise<T>;
|
|
681
|
+
private _setHash;
|
|
682
|
+
private _serializeOverriddenConfig;
|
|
683
|
+
private clearTmpDir;
|
|
694
684
|
}
|
|
695
|
-
interface
|
|
685
|
+
interface SerializedTestProject {
|
|
686
|
+
name: string;
|
|
687
|
+
serializedConfig: SerializedConfig;
|
|
688
|
+
context: ProvidedContext;
|
|
689
|
+
}
|
|
690
|
+
interface InitializeProjectOptions extends TestProjectInlineConfiguration {
|
|
691
|
+
configFile: string | false;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
declare class ReportedTaskImplementation {
|
|
696
695
|
/**
|
|
697
|
-
* The test
|
|
696
|
+
* The project associated with the test or suite.
|
|
698
697
|
*/
|
|
699
|
-
readonly
|
|
698
|
+
readonly project: TestProject;
|
|
700
699
|
/**
|
|
701
|
-
*
|
|
700
|
+
* Unique identifier.
|
|
701
|
+
* This ID is deterministic and will be the same for the same test across multiple runs.
|
|
702
|
+
* The ID is based on the project name, module url and test order.
|
|
702
703
|
*/
|
|
703
|
-
readonly
|
|
704
|
-
}
|
|
705
|
-
interface TestResultSkipped {
|
|
704
|
+
readonly id: string;
|
|
706
705
|
/**
|
|
707
|
-
*
|
|
708
|
-
* You can see which one was used in the `options.mode` option.
|
|
706
|
+
* Location in the module where the test or suite is defined.
|
|
709
707
|
*/
|
|
710
|
-
readonly
|
|
708
|
+
readonly location: {
|
|
709
|
+
line: number;
|
|
710
|
+
column: number;
|
|
711
|
+
} | undefined;
|
|
711
712
|
/**
|
|
712
|
-
*
|
|
713
|
+
* Checks if the test did not fail the suite.
|
|
714
|
+
* If the test is not finished yet or was skipped, it will return `true`.
|
|
713
715
|
*/
|
|
714
|
-
|
|
716
|
+
ok(): boolean;
|
|
715
717
|
/**
|
|
716
|
-
*
|
|
718
|
+
* Custom metadata that was attached to the test during its execution.
|
|
717
719
|
*/
|
|
718
|
-
|
|
720
|
+
meta(): TaskMeta;
|
|
719
721
|
}
|
|
720
|
-
|
|
722
|
+
declare class TestCase extends ReportedTaskImplementation {
|
|
723
|
+
#private;
|
|
724
|
+
readonly type = "test";
|
|
721
725
|
/**
|
|
722
|
-
*
|
|
726
|
+
* Direct reference to the test module where the test or suite is defined.
|
|
723
727
|
*/
|
|
724
|
-
readonly
|
|
728
|
+
readonly module: TestModule;
|
|
725
729
|
/**
|
|
726
|
-
*
|
|
727
|
-
* This value is only available if the test was executed with `logHeapUsage` flag.
|
|
730
|
+
* Name of the test.
|
|
728
731
|
*/
|
|
729
|
-
readonly
|
|
732
|
+
readonly name: string;
|
|
730
733
|
/**
|
|
731
|
-
*
|
|
734
|
+
* Options that the test was initiated with.
|
|
732
735
|
*/
|
|
733
|
-
readonly
|
|
736
|
+
readonly options: TaskOptions;
|
|
734
737
|
/**
|
|
735
|
-
*
|
|
738
|
+
* Parent suite. If the test was called directly inside the module, the parent will be the module itself.
|
|
736
739
|
*/
|
|
737
|
-
readonly
|
|
740
|
+
readonly parent: TestSuite | TestModule;
|
|
738
741
|
/**
|
|
739
|
-
*
|
|
742
|
+
* Full name of the test including all parent suites separated with `>`.
|
|
740
743
|
*/
|
|
741
|
-
|
|
744
|
+
get fullName(): string;
|
|
742
745
|
/**
|
|
743
|
-
*
|
|
744
|
-
*
|
|
746
|
+
* Test results.
|
|
747
|
+
* - **pending**: Test was collected, but didn't finish running yet.
|
|
748
|
+
* - **passed**: Test passed successfully
|
|
749
|
+
* - **failed**: Test failed to execute
|
|
750
|
+
* - **skipped**: Test was skipped during collection or dynamically with `ctx.skip()`.
|
|
745
751
|
*/
|
|
746
|
-
|
|
752
|
+
result(): TestResult;
|
|
747
753
|
/**
|
|
748
|
-
*
|
|
754
|
+
* Test annotations added via the `task.annotate` API during the test execution.
|
|
749
755
|
*/
|
|
750
|
-
|
|
756
|
+
annotations(): ReadonlyArray<TestAnnotation>;
|
|
757
|
+
/**
|
|
758
|
+
* Useful information about the test like duration, memory usage, etc.
|
|
759
|
+
* Diagnostic is only available after the test has finished.
|
|
760
|
+
*/
|
|
761
|
+
diagnostic(): TestDiagnostic | undefined;
|
|
751
762
|
}
|
|
752
|
-
|
|
763
|
+
declare class TestCollection {
|
|
764
|
+
#private;
|
|
765
|
+
constructor(task: Suite | File, project: TestProject);
|
|
753
766
|
/**
|
|
754
|
-
*
|
|
767
|
+
* Returns the test or suite at a specific index.
|
|
755
768
|
*/
|
|
756
|
-
|
|
769
|
+
at(index: number): TestCase | TestSuite | undefined;
|
|
757
770
|
/**
|
|
758
|
-
* The
|
|
771
|
+
* The number of tests and suites in the collection.
|
|
759
772
|
*/
|
|
760
|
-
|
|
773
|
+
get size(): number;
|
|
761
774
|
/**
|
|
762
|
-
*
|
|
763
|
-
* This includes importing everything in the module and executing suite callbacks.
|
|
775
|
+
* Returns the collection in array form for easier manipulation.
|
|
764
776
|
*/
|
|
765
|
-
|
|
777
|
+
array(): (TestCase | TestSuite)[];
|
|
766
778
|
/**
|
|
767
|
-
*
|
|
779
|
+
* Filters all tests that are part of this collection and its children.
|
|
768
780
|
*/
|
|
769
|
-
|
|
781
|
+
allTests(state?: TestState): Generator<TestCase, undefined, void>;
|
|
770
782
|
/**
|
|
771
|
-
*
|
|
783
|
+
* Filters only the tests that are part of this collection.
|
|
772
784
|
*/
|
|
773
|
-
|
|
785
|
+
tests(state?: TestState): Generator<TestCase, undefined, void>;
|
|
774
786
|
/**
|
|
775
|
-
*
|
|
776
|
-
* This value is only available if the test was executed with `logHeapUsage` flag.
|
|
787
|
+
* Filters only the suites that are part of this collection.
|
|
777
788
|
*/
|
|
778
|
-
|
|
789
|
+
suites(): Generator<TestSuite, undefined, void>;
|
|
779
790
|
/**
|
|
780
|
-
*
|
|
791
|
+
* Filters all suites that are part of this collection and its children.
|
|
781
792
|
*/
|
|
782
|
-
|
|
793
|
+
allSuites(): Generator<TestSuite, undefined, void>;
|
|
794
|
+
[Symbol.iterator](): Generator<TestSuite | TestCase, undefined, void>;
|
|
783
795
|
}
|
|
784
|
-
declare function experimental_getRunnerTask(entity: TestCase): Test;
|
|
785
|
-
declare function experimental_getRunnerTask(entity: TestSuite): Suite;
|
|
786
|
-
declare function experimental_getRunnerTask(entity: TestModule): File;
|
|
787
|
-
declare function experimental_getRunnerTask(entity: TestCase | TestSuite | TestModule): Suite | File | Test;
|
|
788
796
|
|
|
789
|
-
type
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
* This pool is used by default.
|
|
798
|
-
*/
|
|
799
|
-
threads?: ThreadsOptions & WorkerContextOptions;
|
|
797
|
+
type ReportedHookContext = {
|
|
798
|
+
readonly name: "beforeAll" | "afterAll";
|
|
799
|
+
readonly entity: TestSuite | TestModule;
|
|
800
|
+
} | {
|
|
801
|
+
readonly name: "beforeEach" | "afterEach";
|
|
802
|
+
readonly entity: TestCase;
|
|
803
|
+
};
|
|
804
|
+
declare abstract class SuiteImplementation extends ReportedTaskImplementation {
|
|
800
805
|
/**
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
* Test isolation (when enabled) is done by spawning a new child process for each test file.
|
|
806
|
+
* Collection of suites and tests that are part of this suite.
|
|
804
807
|
*/
|
|
805
|
-
|
|
808
|
+
readonly children: TestCollection;
|
|
806
809
|
/**
|
|
807
|
-
*
|
|
808
|
-
* Test files are run parallel using `node:worker_threads`.
|
|
809
|
-
*
|
|
810
|
-
* This makes tests run faster, but VM module is unstable. Your tests might leak memory.
|
|
810
|
+
* Errors that happened outside of the test run during collection, like syntax errors.
|
|
811
811
|
*/
|
|
812
|
-
|
|
812
|
+
errors(): SerializedError[];
|
|
813
|
+
}
|
|
814
|
+
declare class TestSuite extends SuiteImplementation {
|
|
815
|
+
#private;
|
|
816
|
+
readonly type = "suite";
|
|
813
817
|
/**
|
|
814
|
-
*
|
|
815
|
-
*
|
|
816
|
-
* Test files are run parallel using `node:child_process` [`fork()`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
|
|
817
|
-
*
|
|
818
|
-
* This makes tests run faster, but VM module is unstable. Your tests might leak memory.
|
|
818
|
+
* Name of the test or the suite.
|
|
819
819
|
*/
|
|
820
|
-
|
|
821
|
-
}
|
|
822
|
-
interface ResolvedPoolOptions extends PoolOptions {
|
|
823
|
-
threads?: ResolvedThreadsOptions & WorkerContextOptions;
|
|
824
|
-
forks?: ResolvedForksOptions & WorkerContextOptions;
|
|
825
|
-
vmThreads?: ResolvedThreadsOptions & VmOptions;
|
|
826
|
-
vmForks?: ResolvedForksOptions & VmOptions;
|
|
827
|
-
}
|
|
828
|
-
interface ThreadsOptions {
|
|
829
|
-
/** Minimum amount of threads to use */
|
|
830
|
-
minThreads?: number | string;
|
|
831
|
-
/** Maximum amount of threads to use */
|
|
832
|
-
maxThreads?: number | string;
|
|
820
|
+
readonly name: string;
|
|
833
821
|
/**
|
|
834
|
-
*
|
|
835
|
-
*
|
|
836
|
-
* @default false
|
|
822
|
+
* Direct reference to the test module where the test or suite is defined.
|
|
837
823
|
*/
|
|
838
|
-
|
|
824
|
+
readonly module: TestModule;
|
|
839
825
|
/**
|
|
840
|
-
*
|
|
841
|
-
*
|
|
842
|
-
* This can improve performance in some cases, but might cause segfault in older Node versions.
|
|
843
|
-
*
|
|
844
|
-
* @default false
|
|
826
|
+
* Parent suite. If suite was called directly inside the module, the parent will be the module itself.
|
|
845
827
|
*/
|
|
846
|
-
|
|
847
|
-
}
|
|
848
|
-
interface ResolvedThreadsOptions extends ThreadsOptions {
|
|
849
|
-
minThreads?: number;
|
|
850
|
-
maxThreads?: number;
|
|
851
|
-
}
|
|
852
|
-
interface ForksOptions {
|
|
853
|
-
/** Minimum amount of child processes to use */
|
|
854
|
-
minForks?: number | string;
|
|
855
|
-
/** Maximum amount of child processes to use */
|
|
856
|
-
maxForks?: number | string;
|
|
828
|
+
readonly parent: TestSuite | TestModule;
|
|
857
829
|
/**
|
|
858
|
-
*
|
|
859
|
-
*
|
|
860
|
-
* @default false
|
|
830
|
+
* Options that suite was initiated with.
|
|
861
831
|
*/
|
|
862
|
-
|
|
863
|
-
}
|
|
864
|
-
interface ResolvedForksOptions extends ForksOptions {
|
|
865
|
-
minForks?: number;
|
|
866
|
-
maxForks?: number;
|
|
867
|
-
}
|
|
868
|
-
interface WorkerContextOptions {
|
|
832
|
+
readonly options: TaskOptions;
|
|
869
833
|
/**
|
|
870
|
-
*
|
|
871
|
-
*
|
|
872
|
-
* @default true
|
|
834
|
+
* Checks if the suite has any failed tests.
|
|
835
|
+
* This will also return `false` if suite failed during collection.
|
|
873
836
|
*/
|
|
874
|
-
|
|
837
|
+
ok: () => boolean;
|
|
875
838
|
/**
|
|
876
|
-
*
|
|
877
|
-
*
|
|
878
|
-
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
|
879
|
-
*
|
|
880
|
-
* Set to `process.execArgv` to pass all arguments of the current process.
|
|
881
|
-
*
|
|
882
|
-
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
|
883
|
-
*
|
|
884
|
-
* @default [] // no execution arguments are passed
|
|
839
|
+
* The meta information attached to the suite during its collection or execution.
|
|
885
840
|
*/
|
|
886
|
-
|
|
887
|
-
}
|
|
888
|
-
interface VmOptions {
|
|
841
|
+
meta: () => TaskMeta;
|
|
889
842
|
/**
|
|
890
|
-
*
|
|
891
|
-
* If you see memory leaks, try to tinker this value.
|
|
843
|
+
* Checks the running state of the suite.
|
|
892
844
|
*/
|
|
893
|
-
|
|
894
|
-
/** Isolation is always enabled */
|
|
895
|
-
isolate?: true;
|
|
845
|
+
state(): TestSuiteState;
|
|
896
846
|
/**
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
|
900
|
-
*
|
|
901
|
-
* Set to `process.execArgv` to pass all arguments of the current process.
|
|
902
|
-
*
|
|
903
|
-
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
|
904
|
-
*
|
|
905
|
-
* @default [] // no execution arguments are passed
|
|
847
|
+
* Full name of the suite including all parent suites separated with `>`.
|
|
906
848
|
*/
|
|
907
|
-
|
|
849
|
+
get fullName(): string;
|
|
908
850
|
}
|
|
909
|
-
|
|
910
|
-
|
|
851
|
+
declare class TestModule extends SuiteImplementation {
|
|
852
|
+
readonly location: undefined;
|
|
853
|
+
readonly type = "module";
|
|
911
854
|
/**
|
|
912
|
-
*
|
|
855
|
+
* This is usually an absolute UNIX file path.
|
|
856
|
+
* It can be a virtual ID if the file is not on the disk.
|
|
857
|
+
* This value corresponds to the ID in the Vite's module graph.
|
|
913
858
|
*/
|
|
914
|
-
readonly
|
|
859
|
+
readonly moduleId: string;
|
|
915
860
|
/**
|
|
916
|
-
*
|
|
861
|
+
* Checks the running state of the test file.
|
|
917
862
|
*/
|
|
918
|
-
|
|
863
|
+
state(): TestModuleState;
|
|
919
864
|
/**
|
|
920
|
-
*
|
|
865
|
+
* Checks if the module has any failed tests.
|
|
866
|
+
* This will also return `false` if module failed during collection.
|
|
921
867
|
*/
|
|
922
|
-
|
|
923
|
-
pool: Pool;
|
|
924
|
-
};
|
|
868
|
+
ok: () => boolean;
|
|
925
869
|
/**
|
|
926
|
-
* The
|
|
870
|
+
* The meta information attached to the module during its collection or execution.
|
|
927
871
|
*/
|
|
928
|
-
|
|
872
|
+
meta: () => TaskMeta;
|
|
929
873
|
/**
|
|
930
|
-
*
|
|
874
|
+
* Useful information about the module like duration, memory usage, etc.
|
|
875
|
+
* If the module was not executed yet, all diagnostic values will return `0`.
|
|
931
876
|
*/
|
|
932
|
-
|
|
877
|
+
diagnostic(): ModuleDiagnostic;
|
|
878
|
+
}
|
|
879
|
+
interface TaskOptions {
|
|
880
|
+
readonly each: boolean | undefined;
|
|
881
|
+
readonly fails: boolean | undefined;
|
|
882
|
+
readonly concurrent: boolean | undefined;
|
|
883
|
+
readonly shuffle: boolean | undefined;
|
|
884
|
+
readonly retry: number | undefined;
|
|
885
|
+
readonly repeats: number | undefined;
|
|
886
|
+
readonly mode: "run" | "only" | "skip" | "todo";
|
|
887
|
+
}
|
|
888
|
+
type TestSuiteState = "skipped" | "pending" | "failed" | "passed";
|
|
889
|
+
type TestModuleState = TestSuiteState | "queued";
|
|
890
|
+
type TestState = TestResult["state"];
|
|
891
|
+
type TestResult = TestResultPassed | TestResultFailed | TestResultSkipped | TestResultPending;
|
|
892
|
+
interface TestResultPending {
|
|
933
893
|
/**
|
|
934
|
-
* The
|
|
894
|
+
* The test was collected, but didn't finish running yet.
|
|
935
895
|
*/
|
|
936
|
-
readonly
|
|
896
|
+
readonly state: "pending";
|
|
937
897
|
/**
|
|
938
|
-
*
|
|
939
|
-
* @experimental In Vitest 4, the project will only support a single pool and this property will be removed.
|
|
898
|
+
* Pending tests have no errors.
|
|
940
899
|
*/
|
|
941
|
-
readonly
|
|
900
|
+
readonly errors: undefined;
|
|
901
|
+
}
|
|
902
|
+
interface TestResultPassed {
|
|
942
903
|
/**
|
|
943
|
-
*
|
|
904
|
+
* The test passed successfully.
|
|
944
905
|
*/
|
|
945
|
-
readonly
|
|
946
|
-
constructor(project: TestProject, moduleId: string, pool: Pool, testLines?: number[] | undefined);
|
|
906
|
+
readonly state: "passed";
|
|
947
907
|
/**
|
|
948
|
-
*
|
|
908
|
+
* Errors that were thrown during the test execution.
|
|
909
|
+
*
|
|
910
|
+
* **Note**: If test was retried successfully, errors will still be reported.
|
|
949
911
|
*/
|
|
950
|
-
|
|
951
|
-
|
|
912
|
+
readonly errors: ReadonlyArray<TestError> | undefined;
|
|
913
|
+
}
|
|
914
|
+
interface TestResultFailed {
|
|
952
915
|
/**
|
|
953
|
-
*
|
|
954
|
-
* @deprecated
|
|
916
|
+
* The test failed to execute.
|
|
955
917
|
*/
|
|
956
|
-
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
declare class TestProject {
|
|
960
|
-
/** @deprecated */
|
|
961
|
-
path: string | number;
|
|
962
|
-
options?: Vitest;
|
|
918
|
+
readonly state: "failed";
|
|
963
919
|
/**
|
|
964
|
-
*
|
|
965
|
-
* @experimental The public Vitest API is experimental and does not follow semver.
|
|
920
|
+
* Errors that were thrown during the test execution.
|
|
966
921
|
*/
|
|
967
|
-
readonly
|
|
922
|
+
readonly errors: ReadonlyArray<TestError>;
|
|
923
|
+
}
|
|
924
|
+
interface TestResultSkipped {
|
|
968
925
|
/**
|
|
969
|
-
*
|
|
926
|
+
* The test was skipped with `only` (on another test), `skip` or `todo` flag.
|
|
927
|
+
* You can see which one was used in the `options.mode` option.
|
|
970
928
|
*/
|
|
971
|
-
readonly
|
|
929
|
+
readonly state: "skipped";
|
|
972
930
|
/**
|
|
973
|
-
*
|
|
931
|
+
* Skipped tests have no errors.
|
|
974
932
|
*/
|
|
975
|
-
|
|
976
|
-
/** @deprecated use `vitest` instead */
|
|
977
|
-
ctx: Vitest;
|
|
933
|
+
readonly errors: undefined;
|
|
978
934
|
/**
|
|
979
|
-
*
|
|
935
|
+
* A custom note passed down to `ctx.skip(note)`.
|
|
980
936
|
*/
|
|
981
|
-
readonly
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
private closingPromise;
|
|
985
|
-
private typecheckFilesList;
|
|
986
|
-
private _globalSetups?;
|
|
987
|
-
private _provided;
|
|
988
|
-
constructor(path: string | number, vitest: Vitest, options?: InitializeProjectOptions | undefined);
|
|
937
|
+
readonly note: string | undefined;
|
|
938
|
+
}
|
|
939
|
+
interface TestDiagnostic {
|
|
989
940
|
/**
|
|
990
|
-
*
|
|
991
|
-
*
|
|
992
|
-
* It is based on the root of the project (not consistent between OS) and its name.
|
|
941
|
+
* If the duration of the test is above `slowTestThreshold`.
|
|
993
942
|
*/
|
|
994
|
-
|
|
995
|
-
// "provide" is a property, not a method to keep the context when destructed in the global setup,
|
|
996
|
-
// making it a method would be a breaking change, and can be done in Vitest 3 at minimum
|
|
943
|
+
readonly slow: boolean;
|
|
997
944
|
/**
|
|
998
|
-
*
|
|
945
|
+
* The amount of memory used by the test in bytes.
|
|
946
|
+
* This value is only available if the test was executed with `logHeapUsage` flag.
|
|
999
947
|
*/
|
|
1000
|
-
|
|
948
|
+
readonly heap: number | undefined;
|
|
1001
949
|
/**
|
|
1002
|
-
*
|
|
950
|
+
* The time it takes to execute the test in ms.
|
|
1003
951
|
*/
|
|
1004
|
-
|
|
952
|
+
readonly duration: number;
|
|
1005
953
|
/**
|
|
1006
|
-
*
|
|
1007
|
-
* @param moduleId The file path
|
|
954
|
+
* The time in ms when the test started.
|
|
1008
955
|
*/
|
|
1009
|
-
|
|
1010
|
-
toJSON(): SerializedTestProject;
|
|
956
|
+
readonly startTime: number;
|
|
1011
957
|
/**
|
|
1012
|
-
*
|
|
958
|
+
* The amount of times the test was retried.
|
|
1013
959
|
*/
|
|
1014
|
-
|
|
960
|
+
readonly retryCount: number;
|
|
1015
961
|
/**
|
|
1016
|
-
*
|
|
962
|
+
* The amount of times the test was repeated as configured by `repeats` option.
|
|
963
|
+
* This value can be lower if the test failed during the repeat and no `retry` is configured.
|
|
1017
964
|
*/
|
|
1018
|
-
|
|
965
|
+
readonly repeatCount: number;
|
|
1019
966
|
/**
|
|
1020
|
-
*
|
|
967
|
+
* If test passed on a second retry.
|
|
1021
968
|
*/
|
|
1022
|
-
|
|
969
|
+
readonly flaky: boolean;
|
|
970
|
+
}
|
|
971
|
+
interface ModuleDiagnostic {
|
|
1023
972
|
/**
|
|
1024
|
-
* The
|
|
973
|
+
* The time it takes to import and initiate an environment.
|
|
1025
974
|
*/
|
|
1026
|
-
|
|
975
|
+
readonly environmentSetupDuration: number;
|
|
1027
976
|
/**
|
|
1028
|
-
*
|
|
977
|
+
* The time it takes Vitest to setup test harness (runner, mocks, etc.).
|
|
1029
978
|
*/
|
|
1030
|
-
|
|
1031
|
-
/** @deprecated use `vite` instead */
|
|
1032
|
-
get server(): ViteDevServer;
|
|
979
|
+
readonly prepareDuration: number;
|
|
1033
980
|
/**
|
|
1034
|
-
*
|
|
981
|
+
* The time it takes to import the test module.
|
|
982
|
+
* This includes importing everything in the module and executing suite callbacks.
|
|
1035
983
|
*/
|
|
1036
|
-
|
|
1037
|
-
/** @deprecated use `isRootProject` instead */
|
|
1038
|
-
isCore(): boolean;
|
|
1039
|
-
/** @deprecated use `createSpecification` instead */
|
|
1040
|
-
createSpec(moduleId: string, pool: string): WorkspaceSpec;
|
|
1041
|
-
/** @deprecated */
|
|
1042
|
-
initializeGlobalSetup(): Promise<void>;
|
|
1043
|
-
onTestsRerun(cb: OnTestsRerunHandler): void;
|
|
1044
|
-
/** @deprecated */
|
|
1045
|
-
teardownGlobalSetup(): Promise<void>;
|
|
1046
|
-
/** @deprecated use `vitest.logger` instead */
|
|
1047
|
-
get logger(): Logger;
|
|
1048
|
-
// it's possible that file path was imported with different queries (?raw, ?url, etc)
|
|
1049
|
-
/** @deprecated use `.vite` or `.browser.vite` directly */
|
|
1050
|
-
getModulesByFilepath(file: string): Set<ModuleNode>;
|
|
1051
|
-
/** @deprecated use `.vite` or `.browser.vite` directly */
|
|
1052
|
-
getModuleById(id: string): ModuleNode | undefined;
|
|
1053
|
-
/** @deprecated use `.vite` or `.browser.vite` directly */
|
|
1054
|
-
getSourceMapModuleById(id: string): TransformResult$1["map"] | undefined;
|
|
1055
|
-
/** @deprecated use `vitest.reporters` instead */
|
|
1056
|
-
get reporters(): Reporter[];
|
|
984
|
+
readonly collectDuration: number;
|
|
1057
985
|
/**
|
|
1058
|
-
*
|
|
1059
|
-
* @param filters String filters to match the test files.
|
|
986
|
+
* The time it takes to import the setup module.
|
|
1060
987
|
*/
|
|
1061
|
-
|
|
1062
|
-
/**
|
|
1063
|
-
* Test files that match the filters.
|
|
1064
|
-
*/
|
|
1065
|
-
testFiles: string[];
|
|
1066
|
-
/**
|
|
1067
|
-
* Typecheck test files that match the filters. This will be empty unless `typecheck.enabled` is `true`.
|
|
1068
|
-
*/
|
|
1069
|
-
typecheckTestFiles: string[];
|
|
1070
|
-
}>;
|
|
1071
|
-
private globAllTestFiles;
|
|
1072
|
-
isBrowserEnabled(): boolean;
|
|
1073
|
-
private markTestFile;
|
|
1074
|
-
/** @deprecated use `serializedConfig` instead */
|
|
1075
|
-
getSerializableConfig(): SerializedConfig;
|
|
988
|
+
readonly setupDuration: number;
|
|
1076
989
|
/**
|
|
1077
|
-
*
|
|
990
|
+
* Accumulated duration of all tests and hooks in the module.
|
|
1078
991
|
*/
|
|
1079
|
-
|
|
1080
|
-
/** @deprecated use `matchesTestGlob` instead */
|
|
1081
|
-
isTargetFile(id: string, source?: string): Promise<boolean>;
|
|
1082
|
-
private isInSourceTestCode;
|
|
1083
|
-
private filterFiles;
|
|
1084
|
-
private _parentBrowser?;
|
|
992
|
+
readonly duration: number;
|
|
1085
993
|
/**
|
|
1086
|
-
*
|
|
1087
|
-
*
|
|
994
|
+
* The amount of memory used by the test module in bytes.
|
|
995
|
+
* This value is only available if the test was executed with `logHeapUsage` flag.
|
|
1088
996
|
*/
|
|
1089
|
-
|
|
997
|
+
readonly heap: number | undefined;
|
|
1090
998
|
/**
|
|
1091
|
-
*
|
|
1092
|
-
* @param moduleId The ID of the module in Vite module graph
|
|
999
|
+
* The time spent importing every non-externalized dependency that Vitest has processed.
|
|
1093
1000
|
*/
|
|
1094
|
-
|
|
1095
|
-
/** @deprecated use `name` instead */
|
|
1096
|
-
getName(): string;
|
|
1097
|
-
/** @deprecated internal */
|
|
1098
|
-
setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
|
|
1099
|
-
private _setHash;
|
|
1100
|
-
private _serializeOverriddenConfig;
|
|
1101
|
-
private clearTmpDir;
|
|
1102
|
-
/** @deprecated */
|
|
1103
|
-
initBrowserProvider(): Promise<void>;
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
interface SerializedTestProject {
|
|
1107
|
-
name: string;
|
|
1108
|
-
serializedConfig: SerializedConfig;
|
|
1109
|
-
context: ProvidedContext;
|
|
1110
|
-
}
|
|
1111
|
-
interface InitializeProjectOptions extends TestProjectInlineConfiguration {
|
|
1112
|
-
configFile: string | false;
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
/**
|
|
1116
|
-
* @deprecated use TestSpecification instead
|
|
1117
|
-
*/
|
|
1118
|
-
type WorkspaceSpec = TestSpecification & [project: TestProject, file: string, options: {
|
|
1119
|
-
pool: Pool;
|
|
1120
|
-
}];
|
|
1121
|
-
type RunWithFiles = (files: TestSpecification[], invalidates?: string[]) => Awaitable<void>;
|
|
1122
|
-
interface ProcessPool {
|
|
1123
|
-
name: string;
|
|
1124
|
-
runTests: RunWithFiles;
|
|
1125
|
-
collectTests: RunWithFiles;
|
|
1126
|
-
close?: () => Awaitable<void>;
|
|
1001
|
+
readonly importDurations: Record<string, ImportDuration>;
|
|
1127
1002
|
}
|
|
1128
|
-
declare function
|
|
1003
|
+
declare function experimental_getRunnerTask(entity: TestCase): Test;
|
|
1004
|
+
declare function experimental_getRunnerTask(entity: TestSuite): Suite;
|
|
1005
|
+
declare function experimental_getRunnerTask(entity: TestModule): File;
|
|
1006
|
+
declare function experimental_getRunnerTask(entity: TestCase | TestSuite | TestModule): Suite | File | Test;
|
|
1129
1007
|
|
|
1130
1008
|
interface CoverageSummaryData {
|
|
1131
1009
|
lines: Totals;
|
|
@@ -1328,6 +1206,8 @@ interface CoverageProvider {
|
|
|
1328
1206
|
mergeReports?: (coverages: CoverageResults[]) => void | Promise<void>;
|
|
1329
1207
|
/** Callback called for instrumenting files with coverage counters. */
|
|
1330
1208
|
onFileTransform?: (sourceCode: string, id: string, pluginCtx: any) => TransformResult | Promise<TransformResult>;
|
|
1209
|
+
/** Callback that's called when the coverage is enabled via a programmatic `enableCoverage` API. */
|
|
1210
|
+
onEnabled?: () => void | Promise<void>;
|
|
1331
1211
|
}
|
|
1332
1212
|
interface ReportContext {
|
|
1333
1213
|
/** Indicates whether all tests were run. False when only specific tests were run. */
|
|
@@ -1555,6 +1435,53 @@ declare class VitestCache {
|
|
|
1555
1435
|
static resolveCacheDir(root: string, dir?: string, projectName?: string): string;
|
|
1556
1436
|
}
|
|
1557
1437
|
|
|
1438
|
+
declare class TypeCheckError extends Error {
|
|
1439
|
+
message: string;
|
|
1440
|
+
stacks: ParsedStack[];
|
|
1441
|
+
name: string;
|
|
1442
|
+
constructor(message: string, stacks: ParsedStack[]);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
interface ErrorOptions {
|
|
1446
|
+
type?: string;
|
|
1447
|
+
fullStack?: boolean;
|
|
1448
|
+
project?: TestProject;
|
|
1449
|
+
verbose?: boolean;
|
|
1450
|
+
screenshotPaths?: string[];
|
|
1451
|
+
task?: Task;
|
|
1452
|
+
showCodeFrame?: boolean;
|
|
1453
|
+
}
|
|
1454
|
+
type Listener = () => void;
|
|
1455
|
+
declare class Logger {
|
|
1456
|
+
ctx: Vitest;
|
|
1457
|
+
outputStream: NodeJS.WriteStream | Writable;
|
|
1458
|
+
errorStream: NodeJS.WriteStream | Writable;
|
|
1459
|
+
private _clearScreenPending;
|
|
1460
|
+
private _highlights;
|
|
1461
|
+
private cleanupListeners;
|
|
1462
|
+
console: Console;
|
|
1463
|
+
constructor(ctx: Vitest, outputStream?: NodeJS.WriteStream | Writable, errorStream?: NodeJS.WriteStream | Writable);
|
|
1464
|
+
log(...args: any[]): void;
|
|
1465
|
+
error(...args: any[]): void;
|
|
1466
|
+
warn(...args: any[]): void;
|
|
1467
|
+
clearFullScreen(message?: string): void;
|
|
1468
|
+
clearScreen(message: string, force?: boolean): void;
|
|
1469
|
+
private _clearScreen;
|
|
1470
|
+
printError(err: unknown, options?: ErrorOptions): void;
|
|
1471
|
+
deprecate(message: string): void;
|
|
1472
|
+
clearHighlightCache(filename?: string): void;
|
|
1473
|
+
highlight(filename: string, source: string): string;
|
|
1474
|
+
printNoTestFound(filters?: string[]): void;
|
|
1475
|
+
printBanner(): void;
|
|
1476
|
+
printBrowserBanner(project: TestProject): void;
|
|
1477
|
+
printUnhandledErrors(errors: ReadonlyArray<unknown>): void;
|
|
1478
|
+
printSourceTypeErrors(errors: TypeCheckError[]): void;
|
|
1479
|
+
getColumns(): number;
|
|
1480
|
+
onTerminalCleanup(listener: Listener): void;
|
|
1481
|
+
private addCleanupListeners;
|
|
1482
|
+
private registerUnhandledRejection;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1558
1485
|
declare class VitestPackageInstaller {
|
|
1559
1486
|
isPackageExists(name: string, options?: {
|
|
1560
1487
|
paths?: string[];
|
|
@@ -1705,6 +1632,7 @@ declare class Vitest {
|
|
|
1705
1632
|
private _state?;
|
|
1706
1633
|
private _cache?;
|
|
1707
1634
|
private _snapshot?;
|
|
1635
|
+
private _coverageProvider?;
|
|
1708
1636
|
constructor(mode: VitestRunMode, cliOptions: UserConfig, options?: VitestOptions);
|
|
1709
1637
|
private _onRestartListeners;
|
|
1710
1638
|
private _onClose;
|
|
@@ -1712,16 +1640,10 @@ declare class Vitest {
|
|
|
1712
1640
|
private _onCancelListeners;
|
|
1713
1641
|
private _onUserTestsRerun;
|
|
1714
1642
|
private _onFilterWatchedSpecification;
|
|
1715
|
-
/** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
|
|
1716
|
-
get invalidates(): Set<string>;
|
|
1717
|
-
/** @deprecated will be removed in 4.0, use `onFilterWatchedSpecification` instead */
|
|
1718
|
-
get changedTests(): Set<string>;
|
|
1719
1643
|
/**
|
|
1720
1644
|
* The global config.
|
|
1721
1645
|
*/
|
|
1722
1646
|
get config(): ResolvedConfig;
|
|
1723
|
-
/** @deprecated use `vitest.vite` instead */
|
|
1724
|
-
get server(): ViteDevServer;
|
|
1725
1647
|
/**
|
|
1726
1648
|
* Global Vite's dev server instance.
|
|
1727
1649
|
*/
|
|
@@ -1739,8 +1661,9 @@ declare class Vitest {
|
|
|
1739
1661
|
* Test results and test file stats cache. Primarily used by the sequencer to sort tests.
|
|
1740
1662
|
*/
|
|
1741
1663
|
get cache(): VitestCache;
|
|
1742
|
-
|
|
1743
|
-
|
|
1664
|
+
enableCoverage(): Promise<void>;
|
|
1665
|
+
disableCoverage(): void;
|
|
1666
|
+
private _coverageOverrideCache;
|
|
1744
1667
|
/**
|
|
1745
1668
|
* Inject new test projects into the workspace.
|
|
1746
1669
|
* @param config Glob, config path or a custom config options.
|
|
@@ -1755,16 +1678,10 @@ declare class Vitest {
|
|
|
1755
1678
|
* Get global provided context.
|
|
1756
1679
|
*/
|
|
1757
1680
|
getProvidedContext(): ProvidedContext;
|
|
1758
|
-
/** @deprecated use `getRootProject` instead */
|
|
1759
|
-
getCoreWorkspaceProject(): TestProject;
|
|
1760
1681
|
/**
|
|
1761
1682
|
* Return project that has the root (or "global") config.
|
|
1762
1683
|
*/
|
|
1763
1684
|
getRootProject(): TestProject;
|
|
1764
|
-
/**
|
|
1765
|
-
* @deprecated use Reported Task API instead
|
|
1766
|
-
*/
|
|
1767
|
-
getProjectByTaskId(taskId: string): TestProject;
|
|
1768
1685
|
getProjectByName(name: string): TestProject;
|
|
1769
1686
|
/**
|
|
1770
1687
|
* Import a file using Vite module runner. The file will be transformed by Vite and executed in a separate context.
|
|
@@ -1787,8 +1704,6 @@ declare class Vitest {
|
|
|
1787
1704
|
*/
|
|
1788
1705
|
mergeReports(directory?: string): Promise<TestRunResult>;
|
|
1789
1706
|
collect(filters?: string[]): Promise<TestRunResult>;
|
|
1790
|
-
/** @deprecated use `getRelevantTestSpecifications` instead */
|
|
1791
|
-
listFiles(filters?: string[]): Promise<TestSpecification[]>;
|
|
1792
1707
|
/**
|
|
1793
1708
|
* Returns the list of test files that match the config and filters.
|
|
1794
1709
|
* @param filters String filters to match the test files
|
|
@@ -1809,12 +1724,6 @@ declare class Vitest {
|
|
|
1809
1724
|
*/
|
|
1810
1725
|
init(): Promise<void>;
|
|
1811
1726
|
/**
|
|
1812
|
-
* @deprecated remove when vscode extension supports "getModuleSpecifications"
|
|
1813
|
-
*/
|
|
1814
|
-
getProjectsByTestFile(file: string): WorkspaceSpec[];
|
|
1815
|
-
/** @deprecated */
|
|
1816
|
-
getFileWorkspaceSpecs(file: string): WorkspaceSpec[];
|
|
1817
|
-
/**
|
|
1818
1727
|
* If there is a test run happening, returns a promise that will
|
|
1819
1728
|
* resolve when the test run is finished.
|
|
1820
1729
|
*/
|
|
@@ -1890,8 +1799,6 @@ declare class Vitest {
|
|
|
1890
1799
|
* Invalidate a file in all projects.
|
|
1891
1800
|
*/
|
|
1892
1801
|
invalidateFile(filepath: string): void;
|
|
1893
|
-
/** @deprecated use `invalidateFile` */
|
|
1894
|
-
updateLastChanged(filepath: string): void;
|
|
1895
1802
|
private reportCoverage;
|
|
1896
1803
|
/**
|
|
1897
1804
|
* Closes all projects and their associated resources.
|
|
@@ -1904,16 +1811,6 @@ declare class Vitest {
|
|
|
1904
1811
|
*/
|
|
1905
1812
|
exit(force?: boolean): Promise<void>;
|
|
1906
1813
|
/**
|
|
1907
|
-
* @deprecated use `globTestSpecifications` instead
|
|
1908
|
-
*/
|
|
1909
|
-
globTestSpecs(filters?: string[]): Promise<TestSpecification[]>;
|
|
1910
|
-
/**
|
|
1911
|
-
* @deprecated use `globTestSpecifications` instead
|
|
1912
|
-
*/
|
|
1913
|
-
globTestFiles(filters?: string[]): Promise<TestSpecification[]>;
|
|
1914
|
-
/** @deprecated filter by `this.projects` yourself */
|
|
1915
|
-
getModuleProjects(filepath: string): TestProject[];
|
|
1916
|
-
/**
|
|
1917
1814
|
* Should the server be kept running after the tests are done.
|
|
1918
1815
|
*/
|
|
1919
1816
|
shouldKeepServer(): boolean;
|
|
@@ -3230,5 +3127,5 @@ type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
|
|
|
3230
3127
|
});
|
|
3231
3128
|
type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
|
|
3232
3129
|
|
|
3233
|
-
export {
|
|
3234
|
-
export type {
|
|
3130
|
+
export { TestSuite as B, CoverageMap as C, experimental_getRunnerTask as E, Logger as L, TestProject as T, Vitest as V, DefaultReporter as aA, DotReporter as aB, GithubActionsReporter as aC, HangingProcessReporter as aD, JsonReporter as aE, JUnitReporter as aF, ReportersMap as aG, TapFlatReporter as aH, TapReporter as aI, VerboseBenchmarkReporter as aJ, VerboseReporter as aK, BaseReporter as aL, BenchmarkReporter as ay, BenchmarkReportsMap as az, TestSpecification as k, VitestPackageInstaller as n, TestCase as q, TestCollection as r, TestModule as t };
|
|
3131
|
+
export type { BrowserProvider as $, ApiConfig as A, TestSuiteState as D, TestSequencerConstructor as F, BenchmarkUserOptions as G, HTMLOptions as H, InlineConfig as I, JsonOptions as J, BrowserBuiltinProvider as K, ModuleDiagnostic as M, BrowserCommand as N, OnServerRestartHandler as O, Pool as P, BrowserCommandContext as Q, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, BrowserConfigOptions as X, BrowserInstanceOption as Y, BrowserModuleMocker as Z, BrowserOrchestrator as _, TestProjectConfiguration as a, BrowserProviderInitializationOptions as a0, BrowserProviderModule as a1, BrowserProviderOptions as a2, BrowserScript as a3, BrowserServerState as a4, BrowserServerStateSession as a5, CDPSession as a6, ParentProjectBrowser as a7, ProjectBrowser as a8, ResolvedBrowserOptions as a9, BenchmarkBuiltinReporters as aM, BuiltinReporterOptions as aN, BuiltinReporters as aO, JsonAssertionResult as aP, JsonTestResult as aQ, JsonTestResults as aR, ToMatchScreenshotComparators as aa, ToMatchScreenshotOptions as ab, BuiltinEnvironment as ac, CSSModuleScopeStrategy as ad, DepsOptimizationOptions as ae, EnvironmentOptions as af, PoolOptions as ag, ProjectConfig as ah, ResolvedProjectConfig as ai, ResolveSnapshotPathHandler as aj, ResolveSnapshotPathHandlerContext as ak, TypecheckConfig as al, VitestEnvironment as am, BaseCoverageOptions as an, CoverageIstanbulOptions as ao, CoverageOptions as ap, CoverageProvider as aq, CoverageProviderModule as ar, CoverageReporter as as, CustomProviderOptions as at, TestRunResult as au, ReportedHookContext as av, Reporter as aw, TestRunEndReason as ax, ReportContext as b, CoverageV8Options as c, UserProjectConfigFn as d, UserProjectConfigExport as e, UserConfig as f, TestProjectInlineConfiguration as g, ResolvedConfig as h, VitestRunMode as i, VitestOptions as j, TestSequencer as l, OnTestsRerunHandler as m, JUnitOptions as o, TaskOptions as p, TestDiagnostic as s, TestModuleState as u, TestResult as v, TestResultFailed as w, TestResultPassed as x, TestResultSkipped as y, TestState as z };
|