2017-03-31 19:40:36 +00:00
|
|
|
#!/bin/bash
|
2021-12-30 23:08:43 +00:00
|
|
|
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
2018-09-07 20:08:05 +00: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-16 03:08:07 +00:00
|
|
|
|
2019-06-29 02:12:42 +00:00
|
|
|
# Script used to run iOS tests.
|
|
|
|
# If no 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
|
2019-06-29 02:12:42 +00:00
|
|
|
# run the RNTester unit and integration tests
|
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)
|
2018-12-20 23:04:40 +00:00
|
|
|
ROOT=$(dirname "$SCRIPTS")
|
2017-03-31 19:40:36 +00:00
|
|
|
|
2020-01-14 21:27:53 +00:00
|
|
|
SKIPPED_TESTS=()
|
|
|
|
# TODO: T60408036 This test crashes iOS 13 for bad access, please investigate
|
|
|
|
# and re-enable. See https://gist.github.com/0xced/56035d2f57254cf518b5.
|
2020-01-15 01:53:04 +00:00
|
|
|
SKIPPED_TESTS+=("-skip-testing:RNTesterUnitTests/RCTJSONTests/testNotUTF8Convertible")
|
2020-01-14 21:27:53 +00:00
|
|
|
|
2017-03-31 19:40:36 +00:00
|
|
|
# Create cleanup handler
|
2019-04-03 17:09:11 +00:00
|
|
|
cleanup() {
|
2018-12-11 04:27:02 +00:00
|
|
|
EXIT=$?
|
2017-03-31 19:40:36 +00:00
|
|
|
set +e
|
|
|
|
|
2018-12-11 04:27:02 +00:00
|
|
|
if [ $EXIT -ne 0 ];
|
2017-03-31 19:40:36 +00:00
|
|
|
then
|
|
|
|
WATCHMAN_LOGS=/usr/local/Cellar/watchman/3.1/var/run/watchman/$USER.log
|
2018-12-11 04:27:02 +00:00
|
|
|
[ -f "$WATCHMAN_LOGS" ] && cat "$WATCHMAN_LOGS"
|
2017-03-31 19:40:36 +00: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 22:28:13 +00:00
|
|
|
# Wait for the package to start
|
2019-04-03 17:09:11 +00:00
|
|
|
waitForPackager() {
|
2017-07-13 22:28:13 +00:00
|
|
|
local -i max_attempts=60
|
|
|
|
local -i attempt_num=1
|
|
|
|
|
2019-04-03 17:09:11 +00:00
|
|
|
until curl -s http://localhost:8081/status | grep "packager-status:running" -q; do
|
2017-07-13 22:28:13 +00: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 15:53:24 +00: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 17:09:11 +00:00
|
|
|
runTests() {
|
2019-06-29 02:12:42 +00:00
|
|
|
# shellcheck disable=SC1091
|
2023-03-27 18:21:56 +00:00
|
|
|
source "$ROOT/scripts/.tests.env"
|
2019-06-29 02:12:42 +00:00
|
|
|
xcodebuild build test \
|
2023-03-27 18:21:56 +00:00
|
|
|
-workspace RNTesterPods.xcworkspace \
|
2019-06-29 02:12:42 +00:00
|
|
|
-scheme RNTester \
|
|
|
|
-sdk iphonesimulator \
|
2020-01-14 21:27:53 +00:00
|
|
|
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS" \
|
|
|
|
"${SKIPPED_TESTS[@]}"
|
2019-04-03 17:09:11 +00:00
|
|
|
}
|
|
|
|
|
2024-06-20 10:13:13 +00:00
|
|
|
buildForTesting() {
|
|
|
|
# shellcheck disable=SC1091
|
|
|
|
source "$ROOT/scripts/.tests.env"
|
|
|
|
xcodebuild build-for-testing \
|
|
|
|
-workspace RNTesterPods.xcworkspace \
|
|
|
|
-scheme RNTester \
|
|
|
|
-sdk iphonesimulator
|
|
|
|
}
|
|
|
|
|
|
|
|
runTestsOnly() {
|
2024-06-27 11:11:44 +00:00
|
|
|
# shellcheck disable=SC1091
|
|
|
|
source "$ROOT/scripts/.tests.env"
|
|
|
|
echo "[Testing] Running tests on $IOS_DEVICE for OS $IOS_TARGET_OS"
|
2024-06-20 10:13:13 +00:00
|
|
|
xcodebuild test \
|
|
|
|
-workspace RNTesterPods.xcworkspace \
|
|
|
|
-scheme RNTester \
|
|
|
|
-sdk iphonesimulator \
|
|
|
|
-destination "platform=iOS Simulator,name=$IOS_DEVICE,OS=$IOS_TARGET_OS" \
|
|
|
|
"${SKIPPED_TESTS[@]}"
|
|
|
|
}
|
|
|
|
|
2019-04-03 17:09:11 +00:00
|
|
|
buildProject() {
|
2019-06-29 02:12:42 +00:00
|
|
|
xcodebuild build \
|
2023-03-27 18:21:56 +00:00
|
|
|
-workspace RNTesterPods.xcworkspace \
|
2019-06-29 02:12:42 +00:00
|
|
|
-scheme RNTester \
|
|
|
|
-sdk iphonesimulator
|
2019-04-03 17:09:11 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 12:20:20 +00:00
|
|
|
xcbeautifyFormat() {
|
2019-04-03 17:09:11 +00:00
|
|
|
if [ "$CI" ]; then
|
|
|
|
# Circle CI expects JUnit reports to be available here
|
2019-12-20 00:53:54 +00:00
|
|
|
REPORTS_DIR="$HOME/react-native/reports/junit"
|
2019-04-03 17:09:11 +00:00
|
|
|
else
|
2022-02-22 10:17:47 +00:00
|
|
|
THIS_DIR=$(cd -P "$(dirname "$(realpath "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
|
2019-04-03 17:09:11 +00:00
|
|
|
|
|
|
|
# Write reports to the react-native root dir
|
|
|
|
REPORTS_DIR="$THIS_DIR/../build/reports"
|
|
|
|
fi
|
|
|
|
|
2023-02-15 12:20:20 +00:00
|
|
|
xcbeautify --report junit --report-path "$REPORTS_DIR/ios/results.xml"
|
2019-04-03 17:09:11 +00:00
|
|
|
}
|
|
|
|
|
2023-03-27 18:21:56 +00:00
|
|
|
preloadBundlesRNIntegrationTests() {
|
2023-05-25 13:28:29 +00:00
|
|
|
# Preload IntegrationTests bundles (packages/rn-tester/)
|
2019-04-03 17:09:11 +00:00
|
|
|
curl -s 'http://localhost:8081/IntegrationTests/IntegrationTestsApp.bundle?platform=ios&dev=true' -o /dev/null
|
|
|
|
}
|
|
|
|
|
2023-03-27 18:21:56 +00: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 17:09:11 +00:00
|
|
|
main() {
|
2023-03-27 18:21:56 +00:00
|
|
|
cd "$ROOT/packages/rn-tester" || exit
|
2019-04-03 17:09:11 +00: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 15:53:24 +00:00
|
|
|
echo "Launch WebSocket Server"
|
2023-05-25 13:28:29 +00:00
|
|
|
sh "./IntegrationTests/launchWebSocketServer.sh" &
|
2022-04-28 15:53:24 +00:00
|
|
|
waitForWebSocketServer
|
2019-04-03 17:09:11 +00:00
|
|
|
|
2022-04-28 15:53:24 +00:00
|
|
|
# Start the packager
|
|
|
|
yarn start --max-workers=1 || echo "Can't start packager automatically" &
|
2023-08-22 19:56:19 +00:00
|
|
|
waitForPackager
|
2023-03-27 18:21:56 +00:00
|
|
|
preloadBundlesRNTester
|
2023-05-25 13:28:29 +00:00
|
|
|
preloadBundlesRNIntegrationTests
|
2019-04-03 17:09:11 +00:00
|
|
|
|
2024-06-20 10:13:13 +00:00
|
|
|
buildForTesting
|
|
|
|
|
2019-04-03 17:09:11 +00:00
|
|
|
# Build and run tests.
|
2024-06-20 10:13:13 +00: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 17:09:11 +00:00
|
|
|
else
|
|
|
|
# Build without running tests.
|
2023-02-15 12:20:20 +00:00
|
|
|
if [ -x "$(command -v xcbeautify)" ]; then
|
|
|
|
buildProject | xcbeautifyFormat && exit "${PIPESTATUS[0]}"
|
2019-04-03 17:09:11 +00:00
|
|
|
else
|
|
|
|
buildProject
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
main "$@"
|