#!/usr/bin/env bash # # E2E Docker Test Runner # # Convenience script for running Playwright E2E tests in Docker. # # Usage: # ./scripts/e2e-docker.sh - Run tests # ./scripts/e2e-docker.sh --build - Force rebuild # ./scripts/e2e-docker.sh --clean - Clean up everything # ./scripts/e2e-docker.sh --report - Open test report # ./scripts/e2e-docker.sh --help - Show help set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" cd "$PROJECT_DIR" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color info() { echo -e "${BLUE}ℹ${NC} $1" } success() { echo -e "${GREEN}✓${NC} $1" } error() { echo -e "${RED}✗${NC} $1" } warn() { echo -e "${YELLOW}⚠${NC} $1" } show_help() { cat </dev/null || true info "Removing test artifacts..." rm -rf test-results/ playwright-report/ info "Pruning Docker build cache..." docker builder prune -f success "Cleanup complete!" } stop_containers() { info "Stopping containers and removing volumes..." docker compose -f docker-compose.e2e.yml down -v success "Containers stopped!" } open_report() { if [[ ! -f "playwright-report/index.html" ]]; then error "No test report found. Run tests first." exit 1 fi info "Opening test report..." # Detect OS and open appropriately if command -v xdg-open &> /dev/null; then xdg-open playwright-report/index.html elif command -v open &> /dev/null; then open playwright-report/index.html elif command -v start &> /dev/null; then start playwright-report/index.html else warn "Could not detect browser opener. Manually open: playwright-report/index.html" fi success "Report opened in browser!" } # Main script logic case "${1:-}" in --help|-h) show_help exit 0 ;; --clean) clean_all run_tests ;; --build) run_tests --build ;; --down) stop_containers exit 0 ;; --report) open_report exit 0 ;; "") run_tests ;; *) error "Unknown option: $1" show_help exit 1 ;; esac