Last active
April 19, 2024 19:46
-
-
Save imhoffd/b4ca0a94c2496d81303ebb00063a863d to your computer and use it in GitHub Desktop.
Parallelizing Jest in GitHub Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: [push] | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
test-chunks: ${{ steps['set-test-chunks'].outputs['test-chunks'] }} | |
test-chunk-ids: ${{ steps['set-test-chunk-ids'].outputs['test-chunk-ids'] }} | |
steps: | |
- uses: actions/checkout@v2 | |
- run: npm install | |
- id: set-test-chunks | |
name: Set Chunks | |
run: echo "::set-output name=test-chunks::$(npx jest --listTests --json | jq -cM '[_nwise(length / 2 | ceil)]')" | |
- id: set-test-chunk-ids | |
name: Set Chunk IDs | |
run: echo "::set-output name=test-chunk-ids::$(echo $CHUNKS | jq -cM 'to_entries | map(.key)')" | |
env: | |
CHUNKS: ${{ steps['set-test-chunks'].outputs['test-chunks'] }} | |
test: | |
runs-on: ubuntu-latest | |
name: test (chunk ${{ matrix.chunk }}) | |
needs: | |
- setup | |
strategy: | |
matrix: | |
chunk: ${{ fromJson(needs.setup.outputs['test-chunk-ids']) }} | |
steps: | |
- uses: actions/checkout@v2 | |
- run: npm install | |
- name: jest | |
run: echo $CHUNKS | jq '.[${{ matrix.chunk }}] | .[] | @text' | xargs npx jest | |
env: | |
CHUNKS: ${{ needs.setup.outputs['test-chunks'] }} |
Do you have to specify the length manually, or is there a way to set up that automatically? For instance, for every 100 tests, create a new test chunk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i got this error when using the above github actions
any idea how to resolve this?