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

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

Open
QuentinLemCode opened this issue Jul 26, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@QuentinLemCode
Copy link

QuentinLemCode commented Jul 26, 2023

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 QuentinLemCode added the bug Something isn't working label Jul 26, 2023
@ArtiomTr
Copy link
Owner

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

@QuentinLemCode
Copy link
Author

QuentinLemCode commented Jul 26, 2023

@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?

@ArtiomTr
Copy link
Owner

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

@M-Schiller
Copy link

M-Schiller commented Aug 27, 2024

Did you find time to look deeper into this yet? Just now, I could observe the same behavior:

jobs:
  coverage:
    runs-on: ubuntu-latest
    permissions:
      checks: write
      pull-requests: write
      contents: write
    steps:
      - uses: actions/checkout@v4
      - uses: ArtiomTr/[email protected]
        with:
          package-manager: yarn
          output: comment, report-markdown
          icons: emoji
          threshold: 80

The code above runs perfectly fine on PRs but breaks on main:

Begin generating report...
Generating report failed
Error: TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at hu (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2.3.0/dist/index.js:2107:5062)
    at d1 (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2.3.0/dist/index.js:2107:5229)
    at b1 (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2.3.0/dist/index.js:2116:35)
    at g9 (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2.3.0/dist/index.js:2133:336)
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2.3.0/dist/index.js:2145:15890
    at wr (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2.3.0/dist/index.js:2136:164)
    at LN (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2.3.0/dist/index.js:2145:15852)
Generating report ended
Begin report publish...
Report publish skipped
Report publish ended
Begin setting outputs...
Setting outputs skipped
Setting outputs ended
Begin failed tests' annotations publication...
Failed tests' annotations publication failed
Error: TypeError: Cannot read properties of undefined (reading 'runReport')
TypeError: Cannot read properties of undefined (reading 'runReport')
    at /home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2.3.0/dist/index.js:2145:16426
    at wr (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2.3.0/dist/index.js:2136:164)
    at LN (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2.3.0/dist/index.js:2145:16270)
Failed tests' annotations publication ended

Could the reason for this behavior be that there is no PR context on main for the bot to comment in?

@imphatic
Copy link

really want to use this but no matter what combination of configs I use i always get the "Error: TypeError: Cannot convert undefined or null to object" as outlined in this issue.

@rsorelli-hedgepoint
Copy link

rsorelli-hedgepoint commented Oct 31, 2024

Hi there,

Today I got the same issue and it seems to be related with the "threshold" flag.
When I ran the action setting the threshold and I do not met it the coversion error occours.
However, it the project passed the threshold the action completes "OK".

      - name: Jest coverage report
        uses: ArtiomTr/[email protected]
        with: 
          skip-step: install
          working-directory: ${{ matrix.test_dir }}
          annotations: coverage
          threshold: 80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants