Jest Coverage Configuration Builder

Configure Jest coverage thresholds and reporting for your project

Generate a Jest configuration focused on coverage: global threshold percentages for statements, branches, functions, and lines, coverage reporters, collectCoverageFrom globs, output directory, and CI-failing enforcement mode.

What does coverageThreshold do?

It sets minimum coverage percentages Jest must meet. If any global metric falls below its number, Jest exits with a non-zero code, which fails your CI pipeline. It does not change which tests run, only the pass or fail gate.

Coverage gating for Jest in one config

A Jest configuration controls not just which tests run but how coverage is measured and whether low coverage fails the build. This tool generates the coverage-focused subset: global thresholds, the files measured, the reporters produced, and the output directory.

How it works

Jest computes four coverage metrics. Statements counts executed statements, branches counts each side of every conditional, functions counts called functions, and lines counts executed source lines. The coverageThreshold.global block sets a minimum percentage for each; if any falls short, Jest exits non-zero and CI fails. Because the check is a simple numeric comparison, edge cases like a 0% target never fail and a 100% target demands every branch be exercised.

collectCoverageFrom is independent of which tests run — it forces files to be instrumented even when no test imports them, so untested files appear as 0% rather than vanishing from the report. Negated globs such as !src/**/*.d.ts remove declaration files and stories that would otherwise dilute the numbers. Reporters in coverageReporters decide the output format: text prints a table, lcov writes the machine-readable file consumed by SonarQube and Codecov, and html renders a browsable report under coverageDirectory.

Tips and example

Run with jest --coverage to activate collection, or set collectCoverage: true as this builder does to make it the default. A typical gate looks like:

{
  "collectCoverage": true,
  "collectCoverageFrom": ["src/**/*.{ts,tsx}", "!src/**/*.d.ts"],
  "coverageDirectory": "coverage",
  "coverageReporters": ["text", "lcov"],
  "coverageThreshold": {
    "global": { "statements": 80, "branches": 75, "functions": 80, "lines": 80 }
  }
}

Start thresholds at your current coverage and ratchet them up so the gate never blocks a clean PR while still preventing regressions.