Skip to content

Commit 43d86f9

Browse files
committed
iOS test script
1 parent ee60b7d commit 43d86f9

1 file changed

Lines changed: 12 additions & 90 deletions

File tree

scripts/test-ios.sh

Lines changed: 12 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,25 @@
11
#!/bin/bash
2-
set -euo pipefail
32

4-
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
5-
EXAMPLE_DIR="${ROOT_DIR}/example"
6-
APP_PROCESS="OPSQLiteExample"
7-
LOG_FILE="${EXAMPLE_DIR}/ios-sim-log.txt"
8-
LOG_STREAM_PID=""
9-
DEVICE_ID=""
3+
cd example
104

11-
pick_device_id() {
12-
DEVICE_ID="$(xcrun simctl list devices | awk -F '[()]' '/Booted/{print $2; exit}')"
5+
xcrun simctl boot "$(xcrun simctl list devices available | grep -m1 'Booted' || xcrun simctl list devices available | grep -m1 'Shutdown' | awk -F '[()]' '{print $2}')"
136

14-
if [[ -z "${DEVICE_ID}" ]]; then
15-
DEVICE_ID="$(xcrun simctl list devices available | awk -F '[()]' '/iPhone 17 .*Shutdown/{print $2; exit}')"
16-
fi
17-
18-
if [[ -z "${DEVICE_ID}" ]]; then
19-
DEVICE_ID="$(xcrun simctl list devices available | awk -F '[()]' '/Shutdown/{print $2; exit}')"
20-
fi
7+
yarn run:ios:release
218

22-
if [[ -z "${DEVICE_ID}" ]]; then
23-
echo "No usable iOS simulator device found."
24-
xcrun simctl list devices available || true
25-
return 1
26-
fi
9+
sleep 5
2710

28-
return 0
29-
}
11+
cd ..
3012

31-
cleanup() {
32-
if [[ -n "${LOG_STREAM_PID}" ]]; then
33-
kill "${LOG_STREAM_PID}" 2>/dev/null || true
34-
fi
35-
}
13+
node ./scripts/poll-in-app-server.js
3614

37-
print_diagnostics() {
38-
echo "=== iOS diagnostics ==="
39-
local diag_device_id="${DEVICE_ID}"
40-
if [[ -z "${diag_device_id}" ]]; then
41-
diag_device_id="$(xcrun simctl list devices | awk -F '[()]' '/Booted/{print $2; exit}')"
42-
fi
43-
44-
if [[ -n "${diag_device_id}" ]]; then
45-
xcrun simctl spawn "${diag_device_id}" log show --style syslog --predicate "process == \"${APP_PROCESS}\"" --info --debug --last 10m || true
15+
if [ $? -ne 0 ]; then
16+
echo "poll-in-app-server failed, printing device logs..."
17+
DEVICE_ID=$(xcrun simctl list devices booted | grep -m1 Booted | awk -F '[()]' '{print $2}')
18+
if [ -n "$DEVICE_ID" ]; then
19+
xcrun simctl spawn "$DEVICE_ID" log show --style syslog --predicate 'process == "OPSQLiteExample"' --info --debug --last 10m
4620
else
4721
echo "No booted simulator device found."
4822
fi
49-
}
50-
51-
on_error() {
52-
local exit_code=$?
53-
echo "❌ iOS test script failed with exit code ${exit_code}"
54-
print_diagnostics
55-
exit "${exit_code}"
56-
}
57-
58-
wait_for_test_result() {
59-
local max_duration_seconds=1200
60-
local start_time
61-
start_time=$(date +%s)
62-
63-
while true; do
64-
if grep -q "OPSQLITE_TEST_RESULT:PASS" "${LOG_FILE}"; then
65-
echo "🟢 iOS test suite passed (from log marker)"
66-
return 0
67-
fi
68-
69-
if grep -q "OPSQLITE_TEST_RESULT:FAIL" "${LOG_FILE}"; then
70-
echo "🟥 iOS test suite failed (from log marker)"
71-
return 1
72-
fi
73-
74-
local now
75-
now=$(date +%s)
76-
if (( now - start_time > max_duration_seconds )); then
77-
echo "🟥 Timed out waiting for iOS test result marker after ${max_duration_seconds}s"
78-
return 1
79-
fi
80-
81-
sleep 5
82-
done
83-
}
84-
85-
trap cleanup EXIT
86-
trap on_error ERR
87-
88-
cd "${EXAMPLE_DIR}"
89-
90-
pick_device_id
91-
92-
xcrun simctl boot "${DEVICE_ID}"
93-
xcrun simctl bootstatus "${DEVICE_ID}" -b
94-
95-
rm -f "${LOG_FILE}"
96-
xcrun simctl spawn "${DEVICE_ID}" log stream --style syslog --level debug --predicate "process == \"${APP_PROCESS}\"" > "${LOG_FILE}" &
97-
LOG_STREAM_PID=$!
98-
99-
yarn run:ios:release
100-
101-
wait_for_test_result
23+
fi
10224

10325

0 commit comments

Comments
 (0)