-
Notifications
You must be signed in to change notification settings - Fork 585
/
Copy pathtest.sh
executable file
·211 lines (182 loc) · 4.91 KB
/
test.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
set -o pipefail
set -e
export TEST_SCRIPT=1
export NPM_CONFIG_PROGRESS=false
TARGET=$1
CONFIGURATION=${2:-Release}
NODE_VERSION=${3:-v12.22.5}
if echo "$CONFIGURATION" | grep -i "^Debug$" > /dev/null ; then
CONFIGURATION="Debug"
fi
USE_REALM_DEBUG=0
if [ "${CONFIGURATION}" == "Debug" ]; then
USE_REALM_DEBUG=1
fi
USE_REALM_SYNC=1
SRCROOT=$(cd "$(dirname "$0")/.." && pwd)
CI_RUN=false
if [ -n "${JENKINS_HOME}" ]; then
CI_RUN=true
fi
SIM_DEVICE_NAME=realm-js-test
# Start current working directory at the root of the project.
cd "$SRCROOT"
# Add node_modules to PATH just in case we weren't called from `npm test`
PATH="$PWD/node_modules/.bin:$PATH"
# SERVER_PID=0
PACKAGER_OUT="$SRCROOT/packager_out.txt"
RUN_STITCH_IN_FORGROUND=""
die() {
echo "$@" >&2
exit 1
}
start_server() {
echo "test.sh: starting stitch"
if [ "$CI_RUN" == "true" ]; then
echo "CI Run detected, not manually starting a server"
return;
fi
RUN_STITCH_IN_FORGROUND="$RUN_STITCH_IN_FORGROUND" ./scripts/start-sync-server.sh
}
stop_server() {
echo stopping server
if [[ -n "$STITCH_DOCKER_ID" ]] ; then
echo "stopping the docker instance that we started earlier: ${STITCH_DOCKER_ID}"
docker stop "$STITCH_DOCKER_ID"
fi
}
startedSimulator=false
log_temp=
test_temp_dir=
nvm_old_default=
cleanup() {
# Kill started object server
stop_server || true
if [ "$(uname)" = 'Darwin' ]; then
echo "shutting down running simulators"
shutdown_ios_simulator >/dev/null 2>&1
# Quit Simulator.app to give it a chance to go down gracefully
if $startedSimulator; then
osascript -e 'tell app "Simulator" to quit without saving' || true
sleep 0.25 # otherwise the pkill following will get it too early
fi
fi
if [[ "$(command -v pkill)" ]]; then
# Kill all child processes.
pkill -9 -P $$ || true
# Kill react native packager
pkill -x node || true
rm -f "$PACKAGER_OUT" "$LOGCAT_OUT"
fi
# Cleanup temp files
if [ -n "$log_temp" ] && [ -e "$log_temp" ]; then
rm "$log_temp" || true
fi
if [ -n "$test_temp_dir" ] && [ -e "$test_temp_dir" ]; then
rm -rf "$test_temp_dir" || true
fi
# Restore nvm state
if [ -n "$nvm_old_default" ]; then
echo Restoring nvm default to $nvm_old_default
nvm alias default $nvm_old_default
echo nvm default restored successfully
fi
}
check_test_results() {
echo "Checking tests results"
if grep -q "REALM_FAILING_TESTS" $(pwd)/build/out.txt; then
echo "*** REALM JS TESTS FAILED. See tests results above ***"
exit 20
else
echo "*** $1 SUCCESS ***"
fi
}
# Cleanup now and also cleanup when this script exits.
cleanup >/dev/null 2>&1
trap cleanup EXIT
echo Checking for nvm installation
# Use a consistent version of Node if possible.
if [[ -z "$(command -v nvm)" ]]; then
set +e
if [ -f "$NVM_DIR/nvm.sh" ]; then
. "$NVM_DIR/nvm.sh" '' || true
elif [ -x "$(command -v brew)" ] && [ -f "$(brew --prefix nvm)/nvm.sh" ]; then
# we must be on mac and nvm was installed with brew
# TODO: change the mac slaves to use manual nvm installation
. "$(brew --prefix nvm)/nvm.sh" '' || true
elif [ -f "$HOME/.nvm/nvm.sh" ]; then
. ~/.nvm/nvm.sh ''
fi
set -e
fi
if [[ "$(command -v nvm)" ]]; then
echo nvm installing $NODE_VERSION
set +e
nvm install $NODE_VERSION
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Error while installing $NODE_VERSION $retVal"
exit $retVal
fi
set -e
echo nvm install of $NODE_VERSION completed
fi
set_nvm_default() {
if [ -n "$REALM_SET_NVM_ALIAS" ] && [[ "$(command -v nvm)" ]]; then
echo REALM_SET_NVM_ALIAS is set.
nvm_old_default="$(nvm alias default --no-colors | cut -d ' ' -f 3)"
echo Setting nvm default alias to $(nvm current)
nvm alias default $(nvm current)
fi
}
# use npm v7
npm install -g npm@7
# Remove cached packages
rm -rf ~/.yarn-cache/npm-realm-*
case "$TARGET" in
"check-environment")
npm run check-environment
;;
"license-check")
[[ $CONFIGURATION == 'Debug' ]] && exit 0
npm run license-check
;;
"jsdoc")
[[ $CONFIGURATION == 'Debug' ]] && exit 0
npm run jsdoc
;;
"start-server")
RUN_STITCH_IN_FORGROUND=true
start_server
;;
"node")
npm run check-environment
if [ "$CI_RUN" == "true" ]; then
npm ci
else
npm ci --build-from-source=realm --realm_enable_sync=${USE_REALM_SYNC} --use_realm_debug=${USE_REALM_DEBUG}
fi
start_server
# Change to a temp directory.
cd "$(mktemp -q -d -t realm.node.XXXXXX)"
test_temp_dir=$PWD # set it to be cleaned at exit
pushd "$SRCROOT/tests"
if [ "$CI_RUN" == "true" ]; then
npm ci
else
npm ci --build-from-source=realm --realm_enable_sync=${USE_REALM_SYNC} --use_realm_debug=${USE_REALM_DEBUG}
fi
npm run test
popd
stop_server
;;
"test-runners")
npm run check-environment
npm ci --build-from-source=realm --use_realm_debug=${USE_REALM_DEBUG}
npm run test-runners
;;
*)
echo "Invalid target '${TARGET}'"
exit 1
esac