You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: react/VITE_POC_NOTES.md
+44-1Lines changed: 44 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,9 +77,52 @@ Fix:
77
77
78
78
(Each of these gets its own sub-issue under FR-2605.)
79
79
80
-
- Jest → Vitest migration (FR-2609)
81
80
- CI pipeline updates (FR-2611)
82
81
82
+
## Vitest migration (react/ only) — partial land (FR-2609)
83
+
84
+
`pnpm --prefix ./react run vitest` now runs 848 tests across 39 files with a **96.9% pass rate (822 passing, 26 failing, 3 files with errors)** out of the box. Remaining failures are per-file / per-test Vitest-semantic differences from Jest, not infrastructure gaps.
85
+
86
+
### What was added
87
+
88
+
-`react/vitest.config.ts` — dedicated Vitest config, separate from `vite.config.ts`. Shares the transform pipeline (`@vitejs/plugin-react` + babel-plugin-relay with per-directory `artifactDirectory` + babel-plugin-react-compiler) so tests exercise the same transforms as dev/prod.
89
+
-`react/__test__/vitest.jest-compat.ts` — a setup file that aliases `globalThis.jest = vi` so legacy `jest.fn()` / `jest.clearAllMocks()` call sites continue to work. Migration aid only; new tests should use `vi.*` directly.
90
+
-`vitest` / `vitest:watch` scripts in `react/package.json`.
91
+
92
+
### Bulk migrations applied
93
+
94
+
Mechanical `jest.` → `vi.` rewrites across 39 test files (perl one-liner in the commit message):
Without this, Vitest's `vi.mock` hoisting does NOT apply to `jest.mock(...)` calls (Vitest only recognises literal `vi.mock` for hoisting). The rewrites restore mock correctness across 14+ files.
101
+
102
+
### Module resolution
103
+
104
+
-`src/` baseUrl via regex alias `{ find: /^src\//, replacement: reactSrc + '/' }`.
105
+
-`backend.ai-ui/*`, `backend.ai-client-esm` mapped to same mocks Jest used.
-`.css` / `.css?raw` → `__test__/rawCss.mock.js` (regex anchored with `^.+` so the entire specifier is replaced; array-form aliases replace the matched portion).
108
+
109
+
### Known remaining failures (per-file fixes, deferred to follow-up)
110
+
111
+
-`react/src/helper/customThemeConfig.test.ts` — 13 tests failing. Uses `Object.defineProperty(process.env, 'NODE_ENV', ...)` 5 times to toggle dev/prod; Vitest's `process.env.NODE_ENV` has an immutable descriptor. Fix: migrate to `vi.stubEnv('NODE_ENV', ...)` + `vi.unstubAllEnvs()` in `afterEach`. Also has event-dispatcher accumulation in nested describes — needs `vi.restoreAllMocks()` between scopes.
112
+
-`react/src/components/MyResourceWithinResourceGroup.test.tsx` — one `vi.mock(path)` without factory argument. Vitest auto-mock does not produce a `default` export for ESM modules; test fails with "vi.mock ... is not returning an object. Did you mean to return an object with a 'default' key?". Fix: change to `vi.mock(path, () => ({ default: vi.fn() }))`.
113
+
-`react/src/hooks/useResourceLimitAndRemaining.test.ts` — also involves default-export mocking; same pattern as above.
114
+
115
+
### Performance
116
+
117
+
- Vitest run: ~20s wall clock for 848 tests (transform 71s, tests 6s — tests themselves are very fast; the time is transform + import cost, paid only once per file).
118
+
- Jest equivalent on the same tree has not been measured in this session; prior expectation was 60-120s. Confidence level: "materially faster" but exact multiplier needs a controlled benchmark.
119
+
120
+
### Still open
121
+
122
+
- BUI (`packages/backend.ai-ui`) Jest → Vitest migration
123
+
- Root `/src` Jest → Vitest migration
124
+
-`transformIgnorePatterns` regex in existing `react/jest.config.cjs` can be deleted once the Jest pipeline is fully retired.
125
+
83
126
## Production `vite build` + Workbox PWA — landed (FR-2608)
84
127
85
128
`pnpm --prefix ./react run vite:build` now produces a working web build with a generated service worker. Output goes to `react/build/`, same directory the craco pipeline uses.
0 commit comments