Skip to content

Run the tests under Vitest and remove Jest and Babel - #308

Merged
jtklein-agents merged 1 commit into
spec/295-replace-jest-and-babel-with-vitest-and-convert-the-tests-to-typescriptfrom
296-run-the-tests-under-vitest-and-remove-jest-and-babel
Nov 22, 2026
Merged

jtklein-agents merged 1 commit into
spec/295-replace-jest-and-babel-with-vitest-and-convert-the-tests-to-typescriptfrom
296-run-the-tests-under-vitest-and-remove-jest-and-babel

Conversation

@jtklein-agents

Copy link
Copy Markdown
Owner

Closes #296. Part of #295.

Summary

yarn react-test, yarn test and CI's yarn react-test step now run vitest run on the Vite the shell already uses. Jest and Babel leave in the same change, so there is never a second test runner.

 package.json            # scripts: "vitest run"; +vitest +jsdom; -jest -babel-jest -5 @babel/* -Babel resolutions pin
-jest.config.js
+vitest.config.mjs       # jsdom, globals off, ordered setup, 3 aliases; linted, kept out of the packaged app
-jest/
-├── babelTransform.js
-├── fileMock.js
-├── setup.js … storeBridge.js
 src/
+├── test/               # setup.js, mobxActionWarning.js, electron.js, sentry.js, storeBridge.js (moved, still JS)
 ├── **/*.test.js        # import { expect, it, vi, … } from 'vitest'; jest.fn/spyOn/restoreAllMocks → vi.*
 └── app/{App,droppedFile,unhandledError,components/ErrorDialog}.test.jsx   # renamed: they hold JSX
 .eslintrc.cjs           # -react-app/jest

Module reloading, in bootstrap, host, provideStateReport and alignmentStore tests:

-jest.isolateModules( () => { Run = require( './Run' ).default; } );
+vi.resetModules();
+const Run = ( await import( './Run' ) ).default;

getActiveState.test.js keeps its mock: the mock functions sit in vi.hoisted, vi.mock is top-level, and the module loads with await import().

Also deleted: the setImmediate polyfill in src/main/updates.test.js and the five testing-library disable comments.

Beyond the ticket's list:

  • !vitest.config.mjs in the packaging excludes, with one assertion in src/pack.test.js. The support files stay out through the existing !src{,/**/*}; the assertion now names src/test/setup.js.
  • src/pageNodeImports.test.js skips .test.jsx as it skips .test.js, so the four renamed tests are not read as page source.
  • The // @ts-nocheck — Jest globals… reason in each test is reworded to "the test is not typed yet". The old reason was no longer true.

Evidence

  • Before (Jest, master at 2044cbc): Test Suites: 66 passed, 66 total / Tests: 471 passed, 471 total
    After (Vitest 5.1.1): Test Files 66 passed (66) / Tests 471 passed (471)
  • yarn lint, yarn typecheck:baseline and yarn react-test exit 0. scripts/typecheck-baseline.txt is unchanged.
  • The Vitest run prints no config warning. It prints electron-builder's "loaded configuration" line from the pack test and a Vitest performance hint about jsdom being created per file.
  • The MobX action-warning proof test (src/mobxActionWarning.test.js, 2 tests) passes, and src/app/App.test.jsx keeps its empty-paint assertion unchanged. I did not mutate the page to watch that assertion fail.

instanceof Error under Vitest's jsdom: it no longer fails. A probe test caught the error from fs.readFileSync( '/nope/nope' ) and got caught instanceof Error === true; typeof setImmediate is 'function'. The realm mismatch behind the CODING_STANDARDS.md rule "Catch message under Jest" does not hold under Vitest. The no-restricted-syntax rule in .eslintrc.cjs that cites the same mismatch is untouched here.

