Frontend Coverage Report Setup
This document describes how frontend test coverage reporting is configured in this project.
Overview
Frontend test coverage is generated using Vitest’s built-in coverage functionality with the v8 coverage provider. Coverage reports are automatically generated during CI builds and uploaded as publicly accessible badges.
Local Development
Running Coverage Reports
# Run tests with coverage report
npm run test:coverage
# View HTML coverage report
open coverage/index.html
Coverage Configuration
Coverage is configured in vitest.config.ts:
coverage: {
provider: 'v8',
reporter: ['text', 'html', 'lcov', 'json'],
exclude: [
'node_modules/',
'src/test/',
'**/*.d.ts',
'**/*.config.*',
'**/coverage/**',
'src/scripts/**',
]
}
CI/CD Integration
Cloud Build Configuration
The cloudbuild.yaml file includes steps to:
- Run frontend tests with coverage
- Extract coverage percentage from the output
- Generate a coverage badge JSON file
- Upload the badge to Google Cloud Storage
Coverage Badge Generation
The coverage badge is generated in the following steps:
- Run Tests with Coverage
CI=true npm run test:coverage > coverage-output.txt 2>&1 - Extract Coverage Percentage
COVERAGE=$(grep -E "All files" coverage-output.txt | head -1 | awk -F'|' '{print $2}' | tr -d ' ') -
Generate Badge JSON
{ "schemaVersion": 1, "label": "${BRANCH_NAME}-frontend-coverage", "message": "${COVERAGE}%", "color": "${COLOR}" } -
Upload to GCS
gsutil cp frontend-coverage-badge.json gs://${BUCKET}/coverage-badges/frontend-${BRANCH_NAME}-coverage.json
Badge Colors
Coverage badges use the following color scheme:
- 90%+: brightgreen
- 80-89%: green
- 70-79%: yellow
- 60-69%: orange
- <60%: red
Using Coverage Badges and Reports
Once uploaded, coverage badges and reports can be accessed via:
Coverage Badge
Direct JSON URL
https://storage.googleapis.com/{BUCKET}/coverage-badges/frontend-{BRANCH}-coverage.json
Shields.io Badge URL
https://img.shields.io/endpoint?url=https://storage.googleapis.com/{BUCKET}/coverage-badges/frontend-{BRANCH}-coverage.json
Markdown Usage with Link to Full Report
[](https://storage.googleapis.com/{BUCKET}/coverage-reports/frontend-{BRANCH}/index.html)
Full Coverage Report
The complete HTML coverage report is available at:
https://storage.googleapis.com/{BUCKET}/coverage-reports/frontend-{BRANCH}/index.html
This report includes:
- File-by-file coverage breakdown
- Line-by-line coverage visualization
- Uncovered code highlighting
- Coverage trends and statistics
Troubleshooting
Coverage Not Generated
If coverage reports are not generated:
- Ensure
@vitest/coverage-v8is installed:npm install --save-dev @vitest/coverage-v8 - Check that the coverage directory exists after running tests:
ls -la coverage/
Badge Not Updating
If the badge doesn’t update:
- Check Cloud Build logs for errors
- Verify the GCS bucket permissions allow public read access
- Clear browser cache or add a cache-busting parameter to the URL
Low Coverage Numbers
If coverage seems unexpectedly low:
- The coverage includes all files, including those without tests
- Check the coverage exclusions in
vitest.config.ts - Review the HTML coverage report to identify untested files
Related Documentation
- Backend Coverage Setup - Similar setup for backend tests
- Testing Guide - General testing documentation