-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
Support for jest shards #286
Comments
Hello @mccraveiro 👋, 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 #268 (comment)? If none of these fix your issue, please ping me, I will try to provide more solutions for that issue. |
@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 |
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: istanbuljs/nyc#1302 As for a workaround there is this: jestjs/jest#11581 as a workaround but it wouldn't be consumable by this GH action. |
I've been struggling with this myself. There are no tools to merge Jest's seemingly proprietary 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: jestjs/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: jestjs/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. |
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 |
I can confirm the above does work. |
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?
|
Interesting, would the approach used in this article help? cc @arminrosu |
any updates? |
here's my solution to this problem. you run jest with sharding as normal but output the report to a different file (in the format of
the script uses the istanbul-lib-coverage package to merge the code coverage together. |
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 #268
Thanks you :)
The text was updated successfully, but these errors were encountered: