Skip to content
Latchkey

How to Generate Jest Coverage in CI

Run Jest with --coverage and configure lcov output so CI has both a printed summary and a machine-readable file.

Add --coverage to your Jest invocation and set coverageReporters to include lcov and text. Jest writes coverage/lcov.info and prints a table you can read in the log.

Steps

  • Run jest --coverage (or npm test -- --coverage) in the CI step.
  • Set coverageReporters to ["text", "lcov", "cobertura"] for both logs and uploads.
  • Point later upload steps at coverage/lcov.info.

jest.config.js

jest.config.js
module.exports = {
  collectCoverage: true,
  coverageDirectory: 'coverage',
  coverageReporters: ['text', 'lcov', 'cobertura'],
  collectCoverageFrom: ['src/**/*.{js,ts}', '!src/**/*.d.ts'],
};

Workflow

.github/workflows/ci.yml
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npx jest --coverage

Gotchas

  • collectCoverageFrom matters: without it, files never imported by a test are counted as fully uncovered or not at all.
  • The text reporter prints to the log; lcov and cobertura are what upload tools consume.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →