AvanzaCast/scripts/e2e-run.sh
Cesar Mendivil 8b458a3ddf feat: add initial LiveKit Meet integration with utility scripts, configs, and core components
- Add Next.js app structure with base configs, linting, and formatting
- Implement LiveKit Meet page, types, and utility functions
- Add Docker, Compose, and deployment scripts for backend and token server
- Provide E2E and smoke test scaffolding with Puppeteer and Playwright helpers
- Include CSS modules and global styles for UI
- Add postMessage and studio integration utilities
- Update package.json with dependencies and scripts for development and testing
2025-11-20 12:50:38 -07:00

200 lines
6.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# scripts/e2e-run.sh
# Orquestador E2E para flujo token: DB -> backend-api -> broadcast-panel -> Playwright -> plugin
# Uso: ./scripts/e2e-run.sh [--no-db] [--no-backend] [--no-frontend] [--no-playwright] [--keep] [--port PORT]
# Guarda logs en /tmp and collect artifacts to /tmp/e2e-artifacts
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
PKG_BACKEND="$ROOT_DIR/packages/backend-api"
PKG_FRONTEND="$ROOT_DIR/packages/broadcast-panel"
ARTIFACT_DIR="/tmp/e2e-artifacts"
PLAYWRIGHT_PORT=3003
FRONTEND_PORT=5176
PLAYWRIGHT_HOST="127.0.0.1"
NO_DB=0
NO_BACKEND=0
NO_FRONTEND=0
NO_PLAYWRIGHT=0
KEEP_RUNNING=0
print_help(){
cat <<EOF
Usage: $0 [options]
Options:
--no-db Skip starting a test DB (assumes DATABASE_URL is set/available)
--no-backend Skip starting backend-api
--no-frontend Skip starting broadcast-panel
--no-playwright Skip starting Playwright run-server (useful if remote)
--keep Keep started services running after script finishes (do not teardown)
--port <n> Frontend port to use (default 5176)
-h, --help Show this help
This script will:
- (optionally) start a DB (if you have docker-compose configured manually)
- run prisma generate
- start backend-api and broadcast-panel in background
- start playwright run-server on ${PLAYWRIGHT_PORT}
- run the E2E plugin: packages/broadcast-panel/e2e/dify-plugin-playwright.mjs
- collect logs and screenshots under ${ARTIFACT_DIR}
Logs are saved under /tmp (see variables in script).
EOF
}
# parse args
while [[ $# -gt 0 ]]; do
case "$1" in
--no-db) NO_DB=1; shift ;;
--no-backend) NO_BACKEND=1; shift ;;
--no-frontend) NO_FRONTEND=1; shift ;;
--no-playwright) NO_PLAYWRIGHT=1; shift ;;
--keep) KEEP_RUNNING=1; shift ;;
--port) FRONTEND_PORT="$2"; shift 2 ;;
-h|--help) print_help; exit 0 ;;
*) echo "Unknown arg: $1"; print_help; exit 1 ;;
esac
done
mkdir -p "$ARTIFACT_DIR"
LOG_BACKEND="/tmp/e2e-backend.log"
LOG_FRONTEND="/tmp/e2e-frontend.log"
LOG_PLAYWRIGHT="/tmp/e2e-playwright.log"
LOG_PLUGIN="/tmp/e2e-plugin.log"
PIDS=()
cleanup() {
local code=$?
echo "Cleaning up (keep=$KEEP_RUNNING)"
if [ "$KEEP_RUNNING" -eq 1 ]; then
echo "--keep specified; leaving processes running (PIDs: ${PIDS[*]})"
exit $code
fi
# kill in reverse order
for pid in "${PIDS[@]}"; do
if ps -p "$pid" > /dev/null 2>&1; then
echo "Killing PID $pid"
kill "$pid" || true
sleep 0.2
fi
done
echo "Collected artifacts in $ARTIFACT_DIR"
exit $code
}
trap cleanup EXIT
# 1) (Optional) DB - we assume user manages DB; provide hint
if [ "$NO_DB" -eq 0 ]; then
echo "NOTE: --no-db not set. This script will NOT automatically start Postgres; ensure your DATABASE_URL points to a reachable Postgres."
echo "If you want a local DB, run your own docker-compose and set DATABASE_URL accordingly."
fi
# 2) Prisma generate + deps
if [ "$NO_BACKEND" -eq 0 ]; then
if [ -d "$PKG_BACKEND" ]; then
echo "Running prisma generate in backend..."
(cd "$PKG_BACKEND" && npm install --no-audit --no-fund) || true
(cd "$PKG_BACKEND" && npx prisma generate) || true
else
echo "Warning: backend package not found at $PKG_BACKEND"
fi
fi
# 3) Start backend in background
if [ "$NO_BACKEND" -eq 0 ]; then
echo "Starting backend-api in background (logs -> $LOG_BACKEND)"
(cd "$PKG_BACKEND" && nohup npm run dev > "$LOG_BACKEND" 2>&1 & echo $! > /tmp/e2e-backend.pid)
sleep 2
if [ -s /tmp/e2e-backend.pid ]; then
PID_B=$(cat /tmp/e2e-backend.pid)
echo "backend PID: $PID_B"
PIDS+=("$PID_B")
else
echo "No backend pid file created; check $LOG_BACKEND"
fi
fi
# 4) Start frontend
if [ "$NO_FRONTEND" -eq 0 ]; then
echo "Starting broadcast-panel frontend on port $FRONTEND_PORT (logs -> $LOG_FRONTEND)"
(cd "$PKG_FRONTEND" && nohup PORT=$FRONTEND_PORT npm run dev -- --port $FRONTEND_PORT > "$LOG_FRONTEND" 2>&1 & echo $! > /tmp/e2e-frontend.pid)
sleep 3
if [ -s /tmp/e2e-frontend.pid ]; then
PID_F=$(cat /tmp/e2e-frontend.pid)
echo "frontend PID: $PID_F"
PIDS+=("$PID_F")
else
echo "No frontend pid file created; check $LOG_FRONTEND"
fi
fi
# 5) Optionally Start Playwright run-server
if [ "$NO_PLAYWRIGHT" -eq 0 ]; then
echo "Starting Playwright run-server on ${PLAYWRIGHT_HOST}:${PLAYWRIGHT_PORT} (logs -> $LOG_PLAYWRIGHT)"
# start in background
nohup npx playwright run-server --port "$PLAYWRIGHT_PORT" --host 0.0.0.0 > "$LOG_PLAYWRIGHT" 2>&1 &
PID_PW=$!
echo $PID_PW > /tmp/e2e-playwright.pid
echo "playwright server PID: $PID_PW"
PIDS+=("$PID_PW")
# wait for it to listen
i=0
until curl -sS "http://127.0.0.1:${PLAYWRIGHT_PORT}/json/version" > /dev/null 2>&1 || [ $i -gt 15 ]; do
sleep 1; i=$((i+1));
done
if [ $i -gt 15 ]; then
echo "Warning: Playwright server did not appear to start; see $LOG_PLAYWRIGHT"
else
echo "Playwright server ready"
fi
fi
# 6) Wait for frontend health
if [ "$NO_FRONTEND" -eq 0 ]; then
echo "Waiting for frontend at http://127.0.0.1:${FRONTEND_PORT}/"
i=0
until curl -sS -I "http://127.0.0.1:${FRONTEND_PORT}/" > /dev/null 2>&1 || [ $i -gt 30 ]; do
sleep 1; i=$((i+1));
done
if [ $i -gt 30 ]; then
echo "Warning: frontend did not respond in time; check $LOG_FRONTEND"
else
echo "Frontend responding"
fi
fi
# 7) Run the plugin E2E
echo "Running plugin E2E (log -> $LOG_PLUGIN)"
PLUGIN_CMD=(node "$PKG_FRONTEND/e2e/dify-plugin-playwright.mjs" --ws "ws://localhost:${PLAYWRIGHT_PORT}" --url "http://localhost:${FRONTEND_PORT}" --out "$ARTIFACT_DIR/dify-shot.png")
# run and capture stdout
"${PLUGIN_CMD[@]}" > "$LOG_PLUGIN" 2>&1 || true
# copy plugin output log to artifacts
cp -f "$LOG_PLUGIN" "$ARTIFACT_DIR/" || true
if [ -f "$ARTIFACT_DIR/dify-shot.png" ]; then
echo "Screenshot saved: $ARTIFACT_DIR/dify-shot.png"
else
echo "No screenshot generated; check $LOG_PLUGIN"
fi
# 8) collect other logs
cp -f "$LOG_BACKEND" "$ARTIFACT_DIR/" 2>/dev/null || true
cp -f "$LOG_FRONTEND" "$ARTIFACT_DIR/" 2>/dev/null || true
cp -f "$LOG_PLAYWRIGHT" "$ARTIFACT_DIR/" 2>/dev/null || true
# 9) print artifact summary
echo "=== Artifacts in $ARTIFACT_DIR ==="
ls -la "$ARTIFACT_DIR" || true
# if not KEEP_RUNNING, cleanup will run via trap
if [ "$KEEP_RUNNING" -eq 1 ]; then
echo "Services left running (use scripts/e2e-run.sh --keep to avoid cleanup)."
# prevent trap from killing
trap - EXIT
fi
exit 0