interface UserConfig {
    alias?: AliasOptions;
    allowOnly?: boolean;
    api?: number | boolean | ApiConfig;
    bail?: number;
    benchmark?: BenchmarkUserOptions;
    browser?: BrowserConfigOptions;
    cache?: false | {
        dir?: string;
    };
    chaiConfig?: ChaiConfig;
    changed?: string | boolean;
    clearMocks?: boolean;
    cliExclude?: string[];
    config?: string | false;
    coverage?: {
        provider?: undefined;
    } & CoverageV8Options | {
        provider: "custom";
    } & CustomProviderOptions | {
        provider: "istanbul";
    } & CoverageIstanbulOptions | {
        provider: "v8";
    } & CoverageV8Options;
    css?: boolean | {
        exclude?: RegExp | RegExp[];
        include?: RegExp | RegExp[];
        modules?: {
            classNameStrategy?: CSSModuleScopeStrategy;
        };
    };
    dangerouslyIgnoreUnhandledErrors?: boolean;
    deps?: DepsOptions;
    diff?: string;
    dir?: string;
    dom?: boolean;
    env?: Record<string, string>;
    environment?: VitestEnvironment;
    environmentMatchGlobs?: [string, VitestEnvironment][];
    environmentOptions?: EnvironmentOptions;
    exclude?: string[];
    expandSnapshotDiff?: boolean;
    fakeTimers?: FakeTimerInstallOpts;
    fileParallelism?: boolean;
    forceRerunTriggers?: string[];
    globalSetup?: string | string[];
    globals?: boolean;
    hideSkippedTests?: boolean;
    hookTimeout?: number;
    include?: string[];
    includeSource?: string[];
    inspect?: boolean;
    inspectBrk?: boolean;
    isolate?: boolean;
    logHeapUsage?: boolean;
    maxConcurrency?: number;
    maxWorkers?: number;
    minWorkers?: number;
    mockReset?: boolean;
    mode?: string;
    name?: string;
    onConsoleLog?: ((log, type) => false | void);
    onStackTrace?: ((error, frame) => boolean | void);
    open?: boolean;
    outputFile?: string | Partial<Record<"default" | "json" | "verbose" | "basic" | "dot" | "tap" | "tap-flat" | "junit" | "hanging-process", string>> & Record<string, string>;
    passWithNoTests?: boolean;
    pool?: "typescript" | "threads" | "forks" | "vmThreads" | string & {};
    poolMatchGlobs?: [string, "typescript" | "threads" | "forks" | "vmThreads" | string & {}][];
    poolOptions?: PoolOptions;
    project?: string | string[];
    related?: string | string[];
    reporters?: Arrayable<"default" | "html" | "json" | "verbose" | "basic" | "dot" | "tap" | "tap-flat" | "junit" | "hanging-process" | Reporter | Omit<string, "default" | "json" | "verbose" | "basic" | "dot" | "tap" | "tap-flat" | "junit" | "hanging-process">>;
    resolveSnapshotPath?: ((path, extension) => string);
    restoreMocks?: boolean;
    retry?: number;
    root?: string;
    runner?: string;
    sequence?: SequenceOptions;
    server?: Omit<ViteNodeServerOptions, "transformMode">;
    setupFiles?: string | string[];
    shard?: string;
    silent?: boolean;
    slowTestThreshold?: number;
    snapshotFormat?: Omit<PrettyFormatOptions, "plugins">;
    teardownTimeout?: number;
    testNamePattern?: string | RegExp;
    testTimeout?: number;
    testTransformMode?: TransformModePatterns;
    typecheck?: Partial<TypecheckConfig>;
    ui?: boolean;
    uiBase?: string;
    unstubEnvs?: boolean;
    unstubGlobals?: boolean;
    update?: boolean;
    watch?: boolean;
    watchExclude?: string[];
    workspace?: string;
}

Hierarchy (view full)

Properties

alias?: AliasOptions

Specifies an Object, or an Array of Object, which defines aliases used to replace values in import or require statements. Will be merged with the default aliases inside resolve.alias.

allowOnly?: boolean

Allow tests and suites that are marked as only

api?: number | boolean | ApiConfig

Serve API options.

When set to true, the default port is 51204.

Default

false
bail?: number

Stop test execution when given number of tests have failed.

Benchmark options.

Default

{}
browser?: BrowserConfigOptions

options for test in a browser environment

Default

false
cache?: false | {
    dir?: string;
}

Options for configuring cache policy.

Type declaration

  • Optional dir?: string

Default

{ dir: 'node_modules/.vitest' }
chaiConfig?: ChaiConfig

