-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ci): add unit tests #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add comprehensive unit tests for: - src/lib/voteConfig.ts: 20 tests covering VOTE_CONFIG structure, getVoteConfig, and getVoteValue functions - src/lib/constants/stages.ts: 6 tests for DEFAULT_STAGE_COLOR constant All tests passing (50/50). Phase 1 of the unit testing plan is now complete.
Set up React Testing Library and add comprehensive unit tests for: - Component tests (87 new tests): - GenreBadge.tsx: 9 tests with mocked useGenres hook - StageBadge.tsx: 11 tests for rendering and styling - StagePin.tsx: 9 tests with mocked useStageQuery hook - ui/badge.tsx: 10 tests for variants and props - ui/button.tsx: 20 tests for variants, sizes, and interactions - ui/card.tsx: 28 tests for all card components Infrastructure: - Added @testing-library/react, @testing-library/jest-dom, @testing-library/user-event - Created test setup file (src/test/setup.ts) for jest-dom matchers - Updated vite.config.test.ts to include setupFiles Total: 137 tests passing (Phase 1 + Phase 2)
Add comprehensive unit tests for custom hooks: - use-mobile.tsx: 10 tests for responsive breakpoint detection - useOnlineStatus.ts: 10 tests for online/offline status tracking - useScrollVisibility.ts: 14 tests for IntersectionObserver wrapper - use-toast.ts: 17 tests for toast state management with reducer - useCookieConsent.ts: 16 tests for GDPR consent management All hooks tests include: - State initialization - Event listener setup and cleanup - State updates and transitions - Edge cases and error handling - Mock implementations for browser APIs Total: 204 tests passing (Phases 1-3 combined)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Add comprehensive unit tests for core utility functions: - utils.ts: 12 tests for cn() function (class name merging with Tailwind) - stageUtils.ts: 11 tests for sortStagesByOrder() sorting algorithm - markdown.ts: 21 tests for parseMarkdown() with GFM support - timeUtils.ts: 44 tests for time formatting and timezone conversion functions - formatTimeRange, formatDateTime, formatTimeOnly - toDatetimeLocal, toISOString - combineDateAndTime, convertLocalTimeToUTC All utilities tests include: - Edge cases and null/undefined handling - Format validation - Timezone conversions - Complex data scenarios Total: 292 tests passing (Phases 1-4 combined)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR establishes a comprehensive unit testing foundation for the UpLine codebase by adding Vitest and React Testing Library. The changes include test infrastructure setup and extensive test coverage across utility functions, custom React hooks, and UI components.
Key Changes:
- Added testing dependencies (@testing-library/jest-dom, @testing-library/react, @testing-library/user-event) and configured Vitest with jsdom environment
- Created 320+ unit tests covering 15 test files across utilities, hooks, and components
- Established consistent testing patterns including browser API mocking and data-fetching hook mocking
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| vite.config.test.ts | Added test setup file configuration to load jest-dom matchers |
| src/test/setup.ts | Test setup file importing @testing-library/jest-dom/vitest for extended matchers |
| src/lib/constants/tests/stages.test.ts | Tests for DEFAULT_STAGE_COLOR constant (some redundancy noted) |
| src/lib/tests/voteConfig.test.ts | Comprehensive tests for vote configuration utilities including type mappings |
| src/lib/tests/utils.test.ts | Tests for cn utility covering class merging and Tailwind conflict resolution |
| src/lib/tests/timeUtils.test.ts | Tests for time formatting functions (test naming issues noted) |
| src/lib/tests/stageUtils.test.ts | Tests for stage sorting logic including null/undefined handling |
| src/lib/tests/markdown.test.ts | Tests for markdown parsing covering GFM features and error handling |
| src/hooks/tests/useScrollVisibility.test.ts | Tests for scroll visibility hook with IntersectionObserver mocking |
| src/hooks/tests/useOnlineStatus.test.ts | Tests for online status hook with navigator.onLine mocking |
| src/hooks/tests/useCookieConsent.test.ts | Tests for cookie consent management with cross-domain storage mocking |
| src/hooks/tests/use-toast.test.ts | Tests for toast notification hook including toast lifecycle |
| src/hooks/tests/use-mobile.test.tsx | Tests for mobile detection hook with matchMedia mocking |
| src/components/ui/tests/card.test.tsx | Tests for Card component family verifying styling and ref forwarding |
| src/components/ui/tests/button.test.tsx | Tests for Button component covering variants, sizes, and interactions |
| src/components/ui/tests/badge.test.tsx | Tests for Badge component covering variants and styling |
| src/components/tests/StagePin.test.tsx | Tests for StagePin component with useStageQuery mocking |
| src/components/tests/StageBadge.test.tsx | Tests for StageBadge component with size and color variations |
| src/components/tests/GenreBadge.test.tsx | Tests for GenreBadge component with useGenres mocking (negative assertion issue noted) |
| package.json | Added testing library dependencies to devDependencies |
| pnpm-lock.yaml | Updated lockfile with new testing dependencies and their transitive deps |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Add GitHub Actions workflow to run Vitest unit tests: - Runs on push to main/develop and on PRs - Executes all 292 unit tests - Generates coverage report on PRs - Uploads coverage artifacts for review This provides fast feedback (~20s) compared to E2E tests.
Fix unhandled errors with webidl-conversions and whatwg-url: - Add pool: "forks" to vitest config for better process isolation - Add global polyfills for Set, Map, WeakMap, WeakSet in test setup This resolves the "Cannot read properties of undefined" errors that were occurring during module loading in the test environment. All 292 tests now pass successfully.
Add globalSetup file to polyfill ArrayBuffer and SharedArrayBuffer properties before any test modules are loaded. This prevents the webidl-conversions package from throwing errors during module import. Changes: - Created vitest.global-setup.ts with early polyfills - Updated vite.config.test.ts to use globalSetup - Enhanced src/test/setup.ts with additional polyfills All 292 tests now pass without unhandled errors.
- Fixed timeUtils test for cross-day time ranges by using times farther apart to ensure they span different days regardless of timezone conversion - Fixed unused variable in useScrollVisibility test - Replaced any types with proper TypeScript types using ReturnType utility - Added optional chaining for potentially undefined function calls in use-toast test - Initialized variables with proper types instead of undefined in use-toast test - Fixed update method call to include required id property in use-toast test - Added null coalescing for querySelector result in card test - Added type annotations and assertions for nullable stage_order values in stageUtils tests
Apply ArrayBuffer/SharedArrayBuffer polyfills at the very top of the vite.config.test.ts file, before any imports. This ensures the polyfills are applied before webidl-conversions is loaded by any dependencies. The previous globalSetup approach didn't work in CI because globalSetup runs in a separate context after modules are already loaded. Moving the polyfill to the config file ensures it runs early enough to prevent 'Cannot read properties of undefined (reading get)' errors in Node 18.
Update CI workflows to use Node.js 22 to match local development environment. This provides: - Better compatibility with modern dependencies - Native support for newer JavaScript features - No need for webidl-conversions polyfills - Consistent behavior between local and CI environments
No description provided.