Skip to content

Add component testing infrastructure for www app#146

Merged
yamcodes merged 14 commits intomainfrom
copilot/fix-52
Oct 7, 2025
Merged

Add component testing infrastructure for www app#146
yamcodes merged 14 commits intomainfrom
copilot/fix-52

Conversation

Copy link
Contributor

Copilot AI commented Sep 11, 2025

Note

We already had a component testing PR (#56) so feel free to reference it for the implementation.

This PR implements comprehensive component testing for the www Next.js application using Vitest and React Testing Library.

What's Added

Testing Infrastructure

  • Vitest configuration with React and jsdom support for component testing
  • Test setup with @testing-library/jest-dom matchers for enhanced assertions
  • Testing dependencies including @testing-library/react, jsdom, and @vitejs/plugin-react
  • Integration with existing monorepo test setup via updated root vitest config

Component Tests

Added comprehensive test coverage for key components:

  • Button component (10 tests) - Tests all variants, sizes, disabled states, custom classes, and asChild behavior
  • Card component (3 tests) - Tests content rendering, styling application, and prop forwarding
  • CopyButton component (3 tests) - Tests rendering, styling, and accessibility features
  • Logo component (4 tests) - Tests text rendering, default styling, custom classes, and HTML semantics
  • StarUsButton component (4 tests) - Tests responsive behavior, link attributes, and custom styling

Configuration Updates

  • Updated root vitest.config.ts to include www app in test projects
  • Added test scripts to www app package.json (test, test:ui, test:coverage)
  • Configured proper test cleanup and mocking support

Test Results

  • 24 new component tests all passing
  • Total test suite: 76 tests (52 existing + 24 new)
  • All tests run successfully across packages and apps
  • Maintains existing test performance and reliability

Benefits

  • Enables confident refactoring of React components
  • Catches regressions early in development
  • Provides foundation for testing complex UI interactions
  • Follows established testing patterns from the repository
  • Supports TypeScript with full type checking

The testing infrastructure follows best practices and integrates seamlessly with the existing monorepo setup, providing a solid foundation for maintaining and expanding the www app's component library.

Fixes #52.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit/integration tests for multiple UI components and hooks, plus shared test setup and project-wide Vitest config with coverage.
  • Documentation
    • Revamped testing philosophy and structure in TESTING.md; added README note on test colocation.
  • Chores
    • Switched Vite React plugin to SWC variant across projects; added test scripts, UI runner, coverage tooling, and typings.
    • Updated Vitest configs (projects, setup files, coverage, path resolution).
    • Ignored coverage directory and *.tar.wim; adjusted lint rules for test files.
    • Minor cleanup and commented code removal.

@vercel
Copy link

vercel bot commented Sep 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
arkenv Ready Ready Preview Comment Oct 7, 2025 4:43pm

@changeset-bot
Copy link

changeset-bot bot commented Sep 11, 2025

⚠️ No Changeset found

Latest commit: 512da98

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI and others added 2 commits September 11, 2025 05:14
Co-authored-by: yamcodes <2014360+yamcodes@users.noreply.github.com>
Co-authored-by: yamcodes <2014360+yamcodes@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Component Testing Add component testing infrastructure for www app Sep 11, 2025
Copilot AI requested a review from yamcodes September 11, 2025 05:17
@github-actions github-actions bot added www Improvements or additions to arkenv.js.org tests This issue or PR is about adding, removing or changing tests labels Sep 11, 2025
@yamcodes
Copy link
Owner

Notice we're using Vitest Projects in this monorepo setup @copilot

Copy link
Contributor Author

Copilot AI commented Sep 12, 2025

Notice we're using Vitest Projects in this monorepo setup @copilot

Yes, exactly! The implementation follows the Vitest Projects pattern where each package/app has its own vitest config with a unique name (arkenv, @arkenv/vite-plugin, www) and the root config orchestrates running all projects together. This provides good isolation while maintaining unified test execution across the monorepo.

@yamcodes yamcodes mentioned this pull request Sep 13, 2025
@yamcodes yamcodes marked this pull request as ready for review October 7, 2025 14:13
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 7, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds extensive component tests and testing infrastructure for apps/www, updates Vitest configs and scripts, tweaks linting and TS types for tests, switches Vite React plugin to the SWC variant across multiple packages, adjusts .gitignore, and makes a minor test-only attribute addition to EditOnGithub. Removes one obsolete test and a commented snippet.

Changes

Cohort / File(s) Summary of changes
Repo tooling and configs
package.json, vitest.config.ts, .gitignore, biome.jsonc
Adds test UI/coverage scripts and devDeps; broadens Vitest project matching and adds coverage config; re-adds *.tar.wim ignore and ignores coverage/; disables useUniqueElementIds for *.test.tsx.
apps/www testing infrastructure
apps/www/package.json, apps/www/vitest.config.ts, apps/www/tests/setup.ts, apps/www/tests/README.md, apps/www/tsconfig.json
Introduces RTL/JSDOM tooling, React SWC plugin, tsconfig paths; sets up Vitest project with setup file and name; documents test colocation; adds jest-dom types.
apps/www component tests
apps/www/components/page/copy-button.test.tsx, apps/www/components/page/edit-on-github.test.tsx, apps/www/components/page/logo.test.tsx, apps/www/components/page/sail-button.test.tsx, apps/www/components/page/star-us-button.test.tsx, apps/www/components/page/video-demo.test.tsx, apps/www/components/ui/button.test.tsx, apps/www/components/ui/heading.test.tsx
Adds new test suites covering rendering, accessibility, props, interactions, routing, external links, and window.open behavior; includes mocks for Sentry, toasts, router, and utilities.
apps/www hook test
apps/www/hooks/use-is-mobile.test.ts
Adds unit tests for responsive hook using mocked matchMedia and viewport sizes.
apps/www minor implementation tweak
apps/www/components/page/edit-on-github.tsx
Adds data-testid="square-pen-icon" on SquarePen icon for testing.
apps/www library cleanup
apps/www/lib/source.tsx, apps/www/lib/utils/cn.test.ts
Removes commented-out helper; deletes cn utility test file.
Vite React SWC migration (multi-package)
apps/playgrounds/vite/package.json, apps/playgrounds/vite/vite.config.ts, examples/with-vite-react-ts/package.json, examples/with-vite-react-ts/vite.config.ts, packages/vite-plugin/package.json
Replaces @vitejs/plugin-react with @vitejs/plugin-react-swc in dependencies/configs.
Add vite plugin dep to playground
apps/playgrounds/vite/package.json
Ensures dependency on "@arkenv/vite-plugin": "workspace:*" (deduplicated).

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

A rabbit taps the keys with glee,
Tests now bloom like clover free.
SWC winds through Vite at night,
Buttons click and links take flight.
Hashes hop, the videos play—
Green fields light our CI day. 🐇✅

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The PR contains updates to playground and example projects, root and package configurations, and plugin packages that fall outside the scope of adding component testing for the www app as defined in issue #52. Consider splitting unrelated updates into separate pull requests or reverting non-www app changes to align this PR with its intended scope.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the main change of adding component testing infrastructure for the www app and directly relates to the PR objectives using clear and descriptive phrasing.
Linked Issues Check ✅ Passed The PR fully addresses issue #52 by introducing Vitest and React Testing Library configuration, adding necessary dependencies and scripts in the www app, and delivering a comprehensive suite of component tests that verify behavior and accessibility for the targeted UI components.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Note

Free review on us!

CodeRabbit is offering free reviews until Wed Oct 08 2025 to showcase some of the refinements we've made.

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

cursor[bot]

This comment was marked as outdated.

yamcodes and others added 3 commits October 7, 2025 19:15
- Updated pnpm version in package.json
- Updated dependencies in pnpm-lock.yaml
- Changed project paths to use glob patterns for better scalability.
- Enhanced coverage configuration with additional reporters and exclusions.
- Updated app-specific Vitest config to use `defineProject` and modified setup file path.
- Removed obsolete setup file for tests in the www app.
@github-actions github-actions bot added the docs Improvements or additions to documentation label Oct 7, 2025
cursor[bot]

This comment was marked as outdated.

- Replaced instances of @vitejs/plugin-react with @vitejs/plugin-react-swc across multiple package.json and config files.
- Updated pnpm-lock.yaml to reflect the new plugin version and dependencies.
- Removed deprecated Babel plugins related to React JSX transformation.
@github-actions github-actions bot added @arkenv/vite-plugin Issues or Pull Requests involving the Vite plugin for ArkEnv example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) labels Oct 7, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 7, 2025

