# Jest coverage exclude: files, folders and lines > Exclude files from Jest coverage with collectCoverageFrom negations or coveragePathIgnorePatterns regexes, ignore lines with comments, and fix excludes that fail. Web page: https://supercov.com/blog/jest-coverage-exclude · Published 2026-11-22 All Supercov pages for agents: https://supercov.com/llms.txt · Full text: https://supercov.com/llms-full.txt The patterns and comments that work in Jest 30.5, and five that look right but are not, each one measured. 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 ```js // 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`. ![Two pattern lists. src/**/*.js followed by !src/generated/** and !src/legacy/** leaves 2 files, 12 of 12 lines. The negations first, then src/**/*.js, adds them all back: 4 files, 14 of 17 lines. coveragePathIgnorePatterns takes regular expressions, and src/generated/** stops Jest.](https://supercov.com/assets/jest-coverage-exclude-flow-1360.0cec11d6c2.webp) *collectCoverageFrom is read in order: the last pattern that matches a file decides.* `coveragePathIgnorePatterns` gave the same two files: ```js 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 ```js 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 | ![A grid of seven setups against four files. Without collectCoverageFrom, legacy is missing. src/**/*.js keeps all four. Adding a negation keeps pricing and receipt. Negations first keep all four. A regular-expression ignore keeps pricing and receipt. A glob in coveragePathIgnorePatterns stops Jest. testPathIgnorePatterns keeps all four.](https://supercov.com/assets/jest-coverage-exclude-grid-1360.7d04eb1cdf.webp) *What each setup left in the report, measured with Jest 30.5.2.* Patterns in `collectCoverageFrom` are globs from `rootDir`; `./src/**` worked the same as `src/**`. ## What Supercov adds ```sh 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](https://supercov.com/compare/jest-coverage.md) for how Jest's two providers count, [Jest coverage threshold](https://supercov.com/blog/jest-coverage-threshold.md) to fail below a floor, and [Vitest coverage exclude](https://supercov.com/blog/vitest-coverage-exclude.md) for Vitest.