-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathe2e_maestro_android
More file actions
executable file
·114 lines (95 loc) · 2.54 KB
/
Copy pathe2e_maestro_android
File metadata and controls
executable file
·114 lines (95 loc) · 2.54 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
REPO_ROOT="$(cd "$ROOT_DIR/../.." && pwd)"
METRO_LOG="${TMPDIR:-/tmp}/checkout-kit-rn-android-metro.log"
METRO_PID=""
APP_ID="com.shopify.checkoutkit.reactnativedemo"
CART_BOOTSTRAP_BASE_LINK="${APP_ID}://cart?productIndex=0&quantity=1"
MAESTRO_FLOWS=()
usage() {
cat <<EOF >&2
Usage: dev rn e2e android [--guest] [--hardcoded-buyer-identity]
Runs all React Native Android Maestro checkout smoke flows by default.
Pass one or more focused scenario flags to run only those flows.
Options:
--guest Run only the guest checkout smoke flow.
--hardcoded-buyer-identity Run only the hardcoded buyer identity smoke flow.
EOF
}
add_maestro_flow() {
local flow="$1"
if [ "${#MAESTRO_FLOWS[@]}" -gt 0 ]; then
for existing_flow in "${MAESTRO_FLOWS[@]}"; do
if [ "$existing_flow" = "$flow" ]; then
return
fi
done
fi
MAESTRO_FLOWS+=("$flow")
}
for arg in "$@"; do
case "$arg" in
--guest)
add_maestro_flow "tests/react-native/checkout-guest.yaml"
;;
--hardcoded-buyer-identity)
add_maestro_flow "tests/react-native/checkout-hardcoded-buyer-identity.yaml"
;;
-h|--help)
usage
exit 0
;;
*)
usage
echo "Unknown option: $arg" >&2
exit 1
;;
esac
done
if [ "${#MAESTRO_FLOWS[@]}" -eq 0 ]; then
MAESTRO_FLOWS=(".")
fi
metro_running() {
curl --silent --fail http://localhost:8081/status | grep -q "packager-status:running"
}
cleanup() {
if [ -n "$METRO_PID" ]; then
kill "$METRO_PID" 2>/dev/null || true
fi
}
wait_for_metro() {
for _ in $(seq 1 60); do
if metro_running; then
return 0
fi
sleep 1
done
echo "Timed out waiting for Metro. Last log lines:" >&2
tail -n 40 "$METRO_LOG" >&2 || true
return 1
}
require_maestro() {
if ! maestro --version >/dev/null 2>&1; then
echo "Maestro is required to run React Native E2E tests." >&2
echo "Install Maestro and make sure maestro --version succeeds." >&2
return 1
fi
}
cd "$ROOT_DIR"
require_maestro
if ! metro_running; then
/opt/dev/bin/dev react-native start >"$METRO_LOG" 2>&1 &
METRO_PID="$!"
trap cleanup EXIT
fi
wait_for_metro
pnpm sample android --local --extra-params "--refresh-dependencies"
(
cd "$REPO_ROOT/e2e"
maestro --platform android test --config config.yaml \
-e "APP_ID=${APP_ID}" \
-e "CART_BOOTSTRAP_BASE_LINK=${CART_BOOTSTRAP_BASE_LINK}" \
"${MAESTRO_FLOWS[@]}"
)