realm-js/scripts/test.sh

179 lines
3.8 KiB
Bash
Raw Normal View History

2015-12-17 12:42:02 -08:00
#!/bin/bash
set -o pipefail
set -e
TARGET="$1"
2016-03-16 17:32:47 -07:00
CONFIGURATION="${2:-"Release"}"
DESTINATION=
PATH="/opt/android-sdk-linux/platform-tools:$PATH"
SRCROOT=$(cd "$(dirname "$0")/.." && pwd)
2016-01-22 13:32:56 -08:00
# 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"
if [[ $TARGET = *-android ]]; then
# Inform the prepublish script to build Android modules.
export REALM_BUILD_ANDROID=1
2016-01-22 13:30:16 -08:00
fi
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"
}
2016-05-13 16:30:57 -07:00
kill_ios_simulator() {
while pgrep -q Simulator; do
# Kill all the current simulator processes as they may be from a
# different Xcode version
pkill Simulator 2>/dev/null || true
# CoreSimulatorService doesn't exit when sent SIGTERM
pkill -9 Simulator 2>/dev/null || true
done
}
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
}
start_packager() {
2016-03-16 13:30:06 -07:00
watchman watch-del-all || true
./node_modules/react-native/packager/packager.sh | tee "$PACKAGER_OUT" &
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-05-13 16:30:57 -07:00
xctest() {
kill_ios_simulator
local dest="$(xcrun simctl list devices | grep -v unavailable | grep -m 1 -o '[0-9A-F\-]\{36\}')"
xcodebuild -scheme "$1" -configuration "$CONFIGURATION" -sdk iphonesimulator -destination id="$dest" build test
}
# Cleanup now and also cleanup when this script exits.
cleanup
trap cleanup EXIT
# Use a consistent version of Node if possible.
if [ -s "${HOME}/.nvm/nvm.sh" ]; then
. "${HOME}/.nvm/nvm.sh"
nvm use 5.4.0 || true
fi
case "$TARGET" in
"eslint")
[[ $CONFIGURATION == 'Debug' ]] && exit 0
npm install
npm run lint .
;;
"jsdoc")
[[ $CONFIGURATION == 'Debug' ]] && exit 0
npm install
npm run jsdoc
;;
"realmjs")
pushd src
2016-05-13 16:30:57 -07:00
xctest RealmJS
;;
"react-tests")
pushd tests/react-test-app
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
npm install
open_chrome
2015-12-17 10:56:08 -08:00
start_packager
2016-01-22 23:23:27 +00:00
2016-03-23 13:20:05 -07:00
pushd ios
2016-05-13 16:30:57 -07:00
xctest ReactTestApp
;;
"react-example")
pushd examples/ReactExample
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
npm install
open_chrome
2015-12-17 10:56:08 -08:00
start_packager
2016-01-22 15:27:17 -08:00
pushd ios
2016-05-13 16:30:57 -07:00
xctest ReactExample
;;
"react-tests-android")
[[ $CONFIGURATION == 'Debug' ]] && exit 0
2016-01-22 12:15:38 -08:00
pushd tests/react-test-app
npm install
open_chrome
start_packager
2016-02-03 16:26:35 +00:00
./run-android.sh
2016-01-22 23:23:27 +00:00
# Despite the docs claiming -c to work, it doesn't, so `-T 1` alleviates that.
adb logcat -c
adb logcat -T 1 | tee "$LOGCAT_OUT" &
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
rm -f tests.xml
adb pull /sdcard/tests.xml .
# Stop running child processes before printing results.
cleanup
2016-01-26 21:10:23 +00:00
echo "********* TESTS COMPLETED *********";
echo "********* File location: $(pwd)/tests.xml *********";
cat tests.xml
;;
2016-04-19 14:10:10 -07:00
"node")
2016-04-19 16:40:48 -07:00
npm install
scripts/download-core.sh
2016-05-13 16:30:57 -07:00
src/node/build-node.sh $CONFIGURATION
2016-04-19 16:40:48 -07:00
2016-05-13 16:30:57 -07:00
# Change to a temp directory.
cd "$(mktemp -q -d -t realm.node.XXXXXX)"
trap "rm -rf '$PWD'" EXIT
2016-04-19 14:10:10 -07:00
2016-05-13 16:30:57 -07:00
node "$SRCROOT/tests"
2016-04-19 14:10:10 -07:00
;;
2016-03-03 14:58:05 -08:00
"object-store")
pushd src/object-store
cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION .
2016-03-03 14:58:05 -08:00
make run-tests
2016-04-19 14:10:10 -07:00
;;
*)
2015-12-16 18:14:14 -08:00
echo "Invalid target '${TARGET}'"
exit 1
esac