MishaKav / jest-coverage-comment

Comments a pull request or commit with the jest code coverage badge, full report and tests summary
MIT License
80 stars 34 forks source link

Does not create output / comment #70

Closed mindrunner closed 1 year ago

mindrunner commented 1 year ago

Something seems broken and I cannot figure out what. It seems like my coverage files were parsed correctly, but then there is no output generated, nor is a comment posted to my PR. What am I missing here?

      - name: Jest Coverage Comment
        uses: MishaKav/jest-coverage-comment@main
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          title: Test Coverage
          multiple-files: |
            Unit Test, ./build/test/unit/coverage/coverage-summary.json
            Integration Test 1, ./build/test/int/coverage/coverage-summary-1.json
            Integration Test 2, ./build/test/int/coverage/coverage-summary-2.json
            Integration Test 3, ./build/test/int/coverage/coverage-summary-3.json
            Integration Test 4, ./build/test/int/coverage/coverage-summary-4.json
          multiple-junitxml-files: |
            Unit Test, ./build/test/unit/junit.xml
            Integration Test 1, ./build/test/int/junit-1.xml
            Integration Test 2, ./build/test/int/junit-2.xml
            Integration Test 3, ./build/test/int/junit-3.xml
            Integration Test 4, ./build/test/int/junit-4.xml

image

      - name: Check the output coverage
        run: |
          echo "Summary Report"
          echo "Coverage Percentage - ${{ steps.coverageComment.outputs.coverage }}"
          echo "Coverage Color - ${{ steps.coverageComment.outputs.color }}"
          echo "Summary Html - ${{ steps.coverageComment.outputs.summaryHtml }}"

          echo "JUnit Report"
          echo "tests - ${{ steps.coverageComment.outputs.tests }}"
          echo "skipped - ${{ steps.coverageComment.outputs.skipped }}"
          echo "failures - ${{ steps.coverageComment.outputs.failures }}"
          echo "errors - ${{ steps.coverageComment.outputs.errors }}"
          echo "time - ${{ steps.coverageComment.outputs.time }}"

          echo "Coverage Report"
          echo "lines - ${{ steps.coverageComment.outputs.lines }}"
          echo "branches - ${{ steps.coverageComment.outputs.branches }}"
          echo "functions - ${{ steps.coverageComment.outputs.functions }}"
          echo "statements - ${{ steps.coverageComment.outputs.statements }}"
          echo "coverage - ${{ steps.coverageComment.outputs.coverage }}"
          echo "color - ${{ steps.coverageComment.outputs.color }}"
          echo "Coverage Html - ${{ steps.coverageComment.outputs.coverageHtml }}"

image

MishaKav commented 1 year ago

You can't see the full output, because you missed an Id, try to add it:

- name: Jest Coverage Comment
   id: coverageComment
   uses: MishaKav/jest-coverage-comment@main

why its not posted posted to my PR I need to see the full workflow and by which trigger you try to run it.

mindrunner commented 1 year ago

Alright, some issues are solved. But not all of them. It seems like a comment is created as soon as I add the pull_request trigger. On push trigger, it does not work. Would that be expected? What I want to achieve is:

1) run test suite on every push 2) post results in open PR (if one exist)

If I have pull_request and push trigger. Tests are ran twice when I push new code to an open PR, which seem senseless to me.

Other issue is the coverage-path parameter. I am supposed to pass the stdout of jest there, right? If I do pass it on to tee as you do in your example, I only get an empty file. If I also redirect stderr, I get the content I would expect, but parsing seems broken:

File read successfully "./build/test/unit/out.txt"
Coverage Report
  coverage: 0
  color: red
  branches: 0
  functions: 0
  lines: 0
  statements: 0
  coverageHtml: <details><summary>Coverage Report (<b>0%</b>)</summary><table><tr><th>File</th><th>% Stmts</th><th>% Branch</th><th>% Funcs</th><th>% Lines</th><th>Uncovered Line #s</th></tr><tbody>&nbsp;</tbody></table></details>

Simplified example:

name: Test
on:
  - push
  - pull_request
jobs:
  unit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: ./.github/actions/yarn-install

      - name: Create coverage directory
        run: mkdir -p build/test/unit/

      - name: Unit
        run: yarn test:unit --coverage 2>&1 | tee ./build/test/unit/out.txt

      - name: Jest Coverage Comment
        id: coverageComment
        uses: MishaKav/jest-coverage-comment@main
        with:
          unique-id-for-comment: unit
          github-token: ${{ secrets.GITHUB_TOKEN }}
          title: Unit Test Coverage
          coverage-path: ./build/test/unit/out.txt
          coverage-summary-path: ./build/test/unit/coverage/coverage-summary.json
          junitxml-path: ./build/test/unit/junit.xml
mindrunner commented 1 year ago

Enabling more coverage reporters seems to solve some of my issues already:

  coverageReporters: [
    'html',
    'json',
    'json-summary',
    'text',
    'text-summary'
  ],
MishaKav commented 1 year ago

You can't achieve both targets on the same run, because of the way that GitHub work (1. run test suite on every push 2. post results in open PR (if one exist))

About the second issue, I'm not sure that I understand your point. If it is something that is related to tee, can you please look at this issue #15

mindrunner commented 1 year ago

Nice, thanks for the information. I am still workin on this and have some roadblocks to get it merged (mainly with sharding of big test suites), but I think that's out of scope of this conversation. Guess we can close