davelosert/vitest-coverage-report-action

Failed to parse the json-summary when specifying custom path and tests are failing

Closed this issue ยท 4 comments

I put the coverage under the top output directory.

Workflow:

      - name: Run test
        run: pnpm test:coverage

      - name: Report Coverage
        if: always() # Also generate the report if tests are failing
        uses: davelosert/vitest-coverage-report-action@v2
        with:
          json-summary-path: ./output/coverage/coverage-summary.json
          json-final-path: ./output/coverage/coverage-final.json

vite.config.ts

import { defineConfig } from 'vite'
import GithubActionsReporter from 'vitest-github-actions-reporter'

const isInCI = !!process.env.GITHUB_ACTIONS

export default defineConfig({
  test: {
    alias: {
      '@/': new URL('./src/', import.meta.url).pathname,
    },
    reporters: isInCI ? ['default', new GithubActionsReporter()] : ['default', 'html'],
    outputFile: {
      html: './output/reporters/html/index.html',
    },
    coverage: {
      enabled: true,
      reporter: isInCI ? ['json-summary', 'json'] : ['html'],
      provider: 'istanbul', // or 'v8'
      reportsDirectory: './output/coverage',
    },
  },
})

Failing tests and report coverage error:

image

Successful tests and report coverage:

image

You can change your vite.config.ts to use the reportOnFailure option., like:

export default defineConfig({
  test: {
    // ..omitted other fields
    coverage: {
      reportOnFailure: true, // add this one
      // ..omitted other fields
    },
  },
})

The default value of it was changed in Vitest 0.34.0.

I hope this helps you ๐Ÿ™‚

Thanks @goibon ! The option reportOnFailure: true is probably right.

But I decide to skip coverage report until the tests are passing, since the previous steps prior to test might be falling sometimes and the coverage report obviously doesn't need to be performed (not always()).
In addition, the coverage report mean little for failed tests.

- name: 'Report Coverage'
      # if: always() # Also generate the report if tests are failing
      uses:  davelosert/vitest-coverage-report-action@v2

@JunlinPan-Crypto: Thank you for reporting. I will put the reportOnFailure option @goibon hinted into the documentation, probably this weekend, to make this more clear.

@goibon : Thank you very much for jumping in here and answering the question! โค

๐ŸŽ‰ This issue has been resolved in version 2.2.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€