|
1 | 1 | #!/bin/bash |
2 | | -set -euo pipefail |
3 | 2 |
|
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 |
10 | 4 |
|
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}')" |
13 | 6 |
|
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 |
21 | 8 |
|
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 |
27 | 10 |
|
28 | | - return 0 |
29 | | -} |
| 11 | +cd .. |
30 | 12 |
|
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 |
36 | 14 |
|
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 |
46 | 20 | else |
47 | 21 | echo "No booted simulator device found." |
48 | 22 | 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 |
102 | 24 |
|
103 | 25 |
|
0 commit comments