Istanbul reporter required for `json-summary` report
Closed this issue · 7 comments
Since v0.32.0, Vitest uses the @vitest/coverage-v8 provider to collect coverage. This provider seems to generate different reports, for example the json-summary
report doesn't exist for v8.
In fact, you explicitly have to switch to istanbul
and add the reporters to generate the json-summary
and json
reports:
npx vitest --coverage.enabled --coverage.provider=istanbul --coverage.reporter=json-summary --coverage.reporter=json
Maybe you could add this info to the README to help others.
Thank you for the great package! ❤️
Hi @zirkelc,
thank you for flagging this. I will have a look at it this weekend!
Hi @zirkelc, thanks again for reporting this! ❤️
However, from what I understand, v8
still supports the json-summary
and, in fact, I am using it with to test this very action since I upgraded to v0.32.0
without problems. It just has to be explicitly defined, as seen in my vite.config.ts.
How did you come to the conclusion that it wouldn't? Do you have an error in one of your packages with it?
Hi @davelosert thanks for taking the time to investigate this.
You're right the issue seems to be related to Vitest workspaces. I created a repo to reproduce this issue: https://github.com/zirkelc/vitest-coverage-json-summary
This repo has two packages packages/foo
and packages/bar
with their own vitest.config.js
and a root vitest.workspace.js
.
If you run the tests from the root, it will not produce the json-summary.json
file:
# ./
vitest run --coverage
However, if you run it inside the packages/foo
, it will produce the json-summary.json
file:
# /packages/foo
vitest run --coverage
If you append the coverage
options as flags and run it from the root, it will also produce the json-summary.json
file:
# ./
vitest --coverage.enabled --coverage.provider=v8 --coverage.reporter=json-summary --coverage.reporter=json
The root folder contains vitest.workspace.js
but no vitest.config.js
, so Vitest ignores these coverage
options on the individual packages/*/vitest.config.js
files. This is also stated in the docs: https://vitest.dev/guide/workspace.html#configuration
I was simply expecting Vitest to hoist these coverage
options from the project configs into the workspace config.
So in summary, to produce the json-summary.json
file in monorepo with Vitest workspaces enabled you either have to add the coverage
to the CLI command or you have to add vitest.config.js
to the root folder.
Hi @zirkelc ,
thank you for finding the error and sharing this! Great information on vitest-workspace compatibility that I'd love to have in the docs!
I am happy to accept a PR to add to the docs if you want to tackle this, else I will do it myself later this week once I find the time. 🙂
Sure, I would be happy to contribute to this great project. I will submit a PR in the next few days.
I had some time and wrote down a few words while the memory is still fresh 😄
Let me know if it's understandable or if I should add anything else.
@zirkelc : Thank you again very much for this contribution! Really appreciate you taking the time to investigate and write up your findings. 🙂
The docs are updated and, with the next release, it will also update on the marketplace.