-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathe2e.sh
More file actions
executable file
·142 lines (111 loc) · 3.62 KB
/
e2e.sh
File metadata and controls
executable file
·142 lines (111 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
set -euo pipefail
# Change to project root
cd "$(dirname "$0")"/..
export NEXT_PUBLIC_ISOLATED_ENV=true
export CI=true
#export NEXT_PUBLIC_LOG_LEVEL=debug
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() { echo -e "${GREEN}[E2E]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
print_warning(){ echo -e "${YELLOW}[WARN]${NC} $1"; }
# Array to track background process PIDs
PIDS=()
# Function to clean up background processes
cleanup() {
print_status "Cleaning up..."
# Stop Firebase emulators
./scripts/firebase_stop.sh
# Kill all background processes
for pid in "${PIDS[@]:-}"; do
if kill -0 "$pid" 2>/dev/null; then
kill "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
fi
done
# Stop Docker containers
if [ "${SKIP_DB_CLEANUP:-}" != "true" ]; then
print_status "Stopping test database..."
docker compose -f scripts/docker-compose.test.yml down -v
fi
sleep 2
print_status "Cleanup complete"
}
# Trap EXIT, INT, TERM to run cleanup automatically
trap cleanup EXIT INT TERM
# Load test environment variables
if [ -f .env.test ]; then
export $(cat .env.test | grep -v '^#' | xargs)
fi
# ✅ Kill stale processes from previous runs
print_status "Killing any stale processes..."
./scripts/firebase_stop.sh
supabase stop --no-backup 2>/dev/null || true
sleep 2 # Give ports time to free up
# Install Playwright browsers
print_status "Installing Playwright browsers..."
npx playwright install chromium # --with-deps
# Start Firebase emulators
print_status "Starting Firebase emulators..."
yarn emulate & PIDS+=($!)
# Wait for emulators to be ready
print_status "Waiting for Firebase emulators..."
npx wait-on \
http-get://127.0.0.1:9099 \
--timeout 30000
# Start Supabase (includes Postgres, Auth, Storage, etc.) and Apply migrations and seed (needs firebase emulator running)
yarn test:db:reset
# Get connection details
STATUS_JSON=$(supabase status --output json)
export NEXT_PUBLIC_SUPABASE_URL=$(echo "$STATUS_JSON" | jq -r '.API_URL')
export NEXT_PUBLIC_SUPABASE_ANON_KEY=$(echo "$STATUS_JSON" | jq -r '.ANON_KEY')
export DATABASE_URL=$(echo "$STATUS_JSON" | jq -r '.DB_URL')
print_status "Supabase started at: $DATABASE_URL"
echo "Supabase env vars:"
echo $NEXT_PUBLIC_SUPABASE_URL
echo $NEXT_PUBLIC_SUPABASE_ANON_KEY
echo $DATABASE_URL
for var in NEXT_PUBLIC_SUPABASE_URL NEXT_PUBLIC_SUPABASE_ANON_KEY DATABASE_URL; do
if [ -z "${!var}" ] || [ "${!var}" = "null" ]; then
echo "Error: $var is not set or null" >&2
exit 1
fi
done
# Start backend API
print_status "Starting backend API..."
yarn --cwd=backend/api dev & PIDS+=($!)
# Wait for API to be ready
print_status "Waiting for API..."
npx wait-on http://localhost:8088/health --timeout 30000 || {
print_error "API failed to start"
exit 1
}
# Start Next.js app
print_status "Starting Next.js app..."
yarn --cwd=web dev & PIDS+=($!)
# Wait for Next.js to be ready
print_status "Waiting for Next.js..."
npx wait-on http://localhost:3000 --timeout 60000 || {
print_error "Next.js failed to start"
exit 1
}
# Run Playwright tests
echo ""
print_status "✅ Running Playwright tests..."
print_status " Useful links:"
print_status " - Front end: http://127.0.0.1:3000"
print_status " - Supabase UI: http://127.0.0.1:54323"
print_status " - Firebase UI: http://127.0.0.1:4000"
TEST_FAILED=0
npx playwright test tests/e2e "$@" || TEST_FAILED=$?
if [ $TEST_FAILED -eq 0 ]; then
print_status "${GREEN}All tests passed!${NC}"
else
print_error "Some tests failed (exit code: $TEST_FAILED)"
fi
exit $TEST_FAILED