Skip to content

Run the tests under Vitest and remove Jest and Babel #296

Closed

Description

@jtklein-agents

Parent

#295

What to build

yarn react-test and CI run the same 471 tests in the same 66 files under Vitest, on the Vite the shell already uses. Jest, babel-jest, every direct @babel/* entry and the Babel transform are gone in the same pull request: there is never a period with two test runners. No test is converted to TypeScript here.

The spike branch 287-vitest-spike holds a working config and the file fixes. Use it as a reference only: it is never merged, and it kept ambient globals and a jest shim, which this ticket must not keep.

Decisions that shape the change:

  • Dev dependencies added: vitest@^5.1.1 and jsdom@^29.1.1, and no other package. @vitejs/plugin-react is not needed.
  • One root vitest.config.mjs: jsdom environment, one ordered setup list (bridge setup, then the MobX action-warning check), globals off, clearMocks: false, no projects, no per-file environment comments. include covers the tests under src and the e2e helper tests. Aliases: electron, the Sentry renderer entry, and the one filenamify alias from the renderer build. CSS needs no mapping.
  • jest.fn, jest.spyOn and jest.restoreAllMocks become the vi.* calls of the same name. Every test and setup file imports the names it uses from vitest, and keeps test or it, whichever it uses today.
  • The four files that use jest.isolateModules use vi.resetModules() and await import(); their tests and loader helpers become async. The one file that uses jest.mock with require uses a top-level vi.mock with its mock functions in vi.hoisted, then await import().
  • The test files that hold JSX are renamed to .jsx with no content change.
  • The support files move from jest/ to src/test/, still JavaScript, with import paths updated.

Out of scope: converting any test to TypeScript, the installBridge helper, replacing eslint-config-react-app, the Playwright specs, changes to production source.

Acceptance criteria

  • yarn react-test and yarn test run Vitest once (no watch) under their current script names, and CI's yarn react-test step runs Vitest.
  • The same 66 files and 471 tests pass. The pull request states the test count per file under Jest on master and under Vitest, and they are equal.
  • The run prints no config warning.
  • package.json has no jest, no babel-jest, no direct @babel/* entry (package.json:88-92,105,115), and no Babel resolutions pin (package.json:219). Only vitest and jsdom are added.
  • yarn.lock has no stanza that only the removed entries required. A @babel/* or *jest* stanza that eslint-config-react-app still requires stays. The pull request lists the removed names it proved absent from both files, and the names that remain with the package that requires each. Do not run a fresh install to check the lock.
  • jest.config.js, the Babel transform and the CSS file mock are deleted, and no jest/ directory remains. The !jest{,/**/*} packaging exclude (package.json:144) and the jest/setup.js assertion in the pack test (src/pack.test.js:65) are removed or updated, and the support files still stay out of the packaged app.
  • The lint scripts (package.json:54-55) no longer name jest.config.js or jest/**, and lint covers vitest.config.mjs.
  • No test or support file contains jest.; each imports what it uses from vitest. Vitest globals is off.
  • The default renderer bridge is still installed before the page store loads: store tests still import Run at the top of the file.
  • The MobX action-warning check still applies to every test, and its proof test still passes.
  • The four module-reloading tests still prove the same import-time behaviour, and the module-mocking test still mocks its module.
  • yarn react-test still fails on an empty page paint.
  • The setImmediate polyfill in the updates test is deleted (src/main/updates.test.js:4,7).
  • The react-app/jest lint preset is removed (.eslintrc.cjs:3) and nothing replaces it. The five testing-library disable comments are deleted (src/app/components/ErrorDialog.test.js:13,43, src/app/droppedFile.test.js:42, src/app/unhandledError.test.js:21, src/app/App.test.js:10).
  • yarn lint, yarn typecheck:baseline and yarn react-test pass, and nothing is added to the typecheck baseline.
  • The pull request states whether instanceof Error still fails under Vitest's jsdom for an error Node's fs throws (the CODING_STANDARDS.md rule "Catch message under Jest" depends on it).

Agent-doc edits (driving dev, main checkout, when this merges)

These files are kept out of git, so no pull request carries them. Line numbers are from master at 2044cbc.

  • AGENTS.md:5: "or Jest setup" → "or Vitest setup".
  • docs/agents/issue-tracker.md:11: "Jest setup" → "Vitest setup".
  • docs/agents/checks.md:7: "the ticket's Jest files" → "the ticket's Vitest files".
  • docs/agents/checks.md:11: "Jest loads the page without the preload, so jest/setup.js owns" → "Vitest loads the page without the preload, so src/test/setup.js owns". "Jest uses jsdom." → "Vitest uses jsdom, and its jsdom keeps Node's setImmediate; no test polyfills it." Delete the three sentences from "Main-process production code keeps bare Node globals" to "races jsdom teardown."
  • docs/agents/checks.md:13: "keeps a Jest literal" → "keeps a test literal".
  • docs/agents/checks.md:19: "Jest does not transform electron-vite, so they load" → "They load".
  • docs/agents/renderer-bridge.md:17: "a Jest test of a pure function" → "a Vitest test of a pure function". :32: "runs on Jest" → "runs on Vitest".
  • CODING_STANDARDS.md:33: jest/storeBridge.js → src/test/storeBridge.js.
  • CODING_STANDARDS.md:43-45: rename "Catch message under Jest" to "Catch message under Vitest" and replace "Jest's jsdom" with "Vitest's jsdom", if the pull request reports the realm mismatch still holds; otherwise delete the section.
  • CODING_STANDARDS.md:49: delete the two sentences about polyfilling setImmediate and the shared Jest setup.
  • CODING_STANDARDS.md: add a "Typed tests" section:
    • A test installs its bridge with installBridge from src/test/, which takes Partial<RendererBridge>. No test assigns to window.rendererBridge. stubBridge goes through the same helper.
    • Mocks are plain vi.fn(). Add a type argument only where a test reads the mock's calls or results and tsc asks for it.
    • A partial store stand-in is cast where it is used. No shared fixture builders.
    • No @ts-nocheck and no @ts-ignore in a test. @ts-expect-error with a one-line reason is allowed only where a test passes a wrong type on purpose to exercise a runtime guard.
    • Every test imports test or it, expect and vi from vitest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions