2015-12-17 20:42:02 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-12-16 02:02:20 +00:00
|
|
|
set -o pipefail
|
|
|
|
set -e
|
|
|
|
|
2016-08-19 17:06:45 +00:00
|
|
|
export TEST_SCRIPT=1
|
|
|
|
export NPM_CONFIG_PROGRESS=false
|
|
|
|
|
2016-01-27 00:12:26 +00:00
|
|
|
TARGET="$1"
|
2016-03-17 00:32:47 +00:00
|
|
|
CONFIGURATION="${2:-"Release"}"
|
2016-01-27 00:12:26 +00:00
|
|
|
DESTINATION=
|
|
|
|
PATH="/opt/android-sdk-linux/platform-tools:$PATH"
|
|
|
|
SRCROOT=$(cd "$(dirname "$0")/.." && pwd)
|
2016-11-18 22:00:30 +00:00
|
|
|
XCPRETTY=`which xcpretty || true`
|
2016-01-22 21:32:56 +00:00
|
|
|
|
2016-01-27 00:12:26 +00:00
|
|
|
# Start current working directory at the root of the project.
|
|
|
|
cd "$SRCROOT"
|
|
|
|
|
2016-04-19 23:57:52 +00:00
|
|
|
# Add node_modules to PATH just in case we weren't called from `npm test`
|
|
|
|
PATH="$PWD/node_modules/.bin:$PATH"
|
|
|
|
|
2016-03-02 23:47:51 +00:00
|
|
|
if [[ $TARGET = *-android ]]; then
|
|
|
|
# Inform the prepublish script to build Android modules.
|
|
|
|
export REALM_BUILD_ANDROID=1
|
2016-01-22 21:30:16 +00:00
|
|
|
fi
|
2015-12-16 02:02:20 +00:00
|
|
|
|
2016-11-09 00:47:20 +00:00
|
|
|
SERVER_PID=0
|
2016-01-27 00:12:26 +00:00
|
|
|
PACKAGER_OUT="$SRCROOT/packager_out.txt"
|
|
|
|
LOGCAT_OUT="$SRCROOT/logcat_out.txt"
|
|
|
|
|
2016-11-09 00:47:20 +00:00
|
|
|
|
|
|
|
download_server() {
|
|
|
|
sh ./scripts/download-object-server.sh
|
|
|
|
}
|
|
|
|
|
|
|
|
start_server() {
|
|
|
|
sh ./object-server-for-testing/start-object-server.command &
|
|
|
|
SERVER_PID=$!
|
|
|
|
}
|
|
|
|
|
|
|
|
stop_server() {
|
|
|
|
if [[ ${SERVER_PID} > 0 ]] ; then
|
|
|
|
kill ${SERVER_PID}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-01-27 00:12:26 +00:00
|
|
|
cleanup() {
|
2016-11-09 00:47:20 +00:00
|
|
|
# Kill started object server
|
|
|
|
stop_server
|
|
|
|
|
|
|
|
# Kill all other child processes.
|
2016-01-27 00:12:26 +00:00
|
|
|
pkill -P $$ || true
|
2016-11-09 00:47:20 +00:00
|
|
|
|
|
|
|
# Kill react native packager
|
2016-01-27 00:12:26 +00:00
|
|
|
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 18:56:08 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-01-27 00:12:26 +00:00
|
|
|
start_packager() {
|
2016-03-16 20:30:06 +00:00
|
|
|
watchman watch-del-all || true
|
2016-02-02 22:52:15 +00:00
|
|
|
./node_modules/react-native/packager/packager.sh | tee "$PACKAGER_OUT" &
|
2016-01-27 00:12:26 +00: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-05-13 23:30:57 +00:00
|
|
|
xctest() {
|
|
|
|
local dest="$(xcrun simctl list devices | grep -v unavailable | grep -m 1 -o '[0-9A-F\-]\{36\}')"
|
2016-08-19 17:06:45 +00:00
|
|
|
if [ -n "$XCPRETTY" ]; then
|
2016-11-10 18:06:48 +00:00
|
|
|
mkdir -p build
|
2016-11-18 22:00:30 +00:00
|
|
|
xcodebuild -scheme "$1" -configuration "$CONFIGURATION" -sdk iphonesimulator -destination id="$dest" build test | tee build/build.log | "$XCPRETTY" -c --no-utf --report junit --output build/reports/junit.xml || {
|
2016-11-10 18:06:48 +00:00
|
|
|
echo "The raw xcodebuild output is available in build/build.log"
|
|
|
|
exit 1
|
|
|
|
}
|
2016-08-19 17:06:45 +00:00
|
|
|
else
|
2016-11-11 19:24:35 +00:00
|
|
|
xcodebuild -scheme "$1" -configuration "$CONFIGURATION" -sdk iphonesimulator -destination id="$dest" build test
|
2016-08-19 17:06:45 +00:00
|
|
|
fi
|
2016-01-27 00:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Cleanup now and also cleanup when this script exits.
|
|
|
|
cleanup
|
|
|
|
trap cleanup EXIT
|
2015-12-16 02:02:20 +00:00
|
|
|
|
2016-02-19 10:53:10 +00:00
|
|
|
# Use a consistent version of Node if possible.
|
|
|
|
if [ -s "${HOME}/.nvm/nvm.sh" ]; then
|
|
|
|
. "${HOME}/.nvm/nvm.sh"
|
2016-11-09 00:47:20 +00:00
|
|
|
nvm use 4.4.7 || true
|
2016-02-19 10:53:10 +00:00
|
|
|
fi
|
|
|
|
|
2016-11-11 07:11:31 +00:00
|
|
|
# Remove cached packages
|
|
|
|
rm -rf ~/.yarn-cache/npm-realm-*
|
|
|
|
|
2016-01-27 00:12:26 +00:00
|
|
|
case "$TARGET" in
|
2016-03-02 23:16:22 +00:00
|
|
|
"eslint")
|
2016-03-17 00:49:20 +00:00
|
|
|
[[ $CONFIGURATION == 'Debug' ]] && exit 0
|
|
|
|
npm install
|
2016-03-02 23:16:22 +00:00
|
|
|
npm run lint .
|
|
|
|
;;
|
2016-02-12 10:47:08 +00:00
|
|
|
"jsdoc")
|
2016-03-17 00:49:20 +00:00
|
|
|
[[ $CONFIGURATION == 'Debug' ]] && exit 0
|
|
|
|
npm install
|
2016-02-12 10:47:08 +00:00
|
|
|
npm run jsdoc
|
|
|
|
;;
|
2016-01-27 00:12:26 +00:00
|
|
|
"realmjs")
|
2016-05-16 23:26:37 +00:00
|
|
|
pushd src
|
2016-05-13 23:30:57 +00:00
|
|
|
xctest RealmJS
|
2016-01-27 00:12:26 +00:00
|
|
|
;;
|
|
|
|
"react-tests")
|
2016-11-15 19:22:15 +00:00
|
|
|
if ! [ -z "${JENKINS_HOME}" ]; then
|
|
|
|
${SRCROOT}/scripts/reset-simulators.sh
|
|
|
|
fi
|
2016-11-11 20:32:20 +00:00
|
|
|
|
2015-12-16 02:02:20 +00:00
|
|
|
pushd tests/react-test-app
|
2015-12-18 23:11:23 +00:00
|
|
|
|
2016-11-11 07:55:26 +00:00
|
|
|
npm install
|
2016-01-27 00:12:26 +00:00
|
|
|
open_chrome
|
2015-12-17 18:56:08 +00:00
|
|
|
start_packager
|
2016-01-22 23:23:27 +00:00
|
|
|
|
2016-03-23 20:20:05 +00:00
|
|
|
pushd ios
|
2016-11-11 19:31:00 +00:00
|
|
|
xctest ReactTestApp || xctest ReactTestApp
|
2016-01-27 00:12:26 +00:00
|
|
|
;;
|
|
|
|
"react-example")
|
2016-11-15 19:22:15 +00:00
|
|
|
if ! [ -z "${JENKINS_HOME}" ]; then
|
|
|
|
${SRCROOT}/scripts/reset-simulators.sh
|
|
|
|
fi
|
2016-11-15 12:49:41 +00:00
|
|
|
|
2015-12-16 02:02:20 +00:00
|
|
|
pushd examples/ReactExample
|
2016-01-27 00:12:26 +00:00
|
|
|
|
2016-02-19 10:28:59 +00:00
|
|
|
npm install
|
2016-02-16 08:37:10 +00:00
|
|
|
open_chrome
|
2015-12-17 18:56:08 +00:00
|
|
|
start_packager
|
|
|
|
|
2016-01-22 23:27:17 +00:00
|
|
|
pushd ios
|
2016-11-12 02:23:44 +00:00
|
|
|
xctest ReactExample || xctest ReactExample
|
2016-01-27 00:12:26 +00:00
|
|
|
;;
|
|
|
|
"react-tests-android")
|
2016-03-17 00:49:20 +00:00
|
|
|
[[ $CONFIGURATION == 'Debug' ]] && exit 0
|
2016-11-18 22:00:30 +00:00
|
|
|
XCPRETTY=''
|
2016-02-08 19:16:18 +00:00
|
|
|
|
2016-01-22 20:15:38 +00:00
|
|
|
pushd tests/react-test-app
|
|
|
|
|
|
|
|
npm install
|
2016-01-27 00:12:26 +00:00
|
|
|
open_chrome
|
2016-02-08 11:09:22 +00: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 22:52:15 +00:00
|
|
|
# Despite the docs claiming -c to work, it doesn't, so `-T 1` alleviates that.
|
2016-01-27 00:12:26 +00:00
|
|
|
adb logcat -c
|
2016-02-02 22:52:15 +00:00
|
|
|
adb logcat -T 1 | tee "$LOGCAT_OUT" &
|
2016-01-27 00:12:26 +00: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 20:15:38 +00:00
|
|
|
|
2016-02-02 22:52:15 +00:00
|
|
|
rm -f tests.xml
|
|
|
|
adb pull /sdcard/tests.xml .
|
2016-01-27 00:12:26 +00:00
|
|
|
|
2016-02-02 22:52:15 +00:00
|
|
|
# Stop running child processes before printing results.
|
|
|
|
cleanup
|
2016-01-26 21:10:23 +00:00
|
|
|
echo "********* TESTS COMPLETED *********";
|
2016-01-27 00:12:26 +00:00
|
|
|
echo "********* File location: $(pwd)/tests.xml *********";
|
2016-02-02 22:52:15 +00:00
|
|
|
cat tests.xml
|
2016-01-27 00:12:26 +00:00
|
|
|
;;
|
2016-04-19 21:10:10 +00:00
|
|
|
"node")
|
2016-11-10 13:42:58 +00:00
|
|
|
if [ "$(uname)" = 'Darwin' ]; then
|
|
|
|
download_server
|
|
|
|
start_server
|
|
|
|
npm_tests_cmd="npm run test"
|
2016-11-15 12:49:41 +00:00
|
|
|
npm install --build-from-source --realm_enable_sync
|
2016-11-10 13:42:58 +00:00
|
|
|
else
|
|
|
|
npm_tests_cmd="npm run test-nosync"
|
2016-11-15 12:49:41 +00:00
|
|
|
npm install --build-from-source
|
2016-11-10 13:42:58 +00:00
|
|
|
fi
|
2016-10-11 20:30:39 +00:00
|
|
|
|
2016-05-13 23:30:57 +00:00
|
|
|
# Change to a temp directory.
|
|
|
|
cd "$(mktemp -q -d -t realm.node.XXXXXX)"
|
|
|
|
trap "rm -rf '$PWD'" EXIT
|
2016-04-19 21:10:10 +00:00
|
|
|
|
2016-10-04 22:02:51 +00:00
|
|
|
pushd "$SRCROOT/tests"
|
|
|
|
npm install
|
2016-11-10 13:42:58 +00:00
|
|
|
eval $npm_tests_cmd
|
2016-10-04 22:02:51 +00:00
|
|
|
popd
|
2016-11-09 00:47:20 +00:00
|
|
|
stop_server
|
2016-04-19 21:10:10 +00:00
|
|
|
;;
|
2016-11-09 20:50:19 +00:00
|
|
|
"node-nosync")
|
|
|
|
npm install --build-from-source
|
|
|
|
|
|
|
|
# Change to a temp directory.
|
|
|
|
cd "$(mktemp -q -d -t realm.node.XXXXXX)"
|
|
|
|
trap "rm -rf '$PWD'" EXIT
|
|
|
|
|
|
|
|
pushd "$SRCROOT/tests"
|
|
|
|
npm install
|
|
|
|
npm run test-nosync
|
|
|
|
popd
|
|
|
|
;;
|
2016-08-10 13:47:55 +00:00
|
|
|
"test-runners")
|
2016-10-11 20:30:39 +00:00
|
|
|
npm install --build-from-source
|
|
|
|
|
2016-08-10 13:50:37 +00:00
|
|
|
for runner in ava mocha jest; do
|
2016-08-10 13:47:55 +00:00
|
|
|
pushd "$SRCROOT/tests/test-runners/$runner"
|
|
|
|
npm install
|
|
|
|
npm test
|
|
|
|
popd
|
|
|
|
done
|
|
|
|
;;
|
2016-03-03 22:58:05 +00:00
|
|
|
"object-store")
|
|
|
|
pushd src/object-store
|
2016-03-17 00:30:29 +00:00
|
|
|
cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION .
|
2016-03-03 22:58:05 +00:00
|
|
|
make run-tests
|
2016-04-19 21:10:10 +00:00
|
|
|
;;
|
2016-10-04 22:02:51 +00:00
|
|
|
"download-object-server")
|
|
|
|
. dependencies.list
|
|
|
|
|
|
|
|
object_server_bundle="realm-object-server-bundled_node_darwin-$REALM_OBJECT_SERVER_VERSION.tar.gz"
|
|
|
|
curl -f -L "https://static.realm.io/downloads/object-server/$object_server_bundle" -o "$object_server_bundle"
|
|
|
|
rm -rf tests/sync-bundle
|
|
|
|
mkdir -p tests/sync-bundle
|
|
|
|
tar -C tests/sync-bundle -xf "$object_server_bundle"
|
|
|
|
rm "$object_server_bundle"
|
|
|
|
|
|
|
|
echo -e "enterprise:\n skip_setup: true\n" >> "tests/sync-bundle/object-server/configuration.yml"
|
|
|
|
touch "tests/sync-bundle/object-server/do_not_open_browser"
|
|
|
|
;;
|
|
|
|
"object-server-integration")
|
2016-11-09 16:28:47 +00:00
|
|
|
echo -e "yes\n" | ./tests/sync-bundle/reset-server-realms.command
|
2016-10-04 22:02:51 +00:00
|
|
|
|
|
|
|
pushd "$SRCROOT/tests"
|
|
|
|
npm install
|
2016-11-09 20:50:19 +00:00
|
|
|
npm run test-sync-integration
|
2016-10-04 22:02:51 +00:00
|
|
|
popd
|
|
|
|
;;
|
2016-01-27 00:12:26 +00:00
|
|
|
*)
|
2015-12-17 02:14:14 +00:00
|
|
|
echo "Invalid target '${TARGET}'"
|
2016-01-27 00:12:26 +00:00
|
|
|
exit 1
|
|
|
|
esac
|