-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest-jetty-setups.sh
More file actions
executable file
·220 lines (184 loc) · 5.84 KB
/
test-jetty-setups.sh
File metadata and controls
executable file
·220 lines (184 loc) · 5.84 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env bash
set -e
# Test script for electric-fiddle jetty 10+ and jetty 9 setups
# Runs each server sequentially, opens browser for manual verification.
#
# Usage:
# ./test-jetty-setups.sh [OPTIONS] [-- EXTRA_DEPS_ALIASES...]
#
# Options:
# --no-browser Skip opening browsers (just check HTTP headers)
# --help Show this help
#
# Examples:
# ./test-jetty-setups.sh # Run with default aliases (dev)
# ./test-jetty-setups.sh -- :local # Add :local alias (monorepo overrides)
# ./test-jetty-setups.sh -- :local :private # Add multiple aliases
# ./test-jetty-setups.sh --no-browser # Automated mode, no browser
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
OPEN_BROWSER=true
EXTRA_ALIASES=""
while [[ $# -gt 0 ]]; do
case $1 in
--no-browser)
OPEN_BROWSER=false
shift
;;
--help)
head -20 "$0" | tail -n +2 | sed 's/^# //' | sed 's/^#//'
exit 0
;;
--)
shift
EXTRA_ALIASES="$*"
break
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage"
exit 1
;;
esac
done
USER_CLJ="src-dev/user.clj"
PORT=8080
SERVER_PID=""
cleanup() {
echo ""
echo "Cleaning up..."
# Kill server
if [[ -n "$SERVER_PID" ]]; then
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
fi
# Restore user.clj
if [[ -f "${USER_CLJ}.orig" ]]; then
mv "${USER_CLJ}.orig" "$USER_CLJ"
fi
echo "Done."
}
trap cleanup EXIT
wait_for_server() {
local max_attempts=60
local attempt=0
echo "Waiting for server on port $PORT..."
while ! curl -s -o /dev/null -w "%{http_code}" http://localhost:$PORT 2>/dev/null | grep -q "200"; do
sleep 1
attempt=$((attempt + 1))
if [[ $attempt -ge $max_attempts ]]; then
echo "FAIL: Server did not start within ${max_attempts}s"
return 1
fi
if (( attempt % 10 == 0 )); then
echo " Still waiting... (${attempt}s)"
fi
done
echo "Server is up!"
}
check_jetty_version() {
local expected_pattern="$1"
local server_header=$(curl -sI http://localhost:$PORT 2>/dev/null | grep -i "^Server:" | tr -d '\r')
echo " $server_header"
if echo "$server_header" | grep -q "$expected_pattern"; then
echo " Header check: PASS ✓"
return 0
else
echo " Header check: FAIL ✗ (expected $expected_pattern)"
return 1
fi
}
stop_server() {
if [[ -n "$SERVER_PID" ]]; then
echo "Stopping server..."
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
SERVER_PID=""
sleep 2 # Give port time to be released
fi
}
# Build aliases string
BASE_ALIASES="dev:electric-tutorial:dustingetz"
if [[ -n "$EXTRA_ALIASES" ]]; then
for alias in $EXTRA_ALIASES; do
alias="${alias#:}" # Strip leading colon if present
BASE_ALIASES="${BASE_ALIASES}:${alias}"
done
fi
echo "========================================"
echo "Electric Fiddle Jetty Setup Tests"
echo "========================================"
echo "Aliases: $BASE_ALIASES"
echo "Browser: $OPEN_BROWSER"
echo ""
# Restore from previous interrupted run if needed, then backup
if [[ -f "${USER_CLJ}.orig" ]]; then
echo "Restoring user.clj from previous interrupted run..."
mv "${USER_CLJ}.orig" "$USER_CLJ"
fi
cp "$USER_CLJ" "${USER_CLJ}.orig"
JETTY10_RESULT=0
JETTY9_RESULT=0
# ===========================================
# Test 1: Jetty 10+
# ===========================================
echo "========================================"
echo "Test 1: Jetty 10+ (default)"
echo "========================================"
cat > "$USER_CLJ" << 'USERCLJ'
(ns user)
(print "[user] loading dev... ") (flush)
(require 'dev)
(println "Ready.")
USERCLJ
echo "Starting server with: clj -A:$BASE_ALIASES -X dev/-main"
clj -A:$BASE_ALIASES -X dev/-main &
SERVER_PID=$!
wait_for_server || { echo "Jetty 10+ failed to start"; exit 1; }
check_jetty_version "Jetty(1[0-9]" || JETTY10_RESULT=1
if $OPEN_BROWSER; then
echo ""
echo "Opening browser: http://localhost:$PORT"
open "http://localhost:$PORT" 2>/dev/null || xdg-open "http://localhost:$PORT" 2>/dev/null || true
echo ""
echo "Verify fiddles load correctly, then press Enter to continue to Jetty 9 test..."
read -r
fi
stop_server
# ===========================================
# Test 2: Jetty 9
# ===========================================
echo ""
echo "========================================"
echo "Test 2: Jetty 9"
echo "========================================"
cat > "$USER_CLJ" << 'USERCLJ'
(ns user)
(print "[user] loading dev... ") (flush)
(require '[dev-jetty9 :as dev])
(println "Ready.")
USERCLJ
echo "Starting server with: clj -A:${BASE_ALIASES}:jetty9 -X dev/-main"
clj -A:${BASE_ALIASES}:jetty9 -X dev/-main &
SERVER_PID=$!
wait_for_server || { echo "Jetty 9 failed to start"; exit 1; }
check_jetty_version "Jetty(9" || JETTY9_RESULT=1
if $OPEN_BROWSER; then
echo ""
echo "Opening browser: http://localhost:$PORT"
open "http://localhost:$PORT" 2>/dev/null || xdg-open "http://localhost:$PORT" 2>/dev/null || true
echo ""
echo "Verify fiddles load correctly, then press Enter to finish..."
read -r
fi
stop_server
# ===========================================
# Summary
# ===========================================
echo ""
echo "========================================"
echo "TEST SUMMARY"
echo "========================================"
echo "Jetty 10+: $([ $JETTY10_RESULT -eq 0 ] && echo 'PASS ✓' || echo 'FAIL ✗')"
echo "Jetty 9: $([ $JETTY9_RESULT -eq 0 ] && echo 'PASS ✓' || echo 'FAIL ✗')"
exit $((JETTY10_RESULT + JETTY9_RESULT))