Skip to content

feat(FR-2609): Vitest migration for react/ (100% pass, 856/856 tests)#6874

Merged
graphite-app[bot] merged 1 commit intomainfrom
04-21-feat_fr-2609_vitest_migration_for_react__96.9_pass_rate_822_848_tests_
Apr 30, 2026
Merged

feat(FR-2609): Vitest migration for react/ (100% pass, 856/856 tests)#6874
graphite-app[bot] merged 1 commit intomainfrom
04-21-feat_fr-2609_vitest_migration_for_react__96.9_pass_rate_822_848_tests_

Conversation

@nowgnuesLee
Copy link
Copy Markdown
Contributor

@nowgnuesLee nowgnuesLee commented Apr 22, 2026

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

  • pnpm --prefix ./react run vitest → 856/856 pass
  • Same React Compiler / Relay transforms as prod build ('use memo' optimisations active in tests)
  • 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).

Copy link
Copy Markdown
Contributor Author

nowgnuesLee commented Apr 22, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • flow:merge-queue - adds this PR to the back of the merge queue
  • flow:hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 22, 2026

Coverage report for ./react

Action wasn't able to generate report within GitHub comment limit. If you're facing this issue, please let me know by commenting under this issue.

Report generated by 🧪jest coverage report action from 40cf0a8

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.ts and 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, but scripts.test still runs Jest. This means pnpm --prefix ./react test (and any tooling/CI that calls it) won’t validate the Vitest suite. Consider making test run Vitest (and optionally add test:jest for 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",

Comment thread react/vitest.config.ts
Comment thread react/VITE_POC_NOTES.md Outdated
@nowgnuesLee nowgnuesLee force-pushed the 04-21-feat_fr-2609_vitest_migration_for_react__96.9_pass_rate_822_848_tests_ branch from f2d5ec5 to 3b0c2a9 Compare April 28, 2026 05:02
@nowgnuesLee nowgnuesLee force-pushed the 04-20-feat_fr-2608_vite_production_build_with_vite-plugin-pwa_service_worker branch 2 times, most recently from 2700534 to 6b87d63 Compare April 28, 2026 05:15
@nowgnuesLee nowgnuesLee force-pushed the 04-21-feat_fr-2609_vitest_migration_for_react__96.9_pass_rate_822_848_tests_ branch 2 times, most recently from 411037f to c25e4c7 Compare April 28, 2026 05:19
@nowgnuesLee nowgnuesLee force-pushed the 04-20-feat_fr-2608_vite_production_build_with_vite-plugin-pwa_service_worker branch from 6b87d63 to aa6796c Compare April 28, 2026 05:19
@nowgnuesLee nowgnuesLee force-pushed the 04-21-feat_fr-2609_vitest_migration_for_react__96.9_pass_rate_822_848_tests_ branch from c25e4c7 to fd46dfb Compare April 28, 2026 05:25
@nowgnuesLee nowgnuesLee force-pushed the 04-20-feat_fr-2608_vite_production_build_with_vite-plugin-pwa_service_worker branch from aa6796c to 98ef760 Compare April 28, 2026 05:25
@nowgnuesLee nowgnuesLee force-pushed the 04-21-feat_fr-2609_vitest_migration_for_react__96.9_pass_rate_822_848_tests_ branch from fd46dfb to 593ff3b Compare April 28, 2026 05:28
@yomybaby yomybaby force-pushed the 04-20-feat_fr-2608_vite_production_build_with_vite-plugin-pwa_service_worker branch from 98ef760 to 8718eb8 Compare April 30, 2026 12:08
@yomybaby yomybaby force-pushed the 04-21-feat_fr-2609_vitest_migration_for_react__96.9_pass_rate_822_848_tests_ branch from 593ff3b to 374a63e Compare April 30, 2026 12:08
@graphite-app
Copy link
Copy Markdown

graphite-app Bot commented 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`).
@graphite-app graphite-app Bot force-pushed the 04-20-feat_fr-2608_vite_production_build_with_vite-plugin-pwa_service_worker branch from 8718eb8 to 5dddc64 Compare April 30, 2026 12:14
@graphite-app graphite-app Bot force-pushed the 04-21-feat_fr-2609_vitest_migration_for_react__96.9_pass_rate_822_848_tests_ branch from 374a63e to 40cf0a8 Compare April 30, 2026 12:15
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
@graphite-app graphite-app Bot merged commit 40cf0a8 into main Apr 30, 2026
6 of 7 checks passed
@graphite-app graphite-app Bot deleted the 04-21-feat_fr-2609_vitest_migration_for_react__96.9_pass_rate_822_848_tests_ branch April 30, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vite PoC Phase 2: migrate Jest to Vitest (react/ + backend.ai-ui/ + root src/)

2 participants