feat(FR-2609): Vitest migration for react/ (100% pass, 856/856 tests)#6874
Merged
graphite-app[bot] merged 1 commit intomainfrom Apr 30, 2026
Conversation
3 tasks
This was referenced Apr 22, 2026
Contributor
Author
3 tasks
This was referenced Apr 22, 2026
Merged
Contributor
Coverage report for
|
This was referenced Apr 27, 2026
21142d6 to
f2d5ec5
Compare
This was referenced Apr 27, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates the react/ workspace test runner from Jest to Vitest while keeping the existing test suite largely intact, including React Compiler + Relay Babel transforms to match the app’s runtime pipeline.
Changes:
- Added a dedicated
react/vitest.config.tsand a Jest-compat shim to reduce churn during the migration. - Updated numerous React workspace tests to use
vi.*APIs and Vitest semantics (timers, mocks, env stubbing). - Updated React workspace dependencies/lockfile to include Vitest + jsdom and recorded migration notes.
Reviewed changes
Copilot reviewed 30 out of 31 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| react/vitest.config.ts | Adds Vitest config, Vite/React transform pipeline, and module aliasing/mocking. |
| react/test/vitest.jest-compat.ts | Adds runtime shim exposing vi as jest for legacy call sites. |
| react/package.json | Adds vitest scripts and dependencies (vitest, jsdom). |
| react/VITE_POC_NOTES.md | Documents Vitest migration status/approach in the Vite PoC notes. |
| react/src/lib/TabCounter.test.ts | Migrates timer/mocking APIs from Jest to Vitest. |
| react/src/hooks/useWebUIConfig.test.ts | Migrates fetch mocking + mock restoration to Vitest APIs. |
| react/src/hooks/useVariantConfigs.test.ts | Migrates react-i18next mock usage + mock typing to Vitest. |
| react/src/hooks/useValidateSessionName.test.tsx | Migrates module mocking to vi.mock. |
| react/src/hooks/useValidateServiceName.test.tsx | Migrates module mocking to vi.mock. |
| react/src/hooks/useTokenizer.test.ts | Migrates tokenizer mocking/casts to Vitest mock types. |
| react/src/hooks/useScrollBreackPoint.test.tsx | Migrates spies/mocks cleanup to Vitest APIs. |
| react/src/hooks/usePrimaryColors.test.tsx | Migrates @ant-design/colors mock to Vitest. |
| react/src/hooks/useMemoWithPrevious.test.tsx | Migrates factory spies to vi.fn. |
| react/src/hooks/useLogout.test.ts | Migrates i18n mocking + spies to Vitest. |
| react/src/hooks/useLoginOrchestration.test.ts | Updates mocks for Vitest hoisting/default-export shape and constructor semantics. |
| react/src/hooks/useKeyboardShortcut.test.ts | Migrates ahooks mock + types to Vitest. |
| react/src/hooks/useHighlight.test.tsx | Migrates multiple module mocks and mock typing to Vitest. |
| react/src/hooks/useControllableState.test.ts | Migrates callback mock creation to vi.fn. |
| react/src/hooks/useBackendAIImageMetaData.test.tsx | Migrates fetch mock to vi.fn. |
| react/src/hooks/tests/useMultiStepNotification.test.tsx | Migrates helper/hook mocks and executor mocks to Vitest. |
| react/src/helper/resultTypes.test.ts | Removes @jest/globals import for Vitest globals. |
| react/src/helper/index.test.tsx | Migrates helper tests’ client method mocks to Vitest. |
| react/src/helper/customThemeConfig.test.ts | Migrates env stubbing to vi.stubEnv/vi.unstubAllEnvs and other mocks to Vitest. |
| react/src/helper/big-number.test.ts | Removes @jest/globals import for Vitest globals. |
| react/src/global-stores.test.ts | Migrates fetch mocks and fake timers to Vitest. |
| react/src/diagnostics/rules/tests/storageProxyRules.test.ts | Removes @jest/globals import for Vitest globals. |
| react/src/diagnostics/rules/tests/endpointRules.test.ts | Removes @jest/globals import for Vitest globals. |
| react/src/diagnostics/rules/tests/cspRules.test.ts | Removes @jest/globals import for Vitest globals. |
| react/src/diagnostics/rules/tests/configRules.test.ts | Removes @jest/globals import for Vitest globals. |
| react/src/components/MyResourceWithinResourceGroup.test.tsx | Fixes Vitest default-export mock shape and migrates mocks to vi.*. |
| pnpm-lock.yaml | Adds Vitest/jsdom dependency graph updates. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
react/package.json:98
- PR description indicates
react/tests are migrated to Vitest, butscripts.teststill runs Jest. This meanspnpm --prefix ./react test(and any tooling/CI that calls it) won’t validate the Vitest suite. Consider makingtestrun Vitest (and optionally addtest:jestfor the legacy runner) or clearly documenting which script is canonical during the transition.
"vite:build": "vite build",
"vitest": "vitest run",
"vitest:watch": "vitest",
"build": "pnpm run build:only && cp -r ./build/* ../build/web/",
"build:only": "NODE_OPTIONS='--max-old-space-size=4096' pnpm run relay && NODE_OPTIONS='--max-old-space-size=4096' craco build",
"test": "NODE_OPTIONS='$NODE_OPTIONS --no-deprecation --experimental-vm-modules' jest",
"eject": "react-scripts eject",
f2d5ec5 to
3b0c2a9
Compare
2700534 to
6b87d63
Compare
411037f to
c25e4c7
Compare
6b87d63 to
aa6796c
Compare
c25e4c7 to
fd46dfb
Compare
aa6796c to
98ef760
Compare
fd46dfb to
593ff3b
Compare
98ef760 to
8718eb8
Compare
593ff3b to
374a63e
Compare
This was referenced Apr 30, 2026
Merge activity
|
…#6874) Resolves #6812(FR-2609) ## Summary Migrates `react/`'s test suite from Jest to Vitest. **856/856 tests passing** under Vitest. (Commit title still reads `96.9% pass rate, 822/848 tests` — that was the baseline before the last-mile fixes landed in-tree via `gt modify`. Current state is 100%; see test-plan counts below.) ### New files - `react/vitest.config.ts` — reuses `@vitejs/plugin-react` + `babel-plugin-react-compiler` + `babel-plugin-relay` so tests and the running app exercise identical transformed code. - `react/__test__/vitest.jest-compat.ts` — exposes `vi` as `jest` globally, so existing `jest.fn()` / `jest.spyOn()` calls in test files continue to work without a sweeping rename. ### Vitest 4 pitfalls fixed inline - **`process.env.NODE_ENV` is non-configurable** in Node 20+. Replaced `Object.defineProperty(process.env, 'NODE_ENV', ...)` with `vi.stubEnv('NODE_ENV', ...)` + `vi.unstubAllEnvs()` in `customThemeConfig.test.ts`. - **Default-export mock shape**: `vi.mock(path, () => Component)` must return `{ default: Component }` for files imported via `import X from ...`. Fixed in `MyResourceWithinResourceGroup.test.tsx`. - **Arrow-function `mockImplementation` called with `new`**: `new TabCount()` throws because arrow functions aren't constructors. Swapped all `MockedTabCount.mockImplementation(() => ({...}))` to `function(this: any) {...}` in `useLoginOrchestration.test.ts`. - **Factory-created vi.fn() mock history** isn't cleared by `vi.restoreAllMocks()` (that only touches `spyOn` spies). Added `vi.clearAllMocks()` in `afterEach` to prevent call-count leakage across tests. ## Test plan - [x] `pnpm --prefix ./react run vitest` → 856/856 pass - [x] Same React Compiler / Relay transforms as prod build (`'use memo'` optimisations active in tests) - [x] `scripts/verify.sh` passes for Lint + Format + Relay checks ## Stack Builds on FR-2608. The broader Jest → Vitest cutover continues in the next PR (BUI + root `/src`).
8718eb8 to
5dddc64
Compare
374a63e to
40cf0a8
Compare
Base automatically changed from
04-20-feat_fr-2608_vite_production_build_with_vite-plugin-pwa_service_worker
to
main
April 30, 2026 12:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Resolves #6812(FR-2609)
Summary
Migrates
react/'s test suite from Jest to Vitest. 856/856 tests passing under Vitest.(Commit title still reads
96.9% pass rate, 822/848 tests— that was the baseline before the last-mile fixes landed in-tree viagt modify. Current state is 100%; see test-plan counts below.)New files
react/vitest.config.ts— reuses@vitejs/plugin-react+babel-plugin-react-compiler+babel-plugin-relayso tests and the running app exercise identical transformed code.react/__test__/vitest.jest-compat.ts— exposesviasjestglobally, so existingjest.fn()/jest.spyOn()calls in test files continue to work without a sweeping rename.Vitest 4 pitfalls fixed inline
process.env.NODE_ENVis non-configurable in Node 20+. ReplacedObject.defineProperty(process.env, 'NODE_ENV', ...)withvi.stubEnv('NODE_ENV', ...)+vi.unstubAllEnvs()incustomThemeConfig.test.ts.vi.mock(path, () => Component)must return{ default: Component }for files imported viaimport X from .... Fixed inMyResourceWithinResourceGroup.test.tsx.mockImplementationcalled withnew:new TabCount()throws because arrow functions aren't constructors. Swapped allMockedTabCount.mockImplementation(() => ({...}))tofunction(this: any) {...}inuseLoginOrchestration.test.ts.vi.restoreAllMocks()(that only touchesspyOnspies). Addedvi.clearAllMocks()inafterEachto prevent call-count leakage across tests.Test plan
pnpm --prefix ./react run vitest→ 856/856 pass'use memo'optimisations active in tests)scripts/verify.shpasses for Lint + Format + Relay checksStack
Builds on FR-2608. The broader Jest → Vitest cutover continues in the next PR (BUI + root
/src).