LocalCoverage.jl icon indicating copy to clipboard operation
LocalCoverage.jl copied to clipboard

JSON coverage summary output

Open twilsonco opened this issue 2 years ago • 2 comments

(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.

twilsonco avatar Sep 22 '23 19:09 twilsonco

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

tpapp avatar Oct 26 '23 09:10 tpapp

Great!

twilsonco avatar Oct 27 '23 06:10 twilsonco