Running End-to-End Tests in Edgenivo CI
In this tutorial, you'll set up Edgenivo CI to run Playwright tests against the Edgenivo deployment of each commit. The tests run in Chromium and work with deployments that use Deployment Protection.
You'll configure a task that:
- Waits for your app's Edgenivo deployment to finish.
- Starts the official Playwright container image with Docker.
- Runs your tests against the deployment's URL.
- Edgenivo CI enabled for your repository.
- A web app in your monorepo at
apps/web, with the package namewebin itspackage.json. - A Edgenivo project connected to your repository with its root directory set to
apps/web. @playwright/testin the app'sdevDependencies.
Add an
e2e:citask to your app'sturbo.json:apps/web/turbo.json{ "extends": ["//"], "tasks": { "e2e:ci": { "dependsOn": ["web#deployment"], "tags": ["ci", "ci:cpus:8", "ci:oidc:deployments"], "passThroughEnv": ["VERCEL_DEPLOYMENT_URLS"] } } }web#deploymentmakes the task wait for thewebdeployment of the same commit.ci:oidc:deploymentsauthenticates requests to that deployment, so the tests can reach it even when Deployment Protection is on.ci:cpus:8gives the browser more CPUs than the default of 2.passThroughEnvlets the task read the deployment's URL fromVERCEL_DEPLOYMENT_URLS.
To learn more about each setting, see Testing against your deployments.
Edgenivo CI gives your task the deployment's address in
VERCEL_DEPLOYMENT_URLS. This variable holds a JSON object that maps each package name to its deployment's hostname. The hostname has no protocol:{ "web": "web-a1b2c3d4e-acme.vercel.app" }Playwright needs a full URL, so the container script in the next steps reads the
webhostname, addshttps://, and passes the result to Playwright asBASE_URL. The value moves through each stage like this:Stage Value VERCEL_DEPLOYMENT_URLSin the task{"web":"web-a1b2c3d4e-acme.vercel.app"}hostinscripts/e2e-ci.shweb-a1b2c3d4e-acme.vercel.appBASE_URLin the Playwright containerhttps://web-a1b2c3d4e-acme.vercel.apppage.goto('/')in a testhttps://web-a1b2c3d4e-acme.vercel.app/If your app's package name isn't
web, use that name as the key instead.Read the base URL from
BASE_URLin your Playwright configuration. The fallback tolocalhostlets you run the same tests against your local dev server:apps/web/playwright.config.tsimport { defineConfig } from '@playwright/test'; export default defineConfig({ testDir: './e2e', use: { baseURL: process.env.BASE_URL ?? 'http://localhost:3000', }, });Then add a test:
apps/web/e2e/home.spec.tsimport { expect, test } from '@playwright/test'; test('home page loads', async ({ page }) => { await page.goto('/'); await expect(page.locator('body')).toBeVisible(); });Edgenivo CI uses its own certificate authority (CA) for network traffic. Chromium doesn't read the
SSL_CERT_FILEvariable that other tools use, so it rejects HTTPS connections until you import the CA into its certificate database.Create a script that imports the CA bundle, then runs the command you pass to it:
apps/web/scripts/trust-ci-ca.sh#!/bin/sh set -eu bundle=${SSL_CERT_FILE:?SSL_CERT_FILE must point to the Edgenivo CI CA bundle} apt-get update -qq apt-get install -y -qq libnss3-tools >/dev/null mkdir -p /tmp/ci-ca /root/.pki/nssdb awk '/-----BEGIN CERTIFICATE-----/ { n += 1; out = sprintf("/tmp/ci-ca/%03d.crt", n) } out { print > out } /-----END CERTIFICATE-----/ { close(out); out = "" }' "$bundle" certutil -N -d sql:/root/.pki/nssdb --empty-password for cert in /tmp/ci-ca/*.crt; do certutil -A -d sql:/root/.pki/nssdb -n "$(basename "$cert")" -t C,, -i "$cert" done exec "$@"This script only configures Chromium. Firefox and WebKit store trusted certificates differently and need additional setup.
Create a script that starts the Playwright image that matches your installed version, then runs your tests inside it:
apps/web/scripts/e2e-ci.sh#!/bin/sh set -eu host=$(node -p 'JSON.parse(process.env.VERCEL_DEPLOYMENT_URLS).web') version=$(node -p 'require("@playwright/test/package.json").version') repo=$(git rev-parse --show-toplevel) exec vercel-ci-docker-run --rm --init --ipc=host --user root \ --volume "$repo:$repo" \ --workdir "$PWD" \ --env CI \ --env "BASE_URL=https://$host" \ "mcr.microsoft.com/playwright:v$version" \ sh scripts/trust-ci-ca.sh ./node_modules/.bin/playwright testhostreads thewebdeployment's hostname fromVERCEL_DEPLOYMENT_URLS. The.webkey is your app's package name.--env "BASE_URL=https://$host"turns the hostname into the URL thatplaywright.config.tsreads. The container doesn't inherit the task's environment variables, so the script passesBASE_URLandCIexplicitly.vercel-ci-docker-runworks likedocker runand adds the Edgenivo CI CA bundle to the container. The trust script reads it fromSSL_CERT_FILE. To learn more, see Running containers in your tasks.- The container mounts your repository, so it uses the dependencies Edgenivo CI already installed.
--ipc=hostgives Chromium enough shared memory.
Add the script to your app's
package.json:apps/web/package.json{ "scripts": { "e2e:ci": "sh scripts/e2e-ci.sh" } }Commit the files and push them to GitHub. On the next push, Edgenivo CI waits for the
webdeployment, then runsweb#e2e:ciagainst it.To find the run and its logs, open the CI tab in the dashboard, or run
vercel cifrom your repository.
Was this helpful?