Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,42 @@ jobs:
- name: Test SDK
run: make test

# `make test` runs `swift test` on macOS, which compiles out every `#if os(iOS)` block, so the
# iOS-only suites (session replay, autocapture, tracing headers, crash reporting, etc.) never run
# there. Run the iOS test target on a simulator so those suites are actually exercised in CI.
test-ios-simulator:
runs-on: macos-15
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1.7.0
with:
xcode-version: latest-stable
- name: Test SDK on iOS Simulator
# Retries (3 iterations) protect merges from transient simulator flakiness; the macOS `test`
# job runs without retries, so a genuine flake still surfaces as a hard failure there.
run: make testOniOSSimulator
- name: Report flaky (retried) tests
# Retries can hide flakiness by turning a transient red into green. Surface any test that only
# passed after a retry so flakes get tracked and fixed instead of silently masked. Best-effort:
# never fails the job.
if: always()
run: |
log=xcodebuild-ios.log
[ -f "$log" ] || { echo "No build log found; skipping flake report."; exit 0; }
# A test that has both a 'failed' and a 'passed' line was retried (flaky). Handle both the
# Swift Testing format (βœ” Test "name" passed) and the XCTest format (Test Case '-[…]' passed).
passed=$( { grep -oE 'Test "[^"]+" passed' "$log" | sed -E 's/^Test "//; s/" passed$//'; \
grep -oE "Test Case '[^']+' passed" "$log" | sed -E "s/^Test Case '//; s/' passed$//"; } | sort -u)
failed=$( { grep -oE 'Test "[^"]+" failed' "$log" | sed -E 's/^Test "//; s/" failed$//'; \
grep -oE "Test Case '[^']+' failed" "$log" | sed -E "s/^Test Case '//; s/' failed$//"; } | sort -u)
flaky=$(comm -12 <(printf '%s\n' "$failed") <(printf '%s\n' "$passed") | grep -v '^$' || true)
if [ -n "$flaky" ]; then
{ echo "### ⚠️ Flaky tests (passed only after a retry)"; echo; echo '```'; echo "$flaky"; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
echo "::warning::Flaky tests detected (passed on retry); see the job summary."
else
echo "No flaky (retried) tests detected." >> "$GITHUB_STEP_SUMMARY"
fi

downgrade-compatibility:
runs-on: macos-15
strategy:
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,18 @@ swiftLint:
swiftFormat:
swiftformat . --swiftversion 5.3

# use -test-iterations 10 if you want to run the tests multiple times
# use -only-testing:PostHogTests/PostHogQueueTest to run only a specific test
# -retry-tests-on-failure -test-iterations 3: a few tests assert real-time behaviour (autocapture
# debounce/flush windows) that can't be made deterministic; on slow, load-variable CI runners those
# windows occasionally slip. Rerun a *failed* test up to 3 times so a transient miss doesn't fail the
# job β€” a genuinely broken test fails all 3 and stays red. Retries can *mask* flakiness, so we tee the
# raw log to xcodebuild-ios.log; CI reads it back to surface tests that only passed after a retry (the
# macOS `test` job runs without retries, so a genuine flake still hard-fails there).
testOniOSSimulator:
set -o pipefail && xcrun xcodebuild test -scheme PostHog -destination 'platform=iOS Simulator,name=iPhone 15,OS=latest' | xcpretty
@device="$$(xcrun simctl list devices available | grep -E '^[[:space:]]*iPhone' | head -1 | sed -E 's/^[[:space:]]*//; s/ \(.*//')"; \
[ -n "$$device" ] || { echo "No available iPhone simulator found; install one via Xcode or 'xcrun simctl create'."; exit 1; }; \
echo "Testing on simulator: $$device"; \
set -o pipefail && xcrun xcodebuild test -scheme PostHog -destination "platform=iOS Simulator,name=$$device" -retry-tests-on-failure -test-iterations 3 | tee xcodebuild-ios.log | xcpretty

testOnMacSimulator:
set -o pipefail && xcrun xcodebuild test -scheme PostHog -destination 'platform=macOS' | xcpretty
Expand Down
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ let package = Package(
"Nimble",
"OHHTTPStubs",
.product(name: "OHHTTPStubsSwift", package: "OHHTTPStubs"),
// SDK imports this @_implementationOnly, so @testable doesn't re-export it;
// the crash-report processor tests need it directly to build a PHPLCrashReport.
.target(name: "PHPLCrashReporter", condition: .when(platforms: [.iOS, .macOS, .tvOS])),
],
path: "PostHogTests",
resources: [
Expand Down
Loading
Loading