Vitest 4 to 5 upgrade checklist
Source: Migrating to Vitest 5.0 unless an item says otherwise. Items 0a-0f are the changes most likely to break a Svelte browser suite; details in config-projects.md (0a, 0b), browser-mode.md (0c), the vitest-browser-svelte bullet of the main SKILL.md (0f), assertions.md (0d), and visual-regression.md (0e).
- 0a. Inline
test.projectsinherit the root config by default (extendsdefaults totrue);extends: falseopts out. Do not repeat root plugins in a project - 0b.
sharedViteServerdefaults totrue: inline projects that don't change the Vite config share one server, and the root config's pluginconfighooks run once - 0c. Browser locators match text exactly by default;
{ exact: false }per call orbrowser.locators.exact: false - 0d.
toHaveTextContentis strict equality withoutRegExp; partial and regex matching moved totoMatchTextContent - 0e.
toMatchScreenshotreferences usebrowser.expect.toMatchScreenshot.screenshotDirectory(default__screenshots__); set it if you setbrowser.screenshotDirectory - 0f.
renderfromvitest-browser-svelte(andvitest-browser-vue) returns a promise:await render(...)
- Runtime floor: Node 22.12+, 24 or 26+ (not 23 or 25) and Vite
>=6.4. Checkpnpm view vitest@<version> engines peerDependencies, with the exact version you install, for its ranges.viteis now a peer dependency; Yarn users must add it topackage.jsonthemselves - Bump every
@vitest/*package to the same version asvitest:@vitest/browser-playwrightdeclares an exact-version peer onvitest(check withpnpm view @vitest/browser-playwright peerDependencies). Bumpvitest-browser-svelteto a release whosevitestpeer includes 5 (pnpm view "vitest-browser-svelte@>=2" version peerDependencies.vitestlists each release's peer) clearMocksistrueby default. Mock call history is cleared before every test. Calls recorded in a setup file, at module scope, or inbeforeAllare gone when the test asserts on them. AbeforeEach(() => vi.clearAllMocks())is now redundant unless the config setsclearMocks: falsevi.mock,vi.unmock,vi.hoistedmust be at the top level. Insidedescribe,test, a function, or a block they now throw (was defined outside of the module's top level scope).vi.doMock/vi.doUnmockare not hoisted and may stay anywhere- Browser automocks return
undefined. Avi.mock(path)with no factory in browser mode no longer calls the real implementation. Usevi.mock(path, { spy: true })to keep the real code while tracking calls - Class mocks keep prototype methods. Instances of
vi.fn(MyClass)now have the class's methods and passinstanceof MyClass. Tests that relied on those methods beingundefinedchange behavior -t/testNamePatternmatches the' > '-joined full name.-t 'math adds'no longer matchesdescribe('math') > test('adds'); use-t 'math > adds', a single segment, or-t 'math.*adds'expect.pollrejects on timeout. A callback or assertion that settles aftertimeoutnow fails withexpect.poll() function didn't resolve in time.(callback) orexpect.poll() assertion didn't resolve in time.(assertion). Raisetimeoutwhere the wait is legitimate. The callback receives{ signal }to cancel in-flight work- Unawaited async assertions fail the test.
expect(p).resolves…,.rejects…, andtoMatchFileSnapshotmust be awaited test.sequential,describe.sequential, and{ sequential: true }are removed. Use{ concurrent: false }toThrow('')matches any message. To assert an empty message usetoThrow(/^$/)- Assertion types take two parameters.
Assertion<string>becomesAssertion<void, string>(sync) orAssertion<Promise<void>, string>(async). Custom matchers augmentMatchers<R, T>;jest.Matchersis no longer read - Vitest formats values with
pretty-formatinstead ofloupewhen it inspects them. Snapshots or assertions that capture inspected output may need updating. Intest.each/test.fortitles, string values in$placeholders lose their quotes (case 'a1'becomescase a1), and the newtaskTitleValueFormatTruncateoption (default40) sets the length limit - Custom browser commands get a
SerializedLocator. Destructure{ selector }instead of taking a string browser.apiis ignored. Move it to the top-levelapioption.browser.isolatenow warns; use top-levelisolate- Artifacts live in
.vitest/. Attachments.vitest/attachments/, failure screenshots.vitest/attachments/failure-screenshots/, blob reports.vitest/blob/, HTML reporter.vitest/index.html(optionoutputDir, notoutputFile). Thejsonandjunitreporters now write.vitest/json/output.jsonand.vitest/junit/output.xmlinstead of stdout; a script that pipes--reporter=jsonintojqbreaks. Use the artifact file orreporters: [['json', { stdout: true }]]. Add.vitestto.gitignore - Config files are not looked up in parent directories. Running
vitestfrom a subdirectory needs--config ../vitest.config.ts, plus--dirto scope test discovery to that subdirectory - A referenced project config that declares
projectsnow becomes a container of nested projects (app (unit),app (e2e)). Vitest 4 ignored that field. The usual trap is a package config built withmergeConfig(rootConfig, …)where the root definestest.projects: it usually fails at startup withProjects definition references a non-existing file or a directory,No projects were found in "...", or a circularprojectserror. Merge a shared config withoutprojectsinstead - Fake timers and
vi.setSystemTime()now also mockTemporal.NowwhenTemporalexists on the global object (native or a global polyfill). Keep it real withvi.useFakeTimers({ toNotFake: ['Temporal'] }) - In
jsdom/happy-dom, assignments toglobalThisorwindownow reach the DOM implementation (e.g.innerWidthaffects happy-dom'smatchMedia). Custom environments:populateGlobal'soriginalsnow holds property descriptors; restore withObject.defineProperty VITEST_POOL_IDandVITEST_WORKER_IDstart at1. Custom reporters:testModule.diagnostic()exposes the 1-basedworkerIdand a newconcurrencyId- Coverage.
coverage.include/excludematch project-root-relative paths withoutcontains('src'meanssrc/**). Glob thresholds no longer inheritperFile - Benchmarks.
benchis a test-context fixture:test('sort', async ({ bench }) => { await bench('sort', fn).run() }).bench.skip/only/todo,benchmark.reporters,benchmark.outputFile,benchmark.compare/--compare,benchmark.outputJson/--outputJsonare removed. TheVitestinstancemodeis always'test' - Packages.
vitestbundles its assertions and no longer shares state with@vitest/expect: register matchers throughexpect.extendfromvitest.@vitest/runnerand@vitest/ws-clientare deprecated.@vitest/browser-webdriveriomoved to the vitest-community organization - Removed entry points.
vitest/coverage,vitest/reporters(usevitest/node);vitest/environments,vitest/snapshot(usevitest/runtime);vitest/runners,vitest/suite(useTestRunnerfromvitest);vitest/mocker(use@vitest/mocker);vitest/internal/module-runner - Programmatic API.
resolveConfigfromvitest/nodereturns the resolved Vite config; the Vitest config is on itstestproperty - Vitest UI and the browser orchestrator need the printed URL. The UI requires the
?token=URL Vitest prints;/__vitest_test__/requires itssessionId
Post-upgrade cleanup
Leftovers that still pass on Vitest 5 but are redundant or misleading:
- Explicit
extends: trueon inline projects: it is the default now, and setting it hides the duplicate-plugin warning beforeEach(() => vi.clearAllMocks())in setup files and tests, a manualmockClear()as the first line of a test (amockClear()between two steps inside one test is not redundant), andvi.clearAllMocks()right aftervi.restoreAllMocks():clearMocks: truealready does this{ exact: true }on locators: exact is the default- Comments and workarounds that name a Vitest 4.x condition ("remove once we are off Vitest 4"): re-check each one, the condition may be met
- An empty
.vitest-attachments/directory (the migration guide spells the old default.vitest-attachements/; check for both) and its.gitignoreentry: artifacts now go to.vitest/ - Old failure screenshots inside
__screenshots__/: Vitest 4 wrote them there, Vitest 5 writes them to.vitest/attachments/failure-screenshots/(migration guide), so anything left in__screenshots__/that is not a reference image is stale