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

Support for jest shards

Open mccraveiro opened this issue 2 years ago • 10 comments

Description

Hey @ArtiomTr, any plans to support jest 28 shards?

I tried to merge them with NYC but it seems to only work with coverage files and not report files. Also when I tried to use the coverage file I got the same erros as https://github.com/ArtiomTr/jest-coverage-report-action/issues/268

Thanks you :)

mccraveiro avatar Jun 17 '22 11:06 mccraveiro

Hello @mccraveiro :wave:,

Don't really know, what are the "shards", but I will try to investigate how they could be used for this action.

About the error that you're getting - have you tried the solutions, described in this comment https://github.com/ArtiomTr/jest-coverage-report-action/issues/268#issuecomment-1148504250? If none of these fix your issue, please ping me, I will try to provide more solutions for that issue.

ArtiomTr avatar Jun 17 '22 13:06 ArtiomTr

@ArtiomTr Shards are a new way of splitting your tests and running them in multiple workers. It's pretty useful in GitHub actions with a matrix strategy.

The issue with shards is that you get n reports.json and then you need to merge them. However, I couldn't merge them in a way that works with this action.

Thank you

mccraveiro avatar Jun 17 '22 13:06 mccraveiro

To clarify, the issue @mccraveiro is having is related to a mismatch in instanbul/nyc versions from what is on their main release vs what is shipped with Jest. There are a handful of other threads that describe the issue and how to patch: https://github.com/istanbuljs/nyc/issues/1302

As for a workaround there is this: https://github.com/facebook/jest/issues/11581 as a workaround but it wouldn't be consumable by this GH action.

brunosala avatar Oct 15 '22 00:10 brunosala

I've been struggling with this myself. There are no tools to merge Jest's seemingly proprietary report.json files, so I have been trying to work with Istanbul's output from Jest instead - I got that merging but the available GitHub actions are lightyears behind what this action does (annotations and comments would have to be coded and added by myself).

We have a slightly different use case for shards. We shard because of memory limitations on the Github Actions workers and the fact that Jest running on recent versions of node eats up TONS of memory: facebook/jest#11956. Even with forced garbage collection, we still hit the cap. So, we shard the larger test suites so that they will finish but the Jest tool itself does not even support code coverage reports with shards: facebook/jest#12751.

I think that if the action allowed us to specify multiple report.json files (possibly through a glob??) and it handled merging them, then it would work beautifully for our needs.

luke-lacroix-healthy avatar Jan 20 '23 14:01 luke-lacroix-healthy

For those also struggling with this, I managed to get it working. Here's an example of a github actions workflow:

  run-tests:
      # ...

      - name: Run Jest
        run: |
          yarn jest \
            --coverage --json --outputFile=coverage/coverage-shard-${{ matrix.shard }}.json --testLocationInResults \
            --shard=${{ matrix.shard }}/${{ strategy.job-total }} \

      - uses: actions/upload-artifact@v3
        with:
          name: coverage-artifacts
          path: coverage/

  report-coverage:
    runs-on: ubuntu-latest
    needs:
      - run-tests
    steps:
      - uses: actions/checkout@v3

      - uses: actions/download-artifact@v3
        with:
          name: coverage-artifacts
          # will cache files for all shards
          path: coverage/

      - name: Merge coverage reports
        run: |
          # Merge sharded reports into one
          jq 'reduce inputs as $i (.; . * $i)' coverage/coverage-shard-*.json > coverage-merged.json

      - name: Publish test results
        uses: ArtiomTr/jest-coverage-report-action@v2
        with:
          base-coverage-file: coverage-merged.json
          coverage-file: coverage-merged.json

arminrosu avatar Feb 12 '23 13:02 arminrosu

I can confirm the above does work.

luke-lacroix-healthy avatar Feb 14 '23 15:02 luke-lacroix-healthy

While the above comment from @arminrosu works, the merged file only reports coverage from one of the shards. Which is leading me to believe that the reduce is not working as expected.

Even when I download the artifacts and run the reduce through jq locally, I do get a merged file but the actual values inside the report are not getting combined which causes the coverage report to be incorrect. Does anyone have any ideas here what the issue could be?

jq 'reduce inputs as $i (.; . * $i)' coverage/coverage-shard-*.json > coverage-merged.json

mhd3v avatar Jul 06 '23 07:07 mhd3v

While the above comment from @arminrosu works, the merged file only reports coverage from one of the shards. Which is leading me to believe that the reduce is not working as expected.

Even when I download the artifacts and run the reduce through jq locally, I do get a merged file but the actual values inside the report are not getting combined which causes the coverage report to be incorrect. Does anyone have any ideas here what the issue could be?

jq 'reduce inputs as $i (.; . * $i)' coverage/coverage-shard-*.json > coverage-merged.json

Interesting, would the approach used in this article help?

cc @arminrosu

MorenoMdz avatar Jul 15 '23 14:07 MorenoMdz