istanbul-js
Menu
Tutorials

Jest coverage: use its provider, scope and thresholds

Enable coverage in Jest itself and choose its collection provider explicitly.

Illustrative coverage measures are checked against a threshold.
Jest owns collection, source selection and threshold settings; configure its provider directly.

Should unimported files affect the result? Which ignore comments does your provider recognize? Jest exposes scope, output and thresholds directly. This setup does not need a second nyc wrapper.

Keep coverage options in Jest

This CommonJS fragment assumes an existing passing suite and application JavaScript under src. Merge the keys into your project's configuration.

jest.config.cjs (merge into existing config)

module.exports = {
  coverageProvider: 'babel',
  collectCoverageFrom: [
    'src/**/*.{js,cjs}',
    '!src/**/*.test.js',
    '!src/**/*.test.cjs'
  ],
  coverageReporters: ['text', 'html', 'lcovonly'],
  coverageThreshold: {
    global: {
      statements: 85,
      branches: 80,
      functions: 85,
      lines: 85
    }
  }
};

package.json (script fragment)

{
  "scripts": {"coverage": "jest --coverage"}
}

These limits illustrate a policy; they are not universal targets. Negated scope patterns follow the positive pattern because Jest applies them in order. Setting collectCoverageFrom does not enable collection alone; this command supplies --coverage.

Choose babel or v8 intentionally

Jest documents babel and v8 providers. The Babel provider recognizes Istanbul ignore hints; the V8 provider uses c8 hints. An Istanbul-style HTML report does not identify which provider collected the data.

When changing providers, inspect a representative branch and any ignored code before comparing totals. Keep provider, transform and scope settings with the tests.

Inspect files, then missing paths

First review the file list. An unimported application file should contribute when it matches collectCoverageFrom. Then inspect missing branches and choose inputs with meaningful assertions. Threshold enforcement can fail after all assertions pass.

SymptomCheck
Unknown coverage or 0/0The source glob and project root.
No terminal summaryInclude text or text-summary in coverageReporters.
Ignore hint has no effectProvider and comment syntax.
Assertions pass; process failsThresholds and missing coverage data.

Replacing coverageReporters replaces Jest's default list. Keep a terminal reporter for readable CI totals. For tool selection across runners, see the integration guide.

Primary sources

Check official documentation against the tools installed in your project. These explanations and examples are independent.