Skip to main content

Coverage Requirements

This guide outlines the test coverage requirements and guidelines for Gradiant.

Coverage Thresholds

Coverage Badge

Global Requirements

{
  "vitest": {
    "coverageThreshold": {
      "global": {
        "statements": 90,
        "branches": 85,
        "functions": 90,
        "lines": 90
      }
    }
  }
}

Critical Paths

The following areas require 100% coverage:
  • Authentication flows
  • Data encryption/decryption
  • Payment processing
  • HIPAA compliance features
  • Security middleware
  • Error handling
  • Data validation

Coverage Reports

HTML Report

Generate and view HTML coverage report:
# Generate report
npm run test:coverage

# Open report in browser
npm run test:coverage:open
Example report structure:
coverage/
├── lcov-report/
│   ├── index.html
│   ├── src/
│   │   ├── auth/
│   │   ├── api/
│   │   └── services/
│   └── assets/
└── lcov.info

Coverage Badges

We use shields.io for coverage badges:
![Coverage](https://img.shields.io/badge/coverage-94%25-brightgreen.svg)
![Statements](https://img.shields.io/badge/statements-95%25-brightgreen.svg)
![Branches](https://img.shields.io/badge/branches-85%25-yellow.svg)
![Functions](https://img.shields.io/badge/functions-92%25-brightgreen.svg)

Coverage Requirements by Type

Unit Tests

  • Components: 95% coverage
    • All props combinations
    • All state transitions
    • Error boundaries
    • Loading states
  • Services: 100% coverage
    • All public methods
    • Error cases
    • Edge cases
    • Timeout handling
  • Utils: 100% coverage
    • All exported functions
    • Input validation
    • Error handling

Integration Tests

  • API Endpoints: 100% coverage
    • All routes
    • HTTP methods
    • Status codes
    • Response formats
  • Database Operations: 95% coverage
    • CRUD operations
    • Transactions
    • Constraints
    • Indexes
  • External Services: 90% coverage
    • API calls
    • Error handling
    • Retry logic
    • Rate limiting

E2E Tests

  • User Flows: 85% coverage
    • Critical paths
    • Authentication
    • Data management
    • Real-time features
  • UI Interactions: 80% coverage
    • Navigation
    • Forms
    • Modals
    • Responsive design

Excluded from Coverage

Configuration Files

  • Environment configs
  • Build scripts
  • Type definitions
  • Documentation

Test Files

  • Test utilities
  • Fixtures
  • Mocks
  • Test setup

Generated Code

  • API clients
  • GraphQL types
  • Migration files
  • Build output

Coverage Monitoring

CI/CD Integration

name: Coverage

on: [push, pull_request]

jobs:
  coverage:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Install dependencies
        run: npm ci

      - name: Run tests with coverage
        run: npm run test:coverage

      - name: Upload coverage
        uses: codecov/codecov-action@v2
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ./coverage/lcov.info
          fail_ci_if_error: true

Local Monitoring

  1. Pre-commit hook:
#!/bin/sh
npm run test:coverage:check
  1. VS Code extension:
{
  "coverage-gutters.showLineCoverage": true,
  "coverage-gutters.showRulerCoverage": true,
  "coverage-gutters.highlightdark": "rgba(45, 121, 10, 0.2)"
}

Best Practices

  1. Regular Monitoring
    • Check coverage reports daily
    • Address coverage gaps promptly
    • Track coverage trends
  2. Coverage Quality
    • Don’t just hit lines
    • Test edge cases
    • Verify actual behavior
  3. Maintenance
    • Update thresholds as needed
    • Remove dead code
    • Keep reports clean
For more information about specific testing areas, refer to: