New Apr 24, 2026

Parallel Tests With GitHub Actions

More Front-end Bloggers All from Kitty Giraudel View Parallel Tests With GitHub Actions on kittygiraudel.com

First post of the year! I’ve been spending quite some time on my Advent of Code repository in December and decided I wanted to run the tests in a GitHub workflow. A short and sweet post about it.

The test suite is pretty slow though, since Advent of Code involves some brute-forcing exercises which take a long time to run. So the idea is to parallelize the tests so they don’t take as long.

I have 8 different folders: one folder per year since 2015. We can use a matrix to create multiple job runs in parallel.

strategy:
  fail-fast: false
  matrix:
    year: [2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]

Then in our step, we can access the name of the job (and the name of our folder) and pass it to our npm test command (which uses Jest, or Mocha or Ava or whatever under the hood).

- name: Run tests
  run: npm test -- ${{ matrix.year }}

Screenshot of a successful test run on GitHub featuring 8 jobs named after years from 2015 to 2022 having run in parallel

That’s it, happy new year! ✨ You can check the code for the whole GitHub Workflow if you want.
name: Tests
on: [push]
jobs:
  tests:
    runs-on: ubuntu-latest

strategy: fail-fast: false matrix: year: [2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]

steps: - name: Check out repository uses: actions/checkout@v2

- name: Unlock input files uses: sliteteam/github-action-git-crypt-unlock@1.2.0 env: GIT_CRYPT_KEY: $

- name: Set up Node.js uses: actions/setup-node@v2 with: node-version: 18 cache: npm

- name: Install dependencies run: npm ci

- name: Run tests run: npm test -- $

Scroll to top