Skip to content

Which Vitest version fits this toolchain, and what replaces each Jest feature the suite uses #286

Closed

Description

@jtklein-agents

Question

Which Vitest version works with Vite 8, electron-vite 6 and Node 22 under Yarn 1, and does it need its own config file or can it read electron.vite.config.js? For each Jest feature this suite uses, what is the Vitest replacement and where does behaviour differ: jest.fn, jest.spyOn, jest.mock (hoisting), jest.isolateModules, jest.restoreAllMocks, moduleNameMapper (electron, @sentry/electron/renderer, .css), setupFiles and setupFilesAfterEnv, transformIgnorePatterns for d3-array, the jsdom environment, and require() in 14 test files. Sources: jest.config.js, jest/, the Vitest docs and migration guide.

Activity

  1. added
    wayfinder:research
    on Nov 22, 2026
  2. jtklein-agents commented on Nov 22, 2026

    @jtklein-agents
    OwnerAuthor

    Resolution

    Full findings, with sources: docs/research/vitest-fit.md on research/vitest-fit. The branch is throwaway and is never merged. Nothing was installed or run.

    Version. Use vitest@^5.1.1 (npm latest). Its engines.node is ^22.12.0 || ^24.0.0 || >=26.0.0 and its vite peer is ^6.4.0 || ^7.0.0 || ^8.0.0, so it fits Node 22.18 (.nvmrc), Node 24 (CI) and Vite 8.3.7. vite is a required peer in v5 and Yarn does not install peers; it is already a direct dev dependency here. Add jsdom@^29.1.1: jsdom 30 and 31 need Node ^22.22.2, which .nvmrc 22.18.0 does not meet. Fallback is vitest@4.1.12.

    Config file. Vitest cannot read electron.vite.config.js. It looks only for vitest.config.*, then vite.config.*, in the root. The electron-vite file exports { main, preload, renderer }, not one Vite config. A root vitest.config.* is needed; it copies the one filenamify alias from the renderer block.

    Jest feature Vitest replacement Behaviour difference
    Globals (it, expect, jest) globals: true, or imports from vitest Off by default. Global types need "types": ["vitest/globals"].
    jest.fn (96) vi.fn None for this suite (mockReset differs; not used).
    jest.spyOn (21) vi.spyOn None.
    jest.restoreAllMocks (1) vi.restoreAllMocks Restores spyOn spies only. The one site is unaffected.
    jest.mock (2) vi.mock, top level only Hoisted, but works only with import, not require. Factory returns every export; default needs a default key. Nested call throws in v5.
    jest.isolateModules (4) None: vi.resetModules() + await import() Async. Clears the whole registry. Top-level imports are not re-evaluated.
    moduleNameMapper electron, @sentry/electron/renderer test.alias Applies to import in the repo's own source only. Not to require, not inside node_modules.
    moduleNameMapper .css Nothing CSS is replaced with an empty string by default.
    setupFiles + setupFilesAfterEnv test.setupFiles, one ordered list Hooks are allowed there. Exports are ignored.
    transform (babel-jest) Nothing Vite's Oxc handles ts, jsx, tsx. Babel goes.
    transformIgnorePatterns (d3-array) Nothing node_modules is loaded by Node; d3-array is "type": "module".
    testEnvironment: 'jsdom' environment: 'jsdom' + jsdom package Default is node. Node globals stay visible next to the DOM ones.
    roots, testMatch test.include Scope it to src and e2e/helpers.
    require() (14 files) import / await import(); createRequire for true CommonJS require exists but leaves Vite: no transform, no alias, no mocks, no TypeScript.
    beforeEach( () => stubBridge() ) (2) Wrap the body in braces A returned value is treated as a teardown function.

    Of the 14 require files: 5 must change (getActiveState, and the 4 isolateModules files), 5 work as they are, 4 (e2e/helpers) load CommonJS helpers that stay CommonJS.

    Open risks for the spike

    1. The electron alias does not reach electron-log and electron-store, which require( 'electron' ) themselves. src/main/updates.test.js is the first test that can show it.
    2. Vitest's jsdom keeps Node's setImmediate. docs/agents/checks.md says React's scheduler then races jsdom teardown.
    3. clearMocks defaults to true in v5. Set clearMocks: false to match Jest.
    4. jsdom jumps from 16 to 29.
    5. jest/mobxActionWarning.js is a setup file and is also imported by a test; both must see one module instance.
    6. Not verified that Oxc picks jsx: "react-jsx" and define-semantics class fields from tsconfig.json. If not, add @vitejs/plugin-react (already installed) to the Vitest config.
    7. The map says 67 test files under src/; a count finds 62.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

wayfinder:research

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions