Check and configure code coverage thresholds and reporting
Configures code coverage thresholds and reporting for test frameworks.
/plugin marketplace add laurigates/claude-plugins/plugin install configure-plugin@lgates-claude-plugins[--check-only] [--fix] [--threshold <percentage>]configure/Check and configure code coverage thresholds and reporting for test frameworks.
This command validates coverage configuration and sets up reporting for CI/CD integration.
Default threshold: 80% (lines, branches, functions, statements)
Supported frameworks:
@vitest/coverage-v8 or @vitest/coverage-istanbul--coveragepytest-cov plugincargo-llvm-cov or cargo-tarpaulinCRITICAL: Before configuring coverage tools, verify latest versions:
Use WebSearch or WebFetch to verify current versions before configuring coverage tools.
Detect test framework and coverage configuration:
| Indicator | Framework | Coverage Tool |
|---|---|---|
vitest.config.* with coverage | Vitest | @vitest/coverage-v8 |
jest.config.* with coverage | Jest | Built-in |
pyproject.toml [tool.coverage] | pytest | pytest-cov |
.cargo/config.toml with coverage | Rust | cargo-llvm-cov |
For each detected framework, check coverage configuration:
Vitest:
v8 or istanbul)text, json, html, lcov)Jest:
collectCoverage enabledcoverageProvider set (v8 or babel)collectCoverageFrom patterns configuredcoverageThresholds configuredcoverageDirectory specifiedcoverageReporters configuredpytest:
pytest-cov installed[tool.coverage.run] section exists[tool.coverage.report] section exists--cov-fail-under)Rust (cargo-llvm-cov):
cargo-llvm-cov installedGenerate formatted compliance report:
Code Coverage Compliance Report
================================
Project: [name]
Framework: [Vitest 2.x | pytest 8.x | cargo-llvm-cov 0.6.x]
Coverage Configuration:
Provider @vitest/coverage-v8 [✅ CONFIGURED | ❌ MISSING]
Reporters text, json, html, lcov [✅ ALL | ⚠️ PARTIAL]
Output directory coverage/ [✅ CONFIGURED | ⚠️ DEFAULT]
Exclusions node_modules, dist, tests [✅ CONFIGURED | ⚠️ INCOMPLETE]
Thresholds:
Lines 80% [✅ PASS | ⚠️ LOW | ❌ NOT SET]
Branches 80% [✅ PASS | ⚠️ LOW | ❌ NOT SET]
Functions 80% [✅ PASS | ⚠️ LOW | ❌ NOT SET]
Statements 80% [✅ PASS | ⚠️ LOW | ❌ NOT SET]
Current Coverage (if available):
Lines 85% [✅ ABOVE THRESHOLD]
Branches 78% [⚠️ BELOW THRESHOLD]
Functions 92% [✅ ABOVE THRESHOLD]
Statements 85% [✅ ABOVE THRESHOLD]
CI/CD Integration:
Coverage upload codecov/coveralls [✅ CONFIGURED | ❌ MISSING]
Artifact upload coverage reports [✅ CONFIGURED | ⚠️ MISSING]
Overall: [X issues found]
Recommendations:
- Increase branch coverage to meet 80% threshold
- Add lcov reporter for better CI integration
- Configure coverage upload to codecov
Install coverage provider:
npm install --save-dev @vitest/coverage-v8
# or for Istanbul
npm install --save-dev @vitest/coverage-istanbul
Update vitest.config.ts:
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
coverage: {
// Provider: v8 (faster) or istanbul (more accurate)
provider: 'v8',
// Reporters
reporter: [
'text', // Console output
'json', // JSON report for tools
'html', // HTML report for browsing
'lcov', // LCOV for CI/CD (codecov, coveralls)
],
// Output directory
reportsDirectory: './coverage',
// Thresholds (fail tests if below)
thresholds: {
lines: 80,
functions: 80,
branches: 80,
statements: 80,
},
// Files to include in coverage
include: ['src/**/*.{js,ts,jsx,tsx}'],
// Files to exclude
exclude: [
'node_modules/',
'dist/',
'tests/',
'**/*.config.*',
'**/*.d.ts',
'**/*.test.*',
'**/*.spec.*',
'**/types/',
'**/__tests__/',
],
// Clean coverage directory before running
clean: true,
// All files should be shown, even if not tested
all: true,
// Skip full coverage check (use thresholds instead)
skipFull: false,
},
},
});
Add coverage scripts to package.json:
{
"scripts": {
"test:coverage": "vitest run --coverage",
"coverage:report": "open coverage/index.html",
"coverage:check": "vitest run --coverage --reporter=json"
}
}
Update jest.config.ts:
import type { Config } from 'jest';
const config: Config = {
// Enable coverage collection
collectCoverage: true,
// Coverage provider (v8 is faster, babel is more compatible)
coverageProvider: 'v8',
// Files to collect coverage from
collectCoverageFrom: [
'src/**/*.{js,jsx,ts,tsx}',
'!src/**/*.d.ts',
'!src/**/*.stories.*',
'!src/**/__tests__/**',
'!src/**/types/**',
],
// Coverage directory
coverageDirectory: 'coverage',
// Coverage reporters
coverageReporters: [
'text',
'text-summary',
'json',
'html',
'lcov',
],
// Coverage thresholds
coverageThresholds: {
global: {
lines: 80,
functions: 80,
branches: 80,
statements: 80,
},
// Per-file thresholds
'./src/critical/**/*.ts': {
lines: 90,
functions: 90,
branches: 90,
statements: 90,
},
},
// Path patterns to skip for coverage
coveragePathIgnorePatterns: [
'/node_modules/',
'/dist/',
'/tests/',
'.config.js',
],
};
export default config;
Install pytest-cov:
uv add --group dev pytest-cov
Update pyproject.toml:
[tool.pytest.ini_options]
addopts = [
"-v",
"--cov=src",
"--cov-report=term-missing",
"--cov-report=html",
"--cov-report=xml",
"--cov-report=json",
"--cov-fail-under=80",
]
[tool.coverage.run]
source = ["src"]
branch = true
parallel = true
omit = [
"*/tests/*",
"*/migrations/*",
"*/__init__.py",
"*/config.py",
"*/settings.py",
]
[tool.coverage.report]
# Precision for coverage percentage
precision = 2
# Show missing line numbers
show_missing = true
# Fail if below threshold
fail_under = 80
# Lines to exclude from coverage
exclude_lines = [
"pragma: no cover",
"def __repr__",
"def __str__",
"if __name__ == .__main__.:",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if False:",
"if TYPE_CHECKING:",
"@abstractmethod",
"@overload",
]
[tool.coverage.html]
directory = "coverage/html"
[tool.coverage.xml]
output = "coverage/coverage.xml"
[tool.coverage.json]
output = "coverage/coverage.json"
Install cargo-llvm-cov:
cargo install cargo-llvm-cov --locked
Create .cargo/config.toml:
[alias]
coverage = "llvm-cov --html --open"
coverage-lcov = "llvm-cov --lcov --output-path lcov.info"
Add to Cargo.toml:
[package.metadata.coverage]
# Exclude files from coverage
exclude = [
"tests/*",
"benches/*",
"examples/*",
]
Run coverage:
# Generate HTML report
cargo coverage
# Generate LCOV for CI
cargo coverage-lcov
Add to workflow:
- name: Run tests with coverage
run: npm run test:coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-report
path: coverage/
Add to workflow:
- name: Run tests with coverage
run: uv run pytest --cov --cov-report=xml --cov-report=html
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-report
path: coverage/
Add to workflow:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Generate coverage
run: cargo llvm-cov --all-features --lcov --output-path lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./lcov.info
flags: unittests
fail_ci_if_error: true
Add to README.md:
Codecov:
[](https://codecov.io/gh/USERNAME/REPO)
Coveralls:
[](https://coveralls.io/github/USERNAME/REPO?branch=main)
Set up Codecov:
CODECOV_TOKENcodecov.yml configuration:
coverage:
status:
project:
default:
target: 80%
threshold: 1%
patch:
default:
target: 80%
comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: false
Update .fvh-standards.yaml:
standards_version: "2025.1"
last_configured: "[timestamp]"
components:
coverage: "2025.1"
coverage_threshold: 80
coverage_provider: "[v8|istanbul|pytest-cov|llvm-cov]"
coverage_reporters: ["text", "json", "html", "lcov"]
coverage_ci: "codecov"
Code Coverage Configuration Complete
=====================================
Framework: Vitest with @vitest/coverage-v8
Threshold: 80% (lines, branches, functions, statements)
Configuration Applied:
✅ Coverage provider installed
✅ Reporters configured (text, json, html, lcov)
✅ Thresholds set to 80%
✅ Exclusions configured
✅ CI/CD integration added
Scripts Added:
✅ npm run test:coverage (generate coverage)
✅ npm run coverage:report (open HTML report)
CI Integration:
✅ Codecov upload configured
✅ Coverage artifacts uploaded
✅ Badge added to README
Next Steps:
1. Run coverage locally:
npm run test:coverage
2. View coverage report:
npm run coverage:report
3. Check coverage in CI:
Push changes and check workflow
4. Monitor coverage trends:
Visit https://codecov.io/gh/USERNAME/REPO
Coverage Reports: coverage/index.html
| Flag | Description |
|---|---|
--check-only | Report status without offering fixes |
--fix | Apply all fixes automatically without prompting |
--threshold <percentage> | Set coverage threshold (default: 80) |
# Check compliance and offer fixes
/configure:coverage
# Check only, no modifications
/configure:coverage --check-only
# Auto-fix with custom threshold
/configure:coverage --fix --threshold 90
/configure:tests first/configure:tests - Configure testing frameworks/test:coverage - Run tests with coverage/configure:all - Run all FVH compliance checks