Skip to content

Commit

Permalink
Tests: Shard JS unit tests (#60045)
Browse files Browse the repository at this point in the history
Split out JS date unit tests
Shard main JS unit tests into 4 shards.

By sharding the tests, they can run in parallel on different runners. This allows the job to complete in less time. Testing suggests the time is reduced by around 50% from 4m to 2m.

Co-authored-by: sirreal <[email protected]>
Co-authored-by: desrosj <[email protected]>
  • Loading branch information
3 people authored Apr 3, 2024
1 parent c963fa5 commit c58ed9d
Showing 1 changed file with 49 additions and 10 deletions.
59 changes: 49 additions & 10 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ concurrency:

jobs:
unit-js:
name: JavaScript (Node.js ${{ matrix.node }})
name: JavaScript (Node.js ${{ matrix.node }}) ${{ matrix.shard }}
runs-on: ubuntu-latest
if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }}
strategy:
fail-fast: false
matrix:
node: ['20', '21']
shard: ['1/4', '2/4', '3/4', '4/4']

steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Checkout repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}

Expand All @@ -39,20 +41,55 @@ jobs:
with:
node-version: ${{ matrix.node }}

- name: Get number of CPU cores
- name: Determine the number of CPU cores
uses: SimenB/github-actions-cpu-cores@97ba232459a8e02ff6121db9362b09661c875ab8 # v2.0.0
id: cpu-cores

- name: npm build
- name: Run build scripts
# It's not necessary to run the full build, since Jest can interpret
# source files with `babel-jest`. Some packages have their own custom
# build tasks, however. These must be run.
run: npx lerna run build

- name: Running the tests
run: npm run test:unit -- --ci --maxWorkers=${{ steps.cpu-cores.outputs.count }} --cacheDirectory="$HOME/.jest-cache"
run: |
npm run test:unit -- \
--ci \
--maxWorkers="${{ steps.cpu-cores.outputs.count }}" \
--shard="${{ matrix.shard }}" \
--cacheDirectory="$HOME/.jest-cache"
unit-js-date:
name: JavaScript Date Tests (Node.js ${{ matrix.node }})
runs-on: ubuntu-latest
if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }}
strategy:
fail-fast: false
matrix:
node: ['20', '21']

steps:
- name: Checkout repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}

- name: Setup Node.js and install dependencies
uses: ./.github/setup-node
with:
node-version: ${{ matrix.node }}

- name: Determine the number of CPU cores
uses: SimenB/github-actions-cpu-cores@97ba232459a8e02ff6121db9362b09661c875ab8 # v2.0.0
id: cpu-cores

- name: Running the date tests
- name: Run build scripts
# It's not necessary to run the full build, since Jest can interpret
# source files with `babel-jest`. Some packages have their own custom
# build tasks, however. These must be run.
run: npx lerna run build

- name: Run the date tests
run: npm run test:unit:date -- --ci --maxWorkers=${{ steps.cpu-cores.outputs.count }} --cacheDirectory="$HOME/.jest-cache"

compute-previous-wordpress-version:
Expand Down Expand Up @@ -134,7 +171,8 @@ jobs:
WP_ENV_CORE: ${{ matrix.wordpress == '' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wordpress ) }}

steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Checkout repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}

Expand Down Expand Up @@ -314,18 +352,19 @@ jobs:
if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }}

steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Checkout repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}

- name: Get number of CPU cores
- name: Determine the number of CPU cores
uses: SimenB/github-actions-cpu-cores@97ba232459a8e02ff6121db9362b09661c875ab8 # v2.0.0
id: cpu-cores

- name: Setup Node.js and install dependencies
uses: ./.github/setup-node

- name: Npm build
- name: Run build scripts
# It's not necessary to run the full build, since Jest can interpret
# source files with `babel-jest`. Some packages have their own custom
# build tasks, however. These must be run.
Expand Down

0 comments on commit c58ed9d

Please sign in to comment.