KC's Workspace
    Preparing search index...

    Construct a type with the properties of T except for those in type K.

    interface BrowserInstanceOption {
        allowOnly?: boolean;
        attachmentsDir?: string;
        bail?: number;
        browser: string;
        chaiConfig?: ChaiConfig;
        clearMocks?: boolean;
        css?:
            | boolean
            | {
                exclude?: RegExp
                | RegExp[];
                include?: RegExp | RegExp[];
                modules?: { classNameStrategy?: CSSModuleScopeStrategy };
            };
        detectAsyncLeaks?: boolean;
        diff?: string
        | SerializedDiffOptions;
        dir?: string;
        disableConsoleIntercept?: boolean;
        env?: Partial<ProcessEnv>;
        exclude?: string[];
        execArgv?: string[];
        expandSnapshotDiff?: boolean;
        expect?: {
            poll?: { interval?: number; timeout?: number };
            requireAssertions?: boolean;
        };
        experimental?: {
            fsModuleCache?: boolean;
            fsModuleCachePath?: string;
            importDurations?: {
                failOnDanger?: boolean;
                limit?: number;
                print?: boolean
                | "on-warn";
                thresholds?: { danger?: number; warn?: number };
            };
            nodeLoader?: boolean;
            openTelemetry?: {
                browserSdkPath?: string;
                enabled: boolean;
                sdkPath?: string;
            };
            vcsProvider?: string
            | VCSProvider;
            viteModuleRunner?: boolean;
        };
        fakeTimers?: FakeTimerInstallOpts;
        fileParallelism?: boolean;
        globals?: boolean;
        globalSetup?: string
        | string[];
        headless?: boolean;
        hideSkippedTests?: boolean;
        hookTimeout?: number;
        include?: string[];
        includeSource?: string[];
        includeTaskLocation?: boolean;
        inspector?: {
            enabled?: boolean;
            host?: string;
            port?: number;
            waitForDebugger?: boolean;
        };
        isolate?: boolean;
        locators?: { testIdAttribute?: string };
        logHeapUsage?: boolean;
        maxConcurrency?: number;
        maxWorkers?: string | number;
        mockReset?: boolean;
        mode?: string;
        name?: string;
        onUnhandledError?: OnUnhandledErrorCallback;
        printConsoleTrace?: boolean;
        projects?: TestProjectConfiguration[];
        provide?: Partial<ProvidedContext>;
        provider?: BrowserProviderOption<object>;
        restoreMocks?: boolean;
        retry?: SerializableRetry;
        screenshotDirectory?: string;
        screenshotFailures?: boolean;
        sequencer?: Omit<SequenceOptions, "sequencer" | "seed">;
        setupFiles?: string | string[];
        snapshotEnvironment?: string;
        snapshotSerializers?: string[];
        strictTags?: boolean;
        tags?: TestTagDefinition[];
        testerHtmlPath?: string;
        testTimeout?: number;
        unstubEnvs?: boolean;
        unstubGlobals?: boolean;
        viewport?: { height: number; width: number };
        vmMemoryLimit?: string | number;
    }

    Hierarchy (View Summary)

    Index

    Properties

    allowOnly?: boolean

    Allow tests and suites that are marked as only

    !process.env.CI
    
    attachmentsDir?: string

    Directory path for storing attachments created by context.annotate

    '.vitest-attachments'
    
    bail?: number

    Stop test execution when given number of tests have failed.

    browser: string

    Name of the browser

    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

    clearMocks?: boolean

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

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

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

    Detect asynchronous resources leaking from the test file.

    false
    
    diff?: string | SerializedDiffOptions

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

    dir?: string

    Base directory to scan for the test files

    config.root

    disableConsoleIntercept?: boolean

    By default, Vitest automatically intercepts console logging during tests for extra formatting of test file, test title, etc... This is also required for console log preview on Vitest UI. However, disabling such interception might help when you want to debug a code with normal synchronous terminal console logging.

    This option has no effect on browser pool since Vitest preserves original logging on browser devtools.

    false
    

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

    exclude?: string[]

    Exclude globs for test files

    ['**/node_modules/**', '**/.git/**']
    
    execArgv?: string[]

    Pass additional arguments to node process when spawning the worker.

    See Command-line API | Node.js for more information.

    Set to process.execArgv to pass all arguments of the current process.

    Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103

    [] // no execution arguments are passed
    
    expandSnapshotDiff?: boolean

    Show full diff when snapshot fails instead of a patch.

    expect?: {
        poll?: { interval?: number; timeout?: number };
        requireAssertions?: boolean;
    }

    Configuration options for expect() matches.

    Type Declaration

    • Optionalpoll?: { interval?: number; timeout?: number }

      Default options for expect.poll()

      • Optionalinterval?: number

        Polling interval in milliseconds

        50
        
      • Optionaltimeout?: number

        Timeout in milliseconds

        1000
        
    • OptionalrequireAssertions?: boolean

      Throw an error if tests don't have any expect() assertions.

    experimental?: {
        fsModuleCache?: boolean;
        fsModuleCachePath?: string;
        importDurations?: {
            failOnDanger?: boolean;
            limit?: number;
            print?: boolean | "on-warn";
            thresholds?: { danger?: number; warn?: number };
        };
        nodeLoader?: boolean;
        openTelemetry?: {
            browserSdkPath?: string;
            enabled: boolean;
            sdkPath?: string;
        };
        vcsProvider?: string
        | VCSProvider;
        viteModuleRunner?: boolean;
    }

    Experimental features

    Type Declaration

    • OptionalfsModuleCache?: boolean

      Enable caching of modules on the file system between reruns.

    • OptionalfsModuleCachePath?: string

      Path relative to the root of the project where the fs module cache will be stored.

      node_modules/.experimental-vitest-cache
      
    • OptionalimportDurations?: {
          failOnDanger?: boolean;
          limit?: number;
          print?: boolean | "on-warn";
          thresholds?: { danger?: number; warn?: number };
      }

      Configure import duration collection and display.

      The limit option controls how many imports to collect and display. The print option controls CLI terminal output. UI can always toggle the breakdown display regardless of print setting.

      • OptionalfailOnDanger?: boolean

        Fail the test run if any import exceeds the danger threshold. When failing, the breakdown is always printed regardless of print setting.

        false
        
      • Optionallimit?: number

        Maximum number of imports to collect and display.

        0 (or 10 if print or UI is enabled)

      • Optionalprint?: boolean | "on-warn"

        When to print import breakdown to CLI terminal after tests finish.

        • true: Always print
        • false: Never print (default)
        • 'on-warn': Print only when any import exceeds the warn threshold
        false
        
      • Optionalthresholds?: { danger?: number; warn?: number }

        Duration thresholds in milliseconds for coloring and warnings.

        • Optionaldanger?: number

          Danger threshold - imports exceeding this are shown in red.

          500
          
        • Optionalwarn?: number

          Warning threshold - imports exceeding this are shown in yellow/orange.

          100
          
    • OptionalnodeLoader?: boolean

      If module runner is disabled, Vitest uses a module loader to transform files to support import.meta.vitest and vi.mock.

      If you don't use these features, you can disable this.

      This option only affects loader.load method, Vitest always defines a loader.resolve to populate the module graph.

    • OptionalopenTelemetry?: { browserSdkPath?: string; enabled: boolean; sdkPath?: string }
    • OptionalvcsProvider?: string | VCSProvider

      Custom provider for detecting changed files. Used with the --changed flag to determine which files have been modified.

      By default, Vitest uses Git to detect changed files. You can provide a custom implementation of the VCSProvider interface to use a different version control system.

    • OptionalviteModuleRunner?: boolean

      Controls whether Vitest uses Vite's module runner to run the code or fallback to the native import.

      If Node.js cannot process the code, consider registering module loader via execArgv.

      true
      

    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 option to 1.

    true
    
    globals?: boolean

    Register apis globally

    false
    
    globalSetup?: string | string[]

    Path to global setup files

    headless?: boolean

    enable headless mode

    process.env.CI
    
    hideSkippedTests?: boolean

    Hide logs for skipped tests

    false
    
    hookTimeout?: number

    Default timeout of a hook in milliseconds

    10000
    
    include?: string[]

    A list of glob patterns that match your test files.

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

    Include globs for in-source test files

    []
    
    includeTaskLocation?: boolean

    Include "location" property inside the test definition

    false
    
    inspector?: {
        enabled?: boolean;
        host?: string;
        port?: number;
        waitForDebugger?: boolean;
    }

    Inspector options. If --inspect or --inspect-brk is enabled, these options will be passed to the inspector.

    Type Declaration

    • Optionalenabled?: boolean

      Enable inspector

    • Optionalhost?: string

      Host to run inspector on

    • Optionalport?: number

      Port to run inspector on

    • OptionalwaitForDebugger?: boolean

      Wait for debugger to connect before running tests

    isolate?: boolean

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

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

    true
    
    locators?: { testIdAttribute?: string }

    Locator options

    Type Declaration

    • OptionaltestIdAttribute?: string

      Attribute used to locate elements by test id

      'data-testid'
      
    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.

    5
    
    maxWorkers?: string | number

    Maximum number or percentage of workers to run tests in.

    mockReset?: boolean

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

    false
    
    mode?: string
    name?: string
    onUnhandledError?: OnUnhandledErrorCallback

    A callback that can return false to ignore an unhandled error

    printConsoleTrace?: boolean

    Always print console stack traces.

    false
    

    Options for projects

    Define variables that will be returned from inject in the test environment.

    // vitest.config.ts
    export default defineConfig({
    test: {
    provide: {
    someKey: 'someValue'
    }
    }
    })
    // test file
    import { inject } from 'vitest'
    const value = inject('someKey') // 'someValue'
    provider?: BrowserProviderOption<object>
    restoreMocks?: boolean

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

    false
    

    Retry configuration for tests.

    • If a number, specifies how many times to retry failed tests
    • If an object, allows fine-grained retry control

    ⚠️ WARNING: Function form is NOT supported in a config file because configurations are serialized when passed to worker threads. Use the function form only in test files directly.

    0 // Don't retry
    
    screenshotDirectory?: string

    Directory where screenshots will be saved when page.screenshot() is called If not set, all screenshots are saved to screenshots directory in the same folder as the test file. If this is set, it will be resolved relative to the project root.

    __screenshots__
    
    screenshotFailures?: boolean

    Should Vitest take screenshots if the test fails

    !browser.ui
    
    sequencer?: Omit<SequenceOptions, "sequencer" | "seed">
    setupFiles?: string | string[]

    Path to setup files

    snapshotEnvironment?: string

    Path to a custom snapshot environment module that has a default export of SnapshotEnvironment object.

    snapshotSerializers?: string[]

    Paths to snapshot serializer modules.

    strictTags?: boolean

    Should Vitest throw an error if test has a tag that is not defined in the config.

    true
    

    Define tags available in your test files.

    If test defines a tag that is not listed here, an error will be thrown.

    testerHtmlPath?: string

    Path to the index.html file that will be used to run tests.

    testTimeout?: number

    Default timeout of a test in milliseconds

    5000
    
    unstubEnvs?: boolean

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

    false
    
    unstubGlobals?: boolean

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

    false
    
    viewport?: { height: number; width: number }

    Default viewport size

    Type Declaration

    • height: number

      Height of the viewport

      896
      
    • width: number

      Width of the viewport

      414
      
    vmMemoryLimit?: string | number

    Specifies the memory limit for worker_thread or child_process before they are recycled. If you see memory leaks, try to tinker this value.