Optionaloptions: VitestOptionsReadonlydistReadonlyloggerThe logger instance used to log messages. It's recommended to use this logger instead of console.
It's possible to override stdout and stderr streams when initiating Vitest.
ReadonlymodeReadonlypackageThe package installer instance used to install Vitest packages.
A list of projects that are currently running.
If projects were filtered with --project flag, they won't appear here.
Provide a value to the test context. This value will be available to all tests with inject.
ReadonlyversionCurrent Vitest version.
ReadonlywatcherA watcher handler. This is not the file system watcher. The handler only exposes methods to handle changed files.
If you have your own watcher, you can use these methods to replicate Vitest behaviour.
Static ReadonlyversionTest results and test file stats cache. Primarily used by the sequencer to sort tests.
The global config.
The global snapshot manager. You can access the current state on snapshot.summary.
ExperimentalThe global test state manager. The State API is experimental and not subject to semver.
Global Vite's dev server instance.
Gracefully cancel the current test run. Vitest will wait until all running tests are finished before cancelling.
Vitest automatically caches test specifications for each file. This method clears the cache for the given file or the whole cache altogether.
OptionalmoduleId: stringCloses all projects and their associated resources. This can only be called once; the closing promise is cached until the server restarts.
Optionalfilters: string[]Collect tests in specified modules. Vitest will run the files to collect tests.
A list of specifications to run.
Creates a coverage provider if coverage is enabled in the config.
Enable the mode that allows updating snapshots when running tests. This method doesn't run any tests.
Every test that runs after this method is called will update snapshots.
To disable the mode, call resetSnapshotUpdate.
Closes all projects and exit the process
Optionalforce: booleanIf true, the process will exit immediately after closing the projects.
ExperimentalReturns module's diagnostic. If testModule is not provided, selfTime and totalTime will be aggregated across all tests.
If the module was not transformed or executed, the diagnostic will be empty.
OptionaltestModule: TestModuleOptionaloptions: { concurrency?: number }Optionalconcurrency?: numberReturns the regexp used for the global test name pattern.
Get test specifications associated with the given module. If module is not a test file, an empty array is returned.
Note: this method relies on a cache generated by globTestSpecifications. If the file was not processed yet, use project.matchesGlobPattern instead.
The module ID to get test specifications for.
Get global provided context.
Returns the list of test files that match the config and filters.
Optionalfilters: string[]String filters to match the test files
Return project that has the root (or "global") config.
Returns the seed, if tests are running in a random order.
Glob test files in every project and create a TestSpecification for each file and pool.
Optionalfilters: string[]String filters to match the test files.
Initialize reporters and the coverage provider. This method doesn't run any tests.
If the --watch flag is provided, Vitest will still run changed tests even if this method was not called.
Invalidate a file in all projects.
Check if the project with a given name should be included.
Merge reports from multiple runs located in the specified directory (value from --merge-reports if not specified).
Optionaldirectory: stringRegister a handler that will be called when the test run is cancelled with vitest.cancelCurrentRun.
Register a handler that will be called when the server is closed.
Register a handler that will be called when a file is changed.
This callback should return true of false indicating whether the test file needs to be rerun.
Register a handler that will be called when the server is restarted due to a config change.
Register a handler that will be called when the tests are rerunning.
Rerun files and trigger onWatcherRerun, onWatcherStart and onTestsRerun events.
A list of specifications to run.
OptionalallTestsRun: booleanIndicates whether all tests were run. This only matters for coverage.
Resets the global test name pattern. This method doesn't run any tests.
Disable the mode that allows updating snapshots when running tests.
Run tests for the given test specifications. This does not trigger onWatcher* events.
A list of specifications to run.
OptionalallTestsRun: booleanIndicates whether all tests were run. This only matters for coverage.
Set the global test name pattern to a regexp. This method doesn't run any tests.
Should the server be kept running after the tests are done.
Initialize reporters, the coverage provider, and run tests. This method can throw an error:
FilesNotFoundError if no tests are foundGitNotFoundError if --related flag is used, but git repository is not initializedError from the user reportersOptionalfilters: string[]String filters to match the test files
Update snapshots in specified files. If no files are provided, it will update files with failed tests and obsolete snapshots.
Optionalfiles: string[]The list of files on the file system
If there is a test run happening, returns a promise that will resolve when the test run is finished.
A path to the built Vitest directory. This is usually a folder in
node_modules.