Skip to content

Commit

Permalink
Add ability to run tests on real devices
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaNH3 committed Mar 9, 2021
1 parent ffa90e8 commit e6a601d
Showing 1 changed file with 48 additions and 16 deletions.
64 changes: 48 additions & 16 deletions apple/testing/default_runner/ios_test_runner.template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,38 +118,70 @@ if [[ -n "$TESTBRIDGE_TEST_ONLY" ]]; then
LAUNCH_OPTIONS_JSON_STR+="\"tests_to_run\":[\"$TESTS\"]"
fi

if [[ "${TEST_HOST_ENVS:-}" != "" ]]; then
TEST_HOST_ENVS=$(echo ${TEST_HOST_ENVS} | tr ";" ",")
TEST_HOST_ENVS=${TEST_HOST_ENVS//:/\":\"}
TEST_HOST_ENVS=${TEST_HOST_ENVS//,/\",\"}
TEST_HOST_ENVS="{\"${TEST_HOST_ENVS}\"}"
if [[ -n "${LAUNCH_OPTIONS_JSON_STR}" ]]; then
LAUNCH_OPTIONS_JSON_STR+=","
fi
LAUNCH_OPTIONS_JSON_STR+="\"app_under_test_env_vars\":${TEST_HOST_ENVS}"
fi

if [[ -n "${LAUNCH_OPTIONS_JSON_STR}" ]]; then
LAUNCH_OPTIONS_JSON_STR+=","
fi
LAUNCH_OPTIONS_JSON_STR+="\"uitest_auto_screenshots\":true"

if [[ -n "${LAUNCH_OPTIONS_JSON_STR}" ]]; then
LAUNCH_OPTIONS_JSON_STR+=","
fi
LAUNCH_OPTIONS_JSON_STR+="\"keep_xcresult_data\":true"

echo $LAUNCH_OPTIONS_JSON_STR
if [[ -n "${LAUNCH_OPTIONS_JSON_STR}" ]]; then
LAUNCH_OPTIONS_JSON_STR="{${LAUNCH_OPTIONS_JSON_STR}}"
LAUNCH_OPTIONS_JSON_PATH="${TMP_DIR}/launch_options.json"
echo "${LAUNCH_OPTIONS_JSON_STR}" > "${LAUNCH_OPTIONS_JSON_PATH}"
runner_flags+=("--launch_options_json_path=${LAUNCH_OPTIONS_JSON_PATH}")
fi

target_flags=()
if [[ -n "$simulator_id" ]]; then
target_flags=(
"test"
"--platform=ios_simulator"
"--id=$simulator_id"
)
cmd=
if [[ "${REAL_DEVICE_TEST:-false}" == "true" ]]; then
cmd=("%(testrunner_binary)s"
"${runner_flags[@]}"
test
"--id=${DEVICE_ID:-0}"
"--platform=${DEVICE_PLATFORM:-ios_device}"
"$@")
else
target_flags=(
"simulator_test"
"--device_type=%(device_type)s"
"--os_version=%(os_version)s"
)
fi

cmd=("%(testrunner_binary)s"
target_flags=()
if [[ -n "$simulator_id" ]]; then
target_flags=(
"test"
"--platform=ios_simulator"
"--id=$simulator_id"
)
else
target_flags=(
"simulator_test"
"--device_type=%(device_type)s"
"--os_version=%(os_version)s"
)
fi
cmd=("%(testrunner_binary)s"
"${runner_flags[@]}"
"${target_flags[@]}"
"${custom_xctestrunner_args[@]}")
fi

"${cmd[@]}" 2>&1
status=$?

set -x

if [ ! -z ${ENABLE_CODE_COVERAGE+x} ] && [[ "${ENABLE_CODE_COVERAGE}" == "true" ]]; then
if [[ "${ENABLE_CODE_COVERAGE:-false}" == "true" ]]; then
OUTPUT_DIR=$(dirname $LLVM_PROFILE_FILE)/$TEST_BUNDLE_NAME
rm -rf $OUTPUT_DIR || true
mkdir -p $OUTPUT_DIR
Expand Down

0 comments on commit e6a601d

Please sign in to comment.