feat(FR-2748): fully migrate test files from jest.* to vi.* and align TS globals#7083
Merged
graphite-app[bot] merged 1 commit intomainfrom Apr 30, 2026
Conversation
This was referenced Apr 27, 2026
Merged
Contributor
Author
Contributor
Coverage Report for backend-ai-ui-coverage (./packages/backend.ai-ui)
File CoverageNo changed files found. |
Contributor
Coverage Report for root-coverage
File CoverageNo changed files found. |
Contributor
Coverage Report for react-coverage (./react)
File Coverage
|
||||||||||||||||||||||||||||||||||||||
660e96a to
0ef6b62
Compare
388ded7 to
06b0e97
Compare
This was referenced Apr 27, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Completes the Jest → Vitest migration by converting remaining jest.* usages in tests to vi.*, removing temporary compatibility shims, and restoring missing ambient TypeScript globals/types.
Changes:
- Migrated remaining test helpers/types from
jest.*tovi.*across React, root, andbackend.ai-uitests; removed@jest/globalsshim usage. - Removed Vitest↔Jest runtime/alias shims from Vitest configs and deleted the shim files.
- Restored/added ambient TypeScript declarations (including Vitest globals references) and updated test setup to expose
globalThis.jestfor@testing-library/domfake-timer detection.
Reviewed changes
Copilot reviewed 29 out of 31 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.config.ts | Removes repo-root Jest-compat setup file from Vitest config. |
| scripts/i18n-merge-driver.test.ts | Replaces jest.clearAllMocks() with vi.clearAllMocks(). |
| react/vitest.config.ts | Removes React Jest-compat setup file from Vitest config. |
| react/vite.config.ts | Adds dev-server allowedHosts parsing and changes default port. |
| react/src/setupTests.ts | Adds globalThis.jest = vi hook for Testing Library fake-timer detection. |
| react/src/hooks/useLoginOrchestration.test.ts | Replaces Jest mocked types/usage with vi.mocked/vi.fn. |
| react/src/hooks/tests/useMultiStepNotification.test.tsx | Migrates mocked function typing and fn() usage to vi.*. |
| react/src/helper/customThemeConfig.test.ts | Migrates spy typing from Jest to Vitest (MockInstance). |
| react/src/helper/big-number.test.ts | Adjusts custom matcher typing augmentation to align with current global matcher typing strategy. |
| react/src/ambient.d.ts | Reintroduces project ambient types + adds Vitest globals reference for TS. |
| react/test/vitest.jest-compat.ts | Deletes React Jest-compat shim file. |
| react/test/matchMedia.mock.js | Moves matchMedia mock off jest.fn() to vi.fn(). |
| packages/backend.ai-ui/vitest.config.ts | Removes @jest/globals alias and Jest-compat setup file from Vitest config. |
| packages/backend.ai-ui/svg.d.ts | Adds Vitest globals reference for TS. |
| packages/backend.ai-ui/src/hooks/useIntervalValue.test.tsx | Migrates timer mocking from Jest fake timers to Vitest fake timers. |
| packages/backend.ai-ui/src/helper/useDebouncedDeferredValue.test.ts | Migrates timer mocking utilities from Jest to Vitest. |
| packages/backend.ai-ui/src/helper/index.test.ts | Removes @jest/globals import (uses globals instead). |
| packages/backend.ai-ui/src/components/BAIUnmountAfterClose.test.tsx | Migrates mock/spies from jest.fn() to vi.fn(). |
| packages/backend.ai-ui/src/components/BAITag.test.tsx | Migrates mock/spies from jest.fn() to vi.fn(). |
| packages/backend.ai-ui/src/components/BAIPropertyFilter.test.tsx | Migrates callback mocks from jest.fn() to vi.fn(). |
| packages/backend.ai-ui/src/components/BAILink.test.tsx | Migrates callback mocks from jest.fn() to vi.fn(). |
| packages/backend.ai-ui/src/components/BAIFlex.test.tsx | Removes @jest/globals import (uses globals instead). |
| packages/backend.ai-ui/src/components/BAICard.test.tsx | Migrates mocks from jest.fn() to vi.fn(). |
| packages/backend.ai-ui/src/components/BAIButton.test.tsx | Migrates mocks from jest.fn() to vi.fn() (including async action tests). |
| packages/backend.ai-ui/src/components/BAIBulkEditFormItem.test.tsx | Migrates callback mock from jest.fn() to vi.fn(). |
| packages/backend.ai-ui/src/test/matchMedia.mock.js | Moves matchMedia mock off jest.fn() to vi.fn(). |
| packages/backend.ai-ui/src/test/matchMedia.mock.cjs | Updates comment wording around mock strategy (still references Jest in header). |
| packages/backend.ai-ui/setupTests.ts | Adds globalThis.jest = vi hook for Testing Library fake-timer detection. |
| packages/backend.ai-ui/test/vitest.jest-compat.ts | Deletes BUI Jest-compat shim file. |
| packages/backend.ai-ui/test/jest-globals-shim.ts | Deletes @jest/globals re-export shim file. |
| test/vitest.jest-compat.ts | Deletes repo-root Jest-compat shim file. |
0ef6b62 to
8981c28
Compare
06b0e97 to
a00cbcb
Compare
8981c28 to
a55f50b
Compare
4c7f5bb to
a579c9b
Compare
a55f50b to
1acb275
Compare
a579c9b to
866800d
Compare
1acb275 to
7437b6e
Compare
866800d to
cfea1f5
Compare
7437b6e to
0353467
Compare
cfea1f5 to
1034319
Compare
0353467 to
5f30412
Compare
This was referenced Apr 30, 2026
Merge activity
|
… TS globals (#7083) Resolves #7081(FR-2748) ## Summary Finishes the Jest → Vitest migration started in FR-2609. The earlier PRs left two compat shims as migration aids (`vitest.jest-compat.ts` setting `globalThis.jest = vi`, and `jest-globals-shim.ts` aliasing `@jest/globals`). Useful at the time but they obscured what was actually a vitest test, and left a TypeScript gap exposed by the audit (`vi` not typed; project globals from the deleted `react/src/react-app-env.d.ts` lost). This PR completes the rename so the shims become unnecessary. ### Mechanical jest.* → vi.* migration (15 test files) - Single-line: `jest.fn`, `jest.spyOn`, `jest.mocked`, `jest.clearAllMocks`, `jest.resetAllMocks`, `jest.restoreAllMocks`, `jest.useFakeTimers`, `jest.useRealTimers`, `jest.runAllTimers`, `jest.advanceTimersByTime`, `jest.runOnlyPendingTimers`. - Multi-line patterns (`const x = jest\n.fn()`) handled via `perl -0777`. - Type positions: `jest.MockedFunction<T>` / `jest.MockedClass<T>` / `jest.SpyInstance` / `jest.SpiedFunction` rewritten to use `vi.mocked(...)` (value) or `MockInstance` / `ReturnType<typeof vi.spyOn>` (type) imported from `'vitest'`. - `matchMedia.mock.js` (used by both react/ and BUI) also moved off `jest.fn()`. ### Drop the runtime compat shims - Removed `__test__/vitest.jest-compat.ts` from root, react/, and BUI. - Removed `packages/backend.ai-ui/__test__/jest-globals-shim.ts`. - Dropped the `@jest/globals` alias from BUI's `vitest.config.ts`. - Dropped the second `setupFiles` entry in all three vitest configs. ### Restore the project's ambient TypeScript types FR-2611 deleted `react/src/react-app-env.d.ts` (CRA-shaped name) along with CRA itself, but the file held real custom types: `DeepPartial`, `SelectivePartial`, `OptionalFieldsOnly`, `NonNullableItem`, `NonNullableNodeOnEdges`, `BackendAIOptions`, `BackendAIClient`, `globalThis.{isElectron, packageVersion, electronInitialHref, …}`, `Window.switchLanguage`, and the `backend.ai-client-esm` module shim. Those all return, now living in `react/src/ambient.d.ts` with the CRA reference removed. ### Wire vitest globals into TypeScript Used `/// <reference types="vitest/globals" />` in ambient `.d.ts` files instead of touching the `tsconfig.json` `"types"` arrays: - `react/src/ambient.d.ts` - `packages/backend.ai-ui/svg.d.ts` **Why not `"types": ["vitest/globals"]` in tsconfig**: that would exclude `@types/jest` from auto-loading, which then breaks `@testing-library/jest-dom`'s default matcher augmentation (`expect(el).toBeInTheDocument()` etc). The reference directive pulls in vitest globals additively without changing the tsconfig `"types"` contract. ### Keep one `globalThis.jest = vi` line in setupTests `@testing-library/dom`'s `waitFor` checks `globalThis.jest` to detect Jest-style fake timers; if present, it switches to its timer-aware polling loop. Without that detection, tests that combine `vi.useFakeTimers()` with `await waitFor(…)` hang — the polling `setTimeout` never fires under faked timers. The line is **no longer a compat shim for project test code** (all test code uses `vi.*` now); it's purely a `@testing-library/dom` integration hook. Comment in both `react/src/setupTests.ts` and `packages/backend.ai-ui/setupTests.ts` explains the new purpose. ## Verification - `bash scripts/verify.sh` → ALL PASS (lint + format + TypeScript). - `pnpm --prefix ./react run vitest` → **856 / 856** pass. - `pnpm --prefix ./packages/backend.ai-ui run vitest` → **319 / 320** (1 pre-existing FR-1731 skip). - `pnpm exec vitest run` (root) → **91 / 91**. - `pnpm run build` (root) and `make dep` (Electron) succeed; built `index.html` references only `manifest.json` (no `manifest.webmanifest`); Electron build emits `es6://assets/index-*` URLs. ## Out of scope - Removing the `globalThis.jest = vi` line entirely (would require reconfiguring `@testing-library/dom` to use vitest's fake-timer integration manually — larger change). - Switching to `@testing-library/jest-dom/vitest` entry (kept the default entry to avoid the BAIFlex snapshot client conflict observed during exploration). - The pre-existing `BAIDomainSelect.test.tsx` `describe.skip` (FR-1731 issue, unrelated to this migration). ## Stack Top of the Vite migration stack (now 14 PRs). Builds on PR #7071 (`feat(FR-2746)` re-enable skipped tests).
1034319 to
cc748d3
Compare
5f30412 to
9fa887b
Compare
graphite-app Bot
pushed a commit
that referenced
this pull request
Apr 30, 2026
Resolves #6809(FR-2606) ## Summary Dev-server regression noticed after the Vite cutover: pages that mount a Monaco editor break at mount time because the `/resources/monaco/vs/*` URL prefix no longer resolves on the dev server. `@monaco-editor/react` loads the Monaco AMD runtime at runtime via: ```ts loader.config({ paths: { vs: '/resources/monaco/vs' } }); ``` (see `react/src/helper/monacoEditor.ts`). The self-hosted prefix exists so the editor works in offline / air-gapped deployments where jsDelivr is unreachable. Pre-Vite, the dev-server side of this contract was the `static` directory list in `react/craco.config.cjs` (lines 44–60 of the now-deleted file): it served `react/node_modules/monaco-editor/min/vs/*` at the `/resources/monaco/vs` URL prefix. Production builds copy the same tree to `build/web/resources/monaco/vs/` via the root `copymonaco` script (`package.json:32`). After #6876 (FR-2611) dropped `craco.config.cjs`, the production `copymonaco` step was preserved but the dev-server-side mapping was not ported to `vite.config.ts`. As a result, in `pnpm run dev`, requests to `/resources/monaco/vs/loader.js` 404 and any page that mounts a Monaco editor breaks. **Fix**: add `monacoStaticPlugin()` to `react/vite.config.ts` mirroring the deleted craco `static` entry. - Serves `/resources/monaco/vs/*` from `react/node_modules/monaco-editor/min/vs/*`. - `apply: 'serve'` — dev-only; production is unchanged because `copymonaco` already populates `build/web/resources/monaco/vs/`. - Path-traversal guard via `filePath.startsWith(monacoRoot)` after `join` normalization. - Registered in the `plugins` array before `projectRootStaticPlugin()` so the narrower Monaco prefix is matched first. ## Verification - [x] `bash scripts/verify.sh` — Relay / Lint / Format / TypeScript all PASS - [ ] `pnpm run dev`, navigate to a Monaco-mounting page (manifest editor on Environments page) — editor renders without console errors, no `cdn.jsdelivr.net` fetches - [ ] DevTools → Network: `/resources/monaco/vs/loader.js`, `/resources/monaco/vs/editor/editor.main.js` return 200 from the dev server ## Stack Top of the Vite migration follow-up stack. Sits on top of #7083 (FR-2748).
Base automatically changed from
04-27-feat_fr-2746_re-enable_5_tests_skipped_during_vitest_migration
to
main
April 30, 2026 12:36
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 #7081(FR-2748)
Summary
Finishes the Jest → Vitest migration started in FR-2609. The earlier PRs left two compat shims as migration aids (
vitest.jest-compat.tssettingglobalThis.jest = vi, andjest-globals-shim.tsaliasing@jest/globals). Useful at the time but they obscured what was actually a vitest test, and left a TypeScript gap exposed by the audit (vinot typed; project globals from the deletedreact/src/react-app-env.d.tslost). This PR completes the rename so the shims become unnecessary.Mechanical jest.* → vi.* migration (15 test files)
jest.fn,jest.spyOn,jest.mocked,jest.clearAllMocks,jest.resetAllMocks,jest.restoreAllMocks,jest.useFakeTimers,jest.useRealTimers,jest.runAllTimers,jest.advanceTimersByTime,jest.runOnlyPendingTimers.const x = jest\n.fn()) handled viaperl -0777.jest.MockedFunction<T>/jest.MockedClass<T>/jest.SpyInstance/jest.SpiedFunctionrewritten to usevi.mocked(...)(value) orMockInstance/ReturnType<typeof vi.spyOn>(type) imported from'vitest'.matchMedia.mock.js(used by both react/ and BUI) also moved offjest.fn().Drop the runtime compat shims
__test__/vitest.jest-compat.tsfrom root, react/, and BUI.packages/backend.ai-ui/__test__/jest-globals-shim.ts.@jest/globalsalias from BUI'svitest.config.ts.setupFilesentry in all three vitest configs.Restore the project's ambient TypeScript types
FR-2611 deleted
react/src/react-app-env.d.ts(CRA-shaped name) along with CRA itself, but the file held real custom types:DeepPartial,SelectivePartial,OptionalFieldsOnly,NonNullableItem,NonNullableNodeOnEdges,BackendAIOptions,BackendAIClient,globalThis.{isElectron, packageVersion, electronInitialHref, …},Window.switchLanguage, and thebackend.ai-client-esmmodule shim. Those all return, now living inreact/src/ambient.d.tswith the CRA reference removed.Wire vitest globals into TypeScript
Used
/// <reference types="vitest/globals" />in ambient.d.tsfiles instead of touching thetsconfig.json"types"arrays:react/src/ambient.d.tspackages/backend.ai-ui/svg.d.tsWhy not
"types": ["vitest/globals"]in tsconfig: that would exclude@types/jestfrom auto-loading, which then breaks@testing-library/jest-dom's default matcher augmentation (expect(el).toBeInTheDocument()etc). The reference directive pulls in vitest globals additively without changing the tsconfig"types"contract.Keep one
globalThis.jest = viline in setupTests@testing-library/dom'swaitForchecksglobalThis.jestto detect Jest-style fake timers; if present, it switches to its timer-aware polling loop. Without that detection, tests that combinevi.useFakeTimers()withawait waitFor(…)hang — the pollingsetTimeoutnever fires under faked timers.The line is no longer a compat shim for project test code (all test code uses
vi.*now); it's purely a@testing-library/domintegration hook. Comment in bothreact/src/setupTests.tsandpackages/backend.ai-ui/setupTests.tsexplains the new purpose.Verification
bash scripts/verify.sh→ ALL PASS (lint + format + TypeScript).pnpm --prefix ./react run vitest→ 856 / 856 pass.pnpm --prefix ./packages/backend.ai-ui run vitest→ 319 / 320 (1 pre-existing FR-1731 skip).pnpm exec vitest run(root) → 91 / 91.pnpm run build(root) andmake dep(Electron) succeed; builtindex.htmlreferences onlymanifest.json(nomanifest.webmanifest); Electron build emitses6://assets/index-*URLs.Out of scope
globalThis.jest = viline entirely (would require reconfiguring@testing-library/domto use vitest's fake-timer integration manually — larger change).@testing-library/jest-dom/vitestentry (kept the default entry to avoid the BAIFlex snapshot client conflict observed during exploration).BAIDomainSelect.test.tsxdescribe.skip(FR-1731 issue, unrelated to this migration).Stack
Top of the Vite migration stack (now 14 PRs). Builds on PR #7071 (
feat(FR-2746)re-enable skipped tests).