feat(frontend): add Vitest testing infrastructure with React Testing …#266
Conversation
Summary of ChangesHello @jmanhype, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request establishes a robust and modern frontend testing infrastructure by integrating Vitest and React Testing Library. It provides the necessary tools, configurations, and foundational test patterns to enable comprehensive unit and integration testing for React components and hooks. This initiative significantly enhances the overall code quality and maintainability of the frontend application. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request does an excellent job of setting up a robust testing infrastructure using Vitest and React Testing Library. The new test files for the hooks are well-structured, comprehensive, and follow best practices for mocking dependencies and testing asynchronous logic. The test utilities and setup files provide a solid foundation for future tests. I have a couple of suggestions to further improve the long-term maintainability and reliability of the test suite.
| })); | ||
|
|
||
| // Mock fetch globally | ||
| global.fetch = vi.fn(); |
There was a problem hiding this comment.
A global mock of fetch that does nothing (vi.fn()) can be dangerous as it will silently swallow any unmocked network requests. This can lead to tests passing when they should be failing because they are making unexpected API calls. It's safer to make unhandled requests throw an error to immediately surface such issues.
Since msw is part of the new dependencies, it should be used for mocking API endpoints. This change will ensure any fetch call not handled by msw or another explicit mock will fail the test.
| global.fetch = vi.fn(); | |
| global.fetch = vi.fn().mockImplementation(() => { | |
| throw new Error('Unhandled fetch request. Please use msw or vi.mock to mock API calls.'); | |
| }); |
| export default defineConfig({ | ||
| plugins: [react()], | ||
| test: { | ||
| globals: true, |
There was a problem hiding this comment.
While using globals: true is convenient, it can lead to global namespace pollution and make it less obvious where test functions like describe and it originate. For better long-term maintainability and to avoid potential conflicts with other libraries (e.g., Cypress), consider setting this to false.
With globals: false, you would need to explicitly import what you need in each test file, which makes them more self-contained and easier to understand:
import { describe, it, expect, vi } from 'vitest';| globals: true, | |
| globals: false, |
…Library - Add vitest and testing dependencies (vitest, @testing-library/react, @testing-library/jest-dom, @testing-library/user-event, jsdom, msw) - Create vitest.config.ts with jsdom environment and path aliases - Add test setup file with global mocks (matchMedia, ResizeObserver, etc.) - Add test utilities with QueryClient and Router wrappers - Create example tests for useFilteredTasks, useTaskMutations, and useAttemptExecution hooks demonstrating testing patterns - Add npm scripts: test, test:run, test:coverage This establishes the foundation for comprehensive frontend test coverage. Co-authored-by: Automagik Genie 🧞 <genie@namastex.ai>
f50696b to
7f0b273
Compare
|
@codex review this pr |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ 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".
| import { renderHook } from '@testing-library/react'; | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { useFilteredTasks } from '../useFilteredTasks'; |
There was a problem hiding this comment.
Import missing useFilteredTasks hook
Running the new Vitest suite will fail immediately because useFilteredTasks is imported from ../useFilteredTasks, but that hook is not present anywhere in frontend/src/hooks (rg only finds this test). Module resolution will throw Cannot find module '../useFilteredTasks', so npm test/vitest cannot start until the hook is implemented or the import is corrected.
Useful? React with 👍 / 👎.
|
@codex review this pr |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ 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".
| @@ -0,0 +1,103 @@ | |||
| import { renderHook } from '@testing-library/react'; | |||
| import { describe, it, expect } from 'vitest'; | |||
| import { useFilteredTasks } from '../useFilteredTasks'; | |||
There was a problem hiding this comment.
Point tests at an existing hook
The new useFilteredTasks test imports ../useFilteredTasks, but there is no such hook anywhere under src/hooks (only the test file exists). Running npm run test will fail immediately with a module-not-found error before any tests execute. Please either add the hook or update the import to target the correct module so the test suite can run.
Useful? React with 👍 / 👎.
…Library
This establishes the foundation for comprehensive frontend test coverage.