Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON coverage summary output #47

Open
twilsonco opened this issue Sep 22, 2023 · 2 comments
Open

JSON coverage summary output #47

twilsonco opened this issue Sep 22, 2023 · 2 comments

Comments

@twilsonco
Copy link
Contributor

twilsonco commented Sep 22, 2023

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

@tpapp
Copy link
Collaborator

tpapp commented Oct 26, 2023

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

@twilsonco
Copy link
Contributor Author

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants