Skip to content

Codex/replace broad matcher in home.test.tsx#65

Closed
shayancoin wants to merge 2 commits intomainfrom
codex/replace-broad-matcher-in-home.test.tsx
Closed

Codex/replace broad matcher in home.test.tsx#65
shayancoin wants to merge 2 commits intomainfrom
codex/replace-broad-matcher-in-home.test.tsx

Conversation

@shayancoin
Copy link
Owner

@shayancoin shayancoin commented Oct 16, 2025

PR Type

[Feature | Fix | Documentation | Other() ]

Short Description

...

Tests Added

...

Summary by CodeRabbit

  • Tests

    • Added Home page UI tests validating heading and description.
    • Introduced test setup for extended DOM assertions and safe matchMedia mocking.
    • Configured Vitest with jsdom, global helpers, and setup files.
  • Chores

    • Added a test script to run the test suite.
    • Updated and cleaned up development dependencies, including testing tools and build-time assets utilities.
    • Added dependencies to enable 3D rendering capabilities.
    • Reorganized dependency declarations to remove duplicates.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 16, 2025

Walkthrough

Adds Vitest-based testing setup and tooling: updates package.json scripts/dependencies, introduces Vitest config, sets up testing environment with jsdom and jest-dom matchers, and adds a Home page test verifying heading and description rendering.

Changes

Cohort / File(s) Summary of edits
Package scripts and dependencies
frontend/package.json
Added test script using Vitest; added React Three libs; added testing/tooling devDependencies (Vitest, Playwright, Testing Library, Vite React plugin, jsdom, gltfpack, meshoptimizer); removed duplicate/legacy entries and reorganized devDependencies.
Test tooling and setup
frontend/vitest.config.ts, frontend/src/test/setupTests.ts
Introduced Vitest config (jsdom env, globals, setup files, include/exclude, React plugin). Added test setup importing jest-dom for Vitest and mocking window.matchMedia when absent.
App tests
frontend/src/app/__tests__/home.test.tsx
New test rendering Home within Providers; asserts presence of hero heading and description text via Testing Library.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

codex

Poem

A hop, a bop, I thump in delight—
Tests now bloom in jsdom’s light.
Vitest whispers, “green,” so clear,
Headings found, descriptions near.
I nibble deps, neat and tight—
Cozy burrow, builds take flight.
🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title “Codex/replace broad matcher in home.test.tsx” reads like a branch name and only mentions a change within one test file, but the pull request actually introduces new dependencies, a Vitest configuration, a test setup file, and multiple changes beyond that single matcher, so it does not accurately summarize the main scope of the PR. Please update the title to clearly and concisely reflect the overall purpose of the PR, for example by mentioning the addition of test setup, Vitest configuration, dependency updates, and the new Home page tests.
Description Check ⚠️ Warning The pull request description consists solely of the template headings with placeholder ellipses and lacks any filled‐in information for PR type, short description, or details about added tests, so it does not meet the repository’s template requirements. Please complete the PR description by specifying the PR type, a concise summary of changes, and details about the tests added so that reviewers have the necessary context.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Docstrings were successfully generated.
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/replace-broad-matcher-in-home.test.tsx

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d2a35c4 and 6f7e2a7.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • frontend/package.json (2 hunks)
  • frontend/src/app/__tests__/home.test.tsx (1 hunks)
  • frontend/src/test/setupTests.ts (1 hunks)
  • frontend/vitest.config.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
frontend/src/app/__tests__/home.test.tsx (2)
frontend/src/app/page.tsx (1)
  • Home (5-12)
frontend/src/app/providers.tsx (1)
  • Providers (21-23)
🔇 Additional comments (7)
frontend/package.json (3)

11-11: LGTM! Test script properly configured.

The test script correctly invokes Vitest and aligns with the new testing infrastructure added in this PR.


24-25: Inconsistent with PR objectives: 3D rendering dependencies added.

The PR title "Codex/replace broad matcher in home.test.tsx" suggests a focused change to test matchers, but this adds 3D rendering libraries (@react-three/drei, @react-three/fiber, zustand) that are unrelated to testing. These additions suggest broader scope changes not mentioned in the PR description.

Can you clarify:

  1. Are these 3D rendering dependencies required for the test changes?
  2. Should these be in a separate PR with appropriate documentation?

Also applies to: 32-32


35-38: All added testing dependencies have no known vulnerabilities. No advisories found for @playwright/test, @testing-library/jest-dom, @testing-library/react, or @vitejs/plugin-react.

frontend/src/test/setupTests.ts (2)

1-1: LGTM! Correct Vitest entrypoint used.

