arbret/scripts/e2e.sh
2025-12-25 00:48:22 +01:00

63 lines
1.6 KiB
Bash
Executable file

#!/bin/bash
set -e
cd "$(dirname "$0")/.."
# E2E tests use a separate database and port to allow parallel execution with backend tests
E2E_PORT=${E2E_PORT:-8001}
E2E_DATABASE_URL="postgresql+asyncpg://postgres:postgres@localhost:5432/arbret_e2e"
# Cleanup function to kill background processes
cleanup() {
kill $BACKEND_PID 2>/dev/null || true
}
# Ensure cleanup runs on exit (normal, error, or interrupt)
trap cleanup EXIT
# Load environment variables if .env exists
if [ -f .env ]; then
set -a
source .env
set +a
fi
# Kill any existing e2e backend (on our specific port)
pkill -f "uvicorn main:app --port $E2E_PORT" 2>/dev/null || true
sleep 1
# Seed the e2e database with roles and test users
cd backend
echo "Seeding e2e database..."
DATABASE_URL="$E2E_DATABASE_URL" uv run python seed.py
cd ..
# Start backend for e2e tests (uses e2e database and separate port)
cd backend
DATABASE_URL="$E2E_DATABASE_URL" uv run uvicorn main:app --port $E2E_PORT --log-level warning &
BACKEND_PID=$!
cd ..
# Wait for backend
sleep 2
# Generate API types from OpenAPI schema (using e2e backend)
echo "Generating API types from e2e backend..."
cd frontend
npx openapi-typescript "http://localhost:$E2E_PORT/openapi.json" -o app/generated/api.ts
cd ..
# Run tests with e2e-specific backend URL
# The frontend will connect to our e2e backend on $E2E_PORT
cd frontend
export NEXT_PUBLIC_API_URL="http://localhost:$E2E_PORT"
if [ -n "$1" ]; then
NODE_NO_WARNINGS=1 npx playwright test "$1"
else
NODE_NO_WARNINGS=1 npm run test:e2e
fi
EXIT_CODE=$?
# Cleanup is handled by trap EXIT
exit $EXIT_CODE