test(ios): add XCTest unit-test infrastructure for native Swift modules#60
test(ios): add XCTest unit-test infrastructure for native Swift modules#60alichherawalla wants to merge 1 commit into
Conversation
Set up the complete iOS unit-test target (OffgridMobileTests) to cover the three custom native modules: - PDFExtractorModuleTests: creates a PDF programmatically, asserts text extraction, truncation, and rejection of invalid paths - CoreMLDiffusionModuleTests: verifies supportedEvents, isNpuSupported, isGenerating, isModelLoaded, cancelGeneration without a live bridge - DownloadManagerModuleTests: verifies supportedEvents event names Changes: - ios/OffgridMobileTests/OffgridMobileTests.swift — 12 XCTest cases - ios/OffgridMobile.xcodeproj/project.pbxproj — OffgridMobileTests target with BUNDLE_LOADER/TEST_HOST pointing at app binary - ios/Podfile + Podfile.lock — test target inherits Pods search paths - .github/workflows/test-ios.yml — CI workflow (push/PR to main) - package.json — test:ios npm script All 12 tests pass on the iPhone 16e simulator (iOS 26.2). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary of ChangesHello @alichherawalla, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the project's testing capabilities by integrating a comprehensive XCTest unit-test infrastructure for its native iOS Swift modules. This foundational work ensures the reliability and maintainability of critical native functionalities, while also streamlining the development workflow with new CI automation and local testing scripts. Additionally, it includes refactorings in the DownloadManagerScreen to improve code organization and prepare for future enhancements. Highlights
Changelog
Ignored Files
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #60 +/- ##
==========================================
+ Coverage 84.06% 84.14% +0.07%
==========================================
Files 68 68
Lines 6415 6426 +11
Branches 1803 1802 -1
==========================================
+ Hits 5393 5407 +14
Misses 649 649
+ Partials 373 370 -3
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request successfully establishes the XCTest unit-testing infrastructure for native Swift modules on iOS. It includes a comprehensive set of test cases for the PDFExtractor, CoreMLDiffusion, and DownloadManager modules, along with the necessary Xcode project and Podfile configurations. Additionally, the PR refactors the DownloadManagerScreen in React Native to improve code organization and testability, and adds a CI workflow for automated iOS testing. The changes are well-structured and follow best practices for React Native and iOS development.
| setTimeout(() => { | ||
| void loadActiveDownloads().then(() => { | ||
| if (dlId) cancelledKeysRef.current.delete(capturedKey); | ||
| }); | ||
| }, 1000); |
There was a problem hiding this comment.
Using setTimeout to wait for native state synchronization is brittle and can lead to race conditions or unnecessary delays in the UI. If the native cancelBackgroundDownload method is asynchronous, it should ideally return a Promise that resolves only when the operation is fully reflected in the native state, or the UI should rely on event-driven updates from the native side.
| let attrs: [NSAttributedString.Key: Any] = [.font: UIFont.systemFont(ofSize: 12)] | ||
| text.draw(in: CGRect(x: 72, y: 72, width: 468, height: 648), withAttributes: attrs) | ||
| } | ||
| try! data.write(to: url) |
There was a problem hiding this comment.
| } | ||
| ) | ||
|
|
||
| waitForExpectations(timeout: 5) |
There was a problem hiding this comment.
| if (upperName.includes(pattern)) return pattern; | ||
| } | ||
| const match = fileName.match(/[QqFf]\d+[_]?[KkMmSs]*/); | ||
| const match = /[QqFf]\d+_?[KkMmSs]*/.exec(fileName); |
There was a problem hiding this comment.


Summary
ios/OffgridMobileTests/OffgridMobileTests.swiftwith 12 XCTest cases covering all 3 custom native Swift modules (PDFExtractorModule, CoreMLDiffusionModule, DownloadManagerModule)OffgridMobileTestsunit-test target toproject.pbxprojwithBUNDLE_LOADER/TEST_HOSTwired to the app binary so@testable import OffgridMobileworkstarget 'OffgridMobileTests'toPodfilewithinherit! :search_pathsso the test target picks up Pods header search paths without relinking.github/workflows/test-ios.ymlCI workflow that runs on push/PR tomaintest:iosnpm script for local runsTest plan
xcodebuild build-for-testingcompiles cleanly (0 errors)CoreMLDiffusionModuleTests(5),DownloadManagerModuleTests(1),PDFExtractorModuleTests(3 — resolve, truncate, reject invalid path)npm run lint)npx tsc --noEmit)🤖 Generated with Claude Code