test workflow (react/metro)
The test workflow from react/metro, explained and optimized by Latchkey.
A
CI health: A - excellent
Run this on Latchkey for self-healing, caching, and up to 58% lower cost.
Grade your own workflow free or run it on Latchkey →What it does
This is the test workflow from the react/metro repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
workflow (.yml)
name: test
on:
workflow_call:
inputs:
node-version:
type: string
required: false
default: '22.x'
runs-on:
type: string
required: false
default: 'ubuntu-latest'
no-lockfile:
type: string
required: false
default: 'false'
jobs:
test:
name: "Tests [Node.js ${{ inputs.node-version }}, ${{ inputs.runs-on }}, ${{ inputs.no-lockfile == 'false' && 'Using yarn.lock' || 'Ignoring yarn.lock' }}]"
runs-on: ${{ inputs.runs-on }}
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/yarn-install
with:
node-version: ${{ inputs.node-version }}
no-lockfile: ${{ inputs.no-lockfile }}
- name: Run Jest Tests
env:
NIGHTLY_TESTS_NO_LOCKFILE: ${{ inputs.no-lockfile }}
shell: bash
run: |
max_attempts=3
attempt=1
until yarn jest --ci --maxWorkers 4 --reporters=default --reporters=jest-junit --rootdir='./'; do
if [ $attempt -ge $max_attempts ]; then
echo "Tests failed after $max_attempts attempts"
exit 1
fi
echo "Attempt $attempt failed, retrying..."
attempt=$((attempt + 1))
sleep 5
done
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: test on: workflow_call: inputs: node-version: type: string required: false default: '22.x' runs-on: type: string required: false default: 'ubuntu-latest' no-lockfile: type: string required: false default: 'false' jobs: test: timeout-minutes: 30 name: "Tests [Node.js ${{ inputs.node-version }}, ${{ inputs.runs-on }}, ${{ inputs.no-lockfile == 'false' && 'Using yarn.lock' || 'Ignoring yarn.lock' }}]" runs-on: ${{ inputs.runs-on }} steps: - uses: actions/checkout@v6 - uses: ./.github/actions/yarn-install with: node-version: ${{ inputs.node-version }} no-lockfile: ${{ inputs.no-lockfile }} - name: Run Jest Tests env: NIGHTLY_TESTS_NO_LOCKFILE: ${{ inputs.no-lockfile }} shell: bash run: | max_attempts=3 attempt=1 until yarn jest --ci --maxWorkers 4 --reporters=default --reporters=jest-junit --rootdir='./'; do if [ $attempt -ge $max_attempts ]; then echo "Tests failed after $max_attempts attempts" exit 1 fi echo "Attempt $attempt failed, retrying..." attempt=$((attempt + 1)) sleep 5 done
What changed
- Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.