Measure and enforce test coverage with Istanbul/nyc, c8, Jest, and Vitest. Covers branch versus line coverage, per-directory thresholds, CI gates, and correctly excluding generated code from reports.
npx skills add https://github.com/PramodDutta/qaskills --skill Code Coverage Analysis
This skill makes an AI agent configure coverage collection correctly (Istanbul instrumentation or V8 native coverage), set thresholds that fail builds, read coverage reports to find genuinely untested branches, and exclude generated or config code so the numbers mean something. Trigger it when a user asks "what is our coverage", wants a coverage gate in CI, or when a coverage/ directory, --coverage flag, .nycrc, or coverageThreshold appears in the project.
if (a && b) return x; can be 100 percent line-covered with three of its four branch outcomes untested.coverageThreshold (Jest), thresholds (Vitest), or --check-coverage (nyc/c8) so CI goes red on regression.all files, not just imported ones. By default some tools only report files touched by tests, so a completely untested module is invisible. Enable all: true (nyc), coverage.all (Vitest), or a broad collectCoverageFrom (Jest).*.d.ts inflate or deflate numbers randomly. Exclude them in config, never by sprinkling ignore comments through generated files.// jest.config.js
module.exports = {
preset: 'ts-jest',
collectCoverage: true,
coverageProvider: 'v8',
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.d.ts',
'!src/**/__generated__/**',
'!src/**/*.stories.tsx',
'!src/test-utils/**',
],
coverageReporters: ['text', 'lcov', 'json-summary'],
coverageThreshold: {
global: {
branches: 80,
functions: 85,
lines: 90,
statements: 90,
},
// Money-handling code gets a stricter gate
'./src/lib/payments/': {
branches: 95,
lines: 98,
},
},
};
npx jest --coverage --ci
# Exit code is 1 if any threshold is missed; CI fails automatically
{
"all": true,
"include": ["src/**/*.ts"],
"exclude": ["**/*.spec.ts", "src/generated/**", "src/migrations/**"],
"reporter": ["text", "html", "lcov"],
"check-coverage": true,
"branches": 80,
"lines": 90,
"functions": 85,
"statements": 90
}
Save as .nycrc.json, then:
npm install --save-dev nyc
npx nyc mocha 'test/**/*.spec.ts'
npx nyc report --reporter=text-summary
c8 reads V8's built-in coverage, so it works with the Node test runner and needs no transpile-time instrumentation:
npm install --save-dev c8
npx c8 --all --src src --reporter=text --reporter=lcov \
--lines 90 --branches 80 --check-coverage \
node --test test/
// vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
coverage: {
provider: 'v8',
all: true,
include: ['src/**/*.ts'],
exclude: ['src/generated/**', 'src/**/*.test.ts', '**/*.config.ts'],
reporter: ['text', 'lcov', 'json-summary'],
thresholds: {
lines: 90,
branches: 80,
functions: 85,
statements: 90,
// Fail if coverage DROPS below auto-updated values
autoUpdate: false,
},
},
},
});
npx vitest run --coverage
// shipping.ts
export function shippingCost(country: string, total: number): number {
if (country === 'US' && total > 50) return 0;
return country === 'US' ? 5 : 15;
}
// shipping.test.ts -- this single test yields 100% LINE coverage
import { shippingCost } from './shipping';
it('ships free for large US orders', () => {
expect(shippingCost('US', 100)).toBe(0);
});
// But branch coverage shows: total <= 50 untested, non-US untested,
// the $5 domestic path untested. Three real behaviors have no test.
The branch report (text reporter prints % Branch per file, the HTML report highlights yellow I/E markers) is how you find these.
// Istanbul-instrumented runners (nyc, babel-plugin-istanbul)
/* istanbul ignore next -- @preserve defensive guard, unreachable after zod validation */
if (typeof input !== 'string') throw new TypeError('input must be a string');
// V8-based runners (vitest --coverage.provider=v8, c8)
/* v8 ignore next 2 */
if (process.platform === 'win32') {
pathSeparator = '\\';
}
Every ignore comment needs a reason suffix; an ignore without a justification is a coverage lie waiting to rot.
# .github/workflows/test.yml (excerpt)
- name: Test with coverage gate
run: npx vitest run --coverage
- name: Print coverage summary to job log
if: always()
run: |
pct_lines=$(jq -r '.total.lines.pct' coverage/coverage-summary.json)
pct_branches=$(jq -r '.total.branches.pct' coverage/coverage-summary.json)
echo "### Coverage: ${pct_lines}% lines / ${pct_branches}% branches" >> "$GITHUB_STEP_SUMMARY"
- name: Upload lcov for review tooling
uses: actions/upload-artifact@v4
with:
name: lcov-report
path: coverage/lcov.info
coverage/index.html) when writing tests for legacy code; the red/yellow highlighting finds untested branches faster than reading source.json-summary totals for speed, keep lcov output for editors and review tools that show per-line coverage in diffs.istanbul ignore on reachable code is technical debt with a receipt.nyc merge, --coverage.reportsDirectory per suite plus lcov merge) before judging.coverage/ get committed; add it to .gitignore.--coverage, coverageThreshold, .nycrc, c8, or @vitest/coverage-v8 to the project.Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup
Use when implementing any feature or bugfix, before writing implementation code
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always
Expert guidance for systematic backtesting of trading strategies. Use when developing, testing, stress-testing, or validating quantitative trading strategies. Covers "beating ideas to death" methodology, parameter robustness testing, slippage modeling, bias prevention, and interpreting backtest results. Applicable when user asks about backtesting, strategy validation, robustness testing, avoiding overfitting, or systematic trading development.
Cloud laboratory platform for automated protein testing and validation. Use when designing proteins and needing experimental validation including binding assays, expression testing, thermostability measurements, enzyme activity assays, or protein sequence optimization. Also use for submitting experiments via API, tracking experiment status, downloading results, optimizing protein sequences for better expression using computational tools (NetSolP, SoluProt, SolubleMPNN, ESM), or managing protein design workflows with wet-lab validation.
This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.
Take pramoddutta/code coverage analysis from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference npm, npx.
Without those the skill loads but fails at the first command.