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 };
            };
        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;
            openTelemetry?: { enabled: boolean; sdkPath?: string };
            printImportBreakdown?: 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?: number;
        screenshotDirectory?: string;
        screenshotFailures?: boolean;
        sequencer?: Omit<SequenceOptions, "sequencer" | "seed">;
        setupFiles?: string | string[];
        snapshotEnvironment?: string;
        snapshotSerializers?: string[];
        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 } }
    
    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;
        openTelemetry?: { enabled: boolean; sdkPath?: string };
        printImportBreakdown?: 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
      
    • OptionalopenTelemetry?: { enabled: boolean; sdkPath?: string }
    • OptionalprintImportBreakdown?: boolean

      Show imports (top 10) that take a long time.

      Enabling this will also show a breakdown by default in UI, but you can always press a button to toggle it.

    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?: number

    Retry the test specific number of times if it fails.

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

    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.