Vitest Team Releases Version 4.0 with Stable Browser Mode and Visual Regression Testing
Briefly

Vitest Team Releases Version 4.0 with Stable Browser Mode and Visual Regression Testing
"A significant new feature in Vitest 4.0 is the stabilization of Browser Mode, which has been in experimental status since earlier versions. This feature allows developers to run tests in real browsers rather than simulated environments like jsdom or happy-dom, providing more accurate testing results. To use Browser Mode, developers now need to install separate provider packages such as @vitest/browser-playwright, @vitest/browser-webdriverio, or @vitest/browser-preview. This change simplifies working with custom options and eliminates the need for TypeScript reference directives."
"Visual regression testing in Vitest 4.0 can be accomplished through the toMatchScreenshot assertion. Vitest captures screenshots of UI components and pages, then compares them against reference images to detect unintended visual changes. Alongside this feature, Vitest introduces a toBeInViewport matcher that allows developers to check if an element is currently in the viewport using the IntersectionObserver API. Vitest 4.0 supports generating Playwright Traces for browser tests."
Vitest 4.0 stabilizes Browser Mode to enable running tests in real browsers instead of jsdom or happy-dom, improving test accuracy. Browser Mode now requires installing provider packages like @vitest/browser-playwright, @vitest/browser-webdriverio, or @vitest/browser-preview. The context import location changes from @vitest/browser/context to vitest/browser while the old path remains functional until the next major release. Visual regression testing is provided via the toMatchScreenshot assertion and a new toBeInViewport matcher uses the IntersectionObserver API. Playwright Traces can be generated for browser tests by enabling the trace option in test.browser or passing the browser.trace flag. The release includes breaking changes that require reviewing the migration path before upgrading.
Read at InfoQ
Unable to calculate read time
[
|
]