From 78ca23c8a5026f55f5255b4833e92df928660192 Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Tue, 10 Sep 2024 09:14:08 +0200 Subject: [PATCH] chore: add doc to run tests on local machine --- README.md | 18 ++++++++++++++++++ e2e/register-login-organisateur.spec.ts | 9 ++++++++- package.json | 4 +++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c6d9ef444..8cddce7b4 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,24 @@ Afin de conserver les données dans le cas d'une mise à jour du schéma de la b `docker compose exec -ti postgres psql -U ` +### Tests end-to-end + +Installer les paquets (sans passer par docker) : + +`yarn` + +Installer les navigateurs (headless) utilisés par Playwright : + +`yarn playwright install` + +Lancer les tests (attention il faut avoir démarré la stack locale via docker, cf plus haut) : + +`yarn tests:e2e` + +Pour débugger ou écrire de nouveaux tests, utiliser l'interface graphique de Playwright : + +`yarn tests:e2e:ui` + ## Kubernetes ## CI/CD diff --git a/e2e/register-login-organisateur.spec.ts b/e2e/register-login-organisateur.spec.ts index f0fc2c9ad..1d3c7ec02 100644 --- a/e2e/register-login-organisateur.spec.ts +++ b/e2e/register-login-organisateur.spec.ts @@ -4,6 +4,7 @@ import path from "path"; const baseUrl = process.env.E2E_BASE_URL || "vao-main.ovh.fabrique.social.gouv.fr"; +const runLocal = process.env.E2E_LOCAL === "true"; const username = process.env.E2E_USERNAME || `e2e-${randomUUID()}@test.com`; const password = "Pizza1234567;"; @@ -12,7 +13,13 @@ const password = "Pizza1234567;"; test.describe.configure({ mode: "serial" }); function getUrl(prefix?: string) { - return `https://${prefix ? prefix + "-" : ""}${baseUrl}`; + if (runLocal) { + if (prefix === "maildev") { + return `http://localhost:1080`; + } + return `http://localhost:3000`; + } + return `${runLocal ? "http" : "https"}://${prefix ? prefix + "-" : ""}${baseUrl}`; } async function login(page) { diff --git a/package.json b/package.json index 76c9c4837..587903cf6 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,9 @@ "lint:frontend-usagers": "yarn --cwd ./packages/frontend-usagers run lint", "lint:frontend-bo": "yarn --cwd ./packages/frontend-bo run lint", "lint:shared": "yarn --cwd ./packages/shared run lint", - "knex": "POSTGRES_HOST=localhost POSTGRES_PORT=5436 env-cmd --no-override knex --cwd ./packages/migrations/src" + "knex": "POSTGRES_HOST=localhost POSTGRES_PORT=5436 env-cmd --no-override knex --cwd ./packages/migrations/src", + "tests:e2e": "E2E_LOCAL=true playwright test", + "tests:e2e:ui": "E2E_LOCAL=true playwright test --ui" }, "devDependencies": { "@commitlint/cli": "^19.0.0",