From 92190727d151a306192f9e791e6c7ece7e7d025e Mon Sep 17 00:00:00 2001 From: dlowder-salesforce Date: Fri, 31 Mar 2017 12:40:36 -0700 Subject: [PATCH] Clean up and remove duplicate code in Travis iOS/tvOS test scripts Summary: **Motivation** Remove duplicated lines in objc-test-ios.sh and objc-test-tvos.sh **Test plan** Travis CI should continue to work as before. Closes https://github.com/facebook/react-native/pull/13173 Differential Revision: D4812177 Pulled By: hramos fbshipit-source-id: 40afe0beab896d741f607f4841df7e9b42f4c17d --- scripts/objc-test-ios.sh | 84 +++------------------------------------ scripts/objc-test-tvos.sh | 67 ++++--------------------------- scripts/objc-test.sh | 62 +++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 138 deletions(-) create mode 100755 scripts/objc-test.sh diff --git a/scripts/objc-test-ios.sh b/scripts/objc-test-ios.sh index 3f909f7a2..c4534e67c 100755 --- a/scripts/objc-test-ios.sh +++ b/scripts/objc-test-ios.sh @@ -6,84 +6,10 @@ ROOT=$(dirname "$SCRIPTS") cd "$ROOT" -# Create cleanup handler -function cleanup { - EXIT_CODE=$? - set +e +SCHEME="UIExplorer" +SDK="iphonesimulator" +DESTINATION="platform=iOS Simulator,name=iPhone 5s,OS=10.1" +TEST="test" - 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 backgrounded jobs - # shellcheck disable=SC2046 - kill $(jobs -p) - # 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 INT TERM EXIT +. ./scripts/objc-test.sh -# If first argument is "test", actually start the packager and run tests. -# Otherwise, just build UIExplorer for tvOS and exit - -if [ "$1" = "test" ]; -then - -# Start the packager -(exec "./packager/launchPackager.command" || echo "Can't start packager automatically") & -(exec "./IntegrationTests/launchWebSocketServer.command" || echo "Can't start web socket server automatically") & - -# wait until packager is ready -PACKAGER_IS_RUNNING="packager-status:running" -SECONDS=0 -STATUS= - -sleep 2 -test "$SECONDS" -ne 0 # Make sure the magic $SECONDS variable works - -set +ex -while [ "$STATUS" != "$PACKAGER_IS_RUNNING" ] && [ "$SECONDS" -lt 60 ]; do - STATUS=$(curl --silent 'http://localhost:8081/status') - sleep 1 -done -set -ex - -if [ "$STATUS" != "$PACKAGER_IS_RUNNING" ]; then - echo "Could not startup packager within $SECONDS seconds" - false -fi - -# Preload the UIExplorerApp bundle for better performance in integration tests -curl 'http://localhost:8081/Examples/UIExplorer/js/UIExplorerApp.ios.bundle?platform=ios&dev=true' -o temp.bundle -rm temp.bundle -curl 'http://localhost:8081/Examples/UIExplorer/js/UIExplorerApp.ios.bundle?platform=ios&dev=true&minify=false' -o temp.bundle -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 - -# Build and test for iOS -# 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 \ - -project "Examples/UIExplorer/UIExplorer.xcodeproj" \ - -scheme "UIExplorer" \ - -sdk "iphonesimulator" \ - -destination "platform=iOS Simulator,name=iPhone 5s,OS=10.1" \ - build test - -else - -# Only build for iOS (check there are no missing files in the Xcode project) -xcodebuild \ - -project "Examples/UIExplorer/UIExplorer.xcodeproj" \ - -scheme "UIExplorer" \ - -sdk "iphonesimulator" \ - build - -fi diff --git a/scripts/objc-test-tvos.sh b/scripts/objc-test-tvos.sh index 943d51091..849f121c5 100755 --- a/scripts/objc-test-tvos.sh +++ b/scripts/objc-test-tvos.sh @@ -2,66 +2,15 @@ set -ex SCRIPTS=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -ROOT=$(dirname $SCRIPTS) +ROOT=$(dirname "$SCRIPTS") -cd $ROOT +cd "$ROOT" -# Create cleanup handler -function cleanup { - EXIT_CODE=$? - set +e +SCHEME="UIExplorer-tvOS" +SDK="appletvsimulator" +DESTINATION="platform=tvOS Simulator,name=Apple TV 1080p,OS=10.1" +# Uncomment the line below to enable tvOS testing +#TEST="test" - 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 +. ./scripts/objc-test.sh -# If first argument is "test", actually start the packager and run tests. -# Otherwise, just build UIExplorer for tvOS and exit - -if [ "$1" = "test" ]; -then - -# Start the packager -open "./packager/launchPackager.command" || echo "Can't start packager automatically" -open "./IntegrationTests/launchWebSocketServer.command" || echo "Can't start web socket server automatically" - -# Preload the UIExplorerApp bundle for better performance in integration tests -sleep 20 -curl 'http://localhost:8081/Examples/UIExplorer/js/UIExplorerApp.ios.bundle?platform=ios&dev=true' -o temp.bundle -rm temp.bundle -curl 'http://localhost:8081/Examples/UIExplorer/js/UIExplorerApp.ios.bundle?platform=ios&dev=true&minify=false' -o temp.bundle -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 - -# Build and test for tvOS -# 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 \ - -project "Examples/UIExplorer/UIExplorer.xcodeproj" \ - -scheme "UIExplorer-tvOS" \ - -sdk "appletvsimulator" \ - -destination "platform=tvOS Simulator,name=Apple TV 1080p,OS=10.1" \ - build test - -else - -# Only build for tvOS (check there are no missing files in the Xcode project) -xcodebuild \ - -project "Examples/UIExplorer/UIExplorer.xcodeproj" \ - -scheme "UIExplorer-tvOS" \ - -sdk "appletvsimulator" \ - build - -fi diff --git a/scripts/objc-test.sh b/scripts/objc-test.sh new file mode 100755 index 000000000..a09b4fbdf --- /dev/null +++ b/scripts/objc-test.sh @@ -0,0 +1,62 @@ +#!/bin/bash +set -ex + +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 + +# If first argument is "test", actually start the packager and run tests. +# Otherwise, just build UIExplorer for tvOS and exit + +if [ "$TEST" = "test" ]; +then + +# Start the packager +open "./packager/launchPackager.command" || echo "Can't start packager automatically" +# Start the WebSocket test server +open "./IntegrationTests/launchWebSocketServer.command" || echo "Can't start web socket server automatically" + +# Preload the UIExplorerApp bundle for better performance in integration tests +sleep 20 +curl 'http://localhost:8081/Examples/UIExplorer/js/UIExplorerApp.ios.bundle?platform=ios&dev=true' -o temp.bundle +rm temp.bundle +curl 'http://localhost:8081/Examples/UIExplorer/js/UIExplorerApp.ios.bundle?platform=ios&dev=true&minify=false' -o temp.bundle +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 + +else + +TEST="" + +fi + +# 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 \ + -project "Examples/UIExplorer/UIExplorer.xcodeproj" \ + -scheme $SCHEME \ + -sdk $SDK \ + -destination "$DESTINATION" \ + build $TEST