33
44# Internal script to run E2E tests inside the container
55
6+ # Cleanup function to kill spawned processes
7+ cleanup () {
8+ echo " 🧹 Cleaning up processes..."
9+ [ -n " $FRONTEND_PID " ] && kill $FRONTEND_PID 2> /dev/null || true
10+ [ -n " $CENTRIFUGO_PID " ] && kill $CENTRIFUGO_PID 2> /dev/null || true
11+ }
12+ trap cleanup EXIT
13+
614echo " 🔧 Setting up test environment..."
715
8- # 0. Ensure bun is installed (needed for UI)
16+ # 0. Kill any stale Vite/bun processes from previous runs
17+ echo " 🧹 Cleaning up stale processes..."
18+ pkill -9 -f " vite.*--port 5173" 2> /dev/null || true
19+ pkill -9 -f " bun run.*5173" 2> /dev/null || true
20+ pkill -9 -f " node.*vite.*5173" 2> /dev/null || true
21+ sleep 2
22+
23+ # 1. Ensure bun is installed (needed for UI)
924if ! command -v bun & > /dev/null; then
1025 echo " ⚠️ Bun not found, installing..."
1126 curl -fsSL https://bun.sh/install | bash
1227 export BUN_INSTALL=" $HOME /.bun"
1328 export PATH=" $BUN_INSTALL /bin:$PATH "
1429fi
1530
16- # 1 . Ensure Centrifugo is available (using the tool script if needed)
31+ # 2 . Ensure Centrifugo is available (using the tool script if needed)
1732if ! command -v centrifugo & > /dev/null; then
1833 echo " ⚠️ Centrifugo not found in PATH, checking tools directory..."
1934 if [ ! -f " tools/centrifugo" ]; then
@@ -22,15 +37,24 @@ if ! command -v centrifugo &> /dev/null; then
2237 export PATH=$PATH :$( pwd) /tools
2338fi
2439
25- # 2 . Start Centrifugo directly (Backend is mocked, but we need real WS)
40+ # 3 . Start Centrifugo directly (Backend is mocked, but we need real WS)
2641echo " 🚀 Starting Centrifugo..."
2742# Using the config from backend/config/centrifugo_config.json
2843CENTRIFUGO_CONFIG=" src/backend/config/centrifugo_config.json"
2944
3045# Generate self-signed certs for testing if missing
3146mkdir -p temp/certs
32- if [ ! -f " temp/certs/server.cert.pem" ]; then
47+ if [ ! -f " temp/certs/server.cert.pem" ] || [ ! -r " temp/certs/server.key.pem" ]; then
48+ echo " 🔐 Generating self-signed certificates..."
49+ # Check if old certs exist with wrong permissions
50+ if [ -f " temp/certs/server.cert.pem" ] && [ ! -w " temp/certs/server.cert.pem" ]; then
51+ echo " ❌ Error: Old certificates exist with wrong permissions (likely created by root)"
52+ echo " Please run: sudo rm -rf temp/certs"
53+ exit 1
54+ fi
55+ rm -f temp/certs/server.cert.pem temp/certs/server.key.pem
3356 openssl req -newkey rsa:2048 -nodes -keyout temp/certs/server.key.pem -x509 -days 365 -out temp/certs/server.cert.pem -subj " /CN=localhost" 2> /dev/null
57+ chmod 644 temp/certs/server.key.pem temp/certs/server.cert.pem
3458fi
3559
3660# Env vars for Centrifugo
@@ -59,28 +83,52 @@ for i in {1..30}; do
5983 sleep 1
6084done
6185
62- # 3 . Serve the Frontend
86+ # 4 . Serve the Frontend
6387echo " 🌐 Starting Frontend Dev Server..."
6488cd src/ui
89+
6590# Install dependencies if needed (container might not have node_modules)
6691if [ ! -d " node_modules" ]; then
6792 echo " 📦 Installing UI dependencies..."
6893 bun install
6994fi
7095
71- # Start vite dev server in background
72- bun run dev --port 5173 > /tmp/vite.log 2>&1 &
96+ # Check for permission issues with dist directory or its subdirectories
97+ if [ -d " dist" ]; then
98+ if [ ! -w " dist" ] || find dist -type d ! -writable 2> /dev/null | grep -q . ; then
99+ echo " ❌ Error: dist directory has wrong permissions (likely created by root)"
100+ echo " Please run: sudo rm -rf src/ui/dist"
101+ kill $CENTRIFUGO_PID || true
102+ exit 1
103+ fi
104+ fi
105+
106+ # Build the frontend for preview mode (eliminates Vite dev optimization issues)
107+ # Note: Using default base path (/) for preview server, not /static for production backend
108+ echo " 🏗️ Building frontend..."
109+ if bun run build-preview > /tmp/vite-build.log 2>&1 ; then
110+ echo " ✅ Frontend build complete!"
111+ else
112+ echo " ❌ Frontend build failed!"
113+ cat /tmp/vite-build.log
114+ kill $CENTRIFUGO_PID || true
115+ exit 1
116+ fi
117+
118+ # Start Vite preview server (serves production build)
119+ echo " 🚀 Starting Vite preview server..."
120+ bun run preview --port 5173 > /tmp/vite.log 2>&1 &
73121FRONTEND_PID=$!
74122
75- # Wait for Frontend
76- echo " ⏳ Waiting for Frontend ..."
123+ # Wait for preview server
124+ echo " ⏳ Waiting for preview server ..."
77125for i in {1..30}; do
78126 if curl -s http://localhost:5173 > /dev/null; then
79- echo " ✅ Frontend is ready!"
127+ echo " ✅ Preview server is ready!"
80128 break
81129 fi
82130 if [ $i -eq 30 ]; then
83- echo " ❌ Frontend failed to start."
131+ echo " ❌ Preview server failed to start."
84132 cat /tmp/vite.log
85133 kill $FRONTEND_PID || true
86134 kill $CENTRIFUGO_PID || true
@@ -89,8 +137,22 @@ for i in {1..30}; do
89137 sleep 1
90138done
91139
92- # 4 . Run Playwright Tests
140+ # 5 . Run Playwright Tests
93141echo " 🧪 Running Playwright Tests..."
142+
143+ # Check for permission issues with Playwright test results
144+ if [ -d " test-results" ] && [ ! -w " test-results" ]; then
145+ echo " ❌ Error: Playwright test-results directory has wrong permissions (likely created by root)"
146+ echo " Please run: sudo rm -rf src/ui/test-results src/ui/playwright-report"
147+ kill $FRONTEND_PID || true
148+ kill $CENTRIFUGO_PID || true
149+ exit 1
150+ fi
151+
152+ # Install Playwright browsers (always run to ensure correct version)
153+ echo " 📦 Ensuring Playwright browsers are installed..."
154+ npx playwright install chromium
155+
94156# BASE_URL is set for playwright.config.ts
95157export BASE_URL=" http://localhost:5173"
96158
0 commit comments