Skip to content

feat: Native iOS code coverage support#83

Open
mfazekas wants to merge 8 commits into
callstackincubator:mainfrom
mfazekas:feat/native-ios-coverage
Open

feat: Native iOS code coverage support#83
mfazekas wants to merge 8 commits into
callstackincubator:mainfrom
mfazekas:feat/native-ios-coverage

Conversation

@mfazekas
Copy link
Copy Markdown
Contributor

@mfazekas mfazekas commented Mar 25, 2026

Summary

Adds native iOS code coverage (LLVM profiling) for Swift/ObjC code exercised by harness tests. Users specify which pods to instrument in rn-harness.config.mjs — no Podfile changes required.

Tested end-to-end with rive-nitro-react-native (RNRive + RiveRuntime pods), producing valid lcov output covering 37 source files.

Changes

  • New @react-native-harness/coverage-ios package with auto-linked pod and CocoaPods post-install hook
  • Hook reads config directly (no dependency on config package schema version), injects coverage flags, patches app xcconfig with -force_load and -fprofile-instr-generate
  • coverage-collector.ts in platform-ios handles profraw merge and lcov export, including Xcode 16+ debug dylib binaries
  • Harness dispose flow collects native coverage before teardown

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 25, 2026

@mfazekas is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

@mfazekas mfazekas force-pushed the feat/native-ios-coverage branch from 6a33bbf to 8cd29d8 Compare March 25, 2026 13:23
@mfazekas
Copy link
Copy Markdown
Contributor Author

@V3RON any feedback on this PR adding native code coverage?!

@V3RON
Copy link
Copy Markdown
Contributor

V3RON commented Mar 27, 2026

Hey @mfazekas 👋
I had to finish some other tasks first, but I'll try to go through it over the weekend and get back to you on Sunday.

Comment thread packages/coverage-ios/HarnessCoverage.podspec Outdated
Comment thread packages/coverage-ios/package.json Outdated
Comment thread packages/coverage-ios/scripts/harness_coverage_hook.rb
mfazekas added 2 commits May 7, 2026 15:43
Add LLVM source-based profiling for native Swift/ObjC code via a new
@react-native-harness/coverage-ios package. Users specify pods to
instrument in rn-harness.config.mjs and coverage flags are injected
automatically at pod install time via Module.prepend on Pod::Installer.
Fix repo URLs (margelo -> callstackincubator) and extract config
loading into a separate script using @react-native-harness/config.
@mfazekas mfazekas force-pushed the feat/native-ios-coverage branch from 8cd29d8 to 4035c23 Compare May 7, 2026 14:14
mfazekas added 3 commits May 8, 2026 07:16
- Guard podspec require_relative and install_modules_dependencies
- Add @objc name annotation to prevent Swift name mangling
- Defer +load class lookup to main queue for Xcode 16+ dylib compat
- Read config directly instead of through Zod-validated schema
- Patch app xcconfig with -force_load and -fprofile-instr-generate
The harness reinstalls the app between test files, wiping the app
container. Move profraw output to /tmp/harness-coverage/ which persists
across app reinstalls on the simulator. Clean the directory at test run
start and after collection.
The direct config reading was a workaround for testing with the old
published config package. Since this PR updates the config schema,
they'll be published together and getConfig() will work correctly.
@mfazekas mfazekas marked this pull request as ready for review May 11, 2026 08:03
- Extract profrawDir as class-level constant
- Remove debug NSLogs, keep only error log
- Add one-line comment explaining ObjC +load bridge
- Rename config_json to pods_json
- Remove silent try/catch in resolve-coverage-pods
- Remove unnecessary 500ms delay before collection
- Align package.json with other packages, bump to 1.1.0
@mfazekas
Copy link
Copy Markdown
Contributor Author

@V3RON sorry for the slow fix loop. I think it's ready now, can you review it again?! Thanks!

@mfazekas mfazekas requested a review from V3RON May 11, 2026 08:04
@V3RON
Copy link
Copy Markdown
Contributor

V3RON commented May 12, 2026

Just to be sure: if there is no 'coverage-ios' package installed, Harness will still execute tests correctly, but it'll not return any data on coverage, correct?

@mfazekas mfazekas changed the title RFC: Native iOS code coverage support feat: Native iOS code coverage support May 12, 2026
@mfazekas
Copy link
Copy Markdown
Contributor Author

Just to be sure: if there is no 'coverage-ios' package installed, Harness will still execute tests correctly, but it'll not return any data on coverage, correct?

Yes, verified. If coverage-ios is not installed, at compile time no native code will be instrumented with coverage flags; at runtime coverage collection will return an empty result and a warning (if coverage.native.ios is configured). Existing users are not affected unless they explicitly install @react-native-harness/coverage-ios and set coverage.native.ios in their harness config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants