Commit 3bf81dd
feat(ci): add unit tests (#24)
* test: add unit tests for voteConfig and stages (Phase 1)
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.
* test: add unit tests for UI components (Phase 2)
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)
* test: add unit tests for custom hooks (Phase 3)
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)
* test: add unit tests for core utilities (Phase 4)
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)
* ci: add unit tests workflow
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: resolve vitest webidl-conversions errors
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.
* fix: add globalSetup to fix webidl-conversions errors
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.
* fix: resolve TypeScript and oxlint errors in test files
- 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
* fix: move webidl-conversions polyfill to config file top
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.
* ci: upgrade Node.js version from 18 to 22
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
* chore: add vite coverage
* chore: upgrade vite deps
* fix
* move test files
* chore: update vite deps
* fix: remove ref to vite.config.test
---------
Co-authored-by: Claude <[email protected]>1 parent 1e628da commit 3bf81dd
File tree
26 files changed
+3231
-494
lines changed- .github/workflows
- src
- components
- ui
- hooks
- lib
- constants
- test
26 files changed
+3231
-494
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | 94 | | |
96 | 95 | | |
97 | 96 | | |
98 | 97 | | |
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
104 | 107 | | |
105 | 108 | | |
106 | 109 | | |
107 | | - | |
108 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
109 | 113 | | |
| 114 | + | |
110 | 115 | | |
111 | 116 | | |
112 | 117 | | |
| |||
118 | 123 | | |
119 | 124 | | |
120 | 125 | | |
121 | | - | |
122 | | - | |
| 126 | + | |
| 127 | + | |
123 | 128 | | |
124 | 129 | | |
125 | 130 | | |
| |||
0 commit comments