Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Cypress parallel testing on GitHub Actions. How to use GitHub matrix to run parallel jobs to split tests with

@knapsack-pro/cypress supports environment variables provided by GitHub Actions to run your tests. You have to define a few things in .github/workflows/main.yaml config file.

  • You need to set KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS environment variable in GitHub repository Settings -> Secrets. See creating and using secrets in GitHub Actions.
  • You should create as many parallel jobs as you need with matrix.ci_node_total and matrix.ci_node_index properties. If your test suite is slow you should use more parallel jobs.

Below you can find config for GitHub Actions.

Video demo Cypress and GitHub Actions

# .github/workflows/main.yaml
name: Main
on: [push]
runs-on: ubuntu-latest
fail-fast: false
node-version: [8.x]
# Set N number of parallel jobs you want to run tests on.
# Use higher number if you have slow tests to split them on more parallel jobs.
# Remember to update ci_node_index below to 0..N-1
ci_node_total: [2]
# set N-1 indexes for parallel jobs
# When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc
ci_node_index: [0, 1]
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
node-version: ${{ matrix.node-version }}
- name: npm install and build
run: |
npm install
npm run build --if-present
- name: Run http server with the app in the background
run: |
npm run start:ci &
- name: Run tests with Knapsack Pro
KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
run: |
$(npm bin)/knapsack-pro-cypress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment