KC's Workspace
    Preparing search index...
    Index

    Constructors

    Properties

    distPath: string

    A path to the built Vitest directory. This is usually a folder in node_modules.

    logger: Logger

    The 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.

    new Vitest('test', {
    stdout: new Writable(),
    })
    packageInstaller: VitestPackageInstaller

    The package installer instance used to install Vitest packages.

    await vitest.packageInstaller.ensureInstalled('@vitest/browser', process.cwd())
    
    projects: TestProject[]

    A list of projects that are currently running. If projects were filtered with --project flag, they won't appear here.

    provide: <T extends never>(key: T, value: ProvidedContext[T]) => void

    Provide a value to the test context. This value will be available to all tests with inject.

    The version control system provider used to detect changed files. This is used with the --changed flag to determine which test files to run. By default, Vitest uses Git. You can provide a custom implementation via experimental.vcsProvider in your config.

    version: string

    Current Vitest version.

    '2.0.0'
    
    watcher: VitestWatcher

    A 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.

    version: string

    Accessors

    Methods

    • Vitest automatically caches test specifications for each file. This method clears the cache for the given file or the whole cache altogether.

      Parameters

      • OptionalmoduleId: string

      Returns void

    • 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.

      Returns void

    • 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.

      Parameters

      • moduleId: string

        The module ID to get test specifications for.

      Returns TestSpecification[]

    • 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.

      Parameters

      Returns void

      const testsToRun = [resolve('./test.spec.ts')]
      vitest.onFilterWatchedSpecification(specification => testsToRun.includes(specification.moduleId))