2017-03-31 12:40:36 -07:00
|
|
|
#!/bin/bash
|
2021-12-30 15:08:43 -08:00
|
|
|
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
2018-09-07 13:08:05 -07:00
|
|
|
#
|
|
|
|
|
# This source code is licensed under the MIT license found in the
|
|
|
|
|
# LICENSE file in the root directory of this source tree.
|
2019-10-15 20:08:07 -07:00
|
|
|
|
2019-06-28 19:12:42 -07:00
|
|
|
# Script used to run iOS tests.
|
|
|
|
|
# If no arguments are passed to the script, it will only compile
|
2017-05-05 20:50:47 -07:00
|
|
|
# the RNTester.
|
2017-04-27 09:05:22 -07:00
|
|
|
# If the script is called with a single argument "test", we'll
|
2019-06-28 19:12:42 -07:00
|
|
|
# run the RNTester unit and integration tests
|
2017-04-27 09:05:22 -07:00
|
|
|
# ./objc-test.sh test
|
|
|
|
|
|
2017-03-31 12:40:36 -07:00
|
|
|
SCRIPTS=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
2018-12-20 15:04:40 -08:00
|
|
|
ROOT=$(dirname "$SCRIPTS")
|
2017-03-31 12:40:36 -07:00
|
|
|
|
2020-01-14 13:27:53 -08:00
|
|
|
SKIPPED_TESTS=()
|
|
|
|
|
|
2017-03-31 12:40:36 -07:00
|
|
|
# Create cleanup handler
|
2019-04-03 10:09:11 -07:00
|
|
|
cleanup() {
|
2018-12-10 20:27:02 -08:00
|
|
|
EXIT=$?
|
2017-03-31 12:40:36 -07:00
|
|
|
set +e
|
|
|
|
|
|
2018-12-10 20:27:02 -08:00
|
|
|
if [ $EXIT -ne 0 ];
|
2017-03-31 12:40:36 -07:00
|
|
|
then
|
|
|
|
|
WATCHMAN_LOGS=/usr/local/Cellar/watchman/3.1/var/run/watchman/$USER.log
|
2018-12-10 20:27:02 -08:00
|
|
|
[ -f "$WATCHMAN_LOGS" ] && cat "$WATCHMAN_LOGS"
|
2017-03-31 12:40:36 -07:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 15:28:13 -07:00
|
|
|
# Wait for the package to start
|
2019-04-03 10:09:11 -07:00
|
|
|
waitForPackager() {
|
2017-07-13 15:28:13 -07:00
|
|
|
local -i max_attempts=60
|
|
|
|
|
local -i attempt_num=1
|
|
|
|
|
|
2019-04-03 10:09:11 -07:00
|
|
|
until curl -s http://localhost:8081/status | grep "packager-status:running" -q; do
|
2017-07-13 15:28:13 -07:00
|
|
|
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!"
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 08:53:24 -07:00
|
|
|
waitForWebSocketServer() {
|
|
|
|
|
local -i max_attempts=60
|
|
|
|
|
local -i attempt_num=1
|
|
|
|
|
|
|
|
|
|
until curl -s http://localhost:5555 | grep "Upgrade Required" -q; do
|
|
|
|
|
if (( attempt_num == max_attempts )); then
|
|
|
|
|
echo "WebSocket Server did not respond in time. No more attempts left."
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
(( attempt_num++ ))
|
|
|
|
|
echo "WebSocket Server did not respond. Retrying for attempt number $attempt_num..."
|
|
|
|
|
sleep 1
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
echo "WebSocket Server is ready!"
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-03 10:09:11 -07:00
|
|
|
runTests() {
|
2019-06-28 19:12:42 -07:00
|
|
|
# shellcheck disable=SC1091
|
2023-03-27 11:21:56 -07:00
|
|
|
source "$ROOT/scripts/.tests.env"
|
2025-12-10 08:47:16 -08:00
|
|
|
xcodebuild test \
|
2023-03-27 11:21:56 -07:00
|
|
|
-workspace RNTesterPods.xcworkspace \
|
2019-06-28 19:12:42 -07:00
|
|
|
-scheme RNTester \
|
|
|
|
|
-sdk iphonesimulator \
|
2020-01-14 13:27:53 -08:00
|
|
|
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS" \
|
2025-12-10 08:47:16 -08:00
|
|
|
-derivedDataPath "/tmp/RNTesterBuild" \
|
|
|
|
|
-resultBundlePath "/tmp/RNTesterTestResults" \
|
2020-01-14 13:27:53 -08:00
|
|
|
"${SKIPPED_TESTS[@]}"
|
2019-04-03 10:09:11 -07:00
|
|
|
}
|
|
|
|
|
|
2024-06-20 03:13:13 -07:00
|
|
|
buildForTesting() {
|
|
|
|
|
# shellcheck disable=SC1091
|
|
|
|
|
source "$ROOT/scripts/.tests.env"
|
2025-12-10 08:47:16 -08:00
|
|
|
bundle install
|
|
|
|
|
bundle exec pod install
|
2024-06-20 03:13:13 -07:00
|
|
|
xcodebuild build-for-testing \
|
|
|
|
|
-workspace RNTesterPods.xcworkspace \
|
|
|
|
|
-scheme RNTester \
|
|
|
|
|
-sdk iphonesimulator \
|
2025-12-10 08:47:16 -08:00
|
|
|
-derivedDataPath "/tmp/RNTesterBuild" \
|
|
|
|
|
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS"
|
2024-06-20 03:13:13 -07:00
|
|
|
}
|
|
|
|
|
|
2019-04-03 10:09:11 -07:00
|
|
|
buildProject() {
|
2019-06-28 19:12:42 -07:00
|
|
|
xcodebuild build \
|
2023-03-27 11:21:56 -07:00
|
|
|
-workspace RNTesterPods.xcworkspace \
|
2019-06-28 19:12:42 -07:00
|
|
|
-scheme RNTester \
|
|
|
|
|
-sdk iphonesimulator
|
2019-04-03 10:09:11 -07:00
|
|
|
}
|
|
|
|
|
|
2023-02-15 04:20:20 -08:00
|
|
|
xcbeautifyFormat() {
|
2019-04-03 10:09:11 -07:00
|
|
|
if [ "$CI" ]; then
|
2025-02-05 09:55:00 -08:00
|
|
|
# CI expects JUnit reports to be available here
|
2019-12-19 16:53:54 -08:00
|
|
|
REPORTS_DIR="$HOME/react-native/reports/junit"
|
2019-04-03 10:09:11 -07:00
|
|
|
else
|
2022-02-22 02:17:47 -08:00
|
|
|
THIS_DIR=$(cd -P "$(dirname "$(realpath "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
|
2019-04-03 10:09:11 -07:00
|
|
|
|
|
|
|
|
# Write reports to the react-native root dir
|
|
|
|
|
REPORTS_DIR="$THIS_DIR/../build/reports"
|
|
|
|
|
fi
|
|
|
|
|
|
2023-02-15 04:20:20 -08:00
|
|
|
xcbeautify --report junit --report-path "$REPORTS_DIR/ios/results.xml"
|
2019-04-03 10:09:11 -07:00
|
|
|
}
|
|
|
|
|
|
2023-03-27 11:21:56 -07:00
|
|
|
preloadBundlesRNIntegrationTests() {
|
2023-05-25 06:28:29 -07:00
|
|
|
# Preload IntegrationTests bundles (packages/rn-tester/)
|
2019-04-03 10:09:11 -07:00
|
|
|
curl -s 'http://localhost:8081/IntegrationTests/IntegrationTestsApp.bundle?platform=ios&dev=true' -o /dev/null
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 11:21:56 -07:00
|
|
|
preloadBundlesRNTester() {
|
|
|
|
|
# Preload RNTesterApp bundles (packages/rn-tester/)
|
|
|
|
|
curl -s 'http://localhost:8081/js/RNTesterApp.ios.bundle?platform=ios&dev=true' -o /dev/null
|
|
|
|
|
curl -s 'http://localhost:8081/js/RNTesterApp.ios.bundle?platform=ios&dev=true&minify=false' -o /dev/null
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-03 10:09:11 -07:00
|
|
|
main() {
|
2023-03-27 11:21:56 -07:00
|
|
|
cd "$ROOT/packages/rn-tester" || exit
|
2019-04-03 10:09:11 -07:00
|
|
|
|
|
|
|
|
# If first argument is "test", actually start the packager and run tests.
|
|
|
|
|
# Otherwise, just build RNTester and exit
|
|
|
|
|
if [ "$1" = "test" ]; then
|
|
|
|
|
|
|
|
|
|
# Start the WebSocket test server
|
2022-04-28 08:53:24 -07:00
|
|
|
echo "Launch WebSocket Server"
|
2023-05-25 06:28:29 -07:00
|
|
|
sh "./IntegrationTests/launchWebSocketServer.sh" &
|
2022-04-28 08:53:24 -07:00
|
|
|
waitForWebSocketServer
|
2019-04-03 10:09:11 -07:00
|
|
|
|
2022-04-28 08:53:24 -07:00
|
|
|
# Start the packager
|
|
|
|
|
yarn start --max-workers=1 || echo "Can't start packager automatically" &
|
2023-08-22 12:56:19 -07:00
|
|
|
waitForPackager
|
2023-03-27 11:21:56 -07:00
|
|
|
preloadBundlesRNTester
|
2023-05-25 06:28:29 -07:00
|
|
|
preloadBundlesRNIntegrationTests
|
2019-04-03 10:09:11 -07:00
|
|
|
|
2024-06-20 03:13:13 -07:00
|
|
|
buildForTesting
|
|
|
|
|
|
2019-04-03 10:09:11 -07:00
|
|
|
# Build and run tests.
|
2024-06-20 03:13:13 -07:00
|
|
|
RESULT=-1
|
|
|
|
|
MAX_RETRY=3
|
|
|
|
|
for ((i=1; i<=MAX_RETRY; i++))
|
|
|
|
|
do
|
|
|
|
|
echo "Attempt #$i of running tests..."
|
|
|
|
|
if [ -x "$(command -v xcbeautify)" ]; then
|
|
|
|
|
runTests | xcbeautifyFormat && exit "${PIPESTATUS[0]}"
|
|
|
|
|
RESULT="$?"
|
|
|
|
|
else
|
|
|
|
|
echo 'Warning: xcbeautify is not installed. Install xcbeautify to generate JUnit reports.'
|
|
|
|
|
runTests
|
|
|
|
|
RESULT="$?"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ "$RESULT" == 0 ]]; then
|
|
|
|
|
# Successful tests!
|
|
|
|
|
echo "Test completed successfully!"
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
echo "Test Failed with code $RESULT!"
|
|
|
|
|
exit $RESULT
|
|
|
|
|
|
2019-04-03 10:09:11 -07:00
|
|
|
else
|
|
|
|
|
# Build without running tests.
|
2023-02-15 04:20:20 -08:00
|
|
|
if [ -x "$(command -v xcbeautify)" ]; then
|
|
|
|
|
buildProject | xcbeautifyFormat && exit "${PIPESTATUS[0]}"
|
2019-04-03 10:09:11 -07:00
|
|
|
else
|
|
|
|
|
buildProject
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
main "$@"
|