Cypress
Overview
This guide explains how to run Cypress tests against Signadot sandboxes. You can run these tests either:
- Directly in your CI pipeline
- Using Signadot Jobs for sandbox-aware test execution
Set Up Routing Context
To run tests against sandboxes, you'll need to configure Cypress to include the appropriate routing headers. This is required regardless of whether you're running tests in CI or using Signadot Jobs.
Add the following to your Cypress support commands:
your_project/cypress/support/command.js
Cypress.Commands.add('config', (from, to) => {
var frontendURL = 'https://yourwebsite.com';
// inject routing key
cy.intercept(frontendURL + '/*', (req) => {
req.headers['baggage'] += ',sd-routing-key=' + Cypress.env('SIGNADOT_ROUTING_KEY');
})
cy.visit(frontendURL);
// ... do more things
})
When running tests, ensure the CYPRESS_SIGNADOT_ROUTING_KEY
environment variable is set with your sandbox's routing key. Cypress requires the CYPRESS_
prefix as mentioned in their official doc.
Running Tests in CI
To run tests directly in your CI pipeline:
- Create a sandbox for testing
- Get the sandbox's routing key
- Set the environment variable and run tests:
export CYPRESS_SIGNADOT_ROUTING_KEY=<your-sandbox-routing-key>
npx cypress run
Running Tests as Signadot Jobs
For sandbox-aware test execution, you can run tests as Signadot Jobs. This provides additional benefits:
- Automatic test failure if the sandbox is terminated or fails
- Built-in artifact collection
- Integrated test reporting
Create Job Runner Group
First, create a Job Runner Group:
your_project/.signadot/testing/cypress-runner.yaml
name: cypress
spec:
cluster: "@{cluster}"
labels:
env: "@{env}"
namespace: <namespace where to run the tests>
image: cypress/included:latest
jobTimeout: 30m
scaling:
manual:
desiredPods: 1
Create Job Specification
your_project/.signadot/testing/e2e-tests-job.yaml
spec:
namePrefix: cypress-e2e
runnerGroup: cypress
script: |
#!/bin/bash
set -e
# Clone the git repo
echo "Cloning repo"
git clone --single-branch -b "@{branch}" \
https://github.com/<org>/<repo>.git
# Run the cypress test
cd <repo>
export CYPRESS_SIGNADOT_ROUTING_KEY=$SIGNADOT_ROUTING_KEY
npx cypress run --spec cypress/e2e/my-test.cy.js
routingContext:
sandbox: "@{sandbox}"
uploadArtifact:
- path: your_project/cypress/videos/my-test.cy.js.mp4