Skip to main content
New to Testkube? Unleash the power of cloud native testing in Kubernetes with Testkube. Get Started >

Sharded Cypress Example

info

This Workflows functionality is not available when running the Testkube Agent in Standalone Mode - Read More

Testkube has built-in support for parallelizing any testing tool - check out the Parallelization documentation for details and examples.

The below example shows how to distribute ("shard") a set of Cypress tests across a configurable number of nodes.

The example below:

  • Loads the Cypress tests from the Git repository (content).
  • Sets the working directory to the tests one (container.workingDir).
  • Installs the project dependencies (steps[0].shell).
  • Runs Cypress tests with dynamic sharding (steps[1].parallel).
    • The shards will be built off the test files in cypress/e2e directory (steps[1].parallel.shards.testFiles).
    • It will have maximum of 5 shards (steps[1].parallel.maxCount).
      • When there is less than or equal to 5 test files, it will run 1 shard per test file.
      • When there will be more than 5 test files, it will distribute them across 5 shards.
    • Each shard will run only selected test files with --spec Cypress' argument (steps[1].parallel.run.args).
Sharded Cypress Workflow
apiVersion: testworkflows.testkube.io/v1
kind: TestWorkflow
metadata:
name: example-sharded-cypress
spec:
content:
git:
uri: https://github.com/kubeshop/testkube
paths:
- test/cypress/executor-tests/cypress-13
container:
image: cypress/included:13.6.4
workingDir: /data/repo/test/cypress/executor-tests/cypress-13

steps:
- name: Install dependencies
shell: 'npm ci'

- name: Run tests
parallel:
maxCount: 5
shards:
testFiles: 'glob("cypress/e2e/**/*.js")'
description: '{{ join(map(shard.testFiles, "relpath(_.value, \"cypress/e2e\")"), ", ") }}'
transfer:
- from: /data/repo
container:
resources:
requests:
cpu: 1
memory: 1Gi
env:
- name: CYPRESS_CUSTOM_ENV
value: CYPRESS_CUSTOM_ENV_value
run:
args:
- --env
- NON_CYPRESS_ENV=NON_CYPRESS_ENV_value
- --spec
- '{{ join(shard.testFiles, ",") }}'

The log output from one of the workers:

Sharded Cypress Log Output