Skip to content

test(analytics-react-native): native iOS XCTest coverage for connectivity module (SDKRN-5) [2.1/5]#1823

Open
Mercy811 wants to merge 7 commits into
sdkrn-5-offline-2-iosfrom
sdkrn-5-offline-3-ios-tests
Open

test(analytics-react-native): native iOS XCTest coverage for connectivity module (SDKRN-5) [2.1/5]#1823
Mercy811 wants to merge 7 commits into
sdkrn-5-offline-2-iosfrom
sdkrn-5-offline-3-ios-tests

Conversation

@Mercy811

@Mercy811 Mercy811 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Part of SDKRN-23 (iOS native connectivity module).

PR 2.1 of 5 in the SDKRN-5 offline-mode stack. Stacked on #1819 (base branch sdkrn-5-offline-2-ios).

Adds native iOS XCTest coverage for AmplitudeReactNativeConnectivity — the follow-up promised in #1819. The key behavior under test: NWPathMonitor delivers the current path as its first update once monitoring starts, the contract the optimistic {isConnected: true} seed in getNetworkConnectivityStatus relies on.

Where the tests live (and why)

The test source lives in the SDK package — packages/analytics-react-native/ios/Tests/AmplitudeConnectivityTests.swift — but is compiled and run by the example app's existing appTests XCTest target, which acts purely as host/runner. A standalone run inside the package isn't possible: the module subclasses RCTEventEmitter, so the tests need React-Core compiled/linked, and RN library pods can't build outside an RN app's pod ecosystem (this is why create-react-native-library runs native tests via the example app too). s.exclude_files = "ios/Tests/**" keeps the XCTest sources out of the shipped pod (verified: absent from the generated Pods project).

Changes

  • New tests (4): seed resolves connected; startObserving() → initial AmplitudeNetworkConnectivityChanged with isConnected == true (real NWPathMonitor); no events after stopObserving(); supportedEvents. An EventCapturingConnectivity subclass overrides sendEvent(withName:body:) to capture events without a live RCTBridge.
  • Module visibility only, no behavior change: classopen class; overridden members marked open/public so the test target can subclass/call them (Swift also requires the static requiresMainQueueSetup override to be public once the class is open).
  • Example app: stale RN template appTests.m ("Welcome to React", never rendered by this app, Metro-dependent) deleted; the SDK test file wired into appTests by file reference; SWIFT_VERSION = 5.0 on the appTests configs. Podfile.lock refreshed (podspec checksum + stale 1.5.54 → 1.5.56 version catch-up).
  • CI: rn-smoke.yml runs xcodebuild test after the iOS build on both arch legs, reusing the same -derivedDataPath so pod compilation is shared; Release config so the host app uses the embedded JS bundle (no Metro).
PR Adds Base
#1802 JS plugin + wiring + tests + no-op native stubs main
#1819 [2/5] Real iOS module (replaces iOS stub) #1802
this [2.1/5] Native iOS XCTest coverage #1819
(next) [3/5] Real Android module (replaces Android stub) #1819
(next) [4/5] Robolectric tests
[5/5] Example app — already merged (#1803)

Test plan

  • Local xcodebuild test (Release, iPhone 16 simulator): all 4 tests pass.
  • Negative check: with monitor.start(queue:) commented out, testEmitsInitialPathUpdateAfterStartObserving fails at its 10s timeout — the suite genuinely exercises the monitor contract.
  • pnpm --filter @amplitude/analytics-react-native test: jest suite unaffected (108 tests / 11 suites pass).
  • rn-smoke CI must pass the new XCTest step on both new-arch legs.

🤖 Generated with Claude Code

@linear-code

linear-code Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

SDKRN-5

SDKRN-23

@Mercy811 Mercy811 changed the title test(analytics-react-native): add native iOS XCTest coverage for connectivity module (SDKRN-5) test(analytics-react-native): native iOS XCTest coverage for connectivity module (SDKRN-5) [2.1/5] Jun 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7b5b433dcd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/rn-smoke.yml
@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

size-limit report 📦

Path Size
packages/analytics-browser/lib/scripts/amplitude-min.js.gz 58.42 KB (0%)
packages/session-replay-browser/lib/scripts/session-replay-browser-min.js.gz 132.01 KB (0%)
packages/unified/lib/scripts/amplitude-min.umd.js.gz 209.46 KB (0%)
@amplitude/element-selector (gzipped esm) 1.75 KB (0%)

Comment thread examples/react-native/app/ios/app.xcodeproj/project.pbxproj Outdated
Comment thread packages/analytics-react-native/ios/Tests/AmplitudeConnectivityTests.swift Outdated
Mercy811 and others added 5 commits June 23, 2026 09:48
…ectivity module (SDKRN-5)

Test source lives in packages/analytics-react-native/ios/Tests (excluded
from the shipped pod via exclude_files); the example app's appTests
target compiles it as host/runner, replacing the stale RN template test.
rn-smoke runs xcodebuild test after the iOS build on both arch legs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
xcodebuild test leaves its destination simulator booted, so the
unconditional simctl boot that follows would fail with "Unable to boot
device in current state: Booted". bootstatus -b boots only if needed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Use lock.withLock {} instead of manual lock()/defer unlock() in the
  EventCapturingConnectivity test helper.
- Reference the test file group-relative ("<group>") instead of
  SOURCE_ROOT in the example app's Xcode project.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Mercy811 Mercy811 force-pushed the sdkrn-5-offline-3-ios-tests branch from b52af25 to ece5968 Compare June 23, 2026 16:59
Mercy811 and others added 2 commits June 23, 2026 10:30
The appTests XCTest target imports the module as a separate module, so
the internal `init()` was invisible and EventCapturingConnectivity could
not be constructed ("no accessible initializers"). Mark it public, like
the other members exposed for the test subclass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
getNetworkConnectivityStatus seeds {isConnected: false} (so startup
events buffer until the monitor reports real status). The test still
asserted the old optimistic-connected seed; update it to expect
disconnected and refresh the stale doc comment on the path-update test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants