davelosert/vitest-coverage-report-action

Wich is the right json-summary ?

WebPirat opened this issue · 6 comments

Hi when i add

https://www.npmjs.com/package/json-summary

getting the error

TypeError: CustomReporter is not a constructor
 ❯ node_modules/vitest/dist/vendor-cli-api.de0530cb.js:9955:16
 ❯ Vitest.setServer node_modules/vitest/dist/vendor-cli-api.de0530cb.js:13397:168
 ❯ configureServer node_modules/vitest/dist/vendor-cli-api.de0530cb.js:14037:11
 ❯ createServer node_modules/vite/dist/node/chunks/dep-79892de8.js:62948:24
 ❯ createVitest node_modules/vitest/dist/vendor-cli-api.de0530cb.js:14069:18
 ❯ startVitest node_modules/vitest/dist/vendor-cli-api.de0530cb.js:20465:15
 ❯ start node_modules/vitest/dist/cli.js:105:17

without it

Error: Failed to load custom Reporter from json-summary....

maybe its a problem with typescript ?

best regards.

Hey @WebPirat ,

there might be a misunderstanding here:
json-summary is a built-in reporter for the coverage-tools used by vitest (c8 and istanbul - see here: https://istanbul.js.org/docs/advanced/alternative-reporters/#json-summary). It is not an additional package that needs installing in your app.

You an use it by using the following vite / vitest configuration (as stated in the docs):

import { defineConfig } from 'vite';

export default defineConfig({
  test: {
    coverage: {
      // you can include other reporters, but 'json-summary' is required, json is recommended
      reporter: ['text', 'json-summary', 'json'],
    }
  }
});

You need to make sure c8 or istanbul is installed, though. But usually, vitest will ask you to do so once you run npx vitest --coverage for the first time.

Vitest workspaces generate coverages (v.30.0) out of the box and do not allow reporters customisation so when i run 'vitest run test --coverage' it never generates a coverage-summary.json file which is required to run the coverage report action. What could be the solution here? I'm using c8 btw

@Oputo50 : I've never worked with vitest workspaces - but from the docs, it might be that you can only define the required reporters in the root config?

This actions definitely requires the coverage-summary.json right now as it is the only way to reliably parse the coverage information. Happy to accept a PR that parses that information from whatever reporter vitest workspaces uses on default though 🙂

@davelosert first of all awesome work on this action!

I guess you could mention the following in a note in your README for the package

      // you can include other reporters, but 'json-summary' is required, json is recommended

You have mentioned it in the code snippet under Usage, but I guess that's pretty easy to miss. I missed it and only realized that it's required once I stumbled upon this issue.

Hey @roerohan, thank you very much for the great feedback, I appreciate it! 🙂
Perfect suggestion, I will add it to the readme.

🎉 This issue has been resolved in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