2025-12-18 21:48:41 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
|
|
2025-12-25 00:48:22 +01:00
|
|
|
# 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"
|
|
|
|
|
|
2025-12-21 23:17:17 +01:00
|
|
|
# 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
|
|
|
|
|
|
2025-12-18 23:33:32 +01:00
|
|
|
# Load environment variables if .env exists
|
|
|
|
|
if [ -f .env ]; then
|
|
|
|
|
set -a
|
|
|
|
|
source .env
|
|
|
|
|
set +a
|
|
|
|
|
fi
|
|
|
|
|
|
2025-12-25 00:48:22 +01:00
|
|
|
# Kill any existing e2e backend (on our specific port)
|
|
|
|
|
pkill -f "uvicorn main:app --port $E2E_PORT" 2>/dev/null || true
|
2025-12-18 21:48:41 +01:00
|
|
|
sleep 1
|
|
|
|
|
|
2025-12-25 00:48:22 +01:00
|
|
|
# Seed the e2e database with roles and test users
|
2025-12-18 23:33:32 +01:00
|
|
|
cd backend
|
2025-12-25 00:48:22 +01:00
|
|
|
echo "Seeding e2e database..."
|
|
|
|
|
DATABASE_URL="$E2E_DATABASE_URL" uv run python seed.py
|
2025-12-18 23:33:32 +01:00
|
|
|
cd ..
|
|
|
|
|
|
2025-12-25 00:48:22 +01:00
|
|
|
# Start backend for e2e tests (uses e2e database and separate port)
|
2025-12-18 21:48:41 +01:00
|
|
|
cd backend
|
2025-12-25 00:48:22 +01:00
|
|
|
DATABASE_URL="$E2E_DATABASE_URL" uv run uvicorn main:app --port $E2E_PORT --log-level warning &
|
2025-12-21 23:00:54 +01:00
|
|
|
BACKEND_PID=$!
|
2025-12-18 21:48:41 +01:00
|
|
|
cd ..
|
|
|
|
|
|
|
|
|
|
# Wait for backend
|
|
|
|
|
sleep 2
|
|
|
|
|
|
2025-12-25 00:48:22 +01:00
|
|
|
# Generate API types from OpenAPI schema (using e2e backend)
|
|
|
|
|
echo "Generating API types from e2e backend..."
|
2025-12-20 23:06:05 +01:00
|
|
|
cd frontend
|
2025-12-25 00:48:22 +01:00
|
|
|
npx openapi-typescript "http://localhost:$E2E_PORT/openapi.json" -o app/generated/api.ts
|
2025-12-20 23:06:05 +01:00
|
|
|
cd ..
|
|
|
|
|
|
2025-12-25 00:48:22 +01:00
|
|
|
# Run tests with e2e-specific backend URL
|
|
|
|
|
# The frontend will connect to our e2e backend on $E2E_PORT
|
2025-12-18 21:48:41 +01:00
|
|
|
cd frontend
|
2025-12-25 00:48:22 +01:00
|
|
|
export NEXT_PUBLIC_API_URL="http://localhost:$E2E_PORT"
|
2025-12-21 18:20:22 +01:00
|
|
|
if [ -n "$1" ]; then
|
|
|
|
|
NODE_NO_WARNINGS=1 npx playwright test "$1"
|
|
|
|
|
else
|
|
|
|
|
NODE_NO_WARNINGS=1 npm run test:e2e
|
|
|
|
|
fi
|
2025-12-18 21:48:41 +01:00
|
|
|
EXIT_CODE=$?
|
|
|
|
|
|
2025-12-21 23:17:17 +01:00
|
|
|
# Cleanup is handled by trap EXIT
|
2025-12-18 21:48:41 +01:00
|
|
|
exit $EXIT_CODE
|
|
|
|
|
|