You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB
Bash

#!/usr/bin/env bash
#
# Run E2E tests (Playwright) against the Docker-composed test stack.
# Builds the app, starts the stack, runs tests, then cleans up.
#
# Usage:
# ./scripts/run-e2e-tests.sh # run all E2E tests
# ./scripts/run-e2e-tests.sh --headed # run with browser visible
# ./scripts/run-e2e-tests.sh generation-live # run specific test file
#
# Prerequisites:
# - Docker and docker compose
# - Node.js (for Playwright)
# - OPENAI_API_KEY env var (for generation-live test)
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
E2E_DIR="$PROJECT_DIR/e2e"
cleanup() {
echo ""
echo "=== Cleaning up test stack ==="
cd "$E2E_DIR"
docker compose -f docker-compose.test.yml down -v --remove-orphans 2>/dev/null || true
}
trap cleanup EXIT
echo "=== Building test Docker image ==="
cd "$E2E_DIR"
docker compose -f docker-compose.test.yml build
echo "=== Starting test stack ==="
docker compose -f docker-compose.test.yml up -d
echo "Waiting for app to be healthy..."
for i in $(seq 1 60); do
if curl -sf http://localhost:8080/api/v1/health >/dev/null 2>&1; then
echo "App is healthy."
break
fi
if [ "$i" -eq 60 ]; then
echo "ERROR: App did not become healthy in time."
echo "--- App logs ---"
docker compose -f docker-compose.test.yml logs app | tail -30
exit 1
fi
sleep 2
done
echo "=== Installing dependencies ==="
cd "$E2E_DIR"
npm install --silent
npx playwright install chromium --with-deps 2>/dev/null || npx playwright install chromium
echo "=== Seeding test database ==="
npx tsx seed.ts
echo "=== Running E2E tests ==="
npx playwright test "$@"
echo "=== All E2E tests passed ==="