2015-04-11 02:07:56 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-03-03 20:42:22 +00:00
|
|
|
# The script has one required argument:
|
|
|
|
# --packager: react-native init, make sure the packager starts
|
|
|
|
# --ios: react-native init, start the packager and run the iOS app
|
|
|
|
# --android: same but run the Android app
|
|
|
|
|
2015-04-11 02:07:56 +00:00
|
|
|
# Abort the mission if any command fails
|
|
|
|
set -e
|
2016-01-06 10:50:08 +00:00
|
|
|
set -x
|
2015-04-11 02:07:56 +00:00
|
|
|
|
2016-03-03 20:42:22 +00:00
|
|
|
if [ -z $1 ]; then
|
2016-03-10 19:58:42 +00:00
|
|
|
echo "Please run the script with --ios, --android or --packager" >&2
|
2016-03-03 20:42:22 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-04-11 02:07:56 +00:00
|
|
|
SCRIPTS=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
|
|
ROOT=$(dirname $SCRIPTS)
|
|
|
|
TEMP=$(mktemp -d /tmp/react-native-XXXXXXXX)
|
|
|
|
|
2015-04-19 03:09:03 +00:00
|
|
|
# When tests run on CI server, we won't be able to see logs
|
|
|
|
# from packager because it runs in a separate window. This is
|
|
|
|
# a simple workaround, see packager/packager.sh
|
|
|
|
export REACT_PACKAGER_LOG="$TEMP/server.log"
|
|
|
|
|
2015-04-11 02:07:56 +00:00
|
|
|
# To make sure we actually installed the local version
|
2015-09-30 14:15:30 +00:00
|
|
|
# of react-native, we will create a temp file inside the template
|
2015-04-11 02:07:56 +00:00
|
|
|
# and check that it exists after `react-native init`
|
2016-03-03 20:42:22 +00:00
|
|
|
MARKER_IOS=$(mktemp $ROOT/local-cli/generator-ios/templates/app/XXXXXXXX)
|
|
|
|
MARKER_ANDROID=$(mktemp $ROOT/local-cli/generator-android/templates/src/XXXXXXXX)
|
2015-04-11 02:07:56 +00:00
|
|
|
|
|
|
|
function cleanup {
|
2015-04-21 22:01:18 +00:00
|
|
|
EXIT_CODE=$?
|
2015-04-19 03:09:03 +00:00
|
|
|
set +e
|
2015-04-21 22:01:18 +00:00
|
|
|
|
|
|
|
if [ $EXIT_CODE -ne 0 ];
|
|
|
|
then
|
|
|
|
WATCHMAN_LOGS=/usr/local/Cellar/watchman/3.1/var/run/watchman/$USER.log
|
|
|
|
[ -f $WATCHMAN_LOGS ] && cat $WATCHMAN_LOGS
|
|
|
|
|
|
|
|
[ -f $REACT_PACKAGER_LOG ] && cat $REACT_PACKAGER_LOG
|
|
|
|
fi
|
|
|
|
|
2016-03-03 20:42:22 +00:00
|
|
|
rm $MARKER_IOS
|
|
|
|
rm $MARKER_ANDROID
|
2015-04-11 02:20:48 +00:00
|
|
|
[ $SINOPIA_PID ] && kill -9 $SINOPIA_PID
|
2015-06-11 00:53:17 +00:00
|
|
|
[ $SERVER_PID ] && kill -9 $SERVER_PID
|
2015-04-11 02:20:48 +00:00
|
|
|
[ -f ~/.npmrc.bak ] && mv ~/.npmrc.bak ~/.npmrc
|
2015-04-11 02:07:56 +00:00
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
cd $TEMP
|
|
|
|
|
|
|
|
# sinopia is npm registry proxy, it is used to make npm
|
|
|
|
# think react-native and react-native-cli are actually
|
|
|
|
# published on npm
|
2016-02-16 18:20:56 +00:00
|
|
|
# Temporarily installing sinopia from a github fork
|
|
|
|
# TODO t10060166 use npm repo when bug is fixed
|
2016-03-04 21:28:43 +00:00
|
|
|
which sinopia || npm install -g git://github.com/bestander/sinopia.git#68707efbab90569d5f52193138936f9281cc410c
|
2015-04-11 02:07:56 +00:00
|
|
|
|
|
|
|
# but in order to make npm use sinopia we temporarily
|
|
|
|
# replace its config file
|
|
|
|
[ -f ~/.npmrc ] && cp ~/.npmrc ~/.npmrc.bak
|
|
|
|
cp $SCRIPTS/e2e-npmrc ~/.npmrc
|
|
|
|
|
|
|
|
sinopia --config $SCRIPTS/e2e-sinopia.config.yml &
|
|
|
|
SINOPIA_PID=$!
|
|
|
|
|
2015-04-11 18:13:47 +00:00
|
|
|
# Make sure to remove old version of react-native in
|
|
|
|
# case it was cached
|
2016-03-10 19:58:42 +00:00
|
|
|
npm cache clear
|
2015-04-11 18:13:47 +00:00
|
|
|
npm unpublish react-native --force
|
|
|
|
npm unpublish react-native-cli --force
|
2015-04-11 02:07:56 +00:00
|
|
|
npm publish $ROOT
|
|
|
|
npm publish $ROOT/react-native-cli
|
|
|
|
|
|
|
|
npm install -g react-native-cli
|
2016-02-16 18:20:56 +00:00
|
|
|
react-native init EndToEndTest
|
2016-03-03 20:42:22 +00:00
|
|
|
cd EndToEndTest
|
2015-04-11 18:13:47 +00:00
|
|
|
|
2016-03-03 20:42:22 +00:00
|
|
|
case $1 in
|
|
|
|
"--packager"*)
|
|
|
|
echo "Running a basic packager test"
|
|
|
|
# Check the packager produces a bundle (doesn't throw an error)
|
|
|
|
react-native bundle --platform android --dev true --entry-file index.android.js --bundle-output android-bundle.js
|
|
|
|
;;
|
|
|
|
"--ios"*)
|
|
|
|
echo "Running an iOS app"
|
|
|
|
cd ios
|
|
|
|
# Make sure we installed local version of react-native
|
|
|
|
ls EndToEndTest/`basename $MARKER_IOS` > /dev/null
|
|
|
|
../node_modules/react-native/packager/packager.sh --nonPersistent &
|
|
|
|
SERVER_PID=$!
|
|
|
|
# Start the app on the simulator
|
|
|
|
xctool -scheme EndToEndTest -sdk iphonesimulator test
|
|
|
|
;;
|
|
|
|
"--android"*)
|
|
|
|
echo "Running an Android app"
|
|
|
|
cd android
|
|
|
|
# Make sure we installed local version of react-native
|
|
|
|
ls `basename $MARKER_ANDROID` > /dev/null
|
|
|
|
../node_modules/react-native/packager/packager.sh --nonPersistent &
|
|
|
|
SERVER_PID=$!
|
|
|
|
# TODO Start the app and check it renders "Welcome to React Native"
|
2016-03-10 19:58:42 +00:00
|
|
|
echo "The Android e2e test is not implemented yet" >&2
|
|
|
|
exit 1
|
2016-03-03 20:42:22 +00:00
|
|
|
;;
|
|
|
|
*)
|
2016-03-10 19:58:42 +00:00
|
|
|
echo "Please run the script with --ios, --android or --packager" >&2
|
|
|
|
exit 1
|
2016-03-03 20:42:22 +00:00
|
|
|
;;
|
|
|
|
esac
|