The import correctly uses @testing-library/jest-dom/vitest which registers matchers for Vitest's expect function. This aligns with the library's best practices for Vitest integration.

Based on learnings.


3-14: LGTM! Safe and complete matchMedia mock.

The implementation properly guards against environments lacking window.matchMedia and provides a complete, type-safe MediaQueryList stub. All required properties and methods are present, preventing runtime errors in tests.

frontend/vitest.config.ts (2)

1-13: LGTM! Standard Vitest configuration for React testing.

The configuration correctly sets up:

  • React plugin for JSX transformation and Fast Refresh
  • jsdom environment for DOM testing (appropriate for React components)
  • Global test functions (describe/it/expect)
  • Setup file integration for jest-dom matchers and mocks
  • Test file discovery pattern matching the actual test location

This aligns with Vitest and React Testing Library best practices.

Based on learnings.


10-11: Verify test discovery pattern: exclude may conflict with future test locations.

The exclude: ['tests/**/*'] pattern will prevent discovery of any tests placed in a top-level tests/ directory, while include only searches under src/. This is likely intentional (keeping tests colocated with source code), but ensure this matches your team's testing conventions.

If tests might be placed in tests/ in the future, consider either:

  1. Removing the exclude pattern (Vitest's default excludes are usually sufficient)
  2. Documenting that tests must live under src/ only

Comment on lines +1 to +20
import { render, screen } from '@testing-library/react'
import { Providers } from '../providers'

import Home from '../page'

describe('Home Page', () => {
it('renders the hero heading and description', () => {
render(<Home />, { wrapper: Providers })

expect(
screen.getByRole('heading', { name: /AI Engineering MVP Template/i })
).toBeInTheDocument()

expect(
screen.getByText(
/A starter template for building AI-powered applications with Vector Institute branding\./i
)
).toBeInTheDocument()
})
})
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

🧩 Analysis chain

Critical inconsistency: PR title claims "replace broad matcher" but this adds NEW broad regex matchers.

This test file is newly created (not replacing existing code), yet the PR title states "replace broad matcher in home.test.tsx". Additionally, the test uses case-insensitive regex patterns (/AI Engineering MVP Template/i and /A starter template.../i) which are inherently broad matchers that:

  • Match case-insensitively
  • Match partial text (regex without anchors)
  • Could match unintended text

If the goal is to replace broad matchers with precise assertions, consider using exact string matches:

-    expect(
-      screen.getByRole('heading', { name: /AI Engineering MVP Template/i })
-    ).toBeInTheDocument()
+    expect(
+      screen.getByRole('heading', { name: 'AI Engineering MVP Template' })
+    ).toBeInTheDocument()

-    expect(
-      screen.getByText(
-        /A starter template for building AI-powered applications with Vector Institute branding\./i
-      )
-    ).toBeInTheDocument()
+    expect(
+      screen.getByText(
+        'A starter template for building AI-powered applications with Vector Institute branding.'
+      )
+    ).toBeInTheDocument()

Verification needed:

  1. What existing test or matcher is being replaced? (None visible in the PR)
  2. Do these exact strings exist in the Hero component?

Run this script to verify the actual text content in the Hero component:


🏁 Script executed:

#!/bin/bash
# Find and examine the Hero component to verify exact text matches

echo "=== Searching for Hero component definition ==="
fd -e tsx -e ts Hero --exec rg -l "export.*Hero"

echo -e "\n=== Examining Hero component content ==="
fd -e tsx -e ts Hero --exec cat {}

echo -e "\n=== Searching for the heading text in codebase ==="
rg -i "AI Engineering MVP Template" --type-add 'web:*.{tsx,jsx,ts,js}' --type web

echo -e "\n=== Searching for the description text in codebase ==="
rg -i "starter template for building AI-powered applications" --type-add 'web:*.{tsx,jsx,ts,js}' --type web

Length of output: 669


Update PR title and use exact string matchers in home.test.tsx

  • The PR title claims replacing broad matchers but adds a new test; update it to reflect adding tests.
  • Replace broad regex matchers in home.test.tsx with exact string assertions for the heading and description.
🤖 Prompt for AI Agents
In frontend/src/app/__tests__/home.test.tsx lines 1-20, update the PR title to
reflect that a new test was added rather than replacing broad matchers, and in
the test replace the broad regex matchers with exact string matchers: use
getByRole('heading', { name: 'AI Engineering MVP Template' }) and getByText('A
starter template for building AI-powered applications with Vector Institute
branding.') (case-exact as in the source) so the assertions match exact strings
rather than regexes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 16, 2025

Caution

Docstrings generation - FAILED

No docstrings were generated.

@shayancoin shayancoin closed this Oct 20, 2025
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.

1 participant