yarn.lock

  • Absent from package.json and yarn.lock: jest, babel-jest, every @jest/* and every jest-* name, babel-plugin-jest-hoist, babel-preset-jest, babel-plugin-istanbul. 133 names left the lock in all (list below).
  • Removed from package.json, still in yarn.lock because eslint-config-react-app requires them: @babel/plugin-proposal-class-properties, @babel/plugin-proposal-private-property-in-object, @babel/plugin-transform-react-jsx, @babel/preset-env, @babel/preset-typescript.
  • The other remaining @babel/* stanzas: 107 reached only from eslint-config-react-app; @babel/core and its helpers also from @vitejs/plugin-react and electron-vite; @babel/parser, traverse, types, generator, template, code-frame also from @emotion/*; @babel/runtime also from @emotion/* and @mui/*; @babel/plugin-transform-react-jsx-self and -source from @vitejs/plugin-react.
  • The one remaining *jest* stanza is eslint-plugin-jest, required by eslint-config-react-app.
  • The lock was rewritten by yarn remove and yarn add, and checked by walking the lock's dependency graph from the direct dependencies. No fresh install.
133 names removed from yarn.lock

@babel/plugin-bugfix-safari-rest-destructuring-rhs-array @babel/plugin-syntax-bigint @babel/plugin-transform-explicit-resource-management @babel/plugin-transform-regexp-modifiers @bcoe/v8-coverage @istanbuljs/load-nyc-config @istanbuljs/schema @jest/console @jest/core @jest/environment @jest/fake-timers @jest/globals @jest/reporters @jest/source-map @jest/test-result @jest/test-sequencer @jest/transform @jest/types @sinonjs/commons @sinonjs/fake-timers @types/graceful-fs @types/istanbul-lib-coverage @types/istanbul-lib-report @types/istanbul-reports @types/prettier @types/stack-utils @types/yargs @types/yargs-parser abab acorn-globals acorn-walk ansi-escapes anymatch babel-jest babel-plugin-istanbul babel-plugin-jest-hoist babel-preset-current-node-syntax babel-preset-jest browser-process-hrtime bser camelcase char-regex cjs-module-lexer co collect-v8-coverage cssom cssstyle dedent detect-newline diff-sequences domexception emittery escodegen esprima execa exit expect fb-watchman get-package-type html-escaper human-signals import-local is-generator-fn istanbul-lib-coverage istanbul-lib-instrument istanbul-lib-report istanbul-lib-source-maps istanbul-reports jest jest-changed-files jest-circus jest-cli jest-config jest-diff jest-docblock jest-each jest-environment-jsdom jest-environment-node jest-get-type jest-haste-map jest-jasmine2 jest-leak-detector jest-matcher-utils jest-message-util jest-mock jest-pnp-resolver jest-regex-util jest-resolve jest-resolve-dependencies jest-runner jest-runtime jest-serializer jest-snapshot jest-util jest-validate jest-watcher jest-worker kleur leven makeerror merge-stream node-int64 normalize-path npm-run-path nwsapi pirates pkg-dir pretty-format prompts querystringify regjsgen requires-port resolve-cwd resolve.exports sisteransi sprintf-js stack-utils string-length strip-final-newline supports-hyperlinks terminal-link test-exclude throat tmpl type-detect typedarray-to-buffer url-parse v8-to-istanbul w3c-hr-time walker whatwg-encoding write-file-atomic ws

Test count per file: 66 files, 471 tests, equal under both runners
File Jest (master) Vitest
e2e/helpers/modeltestOutcome.test.js 7 7
e2e/helpers/newick.test.js 6 6
e2e/helpers/raxmlHpcOutcome.test.js 2 2
e2e/helpers/raxmlNgOutcome.test.js 2 2
src/app/App.test.jsx 1 1
src/app/bootstrap.test.js 2 2
src/app/components/ErrorDialog.test.jsx 3 3
src/app/droppedFile.test.jsx 1 1
src/app/paths.test.js 2 2
src/app/promisedComputed.test.js 1 1
src/app/report.test.js 2 2
src/app/store/AlignmentOptions.test.js 22 22
src/app/store/InputFile.test.js 11 11
src/app/store/Option.test.js 7 7
src/app/store/OutGroup.test.js 8 8
src/app/store/Part.test.js 37 37
src/app/store/Partition.test.js 20 20
src/app/store/Run.computeds.test.js 29 29
src/app/store/RunList.test.js 20 20
src/app/store/RunSimpleOptions.test.js 32 32
src/app/store/alignmentStore.test.js 38 38
src/app/store/astral.test.js 2 2
src/app/store/cancelRun.test.js 2 2
src/app/store/checkOutputName.test.js 1 1
src/app/store/citationConfig.test.js 12 12
src/app/store/finalAlignment.test.js 13 13
src/app/store/host.test.js 3 3
src/app/store/loadAlignment.test.js 3 3
src/app/store/loadAstralTree.test.js 3 3
src/app/store/loadPartitionFile.test.js 3 3
src/app/store/loadTree.test.js 3 3
src/app/store/menu.test.js 2 2
src/app/store/modelSelection.test.js 4 4
src/app/store/openPath.test.js 2 2
src/app/store/pageStoreGaps.test.js 5 5
src/app/store/parseAlignment.test.js 4 4
src/app/store/provideStateReport.test.js 1 1
src/app/store/readText.test.js 1 1
src/app/store/runInputActions.test.js 26 26
src/app/store/runLifecycle.test.js 17 17
src/app/store/selectOutputDir.test.js 3 3
src/app/store/showItemInFolder.test.js 2 2
src/app/store/startRun.test.js 3 3
src/app/store/substitutionOptions.test.js 15 15
src/app/store/treeFileOptions.test.js 27 27
src/app/store/version.test.js 1 1
src/app/store/writeConcatenatedAlignment.test.js 1 1
src/app/unhandledError.test.jsx 1 1
src/main/cancelRun.test.js 6 6
src/main/checkOutput.test.js 3 3
src/main/debugInfo.test.js 1 1
src/main/getActiveState.test.js 1 1
src/main/pageWindowPreferences.test.js 1 1
src/main/parseAlignment.test.js 7 7
src/main/selectAlignment.test.js 3 3
src/main/selectAstralFile.test.js 3 3
src/main/selectOutputDir.test.js 3 3
src/main/selectPartitionFile.test.js 3 3
src/main/selectTree.test.js 3 3
src/main/updates.test.js 6 6
src/mobxActionWarning.test.js 2 2
src/pack.test.js 2 2
src/pageNodeImports.test.js 2 2
src/preload.test.js 2 2
src/sourceMaps.test.js 3 3
src/typecheckBaseline.test.js 7 7

Merge Danger

Door: two-way

Reverting the commit restores Jest and the old lock. It merges into the spec's feature branch, not master.

Blast Radius: tooling

No production source changes. Two things to know:

  • yarn lint still exits 0 but now prints a babel-preset-react-app notice. Without the removed resolutions pin, @babel/plugin-proposal-private-property-in-object resolves to the preset-env placeholder. Keeping the pin would silence it, against the ticket.
  • The agent docs that name Jest and jest/setup.js are outside git; the ticket lists those edits for the main checkout after merge.

🤖 Generated with Claude Code

yarn react-test and yarn test now run `vitest run` on the Vite the shell
already uses. Jest, babel-jest, every direct @babel/* entry, the Babel
resolutions pin, jest.config.js, the Babel transform and the CSS file
mock are gone. Only vitest and jsdom are added.

- One root vitest.config.mjs: jsdom, globals off, ordered setup (bridge,
  then the MobX action-warning check), aliases for electron, the Sentry
  renderer entry and filenamify.
- Support files move from jest/ to src/test/.
- Every test and support file imports what it uses from vitest;
  jest.fn/spyOn/restoreAllMocks become the vi.* calls.
- The four jest.isolateModules files use vi.resetModules() and
  await import(); getActiveState uses vi.hoisted with a top-level vi.mock.
- The four tests that hold JSX are renamed to .jsx, and the page
  Node-import scan skips .test.jsx as it skips .test.js.
- The setImmediate polyfill, the react-app/jest lint preset and the five
  testing-library disable comments are deleted.
- vitest.config.mjs is excluded from the packaged app, with a pack-test
  assertion.

Same 66 files and 471 tests pass, with equal per-file counts under Jest
on master and under Vitest.

Notes for the pull request:
- Under Vitest's jsdom, `instanceof Error` is true for an error Node's fs
  throws, and Node's setImmediate is present. The realm mismatch behind
  "Catch message under Jest" no longer holds.
- yarn lint exits 0 but now prints a babel-preset-react-app notice:
  without the removed resolutions pin,
  @babel/plugin-proposal-private-property-in-object resolves to the
  preset-env placeholder.
- yarn.lock: jest, babel-jest, every @jest/* and jest-* stanza are gone
  (133 names removed in all). Remaining @babel/* stanzas are required by
  eslint-config-react-app, @vitejs/plugin-react, electron-vite, @emotion
  or @mui; eslint-plugin-jest stays for eslint-config-react-app.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jtklein-agents
jtklein-agents merged commit dca2548 into spec/295-replace-jest-and-babel-with-vitest-and-convert-the-tests-to-typescript Nov 22, 2026
9 checks passed
@jtklein-agents
jtklein-agents deleted the 296-run-the-tests-under-vitest-and-remove-jest-and-babel branch November 22, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant