2015-12-17 12:42:02 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-12-15 18:02:20 -08:00
|
|
|
set -o pipefail
|
|
|
|
set -e
|
|
|
|
|
2016-01-26 16:12:26 -08:00
|
|
|
TARGET="$1"
|
|
|
|
CONFIGURATION="${2:-"Debug"}"
|
|
|
|
DESTINATION=
|
|
|
|
PATH="/opt/android-sdk-linux/platform-tools:$PATH"
|
|
|
|
SRCROOT=$(cd "$(dirname "$0")/.." && pwd)
|
2016-01-22 13:32:56 -08:00
|
|
|
|
2016-01-26 16:12:26 -08:00
|
|
|
# Start current working directory at the root of the project.
|
|
|
|
cd "$SRCROOT"
|
|
|
|
|
|
|
|
if [[ $TARGET != *-android ]]; then
|
|
|
|
while pgrep -q Simulator; do
|
2015-12-15 18:02:20 -08:00
|
|
|
# Kill all the current simulator processes as they may be from a
|
|
|
|
# different Xcode version
|
2016-01-22 13:30:16 -08:00
|
|
|
pkill Simulator 2>/dev/null || true
|
2015-12-15 18:02:20 -08:00
|
|
|
# CoreSimulatorService doesn't exit when sent SIGTERM
|
2016-01-22 13:30:16 -08:00
|
|
|
pkill -9 Simulator 2>/dev/null || true
|
|
|
|
done
|
2016-02-11 13:21:15 -08:00
|
|
|
|
2016-01-22 13:30:16 -08:00
|
|
|
DESTINATION="-destination id=$(xcrun simctl list devices | grep -v unavailable | grep -m 1 -o '[0-9A-F\-]\{36\}')"
|
2016-02-11 13:21:15 -08:00
|
|
|
|
|
|
|
# Inform the prepublish script to skip building Android modules.
|
|
|
|
export SKIP_ANDROID_BUILD=1
|
2016-01-22 13:30:16 -08:00
|
|
|
fi
|
2015-12-15 18:02:20 -08:00
|
|
|
|
2016-01-26 16:12:26 -08:00
|
|
|
PACKAGER_OUT="$SRCROOT/packager_out.txt"
|
|
|
|
LOGCAT_OUT="$SRCROOT/logcat_out.txt"
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
# Kill all child processes.
|
|
|
|
pkill -P $$ || true
|
|
|
|
pkill node || true
|
|
|
|
rm -f "$PACKAGER_OUT" "$LOGCAT_OUT"
|
|
|
|
}
|
|
|
|
|
|
|
|
open_chrome() {
|
|
|
|
local dir
|
|
|
|
for dir in "$HOME/Applications" "/Applications"; do
|
|
|
|
if [ -d "$dir/Google Chrome.app" ]; then
|
|
|
|
open "$dir/Google Chrome.app"
|
|
|
|
break
|
|
|
|
fi
|
2015-12-17 10:56:08 -08:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-01-26 16:12:26 -08:00
|
|
|
start_packager() {
|
2016-02-02 14:52:15 -08:00
|
|
|
./node_modules/react-native/packager/packager.sh | tee "$PACKAGER_OUT" &
|
2016-01-26 16:12:26 -08:00
|
|
|
|
|
|
|
while :; do
|
|
|
|
if grep -Fxq "React packager ready." "$PACKAGER_OUT"; then
|
|
|
|
break
|
|
|
|
else
|
|
|
|
echo "Waiting for packager."
|
|
|
|
sleep 2
|
|
|
|
fi
|
|
|
|
done
|
2016-01-26 20:23:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 16:12:26 -08:00
|
|
|
unlock_device() {
|
|
|
|
adb shell input keyevent 82
|
|
|
|
}
|
|
|
|
|
|
|
|
# Cleanup now and also cleanup when this script exits.
|
|
|
|
cleanup
|
|
|
|
trap cleanup EXIT
|
2015-12-15 18:02:20 -08:00
|
|
|
|
2016-01-26 16:12:26 -08:00
|
|
|
case "$TARGET" in
|
|
|
|
"realmjs")
|
2016-01-22 23:23:27 +00:00
|
|
|
xcodebuild -scheme RealmJS -configuration "$CONFIGURATION" -sdk iphonesimulator $DESTINATION build test
|
2016-01-26 16:12:26 -08:00
|
|
|
;;
|
|
|
|
"react-tests")
|
2015-12-15 18:02:20 -08:00
|
|
|
pushd tests/react-test-app
|
2015-12-18 15:11:23 -08:00
|
|
|
|
2015-12-15 18:18:18 -08:00
|
|
|
if [ -f ../../target=node_modules/react_tests_node_modules.zip ]; then
|
2015-12-17 11:55:29 -08:00
|
|
|
unzip -q ../../target=node_modules/react_tests_node_modules.zip
|
2015-12-15 18:18:18 -08:00
|
|
|
fi
|
2016-01-26 16:12:26 -08:00
|
|
|
|
2015-12-16 18:14:14 -08:00
|
|
|
npm update react-native
|
2016-01-26 16:12:26 -08:00
|
|
|
open_chrome
|
2015-12-17 10:56:08 -08:00
|
|
|
start_packager
|
2015-12-15 18:02:20 -08:00
|
|
|
popd
|
2016-01-22 23:23:27 +00:00
|
|
|
|
2015-12-15 18:02:20 -08:00
|
|
|
xcodebuild -scheme RealmReact -configuration "$CONFIGURATION" -sdk iphonesimulator $DESTINATION build test
|
2016-01-26 16:12:26 -08:00
|
|
|
;;
|
|
|
|
"react-example")
|
2015-12-15 18:02:20 -08:00
|
|
|
pushd examples/ReactExample
|
2016-01-26 16:12:26 -08:00
|
|
|
|
2015-12-15 18:18:18 -08:00
|
|
|
if [ -f ../../target=node_modules/react_example_node_modules.zip ]; then
|
2015-12-17 11:55:29 -08:00
|
|
|
unzip -q ../../target=node_modules/react_example_node_modules.zip
|
2015-12-15 18:18:18 -08:00
|
|
|
fi
|
2016-01-26 16:12:26 -08:00
|
|
|
|
2015-12-16 18:14:14 -08:00
|
|
|
npm update react-native
|
2015-12-17 10:56:08 -08:00
|
|
|
start_packager
|
|
|
|
|
2016-01-22 15:27:17 -08:00
|
|
|
pushd ios
|
2015-12-15 18:02:20 -08:00
|
|
|
xcodebuild -scheme ReactExample -configuration "$CONFIGURATION" -sdk iphonesimulator build $DESTINATION
|
2016-01-26 16:12:26 -08:00
|
|
|
;;
|
|
|
|
"react-tests-android")
|
2016-02-08 11:16:18 -08:00
|
|
|
if [[ $CONFIGURATION == 'Debug' ]]; then
|
2016-02-08 11:30:40 -08:00
|
|
|
exit 0
|
2016-02-08 11:16:18 -08:00
|
|
|
fi
|
|
|
|
|
2016-01-26 20:48:47 +00:00
|
|
|
[ -s "${HOME}/.nvm/nvm.sh" ] && . "${HOME}/.nvm/nvm.sh"
|
2016-02-08 11:48:38 -08:00
|
|
|
nvm use 5.4.0 || true
|
2016-01-26 16:12:26 -08:00
|
|
|
|
2016-01-22 12:15:38 -08:00
|
|
|
pushd react-native/android
|
|
|
|
./gradlew installarchives
|
|
|
|
popd
|
|
|
|
|
|
|
|
pushd tests/react-test-app
|
|
|
|
|
|
|
|
npm install
|
2016-01-26 16:12:26 -08:00
|
|
|
open_chrome
|
2016-02-08 03:09:22 -08:00
|
|
|
start_packager
|
2016-02-03 16:26:35 +00:00
|
|
|
./run-android.sh
|
2016-01-22 23:23:27 +00:00
|
|
|
|
2016-02-02 14:52:15 -08:00
|
|
|
# Despite the docs claiming -c to work, it doesn't, so `-T 1` alleviates that.
|
2016-01-26 16:12:26 -08:00
|
|
|
adb logcat -c
|
2016-02-02 14:52:15 -08:00
|
|
|
adb logcat -T 1 | tee "$LOGCAT_OUT" &
|
2016-01-26 16:12:26 -08:00
|
|
|
|
|
|
|
while :; do
|
|
|
|
if grep -q "__REALM_REACT_ANDROID_TESTS_COMPLETED__" "$LOGCAT_OUT"; then
|
|
|
|
break
|
|
|
|
else
|
|
|
|
echo "Waiting for tests."
|
|
|
|
sleep 2
|
|
|
|
fi
|
2016-01-22 23:23:27 +00:00
|
|
|
done
|
2016-01-22 12:15:38 -08:00
|
|
|
|
2016-02-02 14:52:15 -08:00
|
|
|
rm -f tests.xml
|
|
|
|
adb pull /sdcard/tests.xml .
|
2016-01-26 16:12:26 -08:00
|
|
|
|
2016-02-02 14:52:15 -08:00
|
|
|
# Stop running child processes before printing results.
|
|
|
|
cleanup
|
2016-01-26 21:10:23 +00:00
|
|
|
echo "********* TESTS COMPLETED *********";
|
2016-01-26 16:12:26 -08:00
|
|
|
echo "********* File location: $(pwd)/tests.xml *********";
|
2016-02-02 14:52:15 -08:00
|
|
|
cat tests.xml
|
2016-01-26 16:12:26 -08:00
|
|
|
;;
|
|
|
|
*)
|
2015-12-16 18:14:14 -08:00
|
|
|
echo "Invalid target '${TARGET}'"
|
2016-01-26 16:12:26 -08:00
|
|
|
exit 1
|
|
|
|
esac
|