Jest coverage exclude: files, folders and lines
The patterns and comments that work in Jest 30.5, and five that look right but are not, each one measured.
![Include first. Exclude after. A card: ['src/**/*.js', '!src/generated/**'] leaves generated out; the negation first adds it back.](/assets/jest-coverage-exclude-320.2dedc04c4d.webp)
List your source in collectCoverageFrom and put ! patterns after it:
['src/**/*.js', '!src/generated/**']. coveragePathIgnorePatterns works
too, but it takes regular expressions, not globs. To skip lines, use
/* istanbul ignore next */ on the default provider.
Exclude patterns at a glance
| To exclude | Write |
|---|---|
| A folder | collectCoverageFrom: ['src/**/*.js', '!src/generated/**'] |
| A folder, as a regular expression | coveragePathIgnorePatterns: ['/node_modules/', '/src/generated/'] |
| One file | '!src/legacy/old-pricing.js' in collectCoverageFrom |
| From the command line | --collectCoverageFrom='src/**/*.js' --collectCoverageFrom='!src/generated/**' |
| A function or the next statement | /* istanbul ignore next */ |
An if branch | /* istanbul ignore if */ |
Lines, with coverageProvider: 'v8' | /* c8 ignore start */ … /* c8 ignore stop */ |
We ran every setup here with Jest 30.5.2 and Node.js 24. The project has four
source files; no test imports src/legacy/old-pricing.js. With
collectCoverageFrom: ['src/**/*.js'] and nothing excluded, the report has
14 of 17 lines.
Exclude files and folders
// jest.config.js
module.exports = {
collectCoverageFrom: [
'src/**/*.js',
'!src/generated/**',
'!src/legacy/**',
],
};
The report then listed two files, 12 of 12 lines.
Without collectCoverageFrom, Jest reports only the files your tests
require. Our legacy file was missing from that report, and it appeared, at
0 of 2 lines, once collectCoverageFrom named src.

coveragePathIgnorePatterns gave the same two files:
module.exports = {
collectCoverageFrom: ['src/**/*.js'],
coveragePathIgnorePatterns: ['/node_modules/', '/src/generated/', '/src/legacy/'],
};
Each entry is a regular expression matched against the full path. Setting the
option replaces its default, ['/node_modules/'], so keep that entry.
Ignore lines with comments
function format(cents) {
/* istanbul ignore if */
if (cents < 0) {
return `-${format(-cents)}`;
}
return `${Math.floor(cents / 100)}.${String(cents % 100).padStart(2, '0')}`;
}
/* istanbul ignore next */ above a function leaves the whole function out.
These hints work on Jest’s default provider, which instruments with Babel.
With coverageProvider: 'v8' they did nothing: the same file had 5 uncovered
lines and 1 uncovered branch. The V8 provider reads c8 and v8 hints
instead, and its ignore next covers one line, not the next function. Over a
three-line function, /* c8 ignore next */ left the body uncovered; use
/* c8 ignore next 3 */ or start / stop.
Why your Jest coverage exclude isn’t working
| What we tried | What happened |
|---|---|
! patterns before 'src/**/*.js' | Nothing excluded: the later pattern adds the files back |
coveragePathIgnorePatterns: ['src/generated/**'] | Jest stopped: “Invalid regular expression … Nothing to repeat” |
testPathIgnorePatterns instead | No change: it picks which test files run |
istanbul ignore with coverageProvider: 'v8' | Ignored |
c8 ignore next above a function, V8 provider | Only the first line ignored |

Patterns in collectCoverageFrom are globs from rootDir; ./src/** worked
the same as src/**.
What Supercov adds
npx supercov -- npx jest
npx supercov runs latest gaps
Supercov runs the same command and records which test covered each line,
with branches and MC/DC. It decides what counts from your source directories,
not from collectCoverageFrom. See Jest coverage: V8 vs
Babel for how Jest’s two providers count, Jest
coverage threshold to fail below a floor, and
Vitest coverage exclude for Vitest.
More coverage guides
- Jest coverageThreshold: global, per-folder and per-file
- JaCoCo aggregate report for multi-module Maven and Gradle builds
- pytest ignore directory: --ignore, norecursedirs and collect_ignore
- Merge coverage reports from shards: Vitest, Jest and coverage.py
- Statement vs branch coverage, with decision, line and path coverage
- JaCoCo report not generated: the causes in Maven and Gradle
- Kover exclude: classes, packages and generated code
- sonar.coverage.exclusions: why SonarQube ignores your JaCoCo excludes
- istanbul ignore next vs c8 ignore next: every hint, measured
- Go test coverage exclude: files, packages and mocks
- pytest coverage exclude: omit files, folders and lines
- Vitest coverage exclude: files, folders and lines
- JaCoCo exclude in Maven and Gradle: packages, classes and generated code