arbret/scripts/e2e.sh

59 lines
1.1 KiB
Bash
Raw Normal View History

2025-12-18 21:48:41 +01:00
#!/bin/bash
set -e
cd "$(dirname "$0")/.."
# 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-18 21:48:41 +01:00
# Kill any existing backend
pkill -f "uvicorn main:app" 2>/dev/null || true
sleep 1
2025-12-18 23:33:32 +01:00
# Seed the database with roles and test users
cd backend
echo "Seeding database..."
uv run python seed.py
cd ..
2025-12-18 22:24:46 +01:00
# Start backend (SECRET_KEY should be set via .envrc or environment)
2025-12-18 21:48:41 +01:00
cd backend
2025-12-20 22:18:14 +01:00
uv run uvicorn main:app --port 8000 --log-level warning &
BACKEND_PID=$!
2025-12-18 21:48:41 +01:00
cd ..
# Wait for backend
sleep 2
2025-12-20 23:06:05 +01:00
# Generate API types from OpenAPI schema
echo "Generating API types..."
cd frontend
npm run generate-api-types
cd ..
2025-12-20 22:18:14 +01:00
# Run tests (suppress Node.js color warnings)
# If TEST argument is provided, use it as a file pattern
2025-12-18 21:48:41 +01:00
cd frontend
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=$?
# Cleanup is handled by trap EXIT
2025-12-18 21:48:41 +01:00
exit $EXIT_CODE