Skip to content

Instantly share code, notes, and snippets.

@kapoorlakshya
Created April 20, 2023 20:52
Show Gist options
  • Save kapoorlakshya/a6cfd61ea6db14935ad7330f755cc0d8 to your computer and use it in GitHub Desktop.
Save kapoorlakshya/a6cfd61ea6db14935ad7330f755cc0d8 to your computer and use it in GitHub Desktop.
Local testing script to run UI tests using Bazel
set -e
export BITRISE_DEPLOY_DIR="/Users/lakshya.kapoor/src/reddit-ios"
export BITRISE_SOURCE_DIR="/Users/lakshya.kapoor/src/reddit-ios"
export BITRISE_PULL_REQUEST=29378
export REDDIT_BUILD_CONFIGURATION=Debug
export TEST_DEVICE_MODEL="com.apple.CoreSimulator.SimDeviceType.iPhone-14-Pro"
export LAUNCH_OPTIONS_JSON_PATH="/Users/lakshya.kapoor/src/reddit-ios/UITests/Resources/selected_smoke_tests.json"
export REDDIT_EXPERIMENTS_FOR_UI_SMOKE_TESTS="/Users/lakshya.kapoor/src/reddit-ios/experiments_to_test.txt"
# export GH_ENTERPRISE_TOKEN=$GITHUB_REDDIT_TOKEN
# export REDDIT_UI_TEST_TARGET_NAME="${REDDIT_UI_TEST_TARGET_NAME:-UISmokeTests}"
# tools/ui_tests/scripts/create_test_targets_for_experiments.sh $REDDIT_UI_TEST_TARGET_NAME
# rm "$BITRISE_SOURCE_DIR/UITests/UISmokeTests-variants/.DS_Store" || true
export REDDIT_BAZEL_TEST_TARGET='attr(tags,ui-test-variant,kind(ios_ui_test,//UITests/...))'
# REDDIT_IS_MOCK_COMPATIBLE and REDDIT_ENABLE_MOCK_RECORD_MODE are CI level
# kill switches to toggle network stubbing across all builds at once.
TEST_ARGS=()
TEST_ARGS+=(--test_env=REDDIT_IS_MOCK_COMPATIBLE=$REDDIT_IS_MOCK_COMPATIBLE)
TEST_ARGS+=(--test_env=REDDIT_ENABLE_MOCK_RECORD_MODE=$REDDIT_ENABLE_MOCK_RECORD_MODE)
# "Library not loaded: @rpath/XCTestSupport.framework/XCTestSupport" will prevent tests from starting
# if path to `XCTestSupport.framework` is not provided.
TEST_ARGS+=(--test_env=DYLD_FRAMEWORK_PATH="__PLATFORMS__/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks")
if [ -n "$REDDIT_RECORD_UI_TEST_FAILURE_VIDEOS" ]; then
TEST_ARGS+=(--test_env=REDDIT_RECORD_UI_TEST_FAILURE_VIDEOS=1)
fi
# Convert to space separate values
# TODO: Convert JSON to a TXT with expected format once everything is moved to uitest_standard_runner.
if [ ! -z "$LAUNCH_OPTIONS_JSON_PATH" ]; then
TESTS=$(jq -r '.only_test_identifiers[] | gsub("[\\n\\t]"; " ")' $LAUNCH_OPTIONS_JSON_PATH)
TEST_ARGS+=("--test_filter=$TESTS")
fi
bazelisk \
test \
--cache_test_results=no \
--local_test_jobs=1 \
--zip_undeclared_test_outputs=false \
"${TEST_ARGS[@]}" \
$(bazel query "$REDDIT_BAZEL_TEST_TARGET") || echo "Test logs: $(find bazel-out/ -name "test.log")"
# Reddit home grown runner
#
# Boot sim
# OUTPUT=$(./tools/snoozel/scripts/prepare_sim.py)
# PREPARE_SIM_EXITCODE=$?
# PARTS=(${OUTPUT//,/ })
# export SIMULATOR_NAME=${PARTS[0]}
# export SIMULATOR_UDID=${PARTS[1]}
#
# Start test
# bazelisk \
# coverage \
# --cache_test_results=no \
# --local_test_jobs=1 \
# --test_arg=--simulator_name="$SIMULATOR_NAME" \
# --test_arg=--launch_options_json_path="/Users/lakshya.kapoor/src/reddit-ios/UITests/Resources/selected_smoke_tests.json" \
# "//UITests:UISmokeTests" || echo "Test logs: $(find bazel-out/ -name "test.log")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment