Member-only story
Day 3 — Matrix Testing: Prove Your Code Works on Node 18, 20, and 22
My project runs on Node 22 locally.
But what if someone uses it on Node 18? Or the server runs Node 20?
Matrix testing runs your tests across multiple Node versions simultaneously — three parallel jobs, one for each version.
If there is a compatibility issue, you find out before it reaches production.
The workflow
```yaml
name: Matrix CI
on:
push:
branches: [ master, feature/github-actions-practice ]
pull_request:
branches: [ master ]
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20, 22] # Test on 3 Node versions!
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test -- --passWithNoTests --watchAll=false
- name: Build project
run: npm run build
- name: Display Node version
run: |
echo "Testing on Node.js ${{ matrix.node-version }}"
node…









