Test annotations for Jest using GitHub Actions #470
Description
What is the hypothesis?
Feedback on pull requests, as well as the review experience, can be improved using automatic inline annotations that show on what lines the tests failed.
Why is this important?
It avoids the need to move between the actions tab and the pull request, although not a major inconvenience, this might be daunting for trainees since the job run page contains a lot of information that they might not be comfortable with yet. It might be hard for them to even find the actual test output and make sense of what is failing.
This would also improve reviewing by showing exact information as to why and where a trainee's code is failing, which the reviewer can then immediately comment on to provide feedback and resources, thus also increasing the speed of reviews.
Supporting Resources
GitHub Action:
Note Coverage can be disabled and only use failure annotations
https://github.com/marketplace/actions/jest-coverage-report
Partial real-world example:
# The first job is for creating the test report and uploading it as an artifact.
# ...job setup, dependencies, etc. omitted for clarity...
- name: Run tests
run: npm test--json --outputFile=report.json # Note the output file
- name: Upload Jest coverage report
uses: actions/upload-artifact@v3
with:
name: jest-report # Note name for the artifact
path: report.json
retention-days: 1
# In a second job that runs only for pull-requests we download
# the artifact and use the jest-coverage-report action
# ...job setup omitted for clarity...
- name: Download Jest coverage report from test job
uses: actions/download-artifact@v3
with:
name: jest-report
- name: Annotate pull request
uses: ArtiomTr/jest-coverage-report-action@v2
with:
skip-step: all # To disable auto-installing of dependencies and running tests
coverage-file: report.json
base-coverage-file: report.json
annotations: failed-tests # Only failed test annotations, not coverage