mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-18 17:47:32 +00:00
Merge pull request #771 from realm/ex/fix_test_script
Make shellcheck happy about test.sh
This commit is contained in:
commit
cce41ebcf1
@ -15,7 +15,7 @@ ios_sim_default_ios_version=${IOS_SIM_OS:-iOS 10.1}
|
|||||||
|
|
||||||
PATH="/opt/android-sdk-linux/platform-tools:$PATH"
|
PATH="/opt/android-sdk-linux/platform-tools:$PATH"
|
||||||
SRCROOT=$(cd "$(dirname "$0")/.." && pwd)
|
SRCROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||||
XCPRETTY=`which xcpretty || true`
|
XCPRETTY=$(which xcpretty || true)
|
||||||
CI_RUN=false
|
CI_RUN=false
|
||||||
if [ -n "${JENKINS_HOME}" ]; then
|
if [ -n "${JENKINS_HOME}" ]; then
|
||||||
CI_RUN=true
|
CI_RUN=true
|
||||||
@ -47,7 +47,7 @@ start_server() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop_server() {
|
stop_server() {
|
||||||
if [[ ${SERVER_PID} > 0 ]] ; then
|
if [[ ${SERVER_PID} -gt 0 ]] ; then
|
||||||
kill -9 ${SERVER_PID}
|
kill -9 ${SERVER_PID}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -58,20 +58,20 @@ test_temp_dir=
|
|||||||
cleanup() {
|
cleanup() {
|
||||||
# Kill started object server
|
# Kill started object server
|
||||||
stop_server || true
|
stop_server || true
|
||||||
|
|
||||||
# Quit Simulator.app to give it a chance to go down gracefully
|
# Quit Simulator.app to give it a chance to go down gracefully
|
||||||
if $startedSimulator; then
|
if $startedSimulator; then
|
||||||
osascript -e 'tell app "Simulator" to quit without saving' || true
|
osascript -e 'tell app "Simulator" to quit without saving' || true
|
||||||
sleep 0.25 # otherwise the pkill following will get it too early
|
sleep 0.25 # otherwise the pkill following will get it too early
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Kill all child processes.
|
# Kill all child processes.
|
||||||
pkill -9 -P $$ || true
|
pkill -9 -P $$ || true
|
||||||
|
|
||||||
# Kill react native packager
|
# Kill react native packager
|
||||||
pkill node || true
|
pkill node || true
|
||||||
rm -f "$PACKAGER_OUT" "$LOGCAT_OUT"
|
rm -f "$PACKAGER_OUT" "$LOGCAT_OUT"
|
||||||
|
|
||||||
# Cleanup temp files
|
# Cleanup temp files
|
||||||
if [ -n "$log_temp" ] && [ -e "$log_temp" ]; then
|
if [ -n "$log_temp" ] && [ -e "$log_temp" ]; then
|
||||||
rm "$log_temp" || true
|
rm "$log_temp" || true
|
||||||
@ -107,21 +107,21 @@ start_packager() {
|
|||||||
|
|
||||||
xctest() {
|
xctest() {
|
||||||
setup_ios_simulator
|
setup_ios_simulator
|
||||||
|
|
||||||
# - Wait until the simulator is fully booted by waiting for it to launch SpringBoard
|
# - Wait until the simulator is fully booted by waiting for it to launch SpringBoard
|
||||||
printf "Waiting for springboard to ensure device is ready..."
|
printf "Waiting for springboard to ensure device is ready..."
|
||||||
xcrun simctl launch "$IOS_SIM_DEVICE" com.apple.springboard 1>/dev/null 2>/dev/null || true
|
xcrun simctl launch "$IOS_SIM_DEVICE" com.apple.springboard 1>/dev/null 2>/dev/null || true
|
||||||
echo " done"
|
echo " done"
|
||||||
|
|
||||||
# - Run the build and test
|
# - Run the build and test
|
||||||
if [ -n "$XCPRETTY" ]; then
|
if [ -n "$XCPRETTY" ]; then
|
||||||
log_temp=`mktemp build.log.XXXXXX`
|
log_temp=$(mktemp build.log.XXXXXX)
|
||||||
if [ -e "$log_temp" ]; then
|
if [ -e "$log_temp" ]; then
|
||||||
rm "$log_temp"
|
rm "$log_temp"
|
||||||
fi
|
fi
|
||||||
xcrun xcodebuild -scheme "$1" -configuration "$CONFIGURATION" -sdk iphonesimulator -destination name="iPhone 5s" build test 2>&1 | tee "$log_temp" | "$XCPRETTY" -c --no-utf --report junit --output build/reports/junit.xml || {
|
xcrun xcodebuild -scheme "$1" -configuration "$CONFIGURATION" -sdk iphonesimulator -destination name="iPhone 5s" build test 2>&1 | tee "$log_temp" | "$XCPRETTY" -c --no-utf --report junit --output build/reports/junit.xml || {
|
||||||
EXITCODE=$?
|
EXITCODE=$?
|
||||||
printf "*** Xcode Failure (exit code $EXITCODE). The full xcode log follows: ***\n\n"
|
printf "*** Xcode Failure (exit code %s). The full xcode log follows: ***\n\n" "$EXITCODE"
|
||||||
cat "$log_temp"
|
cat "$log_temp"
|
||||||
printf "\n\n*** End Xcode Failure ***\n"
|
printf "\n\n*** End Xcode Failure ***\n"
|
||||||
exit $EXITCODE
|
exit $EXITCODE
|
||||||
@ -139,77 +139,80 @@ xctest() {
|
|||||||
setup_ios_simulator() {
|
setup_ios_simulator() {
|
||||||
# - Ensure one version of xcode is chosen by all tools
|
# - Ensure one version of xcode is chosen by all tools
|
||||||
if [[ -z "$DEVELOPER_DIR" ]]; then
|
if [[ -z "$DEVELOPER_DIR" ]]; then
|
||||||
export DEVELOPER_DIR="$(xcode-select -p)"
|
DEV_DIR="$(xcode-select -p)"
|
||||||
|
export DEVELOPER_DIR=$DEV_DIR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# -- Ensure that the simulator is ready
|
# -- Ensure that the simulator is ready
|
||||||
|
|
||||||
if [ $CI_RUN == true ]; then
|
if [ $CI_RUN == true ]; then
|
||||||
# - Kill the Simulator to ensure we are running the correct one, only when running in CI
|
# - Kill the Simulator to ensure we are running the correct one, only when running in CI
|
||||||
echo "Resetting simulator using toolchain from: $DEVELOPER_DIR"
|
echo "Resetting simulator using toolchain from: $DEVELOPER_DIR"
|
||||||
|
|
||||||
# Quit Simulator.app to give it a chance to go down gracefully
|
# Quit Simulator.app to give it a chance to go down gracefully
|
||||||
local deadline=$((SECONDS+5))
|
local deadline=$((SECONDS+5))
|
||||||
while pgrep -qx Simulator && [ $SECONDS -lt $deadline ]; do
|
while pgrep -qx Simulator && [ $SECONDS -lt $deadline ]; do
|
||||||
osascript -e 'tell app "Simulator" to quit without saving' || true
|
osascript -e 'tell app "Simulator" to quit without saving' || true
|
||||||
sleep 0.25 # otherwise the pkill following will get it too early
|
sleep 0.25 # otherwise the pkill following will get it too early
|
||||||
done
|
done
|
||||||
|
|
||||||
# stop CoreSimulatorService
|
# stop CoreSimulatorService
|
||||||
launchctl remove com.apple.CoreSimulator.CoreSimulatorService 2>/dev/null || true
|
launchctl remove com.apple.CoreSimulator.CoreSimulatorService 2>/dev/null || true
|
||||||
sleep 0.25 # launchtl can take a small moment to kill services
|
sleep 0.25 # launchtl can take a small moment to kill services
|
||||||
|
|
||||||
# kill them with fire
|
# kill them with fire
|
||||||
while pgrep -qx Simulator com.apple.CoreSimulator.CoreSimulatorService; do
|
while pgrep -qx Simulator com.apple.CoreSimulator.CoreSimulatorService; do
|
||||||
pkill -9 -x Simulator com.apple.CoreSimulator.CoreSimulatorService || true
|
pkill -9 -x Simulator com.apple.CoreSimulator.CoreSimulatorService || true
|
||||||
sleep 0.05
|
sleep 0.05
|
||||||
done
|
done
|
||||||
|
|
||||||
# - Prod `simctl` a few times as sometimes it fails the first couple of times after switching XCode vesions
|
# - Prod `simctl` a few times as sometimes it fails the first couple of times after switching XCode vesions
|
||||||
local deadline=$((SECONDS+5))
|
local deadline=$((SECONDS+5))
|
||||||
while [ -z "`xcrun simctl list devices 2>/dev/null`" ] && [ $SECONDS -lt $deadline ]; do
|
while [ -z "$(xcrun simctl list devices 2>/dev/null)" ] && [ $SECONDS -lt $deadline ]; do
|
||||||
: # nothing to see here, will stop cycling on the first successful run
|
: # nothing to see here, will stop cycling on the first successful run
|
||||||
done
|
done
|
||||||
|
|
||||||
# - Choose a device, if it has not already been chosen
|
# - Choose a device, if it has not already been chosen
|
||||||
local deadline=$((SECONDS+5))
|
local deadline=$((SECONDS+5))
|
||||||
while [ -z "$IOS_SIM_DEVICE" ] && [ $SECONDS -lt $deadline ]; do
|
while [ -z "$IOS_SIM_DEVICE" ] && [ $SECONDS -lt $deadline ]; do
|
||||||
export IOS_SIM_DEVICE=`ruby -rjson -e "puts JSON.parse(%x{xcrun simctl list devices --json})['devices'].each{|os,group| group.each{|dev| dev['os'] = os}}.flat_map{|x| x[1]}.select{|x| x['availability'] == '(available)'}.each{|x| x['score'] = (x['name'] == '$ios_sim_default_device_type' ? 1 : 0) + (x['os'] == '$ios_sim_default_ios_version' ? 1 : 0)}.sort_by!{|x| [x['score'], x['name']]}.reverse![0]['udid']"`
|
IOS_DEVICE=$(ruby -rjson -e "puts JSON.parse(%x{xcrun simctl list devices --json})['devices'].each{|os,group| group.each{|dev| dev['os'] = os}}.flat_map{|x| x[1]}.select{|x| x['availability'] == '(available)'}.each{|x| x['score'] = (x['name'] == '$ios_sim_default_device_type' ? 1 : 0) + (x['os'] == '$ios_sim_default_ios_version' ? 1 : 0)}.sort_by!{|x| [x['score'], x['name']]}.reverse![0]['udid']")
|
||||||
|
export IOS_SIM_DEVICE=$IOS_DEVICE
|
||||||
done
|
done
|
||||||
if [ -z "$IOS_SIM_DEVICE" ]; then
|
if [ -z "$IOS_SIM_DEVICE" ]; then
|
||||||
echo "*** Failed to determine the iOS Simulator device to use ***"
|
echo "*** Failed to determine the iOS Simulator device to use ***"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# - Reset the device we will be using if running in CI
|
# - Reset the device we will be using if running in CI
|
||||||
xcrun simctl shutdown "$IOS_SIM_DEVICE" 1>/dev/null 2>/dev/null || true # sometimes simctl gets confused
|
xcrun simctl shutdown "$IOS_SIM_DEVICE" 1>/dev/null 2>/dev/null || true # sometimes simctl gets confused
|
||||||
xcrun simctl erase "$IOS_SIM_DEVICE"
|
xcrun simctl erase "$IOS_SIM_DEVICE"
|
||||||
|
|
||||||
# - Start the target in Simulator.app
|
# - Start the target in Simulator.app
|
||||||
# Note: as of Xcode 7.3.1 `simctl` can not completely boot a simulator, specifically it can not bring up backboard, so GUI apps can not run.
|
# Note: as of Xcode 7.3.1 `simctl` can not completely boot a simulator, specifically it can not bring up backboard, so GUI apps can not run.
|
||||||
# This is fixed in version 8 of Xcode, but we still need the compatibility
|
# This is fixed in version 8 of Xcode, but we still need the compatibility
|
||||||
|
|
||||||
"$DEVELOPER_DIR/Applications/Simulator.app/Contents/MacOS/Simulator" -CurrentDeviceUDID "$IOS_SIM_DEVICE" & # will get killed with all other children at exit
|
"$DEVELOPER_DIR/Applications/Simulator.app/Contents/MacOS/Simulator" -CurrentDeviceUDID "$IOS_SIM_DEVICE" & # will get killed with all other children at exit
|
||||||
startedSimulator=true
|
startedSimulator=true
|
||||||
|
|
||||||
else
|
else
|
||||||
# - ensure that the simulator is running on a developer's workstation
|
# - ensure that the simulator is running on a developer's workstation
|
||||||
open "$DEVELOPER_DIR/Applications/Simulator.app"
|
open "$DEVELOPER_DIR/Applications/Simulator.app"
|
||||||
|
|
||||||
# - Select the first device booted in the simulator, since it will boot something for us
|
# - Select the first device booted in the simulator, since it will boot something for us
|
||||||
local deadline=$((SECONDS+10))
|
local deadline=$((SECONDS+10))
|
||||||
while [ -z "$IOS_SIM_DEVICE" ] && [ $SECONDS -lt $deadline ]; do
|
while [ -z "$IOS_SIM_DEVICE" ] && [ $SECONDS -lt $deadline ]; do
|
||||||
export IOS_SIM_DEVICE=`ruby -rjson -e "puts JSON.parse(%x{xcrun simctl list devices --json})['devices'].each{|os,group| group.each{|dev| dev['os'] = os}}.flat_map{|x| x[1]}.select{|x| x['state'] == 'Booted'}[0]['udid']"`
|
IOS_DEVICE=$(ruby -rjson -e "puts JSON.parse(%x{xcrun simctl list devices --json})['devices'].each{|os,group| group.each{|dev| dev['os'] = os}}.flat_map{|x| x[1]}.select{|x| x['state'] == 'Booted'}[0]['udid']")
|
||||||
|
export IOS_SIM_DEVICE=$IOS_DEVICE
|
||||||
done
|
done
|
||||||
if [ -z "$IOS_SIM_DEVICE" ]; then
|
if [ -z "$IOS_SIM_DEVICE" ]; then
|
||||||
echo "*** Failed to determine the iOS Simulator device in use ***"
|
echo "*** Failed to determine the iOS Simulator device in use ***"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Wait until the boot completes
|
# Wait until the boot completes
|
||||||
printf " waiting for simulator ($IOS_SIM_DEVICE) to boot..."
|
printf " waiting for simulator (%s) to boot..." "$IOS_SIM_DEVICE"
|
||||||
until ruby -rjson -e 'exit JSON.parse(`xcrun simctl list devices -j `)["devices"].flat_map { |d| d[1] }.any? { |d| d["availability"] == "(available)" && d["state"] == "Booted" }'; do
|
until ruby -rjson -e "exit JSON.parse(%x{xcrun simctl list devices --json})['devices'].flat_map { |d| d[1] }.any? { |d| d['availability'] == '(available)' && d['state'] == 'Booted' }"; do
|
||||||
sleep 0.25
|
sleep 0.25
|
||||||
done
|
done
|
||||||
echo " done"
|
echo " done"
|
||||||
@ -222,6 +225,7 @@ trap cleanup EXIT
|
|||||||
|
|
||||||
# Use a consistent version of Node if possible.
|
# Use a consistent version of Node if possible.
|
||||||
if [ -s "${HOME}/.nvm/nvm.sh" ]; then
|
if [ -s "${HOME}/.nvm/nvm.sh" ]; then
|
||||||
|
# shellcheck disable=SC1090
|
||||||
. "${HOME}/.nvm/nvm.sh"
|
. "${HOME}/.nvm/nvm.sh"
|
||||||
nvm use 5.12 || true
|
nvm use 5.12 || true
|
||||||
fi
|
fi
|
||||||
@ -320,7 +324,7 @@ case "$TARGET" in
|
|||||||
|
|
||||||
pushd "$SRCROOT/tests"
|
pushd "$SRCROOT/tests"
|
||||||
npm install
|
npm install
|
||||||
eval $npm_tests_cmd
|
eval "$npm_tests_cmd"
|
||||||
popd
|
popd
|
||||||
stop_server
|
stop_server
|
||||||
;;
|
;;
|
||||||
@ -337,6 +341,11 @@ case "$TARGET" in
|
|||||||
popd
|
popd
|
||||||
;;
|
;;
|
||||||
"test-runners")
|
"test-runners")
|
||||||
|
# Create a fake realm module that points to the source root so that test-runner tests can require('realm')
|
||||||
|
rm -rf "$SRCROOT/tests/test-runners/node-modules/realm"
|
||||||
|
mkdir -p "$SRCROOT/tests/test-runners/node_modules"
|
||||||
|
ln -s "../../.." "$SRCROOT/tests/test-runners/node_modules/realm"
|
||||||
|
|
||||||
npm install --build-from-source
|
npm install --build-from-source
|
||||||
|
|
||||||
for runner in ava mocha jest; do
|
for runner in ava mocha jest; do
|
||||||
@ -348,10 +357,11 @@ case "$TARGET" in
|
|||||||
;;
|
;;
|
||||||
"object-store")
|
"object-store")
|
||||||
pushd src/object-store
|
pushd src/object-store
|
||||||
cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION .
|
cmake -DCMAKE_BUILD_TYPE="$CONFIGURATION" .
|
||||||
make run-tests
|
make run-tests
|
||||||
;;
|
;;
|
||||||
"download-object-server")
|
"download-object-server")
|
||||||
|
# shellcheck disable=SC1091
|
||||||
. dependencies.list
|
. dependencies.list
|
||||||
|
|
||||||
object_server_bundle="realm-object-server-bundled_node_darwin-$REALM_OBJECT_SERVER_VERSION.tar.gz"
|
object_server_bundle="realm-object-server-bundled_node_darwin-$REALM_OBJECT_SERVER_VERSION.tar.gz"
|
||||||
|
1
tests/test-runners/node_modules/realm
generated
vendored
1
tests/test-runners/node_modules/realm
generated
vendored
@ -1 +0,0 @@
|
|||||||
../../..
|
|
Loading…
x
Reference in New Issue
Block a user