Skip to content

JSON coverage summary output #47

Closed

Description

@twilsonco

(I looked a bit and couldn't find anything that does this. Please let me know if this already exists somewhere.)

I'd like to output a coverage summary in JSON similar to jest --coverage --coverageReporters="json-summary" (relevant docs) to produce

  "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 }
  }

This will mimic the structure of the jest output as much as possible. The file will be such that, if test_args are provided (#46), then the top "total" will be replaced with the name of the test set.


I'm torn on whether this belongs in LocalCoverage.jl or Coverage.jl. On the one hand (from a familiar thread):

using Coverage
coverage = process_folder()
LCOV.writefile("lcov.info", coverage)

and note the other possible values of that jest argument are ["clover", "json", "lcov", "text"], so you could argue that lcov and json should be an alternative output option of Coverage.jl.

But on the other hand, using jest --coverageReporters="text-summary" produces:

=============================== Coverage summary ===============================
Statements   : 100% ( 166/166 )
Branches     : 75% ( 18/24 )
Functions    : 100% ( 49/49 )
Lines        : 100% ( 161/161 )
================================================================================

which is very similar to the text summary output of LocalCoverage.jl:

Coverage of /Users/haiiro/NoSync/LocalCoverage.jl/test/DummyPackage/
┌─────────────────────┬───────┬─────┬──────┬──────┐
│ Filename            │ Lines │ Hit │ Miss │    % │
├─────────────────────┼───────┼─────┼──────┼──────┤
│ src/DummyPackage.jl │     1 │   1 │    0 │ 100% │
│ src/bar.jl          │     2 │   1 │    1 │  50% │
│ src/corge/corge.jl  │     1 │   1 │    0 │ 100% │
│ src/corge/grault.jl │     1 │   0 │    1 │   0% │
│ src/qux.jl          │     2 │   1 │    1 │  50% │
│ src/qux.jl          │     2 │   1 │    1 │  50% │
├─────────────────────┼───────┼─────┼──────┼──────┤
│ TOTAL               │     9 │   5 │    4 │  56% │
└─────────────────────┴───────┴─────┴──────┴──────┘

Personally, I think it should go here since the necessary components are already conveniently located and need only be put in a dict to make for easy json output.


For background, I'm interested in storing the json during CI, then reading it during subsequent runs in order to provide a pass/fail based on coverage increase/decrease, similar to what you get out of the box with codecov.io. (It's either this or cough up the $500/yr for codecov pro!)

Happy to PR.

Activity

  1. tpapp commented on Oct 26, 2023

    @tpapp
    Collaborator

    Sorry for the delayed response, a PR would be very welcome.

  2. twilsonco commented on Oct 27, 2023

    @twilsonco
    ContributorAuthor

    Great!

  3. jakobjpeters commented on May 7, 2026

    @jakobjpeters

    I want this too!

  4. twilsonco commented on May 11, 2026

    @twilsonco
    ContributorAuthor

    Thanks for reminding me about this @jakobjpeters. PR submitted!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions