Vitest 4.1 is out!
This release page lists all changes made to the project during the 4.1 beta. To get a review of all the new features, read our blog post.
🚀 Features
- Return a disposable from doMock() - by @kirkwaiblinger in #9332 (e3e65)
- Added chai style assertions - by @ronnakamoto and @sheremet-va in #8842 (841df)
- Update to sinon/fake-timers v15 and add
setTickModeto timer controls - by @atscott and @sheremet-va in #8726 (4b480) - Expose matcher types - by @sheremet-va in #9448 (3e4b9)
- Add
toTestSpecificationto reported tasks - by @sheremet-va in #9464 (1a470) - Show a warning if
vi.mockorvi.hoistedare declared outside of top level of the module - by @sheremet-va in #9387 (5db54) - Track and display expectedly failed tests (.fails) in UI and CLI - by @Copilot, sheremet-va and @sheremet-va in #9476 (77d75)
- Support tags - by @sheremet-va in #9478 (de7c8)
- Implement
aroundEachandaroundAllhooks - by @sheremet-va in #9450 (2a8cb) - Stabilize experimental features - by @sheremet-va in #9529 (b5fd2)
- Accept
neworallin--updateflag - by @sheremet-va in #9543 (a5acf) - Support
metain test options - by @sheremet-va in #9535 (7d622) - Support type inference with a new
test.extendsyntax - by @sheremet-va in #9550 (e5385) - Support vite 8 beta, fix type issues in the config with different vite versions - by @sheremet-va in #9587 (99028)
- Add assertion helper to hide internal stack traces - by @hi-ogawa and Claude Opus 4.6 in #9594 (eeb0a)
- Store failure screenshots using artifacts API - by @macarie in #9588 (24603)
- Allow
vitest listto statically collect tests instead of running files to collect them - by @sheremet-va in #9630 (7a8e7) - Add
--detect-async-leaks- by @AriPerkkio in #9528 (c594d) - Implement
mockThrowandmockThrowOnce- by @thor-juhasz and @sheremet-va in #9512 (61917) - Support
update: "none"and add docs about snapshots behavior on CI - by @hi-ogawa in #9700 (05f18) - Support playwright
launchOptionswithconnectOptions- by @hi-ogawa in #9702 (f0ff1) - Add
page/locator.markAPI to enhance playwright trace - by @hi-ogawa in #9652 (d0ee5) - api:
- Support tests starting or ending with
testinexperimental_parseSpecification- by @jgillick and Jeremy Gillick in #9235 (2f367) - Add filters to
createSpecification- by @sheremet-va in #9336 (c8e6c) - Expose
runTestFilesas alternative torunTestSpecifications- by @sheremet-va in #9443 (43d76) - Add
allowWriteandallowExecoptions toapi- by @sheremet-va in #9350 (20e00) - Allow passing down test cases to
toTestSpecification- by @sheremet-va in #9627 (6f17d)
- Support tests starting or ending with
- browser:
- Add
userEvent.wheelAPI - by @macarie in #9188 (66080) - Add
filterNodeoption to prettyDOM for filtering browser assertion error output - by @Copilot, sheremet-va and @sheremet-va in #9475 (d3220) - Support playwright persistent context - by @hi-ogawa, Claude Opus 4.6 and @sheremet-va in #9229 (f865d)
- Added
detailsPanelPositionoption and button - by @shairez in #9525 (c8a31) - Use BlazeDiff instead of pixelmatch - by @macarie in #9514 (30936)
- Add
findElementand enable strict mode in webdriverio and preview - by @sheremet-va in #9677 (c3f37)
- Add
- cli:
- Add @bomb.sh/tab completions - by @AmirSa12 and @sheremet-va in #8639 (200f3)
- coverage:
- Support
ignore start/stopignore hints - by @AriPerkkio in #9204 (e59c9) - Add
coverage.changedoption to report only changed files - by @kykim00 and @AriPerkkio in #9521 (1d939)
- Support
- experimental:
- Add
onModuleRunnerhook toworker.init- by @sheremet-va in #9286 (e977f) - Option to disable the module runner - by @sheremet-va and @AriPerkkio in #9210 (9be61)
- Add
importDurations: { limit, print }options - by @hi-ogawa, Claude Opus 4.6 and @sheremet-va in #9401 (7e10f) - Add print and fail thresholds for
importDurations- by @hi-ogawa and Claude Opus 4.6 in #9533 (3f7a5)
- Add
- fixtures:
- Pass down file context to
beforeAll/afterAll- by @sheremet-va in #9572 (c8339)
- Pass down file context to
- reporters:
- runner:
- Enhance
retryoptions - by @MazenSamehR, Matan Shavit, @AriPerkkio and @sheremet-va in #9370 (9e4cf)
- Enhance
- ui:
- vitest:
🐞 Bug Fixes
- Deprecate several vitest/* entry points - by @sheremet-va in #9347 (fd459)
- Use
meta.urlincreateRequire- by @sheremet-va in #9441 (e3422) - Preact browser mode init example of render function not async - by @WuMingDao in #9375 (2bea5)
- Deprecate unused types in matcher context - by @sheremet-va in #9449 (20f87)
- Handle
external/noExternalduringconfigEnvironmenthook - by @hi-ogawa and Claude Opus 4.6 in #9508 (59ea2) - Replace default ssr environment runner with Vitest server module runner - by @hi-ogawa and Claude Opus 4.6 in #9506 (cd5db)
- Propagate experimental CLI options to child projects - by @hi-ogawa and Claude Opus 4.6 in #9531 (b624f)
- Show a warning when
browser.isolateis used - by @sheremet-va in #9410 (3d48e) - Fix
vi.mock({ spy: true })node v8 coverage - by @hi-ogawa, hi-ogawa and Claude Opus 4.6 in #9541 (687b6) - Don't show internal ssr handler in errors - by @sheremet-va in #9547 (76c43)
- Close vitest if it failed to start - by @sheremet-va in #9573 (728ba)
- Fix ssr environment runner in project - by @hi-ogawa in #9584 (09006)
- Trim trailing white spaces in code block - by @hi-ogawa in #9591 (f78be)
- Support inline snapshot inside test.for/each - by @hi-ogawa in #9590 (615fd)
- Apply source maps for external module stack trace - by @hi-ogawa in #9152 (79e20)
- Remove the
.namefrom statically collected test - by @sheremet-va in #9596 (b66ff) - Don't suppress warnings on pnp - by @sheremet-va in #9602 (89cbd)
- Support snapshot with
expect.soft- by @iumehara, @hi-ogawa and Claude Opus 4.6 in #9231 (3eb2c) - Log seed when only
sequence.shuffle.testsis enabled - by @kaigritun, Kai Gritun and @sheremet-va in #9576 (8182b) - Externalize
expect/src/utilsfromvitest- by @hi-ogawa in #9616 (48739) - Ignore test.override during static collection - by @sheremet-va in #9620 (09174)
- Increase stacktrace limit for
--detect-async-leaks- by @AriPerkkio in #9638 (9fd4c) - Hanging-reporter link in cli - by @flx-sta in #9649 (7c103)
- Fix teardown timeout of
aroundEach/Allwhen inneraroundEach/Allthrows - by @hi-ogawa in #9657 (4ec6c) - Fix ui mode / html reporter and coverage integration - by @hi-ogawa and Claude Opus 4.6 in #9626 (86fad)
- Don't continue when
aroundEach/Allsetup timed out - by @hi-ogawa in #9670 (bb013) - Align
VitestRunnerConfigoptional fields withSerializedConfig- by @hi-ogawa in #9661 (79520) - Handle Symbol values in format utility - by @nami8824 in #9658 (0583f)
- Deprecate
toBe*spy assertions in favor oftoHaveBeen*(andtoThrowError) - by @sheremet-va in #9665 (4d390) - Don't propagate nested
aroundEach/Allerrors but aggregate them on runner - by @hi-ogawa in #9673 (b6365) - Show a better error if there is a pending dynamic import - by @sheremet-va in #9676 (7ef5c)
- Preserve stack trace of
resolves/rejectschained assertion error - by @hi-ogawa in #9679 (c6151) - Handle module-sync condition in vmThreads/vmForks require - by @lesleh in #9650 and #9651 (bb203)
- Hooks should respect
maxConcurrency- by @hi-ogawa in #9653 (16d13) - Recursively autospy module object - by @hi-ogawa in #9687 (695a8)
- Remove trailing spaces from diff error log - by @hi-ogawa and @sheremet-va in #9680 (395d1)
- Respect project
resolve.conditionsfor externals - by @hi-ogawa in #9717 (1d498) - Use object for WeakMap instead of a symbol to support webcontainers - by @sheremet-va in #9731 (c5225)
- Fix re-mocking virtual module - by @hi-ogawa in #9748 (3cbbb)
- Cancelling should stop current test immediately - by @AriPerkkio in #9729 (0cb2f)
- Make
mockObjectchange backwards compatible - by @sheremet-va in #9744 (84c69) - Fix
URL.nameon jsdom - by @hi-ogawa in #9767 (031f3) - Save and restore module graph in blob reporter - by @hi-ogawa in #9740 (84355)
- Don't silence reporter errors from test runtime events handler in normal run and --merge-reports - by @hi-ogawa in #9727 (4072d)
- Fix
vi.importActual()for virtual modules - by @hi-ogawa and Claude Opus 4.6 in #9772 (1e89e) - Throw
FixtureAccessErrorif suite hook accesses undefined fixture - by @sheremet-va in #9786 (fc2ce) - Allow hyphens in project config file name pattern - by @Koutaro-Hanabusa and @hi-ogawa in #9760 (33e96)
- Manual and redirect mock shouldn't
loadortransformoriginal module - by @hi-ogawa and Claude Opus 4.6 in #9774 (a8216) hideSkippedTestsshould not hidetest.todo- by @oilater in #9562 and #9781 (8181e)- Allow catch/finally for async assertion - by @hi-ogawa in #9827 (031f0)
- Resolve fixture overrides from test's suite in
beforeEachhooks - by @hi-ogawa and Claude Opus 4.6 in #9826 (99e52) - Use isAgent check, not just TTY, for watch mode - by @sheremet-va in #9841 (c3cac)
- Use
performance.nowto measure test timeout duration - by @hi-ogawa and Claude Opus 4.6 in #9795 (f48a6) - Correctly identify concurrent test during static analysis - by @sheremet-va in #9846 (1de0a)
- browser:
- Avoid updating screenshots when
toMatchScreenshotpasses - by @macarie in #9289 (46aab) - Hide injected data-testid attributes - by @sheremet-va in #9503 (c8d2c)
- Throw an error if iframe was reloaded - by @sheremet-va in #9516 (73a81)
- Encode projectName in browser client URL - by @dkkim0122 in #9523 (5b164)
- Don't take failure screenshot if tests have artifacts created by
toMatchScreenshot- by @macarie in #9552 (83ca0) - Remove
--remote-debugging-addressfrom chrome args - by @hi-ogawa and @AriPerkkio in #9712 (f09bb) - Make sure userEvent actions support
ensureAwaited- by @sheremet-va in #9732 (97685) - Types of
getCDPSessionandcdp()- by @AriPerkkio in #9716 (689a2) - Skip esbuild.legalComments when using rolldown-vite - by @Copilot, hi-ogawa and @hi-ogawa in #9803 (3505f)
- Avoid updating screenshots when
- chai:
- Don't allow
deepEqualin the config because it's not serializable - by @sheremet-va in #9666 (9ee99)
- Don't allow
- coverage:
- Infer transform mode for uncovered files - by @AriPerkkio in #9435 (f3967)
thresholds.autoUpdateto preserve ending whitespace - by @AriPerkkio in #9436 (7e534)
- deps:
- docs:
- Fix old
/config/#optionhash links causing hydration errors - by @hi-ogawa, Claude Opus 4.6 and @sheremet-va in #9610 (a603c)
- Fix old
- expect:
toMatchObject(Map/Set)should expectMap/Seton left hand side - by @hi-ogawa and Claude Opus 4.6 in #9532 (381da)- Fix objectContaining with proxy - by @hi-ogawa and Claude Opus 4.6 in #9554 (7ce34)
- Support arbitrary value equality for
toThrowand make Error detection robust - by @hi-ogawa and Claude Opus 4.6 in #9570 (de215)
- mock:
- Inject helpers after hashbang if present - by @sheremet-va in #9545 (65432)
- mocker:
- Update vite's peer dependency range - by @sheremet-va in #9808 (36f9a)
- reporter:
dotreporter leaves pending tests - by @AriPerkkio in #9684 (4d793)
- runner:
- Mark repeated tests as finished on last run - by @AriPerkkio in #9707 (cc735)
- spy:
- Support deep partial in vi.mocked - by @j2h30728 in #8152 and #9493 (71cb5)
- Fallback to object accessor if descriptor's value is
undefined- by @sheremet-va in #9511 (6f181) - Throw correct errors when shorthand methods are used on a class - by @sheremet-va in #9513 (5d0fd)
- types:
bench.reportersno longer gives type errors when passing file name string paths - by @Bertie690 in #9695 (093c8)
- ui:
🏎 Performance
- pretty-format: Combine DOMElement plugins - by @sheremet-va in #9581 (da85a)