fix(ui): wire vitest setup file (drops 507 of 609 type errors)#254
Conversation
src/test/setup.ts already imported and extended jest-dom matchers, mocked matchMedia / IntersectionObserver / ResizeObserver, and registered an afterEach cleanup — but vite.config.ts had no test.setupFiles entry, so the file was never executed. tsc reported 'toBeInTheDocument does not exist on type Assertion<HTMLElement>' across every test file. - Wire test.setupFiles → ./src/test/setup.ts in vite.config.ts - Add the vitest reference + jsdom environment so `npm test` runs in the same environment that exercises the setup file - Add ["node", "vitest/globals", "@testing-library/jest-dom"] to tsconfig types so global, vi.fn, and the matcher overloads resolve Drops project type-check error count 609 → 86 (a –86% delta from a config-only change). The 86 remaining errors are real code bugs that predate this change and will be fixed separately.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99f8f53126
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -1,9 +1,15 @@ | |||
| /// <reference types="vitest" /> | |||
There was a problem hiding this comment.
Reference Vitest config types in Vite config
The triple-slash directive should point to vitest/config, not vitest: /// <reference types="vitest" /> does not add the test field augmentation to Vite's UserConfig. Since ui/tsconfig.node.json includes vite.config.ts, project-reference type checks (for example tsc -b or IDE validation of config files) can fail with 'test' does not exist in type 'UserConfig', even though this file now relies on that property.
Useful? React with 👍 / 👎.
Summary
`src/test/setup.ts` already imported `@testing-library/jest-dom/matchers` and called `expect.extend(matchers)` — but `vite.config.ts` had no `test.setupFiles` entry, so the file was never executed when running typecheck or tests. This caused `tsc` to report `'toBeInTheDocument' does not exist on type 'Assertion'` across every test file.
Changes
Impact
`tsc --noEmit` error count: 609 → 86 (-86% from config-only change)
The 86 remaining errors are real type bugs in production code (Dashboard, AuditLogs, UserSettings, Compliance, …) that predate this PR. Tracked for a follow-up.
Test plan