test: script e2e local + commande npm test:e2e
Reproduit les conditions du job CI e2e (backend natif, auth desactivee, port 2029, projet chromium-desktop) pour valider localement avant chaque push.
This commit is contained in:
@@ -5,6 +5,7 @@ __pycache__/
|
||||
.env.*
|
||||
!.env.example
|
||||
.venv/
|
||||
.venv-e2e/
|
||||
venv/
|
||||
*.egg-info/
|
||||
dist/
|
||||
|
||||
+2
-1
@@ -8,7 +8,8 @@
|
||||
"test": "tests"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"test:e2e": "bash scripts/run-e2e-local.sh"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env bash
|
||||
# =============================================================================
|
||||
# ObsiGate — E2E locaux (Playwright) dans les mêmes conditions que le CI
|
||||
# =============================================================================
|
||||
# Démarre le backend nativement (uvicorn, Python 3.11 via uv) avec :
|
||||
# - auth désactivée (OBSIGATE_AUTH_ENABLED=false, comme le CI)
|
||||
# - fixtures TestVault/TestDir (comme le CI)
|
||||
# - port 2029 (BASE_URL par défaut de playwright.config.ts)
|
||||
# puis exécute la suite Playwright complète (projet chromium-desktop)
|
||||
# et nettoie tout à la sortie.
|
||||
#
|
||||
# Usage :
|
||||
# ./scripts/run-e2e-local.sh # suite complète (desktop)
|
||||
# ./scripts/run-e2e-local.sh --headed # avec navigateur visible
|
||||
# ./scripts/run-e2e-local.sh -g "reset panes" # filtre Playwright
|
||||
#
|
||||
# Prérequis : uv, Node.js. Le venv .venv-e2e est créé automatiquement.
|
||||
# =============================================================================
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
PORT="${E2E_PORT:-2029}"
|
||||
BASE_URL="http://127.0.0.1:$PORT"
|
||||
SERVER_LOG="data/e2e-server.log"
|
||||
|
||||
# ----- Prérequis -----
|
||||
if ! command -v uv &>/dev/null; then
|
||||
echo "[ERR] uv introuvable. Installez-le : https://docs.astral.sh/uv/" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! command -v npx &>/dev/null; then
|
||||
echo "[ERR] npx introuvable. Installez Node.js." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ----- Venv Python 3.11 (créé une seule fois) -----
|
||||
if [[ -x ".venv-e2e/Scripts/python.exe" ]]; then
|
||||
PYTHON=".venv-e2e/Scripts/python.exe"
|
||||
elif [[ -x ".venv-e2e/bin/python" ]]; then
|
||||
PYTHON=".venv-e2e/bin/python"
|
||||
else
|
||||
echo "[INFO] Création du venv .venv-e2e (Python 3.11)..."
|
||||
uv venv .venv-e2e --python 3.11
|
||||
PYTHON=".venv-e2e/Scripts/python.exe"
|
||||
[[ -x "$PYTHON" ]] || PYTHON=".venv-e2e/bin/python"
|
||||
uv pip install --python "$PYTHON" -r backend/requirements.txt
|
||||
fi
|
||||
|
||||
# ----- Port déjà occupé ? -----
|
||||
if curl -sf "$BASE_URL/api/health" >/dev/null 2>&1; then
|
||||
echo "[ERR] Quelque chose répond déjà sur $BASE_URL." >&2
|
||||
echo " Arrêtez-le ou choisissez un autre port : E2E_PORT=2030 $0" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ----- Démarrage du serveur (mêmes conditions que le CI e2e) -----
|
||||
echo "[INFO] Démarrage d'ObsiGate sur $BASE_URL (auth désactivée)..."
|
||||
mkdir -p data
|
||||
OBSIGATE_AUTH_ENABLED=false \
|
||||
VAULT_1_NAME=TestVault \
|
||||
VAULT_1_PATH="$(pwd)/test_vault" \
|
||||
DIR_1_NAME=TestDir \
|
||||
DIR_1_PATH="$(pwd)/test_dir" \
|
||||
"$PYTHON" -m uvicorn backend.main:app --host 127.0.0.1 --port "$PORT" \
|
||||
>"$SERVER_LOG" 2>&1 &
|
||||
SERVER_PID=$!
|
||||
|
||||
cleanup() {
|
||||
echo "[INFO] Arrêt du serveur (PID $SERVER_PID)..."
|
||||
kill "$SERVER_PID" 2>/dev/null || true
|
||||
wait "$SERVER_PID" 2>/dev/null || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# ----- Attente du health check (30 s max, comme le CI) -----
|
||||
for _ in $(seq 1 30); do
|
||||
if curl -sf "$BASE_URL/api/health" >/dev/null 2>&1; then
|
||||
echo "[OK] Serveur prêt."
|
||||
break
|
||||
fi
|
||||
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
|
||||
echo "[ERR] Le serveur a quitté prématurément. Log :" >&2
|
||||
tail -30 "$SERVER_LOG" >&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
curl -sf "$BASE_URL/api/health" >/dev/null || {
|
||||
echo "[ERR] Serveur injoignable sur $BASE_URL. Log :" >&2
|
||||
tail -30 "$SERVER_LOG" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ----- Browsers Playwright (no-op s'ils sont déjà installés) -----
|
||||
npx playwright install chromium
|
||||
|
||||
# ----- Exécution de la suite (projet CI : chromium-desktop) -----
|
||||
echo "[INFO] BASE_URL=$BASE_URL npx playwright test --project=chromium-desktop $*"
|
||||
BASE_URL="$BASE_URL" npx playwright test --project=chromium-desktop "$@"
|
||||
Reference in New Issue
Block a user