-
Notifications
You must be signed in to change notification settings - Fork 9
/
run_tests.sh
executable file
·111 lines (94 loc) · 3.56 KB
/
run_tests.sh
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
#!/bin/bash
set -eE
trap 'xcrun simctl delete "$DEVICE_ID"' ERR
# Parse named arguments
while [[ $# -gt 0 ]]; do
case $1 in
-s|--scheme) SCHEME="$2"; shift;;
-p|--project) PROJECT="$2"; shift;;
-t|--testplan) TESTPLAN="$2"; shift;;
esac
shift
done
if [ -z "$SCHEME" ]; then
echo "No scheme provided"
exit 1
fi
# Function to update xctestrun file
update_xctestrun() {
# Parse named arguments
while [[ $# -gt 0 ]]; do
case $1 in
-k|--key) KEY="$2"; shift;;
-v|--value) VALUE="$2"; shift;;
-t|--target) TARGET="$2"; shift;;
esac
shift
done
if [ -n "$VALUE" ]; then
echo "Updating $KEY with $VALUE"
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.$KEY -string "$VALUE" "$TARGET"
else
echo "No value provided for $KEY"
fi
}
# Set XCBuild defaults
defaults write com.apple.dt.XCBuild IgnoreFileSystemDeviceInodeChanges -bool YES
# Remove and recreate test_results directory
echo "Removing and recreating test_results directory"
rm -rf test_results
mkdir test_results
# Create ephemeral simulator
DEVICE_ID=$(xcrun simctl create "EphemeralSim$SCHEME" "iPhone 14")
echo "Created ephemeral simulator with id: $DEVICE_ID"
if [ -z "$TESTPLAN" ]; then
XCTESTRUN=$(find . -name "*_$SCHEME*.xctestrun")
else
XCTESTRUN=$(find . -name "*_$TESTPLAN*.xctestrun")
fi
# If xctestrun file exists, update it and run test-without-building otherwise run regular test
if [ -z "$XCTESTRUN" ]; then
echo "XCTESTRUN file not found"
(
set -x
#If xctestrun file does not exist, run regular test
set -o pipefail && env NSUnbufferedIO=YES \
xcodebuild \
${PROJECT:+-project "$PROJECT"} \
${TESTPLAN:+-testPlan "$TESTPLAN"} \
-scheme "$SCHEME" \
-destination "platform=iOS Simulator,id=$DEVICE_ID" \
-derivedDataPath DerivedDataCache \
-clonedSourcePackagesDirPath ../SourcePackagesCache \
-resultBundlePath "test_results/$SCHEME.xcresult" \
test \
| tee ./test_results/xcodebuild.log \
| xcbeautify --report junit --junit-report-filename report.junit --report-path ./test_results
)
else
echo "XCTESTRUN file found: $XCTESTRUN"
update_xctestrun --key "RELAY_HOST" --value "$RELAY_HOST" --target "$XCTESTRUN"
update_xctestrun --key "PROJECT_ID" --value "$PROJECT_ID" --target "$XCTESTRUN"
update_xctestrun --key "GM_DAPP_PROJECT_ID" --value "$GM_DAPP_PROJECT_ID" --target "$XCTESTRUN"
update_xctestrun --key "GM_DAPP_PROJECT_SECRET" --value "$GM_DAPP_PROJECT_SECRET" --target "$XCTESTRUN"
update_xctestrun --key "GM_DAPP_HOST" --value "$GM_DAPP_HOST" --target "$XCTESTRUN"
update_xctestrun --key "CAST_HOST" --value "$CAST_HOST" --target "$XCTESTRUN"
update_xctestrun --key "EXPLORER_HOST" --value "$EXPLORER_HOST" --target "$XCTESTRUN"
update_xctestrun --key "JS_CLIENT_API_HOST" --value "$JS_CLIENT_API_HOST" --target "$XCTESTRUN"
(
set -x
set -o pipefail && env NSUnbufferedIO=YES \
xcodebuild \
-xctestrun "$XCTESTRUN" \
-destination "platform=iOS Simulator,id=$DEVICE_ID" \
-derivedDataPath DerivedDataCache \
-clonedSourcePackagesDirPath ../SourcePackagesCache \
-resultBundlePath "test_results/$SCHEME.xcresult" \
test-without-building \
| tee ./test_results/xcodebuild.log \
| xcbeautify --report junit --junit-report-filename report.junit --report-path ./test_results
)
fi
echo "Removing ephemeral simulator"
xcrun simctl delete "$DEVICE_ID"
echo "Done"