Skip to content

Commit

Permalink
Merge pull request #10617 from mzohaibqc/issues/10289
Browse files Browse the repository at this point in the history
[No QA] issue:10289 Speed Up Tests Run Time
  • Loading branch information
AndrewGable authored Oct 11, 2022
2 parents 22435c3 + 6793af4 commit 62394cc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
45 changes: 41 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,38 @@ on:
types: [opened, synchronize]
branches-ignore: [staging, production]

env:
# Number of parallel jobs for jest tests
CHUNKS: 3
jobs:
config:
runs-on: ubuntu-latest
name: Define matrix parameters
outputs:
MATRIX: ${{ steps.set-matrix.outputs.MATRIX }}
JEST_CHUNKS: ${{ steps.set-matrix.outputs.JEST_CHUNKS }}
steps:
- name: Set Matrix
id: set-matrix
uses: actions/github-script@v6
with:
# Generate matrix array i.e. [0, 1, 2, ...., CHUNKS - 1] for test job
script: |
core.setOutput('MATRIX', Array.from({ length: Number(process.env.CHUNKS) }, (v, i) => i + 1));
core.setOutput('JEST_CHUNKS', Number(process.env.CHUNKS) - 1);
test:
needs: config
if: ${{ github.actor != 'OSBotify' || github.event_name == 'workflow_call' }}
runs-on: ubuntu-latest
name: test (job ${{ fromJSON(matrix.chunk) }})
env:
CI: true
strategy:
fail-fast: false
matrix:
chunk: ${{fromJson(needs.config.outputs.MATRIX)}}

steps:
- uses: Expensify/App/.github/actions/composite/setupNode@main

Expand All @@ -23,10 +51,19 @@ jobs:
exit 1
fi
- name: Jest Unit Tests
run: npm run test
env:
CI: true
- name: Cache Jest cache
id: cache-jest-cache
uses: actions/cache@v1
with:
path: .jest-cache
key: ${{ runner.os }}-jest

- name: All Unit Tests
if: ${{ fromJSON(matrix.chunk) < fromJSON(env.CHUNKS) }}
# Split the jest based test files in multiple chunks/groups and then execute them in parallel in different jobs/runners.
run: npx jest --listTests --json | jq -cM '[_nwise(length / ${{ fromJSON(needs.config.outputs.JEST_CHUNKS) }} | ceil)]' | jq '[[]] + .' | jq '.[${{ fromJSON(matrix.chunk) }}] | .[] | @text' | xargs npm test

- name: Pull Request Tests
# Pull request related tests will be run in separate runner in parallel.
if: ${{ fromJSON(matrix.chunk) == fromJSON(env.CHUNKS) }}
run: tests/unit/getPullRequestsMergedBetweenTest.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ storybook-static
# Jest coverage report
/coverage.data
/coverage/
.jest-cache
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@
],
"setupFilesAfterEnv": [
"@testing-library/jest-native/extend-expect"
]
],
"cacheDirectory": "<rootDir>/.jest-cache"
},
"prettier": {
"bracketSpacing": false,
Expand Down

0 comments on commit 62394cc

Please sign in to comment.