Open in StackBlitz

npm i https://pkg.pr.new/arkenv@146
npm i https://pkg.pr.new/@arkenv/vite-plugin@146

commit: 512da98

- Added new dependencies: @swc/plugin-styled-jsx, @testing-library/dom, styled-jsx, and vite-tsconfig-paths in package.json files.
- Updated pnpm-lock.yaml to include new versions and resolutions for added dependencies.
- Modified Vitest configuration to integrate vite-tsconfig-paths for better path resolution.
- Updated testing strategy in TESTING.md to emphasize component behavior and accessibility.
- Added new tests for EditOnGithub and SailButton components, ensuring correct rendering and functionality.
- Improved existing tests for CopyButton and StarUsButton, focusing on accessibility and user interactions.
- Introduced new test files for VideoDemo and Heading components, covering various scenarios and edge cases.
- Updated biome.jsonc to include linter rules for test files.
cursor[bot]

This comment was marked as outdated.

- Add test:ui and test:coverage scripts
- Configure coverage in .gitignore
- Install @vitest/coverage-v8 and @vitest/ui
- Added restoration of document.getElementById mock in afterEach to prevent test pollution.
@yamcodes
Copy link
Owner

yamcodes commented Oct 7, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 7, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 0

♻️ Duplicate comments (5)
examples/with-vite-react-ts/package.json (1)

