Skip to content

Complete jest -> vitest migration#4197

Open
trevor-scheer wants to merge 4 commits intographql:mainfrom
trevor-scheer:trevor/jest-vitest-runner
Open

Complete jest -> vitest migration#4197
trevor-scheer wants to merge 4 commits intographql:mainfrom
trevor-scheer:trevor/jest-vitest-runner

Conversation

@trevor-scheer
Copy link
Copy Markdown
Contributor

@trevor-scheer trevor-scheer commented Apr 18, 2026

Summary

Migrates the last Jest package to vitest and removes all Jest infrastructure from the monorepo. The mechanical jest.*vi.* port was straightforward, but fetch-mock couldn't follow — vitest's mock system doesn't intercept CJS require() calls from node_modules, so jest.mock('@whatwg-node/fetch') silently stops working. Replaced fetch-mock with MSW which intercepts at the network layer.

Changes

  • Port all 10 test files from jest.* to vi.* (imports, mocks, timers, type helpers)
  • Add vitest.config.mts with clearMocks, graphql dedup alias, and graphql-language-service src alias for unbundled workspace resolution
  • Replace fetch-mock v6 with msw v2 for HTTP mocking in GraphQLCache.test and MessageProcessor.spec
  • Remove @whatwg-node/fetch, cross-env from server devDeps (only existed for the old mock setup)
  • Remove jest, ts-jest, @types/jest, @types/fetch-mock, fetch-mock, babel-plugin-macros, eslint-plugin-jest from root
  • Delete jest.config.js, jest.config.base.js, trim babel.config.js env.test block
  • Simplify root scripts: testturbo run test, test:ciyarn tsc && yarn test
  • Replace eslint-plugin-jest with eslint-plugin-vitest for test lint coverage

Necessary changes due to removing Jest

@ts-expect-error on prettier subpath imports

Several files import prettier subpaths like prettier/parser-graphql. With moduleResolution: "node", TypeScript can't resolve these because it doesn't read the exports field in package.json. Previously this worked because @types/prettier@2.6.4 (a transitive dep of jest-snapshot) provided the type declarations. With jest removed, those types are gone. The proper fix is migrating to moduleResolution: "node16" or "bundler", but that's out of scope here.

jsdom added as an explicit dependency

Six packages set environment: 'jsdom' in their vitest configs. Vitest lists jsdom as an optional peer dep, so it must be installed explicitly. It was previously available as a transitive dependency of jest (jest-environment-jsdomjsdom).

Note

The Jest Unit & Integration Tests check will need to be marked as not required in order for this to pass once it's ready to merge.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 18, 2026

⚠️ No Changeset found

Latest commit: a41e83d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@trevor-scheer trevor-scheer changed the title complete jest→vitest migration Complete jest -> vitest migration Apr 18, 2026
@trevor-scheer trevor-scheer force-pushed the trevor/jest-vitest-runner branch 9 times, most recently from d740a1c to c77cdd9 Compare April 18, 2026 21:48
@trevor-scheer trevor-scheer marked this pull request as ready for review April 18, 2026 21:52
@trevor-scheer trevor-scheer force-pushed the trevor/jest-vitest-runner branch 2 times, most recently from 8c5870b to f6f8cca Compare April 18, 2026 22:01
Comment thread package.json Outdated
"test:coverage": "yarn jest --coverage",
"test:watch": "yarn jest --watch",
"test": "turbo run test --filter='./packages/*'",
"test:ci": "yarn tsc && yarn test",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"test:ci": "yarn tsc && yarn test",
"test:ci": "yarn test",

do we really need run this script before tests?

Copy link
Copy Markdown
Collaborator

@dimaMachina dimaMachina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing improvement!

@trevor-scheer trevor-scheer force-pushed the trevor/jest-vitest-runner branch from f6f8cca to f647f1e Compare April 22, 2026 14:57
Use the dedicated vitest integration which properly extends
`expect` and augments vitest types, rather than relying on the
Jest compatibility shim. Drop `@testing-library/jest-dom` from
tsconfig `types` arrays since the `/vitest` entrypoint handles
type augmentation via its own `import 'vitest'` declaration.
@trevor-scheer trevor-scheer force-pushed the trevor/jest-vitest-runner branch from 5a3ee5c to a41e83d Compare April 22, 2026 17:23
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.

2 participants