2017-03-31 19:40:36 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -ex
|
|
|
|
|
2017-04-27 16:05:22 +00:00
|
|
|
# Script used to run iOS and tvOS tests.
|
|
|
|
# Environment variables are used to configure what test to run.
|
|
|
|
# If not arguments are passed to the script, it will only compile
|
2017-05-06 03:50:47 +00:00
|
|
|
# the RNTester.
|
2017-04-27 16:05:22 +00:00
|
|
|
# If the script is called with a single argument "test", we'll
|
2017-05-06 03:50:47 +00:00
|
|
|
# also run the RNTester integration test (needs JS and packager).
|
2017-04-27 16:05:22 +00:00
|
|
|
# ./objc-test.sh test
|
|
|
|
|
2017-03-31 19:40:36 +00:00
|
|
|
SCRIPTS=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
|
|
ROOT=$(dirname $SCRIPTS)
|
|
|
|
|
|
|
|
cd $ROOT
|
|
|
|
|
|
|
|
# Create cleanup handler
|
|
|
|
function cleanup {
|
|
|
|
EXIT_CODE=$?
|
|
|
|
set +e
|
|
|
|
|
|
|
|
if [ $EXIT_CODE -ne 0 ];
|
|
|
|
then
|
|
|
|
WATCHMAN_LOGS=/usr/local/Cellar/watchman/3.1/var/run/watchman/$USER.log
|
|
|
|
[ -f $WATCHMAN_LOGS ] && cat $WATCHMAN_LOGS
|
|
|
|
fi
|
|
|
|
# kill whatever is occupying port 8081 (packager)
|
|
|
|
lsof -i tcp:8081 | awk 'NR!=1 {print $2}' | xargs kill
|
|
|
|
# kill whatever is occupying port 5555 (web socket server)
|
|
|
|
lsof -i tcp:5555 | awk 'NR!=1 {print $2}' | xargs kill
|
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2017-07-13 22:28:13 +00:00
|
|
|
# Wait for the package to start
|
|
|
|
function waitForPackager {
|
|
|
|
local -i max_attempts=60
|
|
|
|
local -i attempt_num=1
|
|
|
|
|
|
|
|
until $(curl -s http://localhost:8081/status | grep "packager-status:running" -q); do
|
|
|
|
if (( attempt_num == max_attempts )); then
|
|
|
|
echo "Packager did not respond in time. No more attempts left."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
(( attempt_num++ ))
|
|
|
|
echo "Packager did not respond. Retrying for attempt number $attempt_num..."
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Packager is ready!"
|
|
|
|
}
|
|
|
|
|
2017-03-31 19:40:36 +00:00
|
|
|
# If first argument is "test", actually start the packager and run tests.
|
2017-05-06 03:50:47 +00:00
|
|
|
# Otherwise, just build RNTester for tvOS and exit
|
2017-03-31 19:40:36 +00:00
|
|
|
|
2017-04-27 16:05:22 +00:00
|
|
|
if [ "$1" = "test" ]; then
|
2017-03-31 19:40:36 +00:00
|
|
|
|
2017-05-23 23:05:52 +00:00
|
|
|
# Start the packager
|
2017-07-16 00:05:11 +00:00
|
|
|
./scripts/packager.sh --max-workers=1 || echo "Can't start packager automatically" &
|
2017-03-31 19:40:36 +00:00
|
|
|
# Start the WebSocket test server
|
|
|
|
open "./IntegrationTests/launchWebSocketServer.command" || echo "Can't start web socket server automatically"
|
|
|
|
|
2017-07-13 22:28:13 +00:00
|
|
|
waitForPackager
|
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
# Preload the RNTesterApp bundle for better performance in integration tests
|
|
|
|
curl 'http://localhost:8081/RNTester/js/RNTesterApp.ios.bundle?platform=ios&dev=true' -o temp.bundle
|
2017-03-31 19:40:36 +00:00
|
|
|
rm temp.bundle
|
2017-05-06 03:50:47 +00:00
|
|
|
curl 'http://localhost:8081/RNTester/js/RNTesterApp.ios.bundle?platform=ios&dev=true&minify=false' -o temp.bundle
|
2017-03-31 19:40:36 +00:00
|
|
|
rm temp.bundle
|
|
|
|
curl 'http://localhost:8081/IntegrationTests/IntegrationTestsApp.bundle?platform=ios&dev=true' -o temp.bundle
|
|
|
|
rm temp.bundle
|
|
|
|
curl 'http://localhost:8081/IntegrationTests/RCTRootViewIntegrationTestApp.bundle?platform=ios&dev=true' -o temp.bundle
|
|
|
|
rm temp.bundle
|
|
|
|
|
2017-04-27 16:05:22 +00:00
|
|
|
# Run tests
|
|
|
|
# TODO: We use xcodebuild because xctool would stall when collecting info about
|
|
|
|
# the tests before running them. Switch back when this issue with xctool has
|
|
|
|
# been resolved.
|
|
|
|
xcodebuild \
|
2017-05-06 03:50:47 +00:00
|
|
|
-project "RNTester/RNTester.xcodeproj" \
|
2017-04-27 16:05:22 +00:00
|
|
|
-scheme $SCHEME \
|
|
|
|
-sdk $SDK \
|
|
|
|
-destination "$DESTINATION" \
|
2018-01-31 22:48:51 +00:00
|
|
|
build test \
|
2018-02-08 22:57:36 +00:00
|
|
|
| xcpretty --report junit --output ~/react-native/reports/junit/objc-xcodebuild-results.xml
|
2017-03-31 19:40:36 +00:00
|
|
|
|
2017-04-27 16:05:22 +00:00
|
|
|
else
|
2017-03-31 19:40:36 +00:00
|
|
|
|
2017-04-27 16:05:22 +00:00
|
|
|
# Don't run tests. No need to pass -destination to xcodebuild.
|
2017-03-31 19:40:36 +00:00
|
|
|
# TODO: We use xcodebuild because xctool would stall when collecting info about
|
|
|
|
# the tests before running them. Switch back when this issue with xctool has
|
|
|
|
# been resolved.
|
|
|
|
xcodebuild \
|
2017-05-06 03:50:47 +00:00
|
|
|
-project "RNTester/RNTester.xcodeproj" \
|
2017-03-31 19:40:36 +00:00
|
|
|
-scheme $SCHEME \
|
|
|
|
-sdk $SDK \
|
2017-05-23 23:05:52 +00:00
|
|
|
build
|
2017-04-27 16:05:22 +00:00
|
|
|
|
|
|
|
fi
|