Code Coverage Quick Reference
Run Code Coverage Locally
npm run test:coverageOutput:
- Runs all tests in
src/**/*.{test,spec}.{js,jsx} - Generates coverage reports in
coverage/directory - Displays coverage percentages in terminal
- Creates HTML report at
coverage/index.html
View Coverage Report in Browser
After running npm run test:coverage, view the interactive HTML report:
Option 1: Using npx http-server (recommended)
cd coverage
npx http-serverThen open the localhost URL shown (usually http://localhost:8080)
Option 2: Using Python
cd coverage
python3 -m http.server 8000Then open http://localhost:8000 in your browser
Option 3: VS Code Live Server
- Install "Live Server" extension
- Right-click
coverage/index.html - Select "Open with Live Server"
What the report shows:
- ✅ Line-by-line coverage (green = tested, red = untested)
- ✅ Coverage by file with statistics
- ✅ Clickable drill-down into each file
- ✅ Missing coverage details
What Gets Tested
Included:
- ✅ All
.test.jsand.spec.jsfiles - ✅ React components
- ✅ Utility functions
- ✅ Library code
Excluded:
- ❌ Storybook files (
.stories.jsx) - ❌ Build output (
dist/) - ❌ Dependencies (
node_modules/)
Coverage Report
Terminal Output
Test Files 3 passed (3)
Tests 13 passed (13)
% Coverage report from v8
File | % Stmts | % Branch | % Funcs | % Lines
-----------|---------|----------|---------|----------
All files | 78.49 | 54.28 | 90 | 79.77
Icon.jsx | 80 | 75 | 100 | 100HTML Report
View detailed report:
open coverage/index.html
# or
firefox coverage/index.htmlShows:
- Line-by-line coverage
- Which lines aren't tested (red highlighting)
- Coverage trends
GitHub Actions
Coverage Workflow
Automatic runs on:
- Push to
devormain - Pull requests to
devormain
Outputs:
coverage/artifact (30-day retention)- PR comment with coverage summary
- Coverage badge
Access coverage:
- Go to Actions tab
- Select "Code Coverage Report" workflow
- Click the run
- Download
coverage-reportartifact
Coverage Thresholds
Current:
- Minimum: 50% (MVP phase)
Recommended by phase:
- Beta: 70%
- Production: 80%+
To adjust threshold:
Edit .github/workflows/coverage.yml:
- name: Check coverage thresholds
run: |
THRESHOLD=70 # Change thisCommon Issues
Tests fail locally but pass in CI
Cause: Firebase credentials missing Fix: Copy .env.local.example to .env.local with dev credentials
"jsdom is not available" error
Fix: Make sure environment: 'jsdom' in vitest.config.js
Coverage showing 0%
Cause: No tests found or tests not running Fix: Check that tests have .test.js or .spec.js suffix
HTML report not generating
Cause: No passing tests Fix: Get at least one test passing first
Writing Tests
Basic Test
import { describe, it, expect } from 'vitest'
import { render } from '@testing-library/react'
import MyComponent from './MyComponent'
describe('MyComponent', () => {
it('renders without crashing', () => {
const { container } = render(<MyComponent />)
expect(container).toBeTruthy()
})
})Test with User Interaction
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
it('handles button click', async () => {
const user = userEvent.setup()
render(<Button onClick={onClick} />)
const button = screen.getByRole('button')
await user.click(button)
expect(onClick).toHaveBeenCalled()
})Improving Coverage
Current Status
- Overall: ~79% statements covered
- Firebase: 64% (expected - mostly stubs)
- Components: 80%+
- Profile screens: 97%
Next Steps
Add tests for untested components
- Focus on high-impact components first
- Start with authentication screens
Increase branch coverage (currently 54%)
- Add tests for error conditions
- Test conditional logic
Mock Firebase properly
- Create shared mocks for firebase.js
- Use them across tests
Files
- Config:
vitest.config.js - Setup:
test.setup.js - Workflow:
.github/workflows/coverage.yml - Tests:
src/**/*.test.js - Reports:
coverage/(gitignored)