Skip to content

Parity Coverage JSON

parity-coverage.json is a language-neutral attribution format for ecosystems whose native coverage output does not include which test covered which line.

Use it when Clover or Cobertura can prove aggregate file coverage, but you also want matched-coverage and coverage-attribution.

Schema

json
{
  "version": 1,
  "globalPercent": 80,
  "files": [
    {
      "path": "src/formatCurrency.ts",
      "coveragePercent": 70,
      "totalExecutableLines": 10,
      "lines": [
        {
          "line": 1,
          "coveredBy": ["formatCurrency.test::coversPrimaryBehavior"]
        }
      ]
    }
  ]
}
FieldRequiredDescription
versionRecommendedFormat version. Use 1.
globalPercentOptionalProject-level coverage percentage from 0 to 100.
files[].pathYesSource path relative to the project root.
files[].coveragePercentRecommendedAll-test coverage percentage for the file.
files[].totalExecutableLinesRequired for matched-coverageNumber of executable lines in the file.
files[].lines[].lineYesExecutable line number.
files[].lines[].coveredByYesTest names that covered that line.

Configuration

yaml
coverage_xml: [.parity/per-test, parity-coverage.json, coverage-xml, clover.xml, cobertura.xml]

structure:
  - name: "Utilities"
    paths:
      source: "src"
      test: "tests"
    rules:
      - minimum-coverage:
          min: 70
      - matched-coverage:
          min: 40

JavaScript Converter Example

This minimal converter shows the shape a custom tool should produce. Real converters should read attribution from the runner, coverage library, or instrumentation layer available in the project.

js
import { writeFileSync } from 'node:fs'

const report = {
  version: 1,
  globalPercent: 80,
  files: [
    {
      path: 'src/formatCurrency.ts',
      coveragePercent: 70,
      totalExecutableLines: 10,
      lines: [
        {
          line: 1,
          coveredBy: ['formatCurrency.test::formats_cents']
        },
        {
          line: 2,
          coveredBy: [
            'formatCurrency.test::formats_cents',
            'checkout.integration.test::renders_total'
          ]
        }
      ]
    }
  ]
}

writeFileSync('parity-coverage.json', `${JSON.stringify(report, null, 2)}\n`)

Then run:

bash
parity check --config=parity.yaml --format=json