Vitest for unit tests#98
Draft
ngAlexander9 wants to merge 10 commits intomainfrom
Draft
Conversation
…onfig to include test types
Co-authored-by: Copilot <copilot@github.com>
…uration Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
…utility Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
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 inpackage.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.
| // 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 on lines
+57
to
+60
| "prepare": "husky", | ||
| "test": "vitest run", | ||
| "test:watch": "vitest", | ||
| "test:coverage": "vitest run --coverage" |
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.
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