@@ -12,11 +12,12 @@ RUN_IOS=0
1212RUN_JS=0
1313
1414RETRY_COUNT=${RETRY_COUNT:- 2}
15- AVD_UUID=$( cat /dev/urandom | tr -dc ' a-zA-Z0-9' | fold -w 8 | head -n 1)
16-
15+ AVD_UUID=$( < /dev/urandom tr -dc ' a-zA-Z0-9' | fold -w 8 | head -n 1)
1716ANDROID_NPM_DEPS=" appium@1.5.1 mocha@2.4.5 wd@0.3.11 colors@1.0.3 pretty-data2@0.40.1"
18- CLI_PACKAGE=$ROOT /react-native-cli/react-native-cli-* .tgz
19- PACKAGE=$ROOT /react-native-* .tgz
17+ CLI_PACKAGE=" $ROOT /react-native-cli/react-native-cli-*.tgz"
18+ PACKAGE=" $ROOT /react-native-*.tgz"
19+ # Version of react-native-dummy to test against
20+ REACT_DUMMY_PLATFORM=react-native-dummy@0.1.0
2021
2122# solve issue with max user watches limit
2223echo 65536 | tee -a /proc/sys/fs/inotify/max_user_watches
@@ -27,7 +28,7 @@ watchman shutdown-server
2728# $2 -- command to run
2829function retry() {
2930 local -r -i max_attempts=" $1 " ; shift
30- local -r cmd=" $@ "
31+ local -r cmd=" $* "
3132 local -i attempt_num=1
3233
3334 until $cmd ; do
@@ -75,7 +76,7 @@ while :; do
7576done
7677
7778function e2e_suite() {
78- cd $ROOT
79+ cd " $ROOT "
7980
8081 if [ $RUN_ANDROID -eq 0 ] && [ $RUN_IOS -eq 0 ] && [ $RUN_JS -eq 0 ]; then
8182 echo " No e2e tests specified!"
@@ -88,8 +89,8 @@ function e2e_suite() {
8889 # To make sure we actually installed the local version
8990 # of react-native, we will create a temp file inside the template
9091 # and check that it exists after `react-native init
91- IOS_MARKER=$( mktemp $ROOT /local-cli/templates/HelloWorld/ios/HelloWorld/XXXXXXXX)
92- ANDROID_MARKER=$( mktemp ${ ROOT} /local-cli/templates/HelloWorld/android/XXXXXXXX)
92+ IOS_MARKER=" $( mktemp " $ROOT " /local-cli/templates/HelloWorld/ios/HelloWorld/XXXXXXXX) "
93+ ANDROID_MARKER=" $( mktemp " $ ROOT" /local-cli/templates/HelloWorld/android/XXXXXXXX) "
9394
9495 # install CLI
9596 cd react-native-cli
@@ -98,8 +99,8 @@ function e2e_suite() {
9899
99100 # can skip cli install for non sudo mode
100101 if [ $RUN_CLI_INSTALL -ne 0 ]; then
101- npm install -g $CLI_PACKAGE
102- if [ $? -ne 0 ] ; then
102+ if ! npm install -g " $CLI_PACKAGE "
103+ then
103104 echo " Could not install react-native-cli globally, please run in su mode"
104105 echo " Or with --skip-cli-install to skip this step"
105106 return 1
@@ -111,7 +112,7 @@ function e2e_suite() {
111112
112113 # create virtual device
113114 if ! android list avd | grep " $AVD_UUID " > /dev/null; then
114- echo no | android create avd -n $AVD_UUID -f -t android-19 --abi default/armeabi-v7a
115+ echo no | android create avd -n " $AVD_UUID " -f -t android-19 --abi default/armeabi-v7a
115116 fi
116117
117118 # newline at end of adb devices call and first line is headers
@@ -124,7 +125,7 @@ function e2e_suite() {
124125 fi
125126
126127 # emulator setup
127- emulator64-arm -avd $AVD_UUID -no-skin -no-audio -no-window -no-boot-anim &
128+ emulator64-arm -avd " $AVD_UUID " -no-skin -no-audio -no-window -no-boot-anim &
128129
129130 bootanim=" "
130131 until [[ " $bootanim " =~ " stopped" ]]; do
@@ -135,23 +136,23 @@ function e2e_suite() {
135136
136137 set -ex
137138
138- ./gradlew :ReactAndroid:installArchives -Pjobs=1 -Dorg.gradle.jvmargs=" -Xmx512m -XX:+HeapDumpOnOutOfMemoryError"
139- if [ $? -ne 0 ] ; then
139+ if ! ./gradlew :ReactAndroid:installArchives -Pjobs=1 -Dorg.gradle.jvmargs=" -Xmx512m -XX:+HeapDumpOnOutOfMemoryError"
140+ then
140141 echo " Failed to compile Android binaries"
141142 return 1
142143 fi
143144 fi
144145
145- npm pack
146- if [ $? -ne 0 ] ; then
146+ if ! npm pack
147+ then
147148 echo " Failed to pack react-native"
148149 return 1
149150 fi
150151
151- cd $TEMP_DIR
152+ cd " $TEMP_DIR "
152153
153- retry $RETRY_COUNT react-native init EndToEndTest --version $PACKAGE --npm
154- if [ $? -ne 0 ] ; then
154+ if ! retry " $RETRY_COUNT " react-native init EndToEndTest --version " $PACKAGE " --npm
155+ then
155156 echo " Failed to execute react-native init"
156157 echo " Most common reason is npm registry connectivity, try again"
157158 return 1
@@ -164,20 +165,21 @@ function e2e_suite() {
164165 echo " Running an Android e2e test"
165166 echo " Installing e2e framework"
166167
167- retry $RETRY_COUNT npm install --save-dev $ANDROID_NPM_DEPS --silent >> /dev/null
168- if [ $? -ne 0 ] ; then
168+ if ! retry " $RETRY_COUNT " npm install --save-dev " $ANDROID_NPM_DEPS " --silent >> /dev/null
169+ then
169170 echo " Failed to install appium"
170171 echo " Most common reason is npm registry connectivity, try again"
171172 return 1
172173 fi
173174
174- cp $SCRIPTS /android-e2e-test.js android-e2e-test.js
175+ cp " $SCRIPTS /android-e2e-test.js" android-e2e-test.js
175176
176- cd android
177+ (
178+ cd android || exit
177179 echo " Downloading Maven deps"
178180 ./gradlew :app:copyDownloadableDepsToLibs
181+ )
179182
180- cd ..
181183 keytool -genkey -v -keystore android/keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname " CN=Android Debug,O=Android,C=US"
182184
183185 node ./node_modules/.bin/appium >> /dev/null &
@@ -188,9 +190,8 @@ function e2e_suite() {
188190 buck build android/app
189191
190192 # hack to get node unhung (kill buckd)
191- kill -9 $( pgrep java)
192-
193- if [ $? -ne 0 ]; then
193+ if ! kill -9 " $( pgrep java) "
194+ then
194195 echo " could not execute Buck build, is it installed and in PATH?"
195196 return 1
196197 fi
@@ -201,8 +202,8 @@ function e2e_suite() {
201202 sleep 15
202203
203204 echo " Executing android e2e test"
204- retry $RETRY_COUNT node node_modules/.bin/_mocha android-e2e-test.js
205- if [ $? -ne 0 ] ; then
205+ if ! retry " $RETRY_COUNT " node node_modules/.bin/_mocha android-e2e-test.js
206+ then
206207 echo " Failed to run Android e2e tests"
207208 echo " Most likely the code is broken"
208209 return 1
@@ -230,24 +231,37 @@ function e2e_suite() {
230231 # js tests
231232 if [ $RUN_JS -ne 0 ]; then
232233 # Check the packager produces a bundle (doesn't throw an error)
233- react-native bundle --max-workers 1 --platform android --dev true --entry-file index.js --bundle-output android-bundle.js
234- if [ $? -ne 0 ] ; then
234+ if ! react-native bundle --max-workers 1 --platform android --dev true --entry-file index.js --bundle-output android-bundle.js
235+ then
235236 echo " Could not build android bundle"
236237 return 1
237238 fi
238239
239- react-native bundle --max-workers 1 --platform ios --dev true --entry-file index.js --bundle-output ios-bundle.js
240- if [ $? -ne 0 ] ; then
240+ if ! react-native bundle --max-workers 1 --platform ios --dev true --entry-file index.js --bundle-output ios-bundle.js
241+ then
241242 echo " Could not build iOS bundle"
242243 return 1
243244 fi
245+
246+ if ! retry " $RETRY_COUNT " npm install --save " $REACT_DUMMY_PLATFORM " --silent >> /dev/null
247+ then
248+ echo " Failed to install react-native-dummy"
249+ echo " Most common reason is npm registry connectivity, try again"
250+ return 1
251+ fi
252+
253+ if ! react-native bundle --max-workers 1 --platform dummy --dev true --entry-file index.js --bundle-output dummy-bundle.js
254+ then
255+ echo " Could not build dummy bundle"
256+ return 1
257+ fi
244258 fi
245259
246260 # directory cleanup
247- rm $IOS_MARKER
248- rm $ANDROID_MARKER
261+ rm " $IOS_MARKER "
262+ rm " $ANDROID_MARKER "
249263
250264 return 0
251265}
252266
253- retry $RETRY_COUNT e2e_suite
267+ retry " $RETRY_COUNT " e2e_suite
0 commit comments