Jest coverage: How can I get a total percentage of coverage?

Thanks to Teneff’s answer, I go with the coverageReporter=”json-summary”.

 jest --coverage --coverageReporters="json-summary" 

This generates a coverage-summary.json file which can easily be parsed. I get the total values directly from the json:

  "total": {
    "lines": { "total": 21777, "covered": 65, "skipped": 0, "pct": 0.3 },
    "statements": { "total": 24163, "covered": 72, "skipped": 0, "pct": 0.3 },
    "functions": { "total": 5451, "covered": 16, "skipped": 0, "pct": 0.29 },
    "branches": { "total": 6178, "covered": 10, "skipped": 0, "pct": 0.16 }
  }

Leave a Comment