Packages

@vitest/spy

5.0.5 · 15 Oct 2026MIT202.7M / weekRepositoryHomepagenpmAtom feed

Your version

2.0.0

major8 Jul 2024Where it was published

2.1.9 is the newest release of 2.x.

In short

20 breaking1 removed38 new63 fixed1 internal

  • breaking

    Simplify mock function generic types and align with jest - by @hi-ogawa

  • breaking

    Remove --segfault-retry

  • breaking

    Run suite hooks in a stack

  • breaking

    ⚠️ This change may cause significant differences in your coverage results compared to Vitest v1. These changes are expected as coverage reporting is now more accurate. See #5423 for more details.

  • breaking

    Add correct location and snapshot fields in json reporter

  • breaking

    Update dependency chai to v5 - by renovate[bot] and @sheremet-va in #5135

  • breaking

    Remove watchExclude

  • breaking

    Change default pool to 'forks'

Release note

Vitest 2.0 is here! This release page lists all changes made to the project during the beta. For the migration guide, please refer to the documentation.

Breaking Changes

  • breaking

    Simplify mock function generic types and align with jest - by @hi-ogawa

  • breaking

    Remove --segfault-retry

    • This flag was introduced to combat threads segfaults. Our current recommendation is to use the new default forks pool instead.

  • breaking

    Run suite hooks in a stack

    • This feels like a more sensible default. Especially with the new onTestFinished hook. This can make your tests run a little bit slower.

  • breaking

    Enable coverage.ignoreEmptyLines by default

    • ⚠️ This change may cause significant differences in your coverage results compared to Vitest v1. These changes are expected as coverage reporting is now more accurate. See #5423 for more details.

  • breaking

    Add correct location and snapshot fields in json reporter

    • Previously, the location field pointed to the error location instead of the test location. Now it is aligned with jest and contains the line and column of a test function, but requires includeTaskLocation to be enabled.

  • breaking

    Update dependency chai to v5 - by renovate[bot] and @sheremet-va in #5135

  • breaking

    Remove watchExclude

  • breaking

    Change default pool to 'forks'

  • breaking

    --merge-reports to support coverage

  • breaking

    Add promise-based return assertions, do not auto-resolve returned promises

    • ⚠️ Vitest no longer unwraps promises in spy.mock.returns. If the function is async or returns a promise, it will always succeed and have a Promise in results. To make migration easier, we introduced spy.mock.settledResults that unwraps promises and expect().toHaveResolved() matcher that accepts unwrapped value.

  • breaking

    Do not exit process if global setup has failed

  • breaking

    Don't exit process if config failed

  • breaking

    Add meta to json output

  • breaking

    Rename indexScripts to orchestratorScripts in the browser config

  • breaking

    Add "vitest list" API to print collected tests without running them

    • ⚠️ This changes the custom pool API - now requires collectTests method alongside runTests.

  • breaking

    Remove the empty suite from the runner

  • breaking

    Support concurrent suites - by @hi-ogawa

  • breaking

    Support overriding exclude in coverage

    • ⚠️ Vitest coverage no longer adds test files to exclude patterns if coverage.exclude was overridden in the config. Add your test patterns manually, or merge your overrides with default ones: ['**/my-pattern.js', ...coverageConfigDefaults.exclude]. See vitest.dev/config/ for an example.

  • breaking

    api: Remove process.exit if workspace project failed to be created

  • breaking

    api: Don't call process.exit manually

Features

  • browser: 🌐 This release lays the groundwork for the next iteration of Vitest Browser Mode. You can read more about our future plans at github.com/vitest-dev/vitest/discussions/5828

  • browser: Add commands to communicate betweens server and the browser

  • browser: Do not reload the page during watch mode

  • browser: Support changing the viewport

  • browser: Add browser iframe mouse interaction

  • browser: Support click event

  • browser: Rename none provider to preview, make it default

  • browser: Run tests in parallel in headless mode, add page.screenshot method

  • browser: Implement several userEvent methods, add fill and dragAndDrop events

  • browser: Introduce expect.dom method and bundle jest-dom matchers with @vitest/browser

  • browser: Expose CDP in the browser

  • browser: Add "init" command for browser tests

  • browser: Add an option to take screenshots if the browser test fails

  • browser: Add tripleClick to interactive api

  • browser: Playwright provider doesn't allow resizing the browser viewport

  • Pretty print diffs coming from cause

  • Allow import statement as vi.mock path for better IDE support

  • removed

    Remove deprecated options

  • Add blob reporter

    • ✅ Run Vitest in separate processes with --reporter=blob flag to generate reports and combine them with vitest --merge-reports later!

  • Add expect.poll utility

  • Add browser.ui option

  • Add median to --output-json

  • Allow augmenting config.test.env

  • Implement module mocking in browser mode

  • Allow configuring expect options in the config

  • Add an option to print console stack trace

  • Add browser frame to UI

  • Image type add bmp - by btea in #5921

  • Add an option to return base64 from page.screenshot

  • Expose parseAst, parseAstAsync from vite

  • config: Allow percentage value for workers option

  • runner: Implement test.for

  • spy: Collect mock.contexts

  • ui: Render tests in a tree

  • ui: Load module graph on tab selection

  • ui: Replace navigation tree with test explorer

  • ui: Add initializing explorer logic

  • ui: Add action to explorer item to show the test/suite line in the source code tab

  • ws-client: Allow change reactive for state, filesMap and idMap

Bug Fixes

  • Print console statements in vmThreads

  • Repeatable --exclude option

  • Remove browser.fileParallelism

  • Install UI icons

  • Vi.waitFor/vi.waitUntil interval is now cleared after it times out

  • ToJSON recursive error serialization

  • Print error properties only in verbose reporter

  • Use TTY reporter when running in Deno

  • Don't override uppercase

  • Clear screen and scrollback on iTerm2

  • Include pretty-format in @vitest/runner for optimization on npm

  • Transpile esnext to node18 to support newest JS and TS features

  • api: Correct project.provide type

  • browser: Display UI

  • browser: Browser actions icons colors

  • browser: Restore the original viewport when unselecting the preset viewport

  • browser: Don't get stuck after the manual page refresh

  • browser: Use iframe id instead of calculating it from filenames

  • browser: Always clean up iframes on rerun

  • browser: Support @testing-library/vue in browser mode out of the box

  • browser: Print correct transformed module graph

  • browser: Use preview provider when running in StackBlitz

  • browser: Specify entries for correct deps optimization

  • browser: Allow iframe to load even if there is a custom CSP header

  • browser: Don't optimize Vitest dependencies

  • browser: Set server.open to false and move error handling after init

  • browser: Show correct prepare time

  • browser: Resolve coverage.reporter from string values

  • browser: Correctly update inline snapshot if changed

  • browser: Remove "util" warning

  • browser: Remove hacky retry

  • browser: Make userEvent more stable when running in parallel

  • browser: Print screenshot path alongside the test error message

  • browser: Print correct stack trace in source files

  • browser: Correctly mock optimized cjs dependencies

  • browser: Support shadow root and svg elements

  • coverage: Clean up empty coverage reports directory

  • coverage: thresholds.autoUpdate to support mergeConfig

  • coverage: Pass thresholds errors to stderr of startVitest()

  • coverage: Exclude bench files from coverage

  • coverage: Vite to ignore dynamic import of provider

  • coverage: Istanbul to support import attributes

  • coverage: Remove work-around for implicit else

  • deps: Update vulnerable test-exclude to v7

  • expect: Fix immutable.js iterable equality

  • forks: Resolve poolOptions.<name>.isolate from forks options

  • runner: Ensure inner suite { sequential: true } correctly overrides outer suite { concurrent: true }

  • runner: Ensure test.each print -0 and -NaN properly

  • snapshot: Fix toMatchFileSnapshot with empty file

  • spy: Correctly track constructor's "this" type

  • types: Mark pool options as not available in project config

  • ui: Show correct module graph and project name in a Vitest workspace

  • ui: Update running todo tests inside todo suites (each)

  • ui: FileDetails title status icon not being updated

  • ui, browser: Disable mouse events when resizing main navigation panel

  • utils: Produce valid snapshot names

  • utils: Fix color util maximum call stack error

  • utils: Package exports

  • vite-node: Expose all envs from .env file, not just with a prefix VITE_

  • vitest: Expose provide to the public API

  • vitest: Cache fs code only for forks pool

  • vitest: Allow testing unandled rejection/exception

  • vitest: Show all failed tests when rerunning a test