irongut/CodeCoverageSummary

Not working with JEST

karthik2265 opened this issue · 5 comments

I am using JEST for testing and I am generating the coverage report in cobertura format, and this error shows up when the workflow is run.

Coverage File: /github/workspace/coverage/cobertura-coverage.xml
Parsing Error: No package data found - /github/workspace/coverage/cobertura-coverage.xml

yml workflow file:

name: Node tests (with coverage)
on:
  push:
    branches:
      - '*'
      - '!master'
      - '!SS-test'
      - '!SS-UAT-test'
      - '!PS-prod'
  pull_request:
    branches:
      - 'master'
jobs:
  unit_tests:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      
      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: 14

      - name: Install npm packages
        run: npm ci
      
      - name: Test 
        run: npm run test:coverage

      - name:
        uses: actions/upload-artifact@v3
        with:
          name: my-artifact
          path: "coverage/" # or path/to/artifact

      - name: Code Coverage Report
        uses: irongut/CodeCoverageSummary@v1.3.0
        with:
          filename: "/coverage/cobertura-coverage.xml"
          badge: true
          fail_below_min: true
          format: markdown
          hide_branch_rate: false
          hide_complexity: true
          indicators: true
          output: both
          thresholds: '60 80'

could someone please help me figure out whats going wrong

found the issue, I only had dummy tests and no real tests for the functions in the project and when I added some real tests it's working fine.

found the issue, I only had dummy tests and no real tests for the functions in the project and when I added some real tests it's working fine.

@karthik2265 Thanks for letting me know. If you have a sample test file you could contribute I'd like to see the output from Jest and add it to my test suite.

Is there a solution for this for when you have a project that actually doesn't have any tests yet? @irongut

We're using this in a NX monorepo, so all apps/packages doesn't have tests yet.

Coverage File: /github/workspace/coverage/apps/blockchain-api/cobertura-coverage.xml
Parsing Error: No package data found - /github/workspace/coverage/apps/blockchain-api/cobertura-coverage.xml
Coverage File: /github/workspace/coverage/apps/web-app/cobertura-coverage.xml
Coverage File: /github/workspace/coverage/apps/notifications-api/cobertura-coverage.xml
Coverage File: /github/workspace/coverage/apps/platform-api/cobertura-coverage.xml

Hey @BeyondEvil , I realized this after a bit of research, If you are using JEST, we can set coverage threshold and we don't need a github action.

take a look at this: https://jestjs.io/docs/configuration#coveragethreshold-object

Thank You

Is there a solution for this for when you have a project that actually doesn't have any tests yet? @irongut

We're using this in a NX monorepo, so all apps/packages doesn't have tests yet.

Coverage File: /github/workspace/coverage/apps/blockchain-api/cobertura-coverage.xml
Parsing Error: No package data found - /github/workspace/coverage/apps/blockchain-api/cobertura-coverage.xml
Coverage File: /github/workspace/coverage/apps/web-app/cobertura-coverage.xml
Coverage File: /github/workspace/coverage/apps/notifications-api/cobertura-coverage.xml
Coverage File: /github/workspace/coverage/apps/platform-api/cobertura-coverage.xml

I ran into this myself.

If you remove the test command from the package.json in the package with no tests then lerna/nx will not run the command in that package.. And so you get no coverage files for that package.

Not ashamed to say, it took me far too long to think of this "workaround"