Skip to content

Vitest for unit tests#98

Draft
ngAlexander9 wants to merge 10 commits intomainfrom
ang/test-suite
Draft

Vitest for unit tests#98
ngAlexander9 wants to merge 10 commits intomainfrom
ang/test-suite

Conversation

@ngAlexander9
Copy link
Copy Markdown
Contributor

@ngAlexander9 ngAlexander9 commented May 1, 2026

Description

Implements infrastructure for writing unit tests for frontend. It's not fully covering all cases, but provides infrastructure and usage patterns for testing frontend business logic as well as UI components.

Motivation

Vitest seems to be a commonly used JS testing framework and goes well with our current usage of vite.

Unit test files are colocated with the component files they test. This seems to be a common organizational pattern, as it allows for shorter import statements, keeps tests and components close (and easier to navigate together), and promotes maintaining and adding to tests.

Screenshots

Pre-merge checklist

  • Code works interactively
  • Code follows the style guide
  • Code contains descriptive docstrings
  • New/changed functions and methods are covered in the test suite where possible
  • Test suite passes locally
  • Test suite passes on GitHub Actions

@ngAlexander9 ngAlexander9 requested a review from Copilot May 1, 2026 22:40
@ngAlexander9 ngAlexander9 changed the title Ang/test suite Vitest for unit tests May 1, 2026
Copy link
Copy Markdown

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

Adds a Vitest + Testing Library setup to enable unit testing of the frontend (business-logic utilities and React components), with a shared render helper for React Query–dependent components.

Changes:

  • Configure Vitest in vite.config.ts (jsdom, globals, setup file) and add test scripts/deps in package.json.
  • Add shared test setup/utilities (src/test/setup.ts, src/test/render.tsx) and initial unit tests for utils/components.
  • Update TypeScript/ESLint configuration to support test files and Vitest globals.

Reviewed changes

Copilot reviewed 9 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vite.config.ts Adds Vitest configuration (jsdom, setup file) and adjusts env logging during tests.
tsconfig.json Updates compiler options/types to support Vitest globals and Node typings.
src/utils/tolerance.test.ts Adds unit tests for tolerance helpers.
src/utils/csvParser.test.ts Adds unit tests for CSV parsing/tag validation helpers.
src/test/setup.ts Loads jest-dom matchers for tests.
src/test/render.tsx Introduces renderWithProviders with a test QueryClient for React Query components.
src/components/TagGroupSelect.test.tsx Adds component tests for TagGroupSelect behavior.
src/components/SearchBar.test.tsx Adds component tests for SearchBar behavior (with icon mocks).
package.json Adds Vitest + Testing Library deps and test scripts.
pnpm-lock.yaml Locks new testing-related dependencies.
.gitignore Adds a rule to ignore *.csv.
.eslintrc.cjs Stops ignoring tests and adds overrides for Vitest globals in test files.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread vite.config.ts
// Use '' prefix to load all env vars (not just VITE_-prefixed ones)
const env = loadEnv(mode, process.cwd(), '');
console.log('API_KEY loaded:', env.API_KEY ? `[set, ${env.API_KEY.length} chars]` : 'MISSING');
if (mode !== 'test') {
Comment thread package.json
Comment on lines +57 to +60
"prepare": "husky",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants