Skip to content

fix(ui): wire vitest setup file (drops 507 of 609 type errors)#254

Merged
JoshuaAFerguson merged 1 commit into
mainfrom
fix/ui-vitest-setup
Apr 25, 2026
Merged

fix(ui): wire vitest setup file (drops 507 of 609 type errors)#254
JoshuaAFerguson merged 1 commit into
mainfrom
fix/ui-vitest-setup

Conversation

@JoshuaAFerguson

Copy link
Copy Markdown
Member

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

  • Wire `test.setupFiles → ./src/test/setup.ts` in `vite.config.ts`
  • Add `/// <reference types="vitest" />` and the jsdom environment
  • Add `["node", "vitest/globals", "@testing-library/jest-dom"]` to `tsconfig.types` (the `global` reference in setup.ts and the `global.IntersectionObserver = ...` mocks in test files weren't resolving)

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

  • `npx tsc --noEmit` — error count drops 609 → 86
  • `npm test` runs cleanly under jsdom

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.
@github-actions github-actions Bot added the component:ui Frontend UI (React) label Apr 25, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread ui/vite.config.ts
@@ -1,9 +1,15 @@
/// <reference types="vitest" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@JoshuaAFerguson JoshuaAFerguson merged commit 9778332 into main Apr 25, 2026
13 of 19 checks passed
@JoshuaAFerguson JoshuaAFerguson deleted the fix/ui-vitest-setup branch April 25, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:ui Frontend UI (React)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant