#!/bin/bash # Self-contained E2E test runner # Starts Redis (Docker), builds Angular+React, starts redis-ui-server, runs tests, cleans up. # Usage: bash tests/run-e2e.sh [--gui] set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" MATERIAL_DIR="$(dirname "$SCRIPT_DIR")" WORKSPACE_DIR="$(dirname "$MATERIAL_DIR")" SERVER_DIR="$WORKSPACE_DIR/redis-ui-server" REDIS_PORT=${P3XR_TEST_REDIS_PORT:-26379} REDIS_CONTAINER="p3xr-test-redis" SERVER_PORT=${P3XR_TEST_SERVER_PORT:-27843} GUI_MODE="" if [[ "$1" == "--gui" ]]; then GUI_MODE="--headed" export P3XR_HEADLESS=false fi # Kill any existing processes on test port PID=$(lsof -ti:$SERVER_PORT 2>/dev/null || true) if [ -n "$PID" ]; then echo "Killing existing process on port $SERVER_PORT (PID $PID)" kill $PID 2>/dev/null || true sleep 1 fi cleanup() { echo "" echo "=== Cleanup ===" [ -n "$SERVER_PID" ] && kill $SERVER_PID 2>/dev/null && echo "Stopped redis-ui-server (PID $SERVER_PID)" docker rm -f $REDIS_CONTAINER 2>/dev/null && echo "Removed Redis container" echo "Done." } trap cleanup EXIT echo "=== Starting test Redis on port $REDIS_PORT ===" docker rm -f $REDIS_CONTAINER 2>/dev/null || true docker run -d --name $REDIS_CONTAINER -p $REDIS_PORT:6379 redis:latest echo "Waiting for Redis..." sleep 2 # Verify Redis if ! docker exec $REDIS_CONTAINER redis-cli ping | grep -q PONG; then echo "ERROR: Redis not responding" exit 1 fi echo "Redis ready on port $REDIS_PORT" # Seed test data docker exec $REDIS_CONTAINER redis-cli SET test:string "hello world" docker exec $REDIS_CONTAINER redis-cli HSET test:hash name Alice age 30 docker exec $REDIS_CONTAINER redis-cli RPUSH test:list item1 item2 item3 docker exec $REDIS_CONTAINER redis-cli SADD test:set red green blue docker exec $REDIS_CONTAINER redis-cli ZADD test:zset 1 alpha 2 beta 3 gamma echo "Test data seeded" # Build Angular + React if needed echo "" echo "=== Building Angular + React ===" cd "$MATERIAL_DIR" if [ ! -f dist/index.html ]; then echo "Building Angular..." yarn build else echo "Angular build exists, skipping" fi if [ ! -f dist-react/index.html ]; then echo "Building React..." yarn build-react else echo "React build exists, skipping" fi # Create test connections config TEST_HOME=$(mktemp -d) cat > "$TEST_HOME/p3xrs.json" < "$TEST_HOME/.p3xrs-conns.json" <