-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·68 lines (60 loc) · 2.39 KB
/
run-tests.sh
File metadata and controls
executable file
·68 lines (60 loc) · 2.39 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
#!/usr/bin/env bash
# Run all Get Based browser tests headlessly
# Starts a temp server, runs tests, kills server on exit
set -e
DIR="$(cd "$(dirname "$0")" && pwd)"
PORT=${PORT:-8000}
# Find Puppeteer — check npx cache, then local node_modules
NODE_PATH_EXTRA=""
if [ -d "$HOME/.npm/_npx" ]; then
NPX_DIR=$(find "$HOME/.npm/_npx" -path "*/node_modules/puppeteer" -type d 2>/dev/null | head -1 | sed 's|/puppeteer$||')
[ -n "$NPX_DIR" ] && NODE_PATH_EXTRA="$NPX_DIR"
fi
[ -d "$DIR/node_modules/puppeteer" ] && NODE_PATH_EXTRA="$DIR/node_modules"
if [ -z "$NODE_PATH_EXTRA" ]; then
echo "Puppeteer not found. Install with: npm i -g puppeteer"
exit 2
fi
# Start server if not already running. nohup + disown fully detaches it
# from the shell — signals sent to the shell's process group won't
# propagate. Log to /tmp so we can inspect if it ever dies unexpectedly.
SERVER_PID=""
if ! curl -s -o /dev/null "http://localhost:$PORT/" 2>/dev/null; then
nohup node "$DIR/dev-server.js" "$PORT" > /tmp/dev-server.log 2>&1 < /dev/null &
SERVER_PID=$!
disown "$SERVER_PID" 2>/dev/null || true
# Poll until listen actually succeeds — a plain sleep 1 was racy on
# slower CI runners. 10s ceiling is defensive.
for i in $(seq 1 40); do
if curl -s -o /dev/null -m 1 "http://localhost:$PORT/"; then break; fi
sleep 0.25
done
echo "Started server on :$PORT (PID $SERVER_PID)"
fi
# Assert dev-server is reachable — fail fast with a useful message if
# something killed it between startup and here. On CI we also tail its
# log for diagnostics.
ensure_server() {
if ! curl -s -o /dev/null -m 2 "http://localhost:$PORT/"; then
echo "dev-server on :$PORT not reachable — aborting"
if [ -f /tmp/dev-server.log ]; then
echo "--- /tmp/dev-server.log (last 40 lines) ---"
tail -40 /tmp/dev-server.log
fi
exit 2
fi
}
cleanup() {
[ -n "$SERVER_PID" ] && kill "$SERVER_PID" 2>/dev/null && echo "Stopped server"
return 0
}
trap cleanup EXIT
# Node-side tests first — no browser, fail fast on module / helper regressions.
node "$DIR/tests/test-no-native-dialogs.js" || exit 1
ensure_server
node "$DIR/tests/test-lens-local-utils.js" || exit 1
node "$DIR/tests/test-dev-server-helpers.js" || exit 1
ensure_server
# HTTP-reliant test before the Puppeteer suite.
PORT=$PORT node "$DIR/tests/test-dev-server-origin.js" || exit 1
PORT=$PORT NODE_PATH="$NODE_PATH_EXTRA" node "$DIR/run-tests.js"