Modify default Chai config. Vitest uses Chai for expect and assert matches. https://github.com/chaijs/chai/blob/4.x.x/lib/chai/config.js

changed?: string | boolean

Runs tests that are affected by the changes in the repository, or between specified branch or commit hash Requires initialized git repository

Default

false
clearMocks?: boolean

Will call .mockClear() on all spies before each test

Default

false
cliExclude?: string[]

Additional exclude patterns

config?: string | false

Path to the config file.

Default resolving to vitest.config.*, vite.config.*

Setting to false will disable config resolving.

coverage?: {
    provider?: undefined;
} & CoverageV8Options | {
    provider: "custom";
} & CustomProviderOptions | {
    provider: "istanbul";
} & CoverageIstanbulOptions | {
    provider: "v8";
} & CoverageV8Options

Coverage options

css?: boolean | {
    exclude?: RegExp | RegExp[];
    include?: RegExp | RegExp[];
    modules?: {
        classNameStrategy?: CSSModuleScopeStrategy;
    };
}

Indicates if CSS files should be processed.

When excluded, the CSS files will be replaced with empty strings to bypass the subsequent processing.

Type declaration

Default

{ include: [], modules: { classNameStrategy: false } }
dangerouslyIgnoreUnhandledErrors?: boolean

Ignore any unhandled errors that occur

deps?: DepsOptions

Handling for dependencies inlining or externalizing

diff?: string

Path to a module which has a default export of diff config.

dir?: string

Base directory to scan for the test files

Default

config.root

dom?: boolean

Use happy-dom

env?: Record<string, string>

Custom environment variables assigned to process.env before running tests.

environment?: VitestEnvironment

Running environment

Supports 'node', 'jsdom', 'happy-dom', 'edge-runtime'

If used unsupported string, will try to load the package vitest-environment-${env}

Default

'node'
environmentMatchGlobs?: [string, VitestEnvironment][]

Automatically assign environment based on globs. The first match will be used. This has effect only when running tests inside Node.js.

Format: [glob, environment-name]

Default

[]

Example

[
// all tests in tests/dom will run in jsdom
['tests/dom/**', 'jsdom'],
// all tests in tests/ with .edge.test.ts will run in edge-runtime
['**/*.edge.test.ts', 'edge-runtime'],
// ...
]
environmentOptions?: EnvironmentOptions

Environment options.

exclude?: string[]

Exclude globs for test files

Default

['node_modules', 'dist', '.idea', '.git', '.cache']
expandSnapshotDiff?: boolean

Show full diff when snapshot fails instead of a patch.

fakeTimers?: FakeTimerInstallOpts

Options for @sinon/fake-timers

fileParallelism?: boolean

Should all test files run in parallel. Doesn't affect tests running in the same file. Setting this to false will override maxWorkers and minWorkers options to 1.

Default

true
forceRerunTriggers?: string[]

Glob patter of file paths that will trigger the whole suite rerun

Useful if you are testing calling CLI commands

Default

[]
globalSetup?: string | string[]

Path to global setup files

globals?: boolean

Register apis globally

Default

false
hideSkippedTests?: boolean

Hide logs for skipped tests

Default

false
hookTimeout?: number

Default timeout of a hook in milliseconds

Default

10000
include?: string[]

Include globs for test files

Default

['**/*.{test,spec}.?(c|m)[jt]s?(x)']
includeSource?: string[]

Include globs for in-source test files

Default

[]
inspect?: boolean

Debug tests by opening node:inspector in worker / child process. Provides similar experience as --inspect Node CLI argument.

Requires poolOptions.threads.singleThread: true OR poolOptions.forks.singleFork: true.

inspectBrk?: boolean

Debug tests by opening node:inspector in worker / child process and wait for debugger to connect. Provides similar experience as --inspect-brk Node CLI argument.

Requires poolOptions.threads.singleThread: true OR poolOptions.forks.singleFork: true.

isolate?: boolean

Run tests in an isolated environment. This option has no effect on vmThreads pool.

Disabling this option might improve performance if your code doesn't rely on side effects.

Default

true
logHeapUsage?: boolean

Show heap usage after each test. Useful for debugging memory leaks.

maxConcurrency?: number

A number of tests that are allowed to run at the same time marked with test.concurrent.

Default

5
maxWorkers?: number

Maximum number of workers to run tests in. poolOptions.{threads,vmThreads}.maxThreads/poolOptions.forks.maxForks has higher priority.

minWorkers?: number

Minimum number of workers to run tests in. poolOptions.{threads,vmThreads}.minThreads/poolOptions.forks.minForks has higher priority.

