Skip to content

Commit b214410

Browse files
jonphippsclaude
andcommitted
fix: add smart server detection to prevent port conflicts in E2E tests
- Check if servers are already running before starting new ones - Use existing servers when available to avoid disruption - Only start/stop servers when necessary - Add proper cleanup for servers started by the hook This prevents port conflicts when development servers are already running and makes E2E testing work in both development and clean environments. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent eb69022 commit b214410

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

.husky/pre-push-optimized

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,43 @@ if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "dev" ]; then
6767
if echo "$AFFECTED_PROJECTS" | grep -q "portal"; then
6868
echo "🌐 Portal affected - running E2E tests against built files..."
6969

70-
# Start servers for built files
71-
echo "🚀 Starting servers for built files..."
72-
pnpm serve:all &
73-
SERVER_PID=$!
74-
75-
# Wait for servers to be ready
76-
echo "⏳ Waiting for servers to start..."
77-
sleep 10
78-
79-
# Check if portal is accessible
70+
# Check if servers are already running
8071
if curl -s http://localhost:3000 > /dev/null; then
81-
echo "✅ Servers ready, running E2E tests..."
72+
echo "✅ Servers already running, using existing servers for E2E tests..."
8273
npx playwright test --config=playwright.config.pre-push.ts || {
8374
echo "⚠️ E2E tests failed but continuing (non-blocking for protected branches)"
8475
}
8576
else
86-
echo "❌ Servers failed to start, skipping E2E tests"
77+
echo "🚀 Starting servers for built files..."
78+
# Stop any existing servers first
79+
pnpm stop:all || true
80+
sleep 2
81+
82+
# Start fresh servers
83+
pnpm serve:all &
84+
SERVER_PID=$!
85+
86+
# Wait for servers to be ready
87+
echo "⏳ Waiting for servers to start..."
88+
sleep 10
89+
90+
# Check if portal is accessible
91+
if curl -s http://localhost:3000 > /dev/null; then
92+
echo "✅ Servers ready, running E2E tests..."
93+
npx playwright test --config=playwright.config.pre-push.ts || {
94+
echo "⚠️ E2E tests failed but continuing (non-blocking for protected branches)"
95+
}
96+
97+
# Cleanup our servers
98+
echo "🧹 Stopping servers..."
99+
kill $SERVER_PID 2>/dev/null || true
100+
pnpm stop:all || true
101+
else
102+
echo "❌ Servers failed to start, skipping E2E tests"
103+
kill $SERVER_PID 2>/dev/null || true
104+
fi
87105
fi
88106

89-
# Cleanup servers
90-
echo "🧹 Stopping servers..."
91-
kill $SERVER_PID 2>/dev/null || true
92-
pnpm stop:all || true
93-
94107
else
95108
echo "📝 Portal not affected - skipping E2E tests"
96109
fi

0 commit comments

Comments
 (0)