Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Jest finds and runs the tests, but the coverage report is empty or incomplete

ErrorCoverage data for global was not found

Short answer

Jest only reports coverage for files that tests load, unless collectCoverageFrom lists globs for the rest. Coverage also needs collectCoverage or the --coverage flag. An empty report usually means those globs match nothing, a later pattern cancelled a negation, or coveragePathIgnorePatterns excludes your source folder.

  • Applies to Jest 29, Jest 30, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run Jest with the coverage flag and an explicit glob on the command line. If files now appear, the config is missing or has the wrong patterns.

    npx jest --coverage --collectCoverageFrom='src/**/*.{js,jsx,ts,tsx}'
  2. 2Match what you see, then jump to its fix

    1. 1Tests run, no coverage table prints, no coverage folder appears.Coverage is not switched onFix
    2. 2Only files imported by some test show up; files no test touches are absent.Untested files are missing because collectCoverageFrom is not setFix
    3. 3You excluded a folder with ! but its files are still in the report.A negated pattern is cancelled by a later patternFix
    4. 4Coverage data for global was not found, or the report is empty although tests pass.The source folder is outside roots or matches an ignore patternFix

What does the error look like?

  • Coverage data for global was not found
  • Tests pass but the coverage table lists only a few files, or none

Cause 1 of 4

Coverage is not switched on

1Check

collectCoverage defaults to false, and collectCoverageFrom needs collectCoverage to be true or the --coverage flag.

grep -n "coverage" package.json jest.config.*

2Fix

Run with --coverage, or set collectCoverage in the config.

// jest.config.js
module.exports = {
  collectCoverage: true,
  coverageDirectory: 'coverage',
};

3Verify

A table prints after the run and the coverage folder exists.

npx jest && ls coverage

Confirmed by jestjs.io

Did this fix it?

Cause 2 of 4

Untested files are missing because collectCoverageFrom is not set

1Check

Jest collects coverage for files that tests load. A file with no test is included only if it matches a pattern in collectCoverageFrom.

grep -n "collectCoverageFrom" jest.config.* package.json

2Fix

List the source globs and exclude folders you do not want counted.

module.exports = {
  collectCoverageFrom: [
    'src/**/*.{js,jsx,ts,tsx}',
    '!**/node_modules/**',
    '!src/**/*.d.ts',
  ],
};

3Verify

Run with coverage; previously untested files now appear with 0 percent.

npx jest --coverage

Confirmed by jestjs.io

Did this fix it?

Cause 3 of 4

A negated pattern is cancelled by a later pattern

1Check

Patterns apply in the order written, so a negation followed by a broad glob is overwritten.

grep -n -A8 "collectCoverageFrom" jest.config.*

2Fix

Put negated patterns after the patterns they carve from.

collectCoverageFrom: ['**/*.js', '!**/__tests__/**'],

3Verify

The excluded folder no longer appears.

npx jest --coverage

Confirmed by jestjs.io

Did this fix it?

Cause 4 of 4

The source folder is outside roots or matches an ignore pattern

1Check

roots tells Jest where to look for test and source files, and files matching coveragePathIgnorePatterns are skipped. The default ignore is /node_modules/. A broad custom pattern can hide your own code. The page notes the message appears when your glob patterns are not matching any files.

grep -n "roots\|coveragePathIgnorePatterns\|testMatch" jest.config.* package.json

2Fix

Include the source directory in roots, and write ignore patterns with <rootDir> so they cannot match more than intended.

module.exports = {
  roots: ['<rootDir>/src/'],
  coveragePathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/build/'],
};

3Verify

Run with coverage and confirm the table lists your files.

npx jest --coverage

Confirmed by jestjs.io

Did this fix it?

How do I stop it coming back?

  • Keep collectCoverageFrom in the shared Jest config, not only in a CI command.
  • Open the coverage table in CI logs once after every config change, so an empty report is noticed.
  • Remember the v8 provider uses c8 ignore comments, the default babel provider uses istanbul ignore comments.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.