22-22: Verify plugin version compatibility with Vite 7 and React 19.

Similar to other files in this PR, the change to @vitejs/plugin-react-swc v4.1.0 may represent a version downgrade. Ensure the plugin version is compatible with Vite ^7.1.5 and React ^19.0.0.

apps/playgrounds/vite/package.json (1)

21-21: Verify plugin version compatibility with Vite 7 and React 19.

Same concern as other files: ensure @vitejs/plugin-react-swc v4.1.0 is compatible with Vite ^7.1.9 and React ^19.2.0.

apps/www/components/page/logo.test.tsx (1)

6-8: Potential redundant cleanup call.

Similar to other test files, this manual cleanup may be unnecessary if global cleanup is configured in the test setup.

apps/www/components/page/edit-on-github.test.tsx (1)

54-56: Potential redundant cleanup call.

apps/www/components/page/video-demo.test.tsx (1)

18-20: Potential redundant cleanup call.

🧹 Nitpick comments (10)
apps/www/components/page/sail-button.test.tsx (2)

35-44: Strengthen animation verification.

The test verifies that the link remains in the document after click, but doesn't validate the actual animation state. Consider checking for animation-related classes or state changes if the component exposes them.

If the component has observable animation states (e.g., CSS classes, data attributes), add assertions like:

 await user.click(link);
 
-// The button should still be rendered (animation state change)
-expect(link).toBeInTheDocument();
+// Verify animation state is triggered
+expect(link).toHaveClass("animating"); // or relevant animation class
+expect(link).toBeInTheDocument();

82-86: Consider icon-specific verification.

The test only verifies text content, not the actual Sailboat icon component. If icon rendering is critical, consider using a data-testid on the icon similar to the SquarePen icon approach in edit-on-github.tsx.

apps/www/components/page/copy-button.test.tsx (1)

48-52: Strengthen prop forwarding test.

The test doesn't actually verify that additional props are forwarded. Consider passing a specific prop and asserting its presence.