mockReset?: boolean

Will call .mockReset() on all spies before each test

Default

false
mode?: string

Overrides Vite mode

Default

'test'
name?: string

Name of the project. Will be used to display in the reporter.

onConsoleLog?: ((log, type) => false | void)

Custom handler for console.log in tests.

Return false to ignore the log.

Type declaration

    • (log, type): false | void
    • Custom handler for console.log in tests.

      Return false to ignore the log.

      Parameters

      • log: string
      • type: "stdout" | "stderr"

      Returns false | void

onStackTrace?: ((error, frame) => boolean | void)

Enable stack trace filtering. If absent, all stack trace frames will be shown.

Return false to omit the frame.

Type declaration

    • (error, frame): boolean | void
    • Enable stack trace filtering. If absent, all stack trace frames will be shown.

      Return false to omit the frame.

      Parameters

      Returns boolean | void

open?: boolean

Open UI automatically.

Default

true
outputFile?: string | Partial<Record<"default" | "json" | "verbose" | "basic" | "dot" | "tap" | "tap-flat" | "junit" | "hanging-process", string>> & Record<string, string>

Write test results to a file when the --reporter=jsonor--reporter=junit` option is also specified. Also definable individually per reporter by using an object instead.

passWithNoTests?: boolean

Pass with no tests

pool?: "typescript" | "threads" | "forks" | "vmThreads" | string & {}

Pool used to run tests in.

Supports 'threads', 'forks', 'vmThreads'

Default

'threads'
poolMatchGlobs?: [string, "typescript" | "threads" | "forks" | "vmThreads" | string & {}][]

Automatically assign pool based on globs. The first match will be used.

Format: [glob, pool-name]

Default

[]

Example

[
// all tests in "forks" directory will run using "poolOptions.forks" API
['tests/forks/**', 'forks'],
// all other tests will run based on "poolOptions.threads" option, if you didn't specify other globs
// ...
]
poolOptions?: PoolOptions

Pool options

project?: string | string[]

Name of the project or projects to run.

related?: string | string[]

Run tests that cover a list of source files

reporters?: Arrayable<"default" | "html" | "json" | "verbose" | "basic" | "dot" | "tap" | "tap-flat" | "junit" | "hanging-process" | Reporter | Omit<string, "default" | "json" | "verbose" | "basic" | "dot" | "tap" | "tap-flat" | "junit" | "hanging-process">>

Custom reporter for output. Can contain one or more built-in report names, reporter instances, and/or paths to custom reporters.

resolveSnapshotPath?: ((path, extension) => string)

Resolve custom snapshot path

Type declaration

    • (path, extension): string
    • Resolve custom snapshot path

      Parameters

      • path: string
      • extension: string

      Returns string

restoreMocks?: boolean

Will call .mockRestore() on all spies before each test

Default

false
retry?: number

Retry the test specific number of times if it fails.

Default

0
root?: string

Project root

Default

process.cwd()
runner?: string

Path to a custom test runner.

sequence?: SequenceOptions

Options for configuring the order of running tests.

server?: Omit<ViteNodeServerOptions, "transformMode">

Vite-node server options

setupFiles?: string | string[]

Path to setup files

shard?: string

Test suite shard to execute in a format of /. Will divide tests into a count numbers, and run only the indexed part. Cannot be used with enabled watch.

Example

--shard=2/3
silent?: boolean

Silent mode

Default

false
slowTestThreshold?: number

The number of milliseconds after which a test is considered slow and reported as such in the results.

Default

300
snapshotFormat?: Omit<PrettyFormatOptions, "plugins">

Format options for snapshot testing.

teardownTimeout?: number

Default timeout to wait for close when Vitest shuts down, in milliseconds

Default

10000
testNamePattern?: string | RegExp

run test names with the specified pattern

testTimeout?: number

Default timeout of a test in milliseconds

Default

5000
testTransformMode?: TransformModePatterns

Determine the transform method for all modules imported inside a test that matches the glob pattern.

Options for configuring typechecking test environment.

ui?: boolean

Enable Vitest UI

uiBase?: string

Base url for the UI

Default

'/__vitest__/'
unstubEnvs?: boolean

Will restore all env stubs to their original values before each test

Default

false
unstubGlobals?: boolean

Will restore all global stubs to their original values before each test

Default

false
update?: boolean

Update snapshot

Default

false
watch?: boolean

Watch mode

Default

true
watchExclude?: string[]

Glob pattern of file paths to be ignore from triggering watch rerun

workspace?: string

Path to a workspace configuration file

Generated using TypeDoc