Jest finds and runs the tests, but the coverage report is empty or incomplete
Coverage data for global was not foundShort 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.
Fix it fast
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}'2Match what you see, then jump to its fix
- 1
Tests run, no coverage table prints, no coverage folder appears.Coverage is not switched onFix - 2
Only files imported by some test show up; files no test touches are absent.Untested files are missing because collectCoverageFrom is not setFix - 3
You excluded a folder with ! but its files are still in the report.A negated pattern is cancelled by a later patternFix - 4
Coverage 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
- 1
What does the error look like?
Coverage data for global was not foundTests 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 coverageConfirmed by jestjs.io
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.json2Fix
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 --coverageConfirmed by jestjs.io
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 --coverageConfirmed by jestjs.io
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.json2Fix
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 --coverageConfirmed by jestjs.io
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
Jest finds no test files and exits with code 1
No tests found, exiting with code 1
Jest exits with code 1 when its file scan matches nothing.
5 causes, each with a fixWeb 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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fix