Apply this diff to properly test prop forwarding:

 it("forwards additional props", () => {
-  render(<CopyButton command="npm install arkenv" />);
+  render(<CopyButton command="npm install arkenv" data-testid="copy-btn" />);
   const button = screen.getByRole("button");
-  expect(button).toBeInTheDocument();
+  expect(button).toHaveAttribute("data-testid", "copy-btn");
 });
apps/www/hooks/use-is-mobile.test.ts (1)

63-90: Strengthen media query change test.

The test doesn't actually verify that the hook responds to media query changes. Consider simulating a query change event and verifying the hook's response.

To properly test media query changes:

 it("handles media query changes", () => {
-  // Mock window.innerWidth for desktop
   Object.defineProperty(window, "innerWidth", {
     writable: true,
     configurable: true,
     value: 1024,
   });
 
+  let changeHandler: ((event: MediaQueryListEvent) => void) | null = null;
   mockMatchMedia.mockReturnValue({
     matches: false,
     media: "(max-width: 768px)",
     onchange: null,
     addListener: vi.fn(),
     removeListener: vi.fn(),
-    addEventListener: vi.fn(),
+    addEventListener: vi.fn((_, handler) => {
+      changeHandler = handler as (event: MediaQueryListEvent) => void;
+    }),
     removeEventListener: vi.fn(),
     dispatchEvent: vi.fn(),
   });
 
   const { result, unmount } = renderHook(() => useIsMobile());
+  expect(result.current).toBe(false);
 
-  // The hook should render without errors and return a boolean
-  expect(typeof result.current).toBe("boolean");
+  // Simulate media query change to mobile
+  if (changeHandler) {
+    changeHandler({ matches: true } as MediaQueryListEvent);
+  }
+  
+  // Verify hook updates to mobile state
+  expect(result.current).toBe(true);
 
   unmount();
-  // Test passes if no errors are thrown
-  expect(true).toBe(true);
 });
apps/www/components/page/star-us-button.test.tsx (1)

5-6: Enhance fetch mock in tests
Keep mocking global.fetch to avoid real API calls, but stub its implementation (e.g. mockResolvedValue({ ok: true, json: () => Promise.resolve({ stargazers_count: 42 }) })), then add assertions:

apps/www/components/ui/button.test.tsx (2)

7-9: Potential redundant cleanup call.

The manual cleanup() call in afterEach may be redundant if apps/www/tests/setup.ts already configures global cleanup. Per Testing Library's documentation, cleanup is automatically handled when using modern versions with proper setup.

Verify if the global setup already handles cleanup:

#!/bin/bash
# Check if global cleanup is configured in the test setup file
cat apps/www/tests/setup.ts | grep -i cleanup

83-93: Consider verifying variant and size styling.

While these tests confirm the component renders with variant/size props, they don't verify that the correct styling classes are applied. This could miss bugs where props are accepted but don't affect rendering.

If you want stronger assertions, consider checking for specific classes:

 it("supports different variants through props", () => {
   render(<Button variant="outline">Outline</Button>);
   const button = screen.getByRole("button");
   expect(button).toBeInTheDocument();
+  expect(button).toHaveClass("variant-outline"); // or whatever class the variant applies
 });

However, if you're following the "test behavior, not styling" philosophy from TESTING.md, the current approach is acceptable.

apps/www/components/page/video-demo.test.tsx (3)

14-15: Redundant mock clearing.

Line 15's mockWindowOpen.mockClear() is unnecessary because line 14's vi.clearAllMocks() already clears all mocks, including mockWindowOpen.

Apply this diff:

 beforeEach(() => {
   vi.clearAllMocks();
-  mockWindowOpen.mockClear();
 });

30-47: Consider consolidating duplicate video attribute tests.

Lines 30-47, 157-168, and 170-178 test similar or identical video attributes. This creates maintenance burden without adding value.

Consider consolidating these into a single comprehensive test or removing the duplicate assertions to keep tests DRY.

Also applies to: 157-168, 170-178


108-120: Redundant StackBlitz URL verification tests.

