Cleanup test script
This should make it cleanup artifacts more reliably, and gives the script a consistent style.
This commit is contained in:
parent
4917a8e939
commit
bcc53c089f
118
scripts/test.sh
118
scripts/test.sh
|
@ -3,11 +3,17 @@
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
TARGET=$1
|
TARGET="$1"
|
||||||
CONFIGURATION=${2:-"Debug"}
|
CONFIGURATION="${2:-"Debug"}"
|
||||||
|
DESTINATION=
|
||||||
|
PATH="/opt/android-sdk-linux/platform-tools:$PATH"
|
||||||
|
SRCROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||||
|
|
||||||
if [ "$TARGET" != "react-tests-android" ]; then
|
# Start current working directory at the root of the project.
|
||||||
while pgrep -q Simulator; do
|
cd "$SRCROOT"
|
||||||
|
|
||||||
|
if [[ $TARGET != *-android ]]; then
|
||||||
|
while pgrep -q Simulator; do
|
||||||
# Kill all the current simulator processes as they may be from a
|
# Kill all the current simulator processes as they may be from a
|
||||||
# different Xcode version
|
# different Xcode version
|
||||||
pkill Simulator 2>/dev/null || true
|
pkill Simulator 2>/dev/null || true
|
||||||
|
@ -17,16 +23,32 @@ while pgrep -q Simulator; do
|
||||||
DESTINATION="-destination id=$(xcrun simctl list devices | grep -v unavailable | grep -m 1 -o '[0-9A-F\-]\{36\}')"
|
DESTINATION="-destination id=$(xcrun simctl list devices | grep -v unavailable | grep -m 1 -o '[0-9A-F\-]\{36\}')"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PACKAGER_OUT="packager_out.txt"
|
PACKAGER_OUT="$SRCROOT/packager_out.txt"
|
||||||
|
LOGCAT_OUT="$SRCROOT/logcat_out.txt"
|
||||||
|
|
||||||
function start_packager()
|
cleanup() {
|
||||||
{
|
# Kill all child processes.
|
||||||
rm -f $PACKAGER_OUT
|
pkill -P $$ || true
|
||||||
./node_modules/react-native/packager/packager.sh | tee $PACKAGER_OUT &
|
pkill node || true
|
||||||
while :;
|
rm -f "$PACKAGER_OUT" "$LOGCAT_OUT"
|
||||||
do
|
}
|
||||||
if grep -Fxq "React packager ready." $PACKAGER_OUT
|
|
||||||
then
|
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
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
start_packager() {
|
||||||
|
# Starting with --nonPersistent will avoid starting a file watcher.
|
||||||
|
./node_modules/react-native/packager/packager.sh --nonPersistent | tee "$PACKAGER_OUT" &
|
||||||
|
|
||||||
|
while :; do
|
||||||
|
if grep -Fxq "React packager ready." "$PACKAGER_OUT"; then
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
echo "Waiting for packager."
|
echo "Waiting for packager."
|
||||||
|
@ -35,69 +57,66 @@ function start_packager()
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function unlock_device()
|
unlock_device() {
|
||||||
{
|
adb shell input keyevent 82
|
||||||
/opt/android-sdk-linux/platform-tools/adb shell input keyevent 82
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# kill old packagers
|
# Cleanup now and also cleanup when this script exits.
|
||||||
pkill node || true
|
cleanup
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
if [ "$TARGET" = "realmjs" ]; then
|
case "$TARGET" in
|
||||||
|
"realmjs")
|
||||||
xcodebuild -scheme RealmJS -configuration "$CONFIGURATION" -sdk iphonesimulator $DESTINATION build test
|
xcodebuild -scheme RealmJS -configuration "$CONFIGURATION" -sdk iphonesimulator $DESTINATION build test
|
||||||
elif [ "$TARGET" = "react-tests" ]; then
|
;;
|
||||||
|
"react-tests")
|
||||||
pushd tests/react-test-app
|
pushd tests/react-test-app
|
||||||
|
|
||||||
if [ -d ~/Applications/Google\ Chrome.app ]; then
|
|
||||||
open ~/Applications/Google\ Chrome.app
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f ../../target=node_modules/react_tests_node_modules.zip ]; then
|
if [ -f ../../target=node_modules/react_tests_node_modules.zip ]; then
|
||||||
unzip -q ../../target=node_modules/react_tests_node_modules.zip
|
unzip -q ../../target=node_modules/react_tests_node_modules.zip
|
||||||
fi
|
fi
|
||||||
|
|
||||||
npm update react-native
|
npm update react-native
|
||||||
|
open_chrome
|
||||||
start_packager
|
start_packager
|
||||||
popd
|
popd
|
||||||
|
|
||||||
xcodebuild -scheme RealmReact -configuration "$CONFIGURATION" -sdk iphonesimulator $DESTINATION build test
|
xcodebuild -scheme RealmReact -configuration "$CONFIGURATION" -sdk iphonesimulator $DESTINATION build test
|
||||||
elif [ "$TARGET" = "react-example" ]; then
|
;;
|
||||||
|
"react-example")
|
||||||
pushd examples/ReactExample
|
pushd examples/ReactExample
|
||||||
|
|
||||||
if [ -f ../../target=node_modules/react_example_node_modules.zip ]; then
|
if [ -f ../../target=node_modules/react_example_node_modules.zip ]; then
|
||||||
unzip -q ../../target=node_modules/react_example_node_modules.zip
|
unzip -q ../../target=node_modules/react_example_node_modules.zip
|
||||||
fi
|
fi
|
||||||
|
|
||||||
npm update react-native
|
npm update react-native
|
||||||
start_packager
|
start_packager
|
||||||
|
|
||||||
pushd ios
|
pushd ios
|
||||||
xcodebuild -scheme ReactExample -configuration "$CONFIGURATION" -sdk iphonesimulator build $DESTINATION
|
xcodebuild -scheme ReactExample -configuration "$CONFIGURATION" -sdk iphonesimulator build $DESTINATION
|
||||||
popd
|
;;
|
||||||
elif [ "$TARGET" = "react-tests-android" ]; then
|
"react-tests-android")
|
||||||
[ -s "${HOME}/.nvm/nvm.sh" ] && . "${HOME}/.nvm/nvm.sh"
|
[ -s "${HOME}/.nvm/nvm.sh" ] && . "${HOME}/.nvm/nvm.sh"
|
||||||
nvm use 5.4.0
|
nvm use 5.4.0
|
||||||
|
|
||||||
pushd react-native/android
|
pushd react-native/android
|
||||||
./gradlew installarchives
|
./gradlew installarchives
|
||||||
popd
|
popd
|
||||||
|
|
||||||
pushd tests/react-test-app
|
pushd tests/react-test-app
|
||||||
|
|
||||||
if [ -d ~/Applications/Google\ Chrome.app ]; then
|
|
||||||
open ~/Applications/Google\ Chrome.app
|
|
||||||
fi
|
|
||||||
|
|
||||||
npm install
|
npm install
|
||||||
|
open_chrome
|
||||||
start_packager
|
start_packager
|
||||||
unlock_device
|
unlock_device
|
||||||
./run-android.sh
|
./run-android.sh
|
||||||
|
|
||||||
LOGCAT_OUT="logcat_out.txt"
|
adb logcat -c
|
||||||
rm -f $LOGCAT_OUT
|
adb logcat | tee "$LOGCAT_OUT" &
|
||||||
|
|
||||||
/opt/android-sdk-linux/platform-tools/adb logcat -c
|
while :; do
|
||||||
/opt/android-sdk-linux/platform-tools/adb logcat | tee $LOGCAT_OUT &
|
if grep -q "__REALM_REACT_ANDROID_TESTS_COMPLETED__" "$LOGCAT_OUT"; then
|
||||||
while :;
|
|
||||||
do
|
|
||||||
if grep -q "__REALM_REACT_ANDROID_TESTS_COMPLETED__" $LOGCAT_OUT
|
|
||||||
then
|
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
echo "Waiting for tests."
|
echo "Waiting for tests."
|
||||||
|
@ -105,16 +124,13 @@ elif [ "$TARGET" = "react-tests-android" ]; then
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
/opt/android-sdk-linux/platform-tools/adb pull /sdcard/tests.xml . || true
|
adb pull /sdcard/tests.xml . || true
|
||||||
echo "********* TESTS COMPLETED *********";
|
|
||||||
echo "********* File location: `pwd`/tests.xml *********";
|
|
||||||
more tests.xml
|
|
||||||
else
|
|
||||||
echo "Invalid target '${TARGET}'"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# kill all children
|
echo "********* TESTS COMPLETED *********";
|
||||||
pkill -P $$ || true
|
echo "********* File location: $(pwd)/tests.xml *********";
|
||||||
pkill node || true
|
more tests.xml
|
||||||
rm -f $PACKAGER_OUT
|
;;
|
||||||
rm -f $LOGCAT_OUT
|
*)
|
||||||
|
echo "Invalid target '${TARGET}'"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
Loading…
Reference in New Issue