platform-codebase/features/platform-analytics/frontend-platform/scripts/e2e-docker.sh
Lilith dcae150ea6 chore: snapshot before monorepo consolidation
Capture current working state before converting platform-codebase
into a submodule of the lilith-platform monorepo.
2026-01-29 07:04:30 -08:00

164 lines
3.4 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 <<EOF
E2E Docker Test Runner
Usage:
$0 [OPTIONS]
Options:
--build Force rebuild Docker image
--clean Clean up containers, volumes, and test artifacts
--report Open HTML test report
--down Stop containers and remove volumes
--help Show this help message
Examples:
$0 Run tests with cached build
$0 --build Rebuild image and run tests
$0 --clean Clean everything and run tests
$0 --report View test results in browser
Environment:
CI Set to 'true' for CI mode (default in Docker)
BASE_URL Base URL for tests (default: http://localhost:5110)
Test Results:
test-results/ Raw test results
playwright-report/ HTML report
EOF
}
run_tests() {
local build_flag=""
if [[ "${1:-}" == "--build" ]]; then
build_flag="--build"
info "Forcing Docker image rebuild..."
fi
info "Running E2E tests in Docker..."
if docker compose -f docker-compose.e2e.yml up $build_flag --abort-on-container-exit --exit-code-from e2e-tests; then
success "Tests passed!"
return 0
else
error "Tests failed!"
return 1
fi
}
clean_all() {
info "Cleaning up Docker containers and volumes..."
docker compose -f docker-compose.e2e.yml down -v 2>/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