feat: add test runner scripts for integration and E2E tests
- scripts/run-integration-tests.sh: spins up Postgres, runs cargo tests - scripts/run-e2e-tests.sh: builds Docker, starts stack, runs Playwright - fix: remove SESSION_SECRET from e2e docker-compose.test.yml Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>master
parent
370e033506
commit
de8e5ab85c
@ -0,0 +1,61 @@
|
||||
#!/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 Playwright dependencies ==="
|
||||
cd "$E2E_DIR"
|
||||
npm install --silent
|
||||
npx playwright install chromium --with-deps 2>/dev/null || npx playwright install chromium
|
||||
|
||||
echo "=== Running E2E tests ==="
|
||||
npx playwright test "$@"
|
||||
|
||||
echo "=== All E2E tests passed ==="
|
||||
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Run backend integration tests (Rust).
|
||||
# Starts a Postgres container, runs tests, then cleans up.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/run-integration-tests.sh # run all integration tests
|
||||
# ./scripts/run-integration-tests.sh pipeline # run only pipeline_test
|
||||
#
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
CONTAINER_NAME="ai-synth-integration-db"
|
||||
PG_PORT=5434
|
||||
PG_USER="test_user"
|
||||
PG_PASS="test_password"
|
||||
PG_DB="postgres"
|
||||
|
||||
cleanup() {
|
||||
echo "Cleaning up..."
|
||||
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
echo "=== Starting Postgres for integration tests ==="
|
||||
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
|
||||
docker run -d \
|
||||
--name "$CONTAINER_NAME" \
|
||||
-e POSTGRES_USER="$PG_USER" \
|
||||
-e POSTGRES_PASSWORD="$PG_PASS" \
|
||||
-e POSTGRES_DB="$PG_DB" \
|
||||
-p "127.0.0.1:${PG_PORT}:5432" \
|
||||
--health-cmd "pg_isready -U $PG_USER -d $PG_DB" \
|
||||
--health-interval 5s \
|
||||
--health-timeout 3s \
|
||||
--health-retries 10 \
|
||||
postgres:17-alpine
|
||||
|
||||
echo "Waiting for Postgres to be ready..."
|
||||
for i in $(seq 1 30); do
|
||||
if docker exec "$CONTAINER_NAME" pg_isready -U "$PG_USER" -d "$PG_DB" >/dev/null 2>&1; then
|
||||
echo "Postgres is ready."
|
||||
break
|
||||
fi
|
||||
if [ "$i" -eq 30 ]; then
|
||||
echo "ERROR: Postgres did not become ready in time."
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
export TEST_DATABASE_URL="postgres://${PG_USER}:${PG_PASS}@127.0.0.1:${PG_PORT}/${PG_DB}"
|
||||
|
||||
echo "=== Running integration tests ==="
|
||||
cd "$PROJECT_DIR/backend"
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "Running: cargo test --test $1 -- --nocapture"
|
||||
cargo test --test "$1" -- --nocapture
|
||||
else
|
||||
echo "Running: cargo test (all integration + unit tests)"
|
||||
cargo test -- --nocapture
|
||||
fi
|
||||
|
||||
echo "=== All tests passed ==="
|
||||
Loading…
Reference in New Issue