jest-coverage-report-action icon indicating copy to clipboard operation
jest-coverage-report-action copied to clipboard

Generating report failed with TypeError: Cannot convert undefined or null to object

Open QuentinLemCode opened this issue 2 years ago • 8 comments
trafficstars

Describe a bug

Hello, The action fail on main branches while it works on PR. See the screenshot below and the report.json gist link

Expected behavior

The report is generated and a comment is added to the PR

Details

  • Action version: latest
  • OS, where your action is running (windows, linux): linux
  • action.yml file
  unit-tests:
    name: Unit Tests
    runs-on: ubuntu-latest
    timeout-minutes: 10
    env:
      NODE_ENV: test
    steps:
      - uses: actions/checkout@v3
      - uses: ./.github/actions/setup-node
      - name: Run Tests
        run: npm run test:ci
      - name: Save coverage report
        uses: actions/upload-artifact@v3
        with:
          name: coverage-report
          path: coverage
          retention-days: 1
      - name: Publish Coverage
        uses: artiomtr/jest-coverage-report-action@f1a1382101d9b92b38e3df05c9ed89a834af97c8
        with:
          coverage-file: ./coverage/report.json
          github-token: ${{ secrets.GITHUB_TOKEN }}
          threshold: 90
          annotations: coverage
          skip-step: all
  • Screenshots

image image https://gist.github.com/QuentinLemCode/3600641d8b3db7c6c5753c1896ce9224

Additional context

QuentinLemCode avatar Jul 26 '23 10:07 QuentinLemCode

Hello @QuentinLemCode 👋,

Looks like the coverage file coverage/report.json has an invalid format. Please make sure you're generating a coverage file with the necessary flags: https://github.com/ArtiomTr/jest-coverage-report-action#customizing-test-script

ArtiomTr avatar Jul 26 '23 11:07 ArtiomTr

@ArtiomTr Thanks for reply I don't see what's wrong with my report.json file. Also the jest command line is the same than in other branches, but it fail only on main. Can you take a look at the gist?

QuentinLemCode avatar Jul 26 '23 11:07 QuentinLemCode

Try to specify:

        with:
          coverage-file: ./coverage/report.json
          base-coverage-file: ./coverage/report.json # this line added
          github-token: ${{ secrets.GITHUB_TOKEN }}
          threshold: 90
          annotations: coverage
          skip-step: all

This will skip coverage comparison. This is not ideal, but at least your CI will work for now. I need more time to dig deeper into this issue

ArtiomTr avatar Jul 26 '23 12:07 ArtiomTr