Commit a7d3895
feat: add MSW for mocking GitHub API in tests (#90)
This commit sets up Mock Service Worker (MSW) for comprehensive GitHub API mocking in tests, replacing manual jest.mock patterns with realistic network-level mocks.
## Changes
### Core Testing Infrastructure
- **src/test/msw-setup.ts**: MSW server setup with lifecycle hooks
- **src/test/github-handlers.ts**: 35+ GitHub API endpoint handlers
- **src/test/README.md**: Comprehensive documentation and usage guide
### Test Suite
- **src/gh.spec.ts**: Full test coverage for gh and ghc clients
- 35 tests covering all major GitHub API operations
- Tests for repos, pulls, issues, git, and users APIs
- Cache behavior tests for ghc wrapper
- Error handling tests (404, rate limits)
### Configuration
- **bunfig.toml**: Added MSW setup to test preload
- **package.json**: Added msw@^2.11.6 as dev dependency
## Coverage
All GitHub API endpoints used in the codebase:
- **Repos**: get, createFork, getBranch, listTags, getCommit, listReleases, webhooks
- **Pulls**: list, get, create, update, requestReviewers, listReviewComments
- **Issues**: list, get, update, comments, labels, timeline
- **Git**: getTag, deleteRef
- **Users**: getAuthenticated, getByUsername
## Benefits
1. **Realistic mocking**: Tests actual HTTP requests, not module implementations
2. **Type safety**: Full TypeScript support with Octokit types
3. **Centralized**: Single source of truth for mock data
4. **Maintainable**: Easy to add new endpoints
5. **Transparent**: Existing tests continue to work
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude <[email protected]>1 parent 9f4da8b commit a7d3895
File tree
9 files changed
+1806
-82
lines changed- src
- check
- test
9 files changed
+1806
-82
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
| |||
This file was deleted.
0 commit comments