Skip to content

feat(frontend): add Vitest testing infrastructure with React Testing …#266

Open
jmanhype wants to merge 1 commit intoautomagik-dev:devfrom
jmanhype:claude/setup-vitest-testing-01Ru23G7W1xpih7AFRLAyoN9
Open

feat(frontend): add Vitest testing infrastructure with React Testing …#266
jmanhype wants to merge 1 commit intoautomagik-dev:devfrom
jmanhype:claude/setup-vitest-testing-01Ru23G7W1xpih7AFRLAyoN9

Conversation

@jmanhype
Copy link

…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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Vitest and React Testing Library Integration: Introduced Vitest as the primary testing framework for the frontend, along with React Testing Library for component and hook testing.
  • Essential Testing Dependencies: Added key dependencies including @testing-library/jest-dom, @testing-library/user-event, jsdom, and msw to support comprehensive testing scenarios.
  • Vitest Configuration: Configured Vitest to use the JSDOM environment for browser-like testing and set up path aliases for easier module resolution.
  • Global Test Setup and Utilities: Created a global setup file with mocks for browser APIs like matchMedia, ResizeObserver, and IntersectionObserver, and provided test utilities for wrapping components with QueryClient and BrowserRouter.
  • Example Tests for Hooks: Included example tests for useFilteredTasks, useTaskMutations, and useAttemptExecution hooks, demonstrating established testing patterns.
  • New npm Test Scripts: Added new npm scripts ('test', 'test:run', 'test:coverage') to easily execute tests and generate coverage reports.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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();
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
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,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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';
Suggested change
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>
@jmanhype jmanhype force-pushed the claude/setup-vitest-testing-01Ru23G7W1xpih7AFRLAyoN9 branch from f50696b to 7f0b273 Compare November 28, 2025 19:01
@namastex888
Copy link
Contributor

@codex review this pr

Copy link

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

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.

ℹ️ 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 on lines +1 to +3
import { renderHook } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { useFilteredTasks } from '../useFilteredTasks';

Choose a reason for hiding this comment

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

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

@jmanhype
Copy link
Author

@codex review this pr

Copy link

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

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.

ℹ️ 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';

Choose a reason for hiding this comment

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

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

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.

3 participants

Comments