Lines 108-120 and 122-135 test the exact same behavior (clicking opens the correct StackBlitz URL). The second test adds no additional coverage.

Consider removing one of these tests or differentiating them (e.g., test different file parameter values if that's parameterizable).

Also applies to: 122-135

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 430a1cf and 253af30.

⛔ Files ignored due to path filters (2)
  • examples/with-vite-react-ts/package-lock.json is excluded by !**/package-lock.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (27)
  • .gitignore (1 hunks)
  • TESTING.md (1 hunks)
  • apps/playgrounds/vite/package.json (1 hunks)
  • apps/playgrounds/vite/vite.config.ts (1 hunks)
  • apps/www/components/page/copy-button.test.tsx (1 hunks)
  • apps/www/components/page/edit-on-github.test.tsx (1 hunks)
  • apps/www/components/page/edit-on-github.tsx (1 hunks)
  • apps/www/components/page/logo.test.tsx (1 hunks)
  • apps/www/components/page/sail-button.test.tsx (1 hunks)
  • apps/www/components/page/star-us-button.test.tsx (1 hunks)
  • apps/www/components/page/video-demo.test.tsx (1 hunks)
  • apps/www/components/ui/button.test.tsx (1 hunks)
  • apps/www/components/ui/heading.test.tsx (1 hunks)
  • apps/www/hooks/use-is-mobile.test.ts (1 hunks)
  • apps/www/lib/source.tsx (0 hunks)
  • apps/www/lib/utils/cn.test.ts (0 hunks)
  • apps/www/package.json (2 hunks)
  • apps/www/tests/README.md (1 hunks)
  • apps/www/tests/setup.ts (1 hunks)
  • apps/www/tsconfig.json (1 hunks)
  • apps/www/vitest.config.ts (1 hunks)
  • biome.jsonc (1 hunks)
  • examples/with-vite-react-ts/package.json (1 hunks)
  • examples/with-vite-react-ts/vite.config.ts (1 hunks)
  • package.json (2 hunks)
  • packages/vite-plugin/package.json (1 hunks)
  • vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • apps/www/lib/source.tsx
  • apps/www/lib/utils/cn.test.ts
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-12T06:23:45.463Z
Learnt from: CR
PR: yamcodes/arkenv#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-12T06:23:45.463Z
Learning: Applies to **/*.test.ts : In tests, save and restore process.env in setup/teardown (beforeEach/afterEach) to avoid leakage between cases

Applied to files:

  • apps/www/tests/setup.ts
📚 Learning: 2025-09-12T06:23:45.463Z
Learnt from: CR
PR: yamcodes/arkenv#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-12T06:23:45.463Z
Learning: Applies to **/*.test.ts : Use Vitest's describe/it structure in tests

Applied to files:

  • apps/www/tests/setup.ts
  • TESTING.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: pkg-pr-new
🔇 Additional comments (29)
apps/www/tests/README.md (1)

1-8: LGTM!

Clear and concise documentation of the test colocation strategy. The example effectively demonstrates the expected file structure.

.gitignore (1)

39-42: LGTM!

Appropriate additions to ignore coverage artifacts generated by the new testing infrastructure and archive files.

apps/playgrounds/vite/package.json (1)

14-14: LGTM!

Appropriate addition of the ArkEnv Vite plugin dependency to the playground app.

apps/playgrounds/vite/vite.config.ts (1)

2-2: LGTM!

The import change to the SWC-based React plugin is consistent with the package.json update, and the usage pattern remains identical.

examples/with-vite-react-ts/vite.config.ts (1)

2-2: LGTM!

Consistent with other Vite configuration updates in this PR.

vitest.config.ts (2)

5-5: LGTM!

The switch from an explicit project list to glob patterns ["packages/*", "apps/*"] improves maintainability by automatically including new packages and apps without config updates.


6-30: LGTM!

Comprehensive coverage configuration with sensible defaults:

  • v8 provider is the modern Vitest standard
  • Multiple reporter formats (text, json, html) for different consumption needs
  • Extensive and appropriate exclude patterns covering build outputs, test files, config files, examples, type definitions, and static assets
packages/vite-plugin/package.json (1)

17-17: No compatibility issues found for @vitejs/plugin-react-swc v4.1.0. Peer dependencies include Vite ^7, and the plugin does not restrict React versions—compatible with React 19.

package.json (1)

17-18: LGTM! Test infrastructure additions align with PR objectives.

The new test:ui and test:coverage scripts, along with the corresponding Vitest dependencies, properly support the component testing infrastructure being introduced.

Also applies to: 24-25

apps/www/components/page/star-us-button.test.tsx (1)

14-19: LGTM! Comprehensive test coverage.

The test suite provides excellent coverage of StarUsButton functionality:

  • Verifies dual rendering (mobile/desktop)
  • Validates link attributes (href, target, rel)
  • Confirms custom className support
  • Ensures proper accessibility attributes

Also applies to: 21-30, 32-37, 39-45, 47-57

apps/www/components/page/sail-button.test.tsx (1)

23-33: LGTM! Thorough click behavior testing.

The test suite properly validates:

  • Rendering and link attributes
  • Different click behaviors (middle, ctrl, meta)
  • Accessibility of button text

Also applies to: 46-56, 58-68, 70-80, 88-92

apps/www/components/page/copy-button.test.tsx (1)

22-27: LGTM! Good accessibility and behavior coverage.

The tests properly verify:

  • Accessibility attributes (aria-label)
  • Icon rendering
  • Command prop handling
  • Button styling (hover classes)

Also applies to: 29-33, 35-39, 41-46

apps/www/hooks/use-is-mobile.test.ts (1)

17-38: LGTM! Solid mobile/desktop detection tests.

The tests properly verify the hook's behavior for different screen sizes with correct matchMedia mocking.

Also applies to: 40-61

apps/www/components/ui/heading.test.tsx (2)

16-20: LGTM! Mock cleanup properly implemented.

The use of vi.restoreAllMocks() in the afterEach hook properly addresses the previous concern about test pollution. This ensures document.getElementById and other mocks are fully restored between tests.


22-27: LGTM! Comprehensive Heading component tests.

The test suite provides excellent coverage:

  • Rendering without/with id
  • Custom heading levels (h1, h2, etc.)
  • Anchor link functionality and scrolling behavior
  • Hash updates
  • Custom className and prop forwarding
  • Accessibility attributes

Also applies to: 29-36, 38-46, 48-65, 67-80, 82-90, 92-100, 102-107

apps/www/components/page/edit-on-github.tsx (1)

32-32: LGTM! Appropriate test hook.

The data-testid attribute enables reliable icon querying in tests without affecting production behavior.

apps/www/tests/setup.ts (1)

1-9: LGTM! Proper test setup configuration.

The setup file correctly:

  • Extends Vitest's expect with jest-dom matchers for enhanced DOM assertions
  • Registers global cleanup after each test to prevent test pollution

This aligns with testing best practices and the learnings about proper test isolation. Based on learnings.

apps/www/tsconfig.json (1)

18-18: LGTM!

Adding @testing-library/jest-dom to the types array enables TypeScript to recognize jest-dom matchers globally across all test files, which is the standard approach for this library.

apps/www/package.json (2)

11-13: LGTM!

The test scripts follow standard Vitest conventions and provide good coverage for different testing scenarios (basic run, UI mode, and coverage reporting).


48-66: LGTM!

The testing dependencies are well-chosen and align with modern React testing practices. The SWC-based toolchain (lines 48, 59) provides faster transforms than Babel, and the Testing Library ecosystem (lines 50-53) is the industry standard for React component testing.

apps/www/components/ui/button.test.tsx (1)

11-103: Excellent test coverage!

The test suite comprehensively covers the Button component's behavior, including accessibility (keyboard navigation, focus), interaction patterns (clicks, disabled state), composition (asChild), and prop forwarding. This aligns well with the testing philosophy documented in TESTING.md.

apps/www/components/page/logo.test.tsx (2)

17-25: Consider whether CSS class testing aligns with testing philosophy.

According to TESTING.md lines 24-25, the testing philosophy states "What We Don't Test: Pure styling or CSS classes." These tests explicitly verify CSS classes like font-bold, decoration-wavy, etc.

If these classes are part of the component's guaranteed API (e.g., consumers rely on them for overrides or specificity), then testing them is reasonable. Otherwise, consider focusing on behavioral aspects instead.

Based on learnings


35-40: Good semantic element verification!

Testing that the component renders as a CODE element is valuable, as it verifies the semantic HTML structure that affects accessibility and styling context.

apps/www/components/page/edit-on-github.test.tsx (1)

1-233: Excellent test coverage with proper mocking strategy!

This test suite exemplifies the "mock at component boundaries" principle from TESTING.md. The tests comprehensively cover:

  • Path handling variations and edge cases (lines 86-152)
  • Error scenarios with proper Sentry integration (lines 171-217)
  • Accessibility attributes (lines 68-70, 95-96)
  • Environment variable configuration (lines 99-125)

The mocking strategy isolates the component while still testing its integration with utilities like getLinkTitleAndHref.

apps/www/components/page/video-demo.test.tsx (1)

205-220: Excellent error handling test!

Testing the graceful handling of popup blockers (when window.open returns null) is important for resilient user experience. This ensures the component doesn't throw errors in restrictive environments.

TESTING.md (2)

13-36: Excellent testing philosophy documentation!

The new Component Testing Philosophy section provides clear, actionable guidance that aligns with modern React testing best practices:

  • Behavioral focus over implementation details (lines 15-22)
  • Accessibility-first testing approach (line 32)
  • Smart mocking strategy at component boundaries (line 33)
  • Co-location principle for maintainability (line 35)

This guidance will help maintain consistent, high-quality tests across the codebase.

Based on learnings


3-3: Improved clarity in testing strategy.

The rewording from generic "combines" to "focused testing that combines" (line 3) and clarifying examples' dual purposes (lines 7-9) makes the testing approach more concrete and understandable.

Also applies to: 7-11

apps/www/vitest.config.ts (2)

5-11: LGTM - Configuration correctly migrated to project-scoped setup!

The changes properly address the path alias resolution:

  1. defineProject usage (line 5) correctly scopes this config to the www app within the monorepo's Vitest workspace
  2. tsconfigPaths plugin (line 10) handles the ~/* path aliases by reading from tsconfig.json, replacing the manual alias configuration
  3. React SWC plugin (lines 7-9) provides faster compilation with styled-jsx support

The previous concern about path alias resolution failures is resolved by using the tsconfigPaths plugin, which properly applies aliases within the test environment.


13-15: Good test configuration!

The test name "arkenv.js.org" clearly identifies this project in test output, and the setup file properly extends the test environment with jest-dom matchers and global cleanup.

- Remove redundant mock resets
- Simplify test setup
process.env.NEXT_PUBLIC_DOCS_CONTENT_PATH = "apps/www/content/docs/";
process.env.NEXT_PUBLIC_GITHUB_URL = "https://github.com/yamcodes/arkenv";
});

Copy link

Choose a reason for hiding this comment

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

Bug: Test Pollution from Uncleaned Environment Variables

The beforeEach hook sets process.env variables, but the afterEach hook doesn't clean them up. This can lead to test pollution, where environment variables from one test affect subsequent tests, potentially causing flakiness.

Fix in Cursor Fix in Web

@yamcodes yamcodes merged commit 9d36749 into main Oct 7, 2025
18 checks passed
@yamcodes yamcodes deleted the copilot/fix-52 branch October 7, 2025 16:43
This was referenced Nov 1, 2025
This was referenced Nov 21, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@arkenv/vite-plugin Issues or Pull Requests involving the Vite plugin for ArkEnv docs Improvements or additions to documentation example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) tests This issue or PR is about adding, removing or changing tests www Improvements or additions to arkenv.js.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Component Testing

2 participants