@bugsee/react-native 0.0.0-stage → 7.0.0-beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/BugseeReactNative.podspec +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +557 -2
  4. package/android/build.gradle +162 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +33 -0
  7. package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
  8. package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
  9. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
  10. package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
  11. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
  12. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
  13. package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
  14. package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
  15. package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
  16. package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
  17. package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
  18. package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
  19. package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
  20. package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
  21. package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
  22. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
  23. package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
  24. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
  25. package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
  26. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
  27. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
  28. package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
  29. package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
  30. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
  31. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
  32. package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
  33. package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
  34. package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
  35. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
  36. package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
  37. package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
  38. package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
  39. package/app.plugin.js +4 -0
  40. package/ios/BGSRNConsoleCapture.h +52 -0
  41. package/ios/BGSRNConsoleCapture.mm +344 -0
  42. package/ios/BugseeModule.h +25 -0
  43. package/ios/BugseeModule.mm +2728 -0
  44. package/ios/Package.swift +71 -0
  45. package/ios/Support/Package.resolved +14 -0
  46. package/ios/Support/Package.swift +44 -0
  47. package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
  48. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
  49. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
  50. package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
  51. package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
  52. package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
  53. package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
  54. package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
  55. package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
  56. package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
  57. package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
  58. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
  59. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
  60. package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
  61. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
  62. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
  63. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
  64. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
  65. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
  66. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
  67. package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
  68. package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
  69. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
  70. package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
  71. package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
  72. package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
  73. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
  74. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
  75. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
  76. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
  77. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
  78. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
  79. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
  80. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
  81. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
  82. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
  83. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
  84. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
  85. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
  86. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
  87. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
  88. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
  89. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
  90. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
  91. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
  92. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
  93. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
  94. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
  95. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
  96. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
  97. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
  98. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
  99. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
  100. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
  101. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
  102. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
  103. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
  104. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
  105. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
  106. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
  107. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
  108. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
  109. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
  110. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
  111. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
  112. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
  113. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
  114. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
  115. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
  116. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
  117. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
  118. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
  119. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
  120. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
  121. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
  122. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
  123. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
  124. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
  125. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
  126. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
  127. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
  128. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
  129. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
  130. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
  131. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
  132. package/ios/react-native-spm-prefix.h +10 -0
  133. package/native-versions.json +10 -0
  134. package/package.json +62 -3
  135. package/plugin/build/bundle-phase.d.ts +41 -0
  136. package/plugin/build/bundle-phase.js +116 -0
  137. package/plugin/build/bundle-phase.js.map +1 -0
  138. package/plugin/build/dsym-script.d.ts +32 -0
  139. package/plugin/build/dsym-script.js +159 -0
  140. package/plugin/build/dsym-script.js.map +1 -0
  141. package/plugin/build/endpoint.d.ts +30 -0
  142. package/plugin/build/endpoint.js +69 -0
  143. package/plugin/build/endpoint.js.map +1 -0
  144. package/plugin/build/gradle.d.ts +65 -0
  145. package/plugin/build/gradle.js +1066 -0
  146. package/plugin/build/gradle.js.map +1 -0
  147. package/plugin/build/index.d.ts +85 -0
  148. package/plugin/build/index.js +217 -0
  149. package/plugin/build/index.js.map +1 -0
  150. package/plugin/build/manifest.d.ts +48 -0
  151. package/plugin/build/manifest.js +69 -0
  152. package/plugin/build/manifest.js.map +1 -0
  153. package/plugin/build/native-versions.baked.json +4 -0
  154. package/plugin/build/native-versions.d.ts +10 -0
  155. package/plugin/build/native-versions.js +27 -0
  156. package/plugin/build/native-versions.js.map +1 -0
  157. package/plugin/build/pbx-string.d.ts +8 -0
  158. package/plugin/build/pbx-string.js +31 -0
  159. package/plugin/build/pbx-string.js.map +1 -0
  160. package/plugin/build/podfile.d.ts +3 -0
  161. package/plugin/build/podfile.js +28 -0
  162. package/plugin/build/podfile.js.map +1 -0
  163. package/plugin/build/properties.d.ts +19 -0
  164. package/plugin/build/properties.js +41 -0
  165. package/plugin/build/properties.js.map +1 -0
  166. package/plugin/build/scheme.d.ts +20 -0
  167. package/plugin/build/scheme.js +107 -0
  168. package/plugin/build/scheme.js.map +1 -0
  169. package/react-native.config.js +26 -0
  170. package/scripts/bugsee-sourcemaps.gradle +201 -0
  171. package/scripts/bugsee-xcode.sh +83 -0
  172. package/scripts/compose-then-inject.js +113 -0
  173. package/scripts/hermes-sourcemaps.js +634 -0
  174. package/scripts/hermesc-preserve-js.cmd +6 -0
  175. package/scripts/hermesc-preserve-js.js +200 -0
  176. package/scripts/hermesc-preserve-js.sh +7 -0
  177. package/src/NativeBugsee.ts +622 -0
  178. package/src/apm/notify.ts +58 -0
  179. package/src/apm/span.ts +403 -0
  180. package/src/apm/types.ts +57 -0
  181. package/src/appearance/report.ts +171 -0
  182. package/src/architecture.ts +48 -0
  183. package/src/attributes/errors.ts +39 -0
  184. package/src/attributes/validate.ts +150 -0
  185. package/src/breadcrumbs/add.ts +58 -0
  186. package/src/breadcrumbs/data.ts +33 -0
  187. package/src/breadcrumbs/filter.ts +215 -0
  188. package/src/breadcrumbs/types.ts +64 -0
  189. package/src/bridge/json.ts +110 -0
  190. package/src/console/capture.ts +180 -0
  191. package/src/console/dedup.ts +175 -0
  192. package/src/data/validate.ts +259 -0
  193. package/src/errorName.ts +32 -0
  194. package/src/exceptions/ErrorBoundary.tsx +92 -0
  195. package/src/exceptions/RootErrorReporter.tsx +61 -0
  196. package/src/exceptions/debugIds.ts +118 -0
  197. package/src/exceptions/handlers.ts +236 -0
  198. package/src/exceptions/options.ts +85 -0
  199. package/src/exceptions/payload.ts +456 -0
  200. package/src/exceptions/report.ts +170 -0
  201. package/src/exceptions/sha1.ts +148 -0
  202. package/src/exceptions/stack.ts +355 -0
  203. package/src/index.ts +962 -0
  204. package/src/logs/filter.ts +90 -0
  205. package/src/logs/log.ts +36 -0
  206. package/src/network/add.ts +165 -0
  207. package/src/network/filter.ts +198 -0
  208. package/src/options/AndroidLaunchOptions.ts +78 -0
  209. package/src/options/BugseeLaunchOptions.ts +190 -0
  210. package/src/options/IOSLaunchOptions.ts +57 -0
  211. package/src/options/android-options-manifest.json +646 -0
  212. package/src/options/createDefaultLaunchOptions.ts +29 -0
  213. package/src/options/endpoint.ts +58 -0
  214. package/src/options/enums.ts +104 -0
  215. package/src/options/ios-enums.json +19 -0
  216. package/src/options/keys.ts +39 -0
  217. package/src/options/option-enums.json +34 -0
  218. package/src/options/option-keys.json +107 -0
  219. package/src/report/BugseeReport.ts +264 -0
  220. package/src/report/CreatedReport.ts +127 -0
  221. package/src/report/dispatcher.ts +95 -0
  222. package/src/report/errors.ts +48 -0
  223. package/src/report/fields.ts +40 -0
  224. package/src/report/types.ts +157 -0
  225. package/src/report/validate.ts +197 -0
  226. package/src/secure/BugseeSecure.tsx +202 -0
  227. package/src/secure/ancestry.ts +622 -0
  228. package/src/secure/drivers.ts +342 -0
  229. package/src/secure/followEvents.ts +57 -0
  230. package/src/secure/hold.ts +99 -0
  231. package/src/secure/measureLoop.ts +323 -0
  232. package/src/secure/nativeAnimation.ts +1005 -0
  233. package/src/secure/rectangles.ts +93 -0
  234. package/src/secure/registry.ts +237 -0
  235. package/src/secure/surface.ts +83 -0
  236. package/src/secure/tracker.ts +723 -0
  237. package/src/secure/transition.ts +488 -0
  238. package/src/secure/unit.ts +22 -0
  239. package/src/status.ts +16 -0
  240. package/src/version.ts +9 -0
  241. package/src/viewtree/anchor.tsx +105 -0
  242. package/src/viewtree/constants.ts +20 -0
  243. package/src/viewtree/fiber.ts +251 -0
  244. package/src/viewtree/requests.ts +347 -0
  245. package/src/viewtree/walk.ts +902 -0
  246. package/src/wrapper/channel.ts +33 -0
  247. package/src/wrapper/collect.ts +52 -0
  248. package/src/wrapper/events.ts +45 -0
  249. package/src/wrapper/identity.ts +54 -0
  250. package/src/wrapper/lifecycle-events.ts +89 -0
@@ -0,0 +1,134 @@
1
+ @import XCTest;
2
+ @import BugseeRNSupport;
3
+
4
+ #import <stdatomic.h>
5
+
6
+ /// Pins `BGSRNSettleOnce`: a promise-returning native method must settle
7
+ /// exactly once even when the SDK never calls its completion (iOS simulator
8
+ /// verified fact for `logUnhandledException`).
9
+ @interface BGSRNSettleOnceTests : XCTestCase
10
+ @end
11
+
12
+ @implementation BGSRNSettleOnceTests
13
+
14
+ - (void)tearDown {
15
+ BGSRNSettleOnceRaceWindow = nil;
16
+ [super tearDown];
17
+ }
18
+
19
+ - (void)testSettlesOnceWhenCalled {
20
+ XCTestExpectation *settled = [self expectationWithDescription:@"settle ran"];
21
+ __block NSInteger count = 0;
22
+
23
+ dispatch_queue_t queue = dispatch_queue_create("com.bugsee.rn.settle-once.test", DISPATCH_QUEUE_SERIAL);
24
+ dispatch_block_t trigger = BGSRNSettleOnce(5000, queue, ^{
25
+ count += 1;
26
+ [settled fulfill];
27
+ });
28
+
29
+ trigger();
30
+ trigger();
31
+
32
+ [self waitForExpectations:@[ settled ] timeout:2];
33
+ XCTAssertEqual(count, 1);
34
+ XCTAssertEqual(BGSRNUnhandledCompletionDeadlineMs, 1500);
35
+ }
36
+
37
+ - (void)testSettlesAtTheDeadlineWhenNeverCalled {
38
+ XCTestExpectation *settled = [self expectationWithDescription:@"deadline settle"];
39
+ __block NSInteger count = 0;
40
+
41
+ dispatch_queue_t queue = dispatch_queue_create("com.bugsee.rn.settle-once.deadline", DISPATCH_QUEUE_SERIAL);
42
+ (void)BGSRNSettleOnce(50, queue, ^{
43
+ count += 1;
44
+ [settled fulfill];
45
+ });
46
+
47
+ [self waitForExpectations:@[ settled ] timeout:2];
48
+ XCTAssertEqual(count, 1);
49
+ }
50
+
51
+ - (void)testACallAfterTheDeadlineDoesNothing {
52
+ XCTestExpectation *settled = [self expectationWithDescription:@"deadline only"];
53
+ __block NSInteger count = 0;
54
+
55
+ dispatch_queue_t queue = dispatch_queue_create("com.bugsee.rn.settle-once.after", DISPATCH_QUEUE_SERIAL);
56
+ dispatch_block_t trigger = BGSRNSettleOnce(50, queue, ^{
57
+ count += 1;
58
+ [settled fulfill];
59
+ });
60
+
61
+ [self waitForExpectations:@[ settled ] timeout:2];
62
+ XCTAssertEqual(count, 1);
63
+
64
+ trigger();
65
+ // Give any late call a turn on the queue; count must stay 1.
66
+ XCTestExpectation *quiet = [self expectationWithDescription:@"quiet after"];
67
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(100 * NSEC_PER_MSEC)), queue, ^{
68
+ [quiet fulfill];
69
+ });
70
+ [self waitForExpectations:@[ quiet ] timeout:2];
71
+ XCTAssertEqual(count, 1);
72
+ }
73
+
74
+ /// Two threads share a two-phase barrier around the once-flag load. An atomic
75
+ /// exchange still settles once; a plain `BOOL` lets both through. The barrier
76
+ /// makes that race deterministic rather than relying on luck.
77
+ ///
78
+ /// `settle` runs on the caller threads, not the serial deadline queue, so the
79
+ /// counter is atomic: a non-atomic `count += 1` can lose a double-settle and
80
+ /// leave mutate (3) green while settling twice.
81
+ - (void)testTwoConcurrentCallsSettleOnce {
82
+ __block atomic_int count = 0;
83
+ dispatch_queue_t queue = dispatch_queue_create("com.bugsee.rn.settle-once.race", DISPATCH_QUEUE_SERIAL);
84
+ // No deadline. A positive deadline is a third caller into this two-party
85
+ // barrier, and on a slow CI runner it fires while the two threads are still
86
+ // parked and steals a `go` signal. The threads then never leave the group.
87
+ dispatch_block_t trigger = BGSRNSettleOnce(0, queue, ^{
88
+ atomic_fetch_add_explicit(&count, 1, memory_order_relaxed);
89
+ });
90
+
91
+ // One pair per window. A shared `go` lets the faster caller leave the
92
+ // first window, enter the second, and consume the other caller's release.
93
+ // That caller then never reaches the second window (CI: caller 3 timed out).
94
+ dispatch_semaphore_t entered0 = dispatch_semaphore_create(0);
95
+ dispatch_semaphore_t entered1 = dispatch_semaphore_create(0);
96
+ dispatch_semaphore_t release0 = dispatch_semaphore_create(0);
97
+ dispatch_semaphore_t release1 = dispatch_semaphore_create(0);
98
+ BGSRNSettleOnceRaceWindow = ^{
99
+ static _Thread_local int phase = 0;
100
+ const int step = phase++;
101
+ dispatch_semaphore_signal(step == 0 ? entered0 : entered1);
102
+ dispatch_semaphore_wait(step == 0 ? release0 : release1, DISPATCH_TIME_FOREVER);
103
+ };
104
+
105
+ dispatch_group_t group = dispatch_group_create();
106
+ for (int i = 0; i < 2; i++) {
107
+ dispatch_group_async(group, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
108
+ trigger();
109
+ });
110
+ }
111
+
112
+ // Window 0: both arrive before the load. Window 1: both have loaded.
113
+ // A finite wait: DISPATCH_TIME_FOREVER here never returns if a caller fails
114
+ // to arrive, and xcodebuild then sits until the job is killed. The deadline
115
+ // is per window so the first window cannot consume the second's budget.
116
+ dispatch_semaphore_t entered[2] = {entered0, entered1};
117
+ dispatch_semaphore_t release[2] = {release0, release1};
118
+ for (int phase = 0; phase < 2; phase++) {
119
+ const dispatch_time_t arrived = dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC);
120
+ XCTAssertEqual(dispatch_semaphore_wait(entered[phase], arrived), 0,
121
+ @"caller 0 did not reach window %d", phase);
122
+ XCTAssertEqual(dispatch_semaphore_wait(entered[phase], arrived), 0,
123
+ @"caller 1 did not reach window %d", phase);
124
+ dispatch_semaphore_signal(release[phase]);
125
+ dispatch_semaphore_signal(release[phase]);
126
+ }
127
+
128
+ XCTAssertEqual(dispatch_group_wait(group, dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC)), 0,
129
+ @"concurrent callers did not finish");
130
+ XCTAssertEqual(atomic_load_explicit(&count, memory_order_relaxed), 1,
131
+ @"two concurrent calls settled more than once");
132
+ }
133
+
134
+ @end
@@ -0,0 +1,153 @@
1
+ @import XCTest;
2
+ @import Bugsee;
3
+ @import BugseeRNSupport;
4
+
5
+ @interface BGSRNFakeSpan : NSObject <BGSRNRetainedSpan>
6
+ @property (nonatomic) BOOL finished;
7
+ @property (nonatomic, strong) NSNumber *finishedWith;
8
+ @property (nonatomic, strong) NSMutableArray<BGSRNFakeSpan *> *children;
9
+ @end
10
+
11
+ @implementation BGSRNFakeSpan
12
+
13
+ - (instancetype)init {
14
+ self = [super init];
15
+ if (self) {
16
+ _children = [NSMutableArray array];
17
+ }
18
+ return self;
19
+ }
20
+
21
+ - (void)bgsrnFinishWithStatus:(NSNumber *)status {
22
+ if (_finished) {
23
+ return;
24
+ }
25
+ _finished = YES;
26
+ _finishedWith = status;
27
+ for (BGSRNFakeSpan *child in _children) {
28
+ if (!child.finished) {
29
+ [child bgsrnFinishWithStatus:@(BGSSpanStatusCancelled)];
30
+ }
31
+ }
32
+ }
33
+
34
+ - (BOOL)bgsrnIsFinished {
35
+ return _finished;
36
+ }
37
+
38
+ @end
39
+
40
+ @interface BGSRNStickySpan : NSObject <BGSRNRetainedSpan>
41
+ @property (nonatomic) BOOL finishCalled;
42
+ @end
43
+
44
+ @implementation BGSRNStickySpan
45
+ - (void)bgsrnFinishWithStatus:(NSNumber *)status {
46
+ _finishCalled = YES;
47
+ }
48
+ - (BOOL)bgsrnIsFinished {
49
+ return NO;
50
+ }
51
+ @end
52
+
53
+ @interface BGSRNSpanHandlesTests : XCTestCase
54
+ @end
55
+
56
+ @implementation BGSRNSpanHandlesTests
57
+
58
+ /// The pin: after finish the registry must not still hold the span.
59
+ - (void)testAFinishedSpanIsReleased {
60
+ BGSRNSpanHandles *handles = [BGSRNSpanHandles new];
61
+ BGSRNFakeSpan *span = [BGSRNFakeSpan new];
62
+ NSString *handle = [handles retainSpan:span adapter:span];
63
+ NSArray<NSString *> *released = [handles finishHandle:handle status:nil];
64
+ XCTAssertEqualObjects(released, @[handle]);
65
+ XCTAssertTrue(span.finished);
66
+ XCTAssertNil(span.finishedWith);
67
+ XCTAssertFalse([handles containsHandle:handle]);
68
+ XCTAssertEqual(handles.liveCount, 0u);
69
+ }
70
+
71
+ - (void)testFinishingAParentReleasesAFinishedChild {
72
+ BGSRNSpanHandles *handles = [BGSRNSpanHandles new];
73
+ BGSRNFakeSpan *parent = [BGSRNFakeSpan new];
74
+ BGSRNFakeSpan *child = [BGSRNFakeSpan new];
75
+ [parent.children addObject:child];
76
+ NSString *parentHandle = [handles retainSpan:parent adapter:parent];
77
+ NSString *childHandle = [handles retainSpan:child adapter:child];
78
+ NSArray<NSString *> *released = [handles finishHandle:parentHandle status:nil];
79
+ XCTAssertTrue([released containsObject:parentHandle]);
80
+ XCTAssertTrue([released containsObject:childHandle]);
81
+ XCTAssertTrue(child.finished);
82
+ XCTAssertEqual(child.finishedWith.integerValue, (NSInteger)BGSSpanStatusCancelled);
83
+ XCTAssertFalse([handles containsHandle:childHandle]);
84
+ XCTAssertEqual(handles.liveCount, 0u);
85
+ }
86
+
87
+ - (void)testAnUnfinishedSpanStaysRetained {
88
+ BGSRNSpanHandles *handles = [BGSRNSpanHandles new];
89
+ BGSRNFakeSpan *finished = [BGSRNFakeSpan new];
90
+ BGSRNFakeSpan *live = [BGSRNFakeSpan new];
91
+ NSString *finishedHandle = [handles retainSpan:finished adapter:finished];
92
+ NSString *liveHandle = [handles retainSpan:live adapter:live];
93
+ [handles finishHandle:finishedHandle status:@(BGSSpanStatusError)];
94
+ XCTAssertFalse([handles containsHandle:finishedHandle]);
95
+ XCTAssertTrue([handles containsHandle:liveHandle]);
96
+ XCTAssertEqual(handles.liveCount, 1u);
97
+ XCTAssertEqual(finished.finishedWith.integerValue, (NSInteger)BGSSpanStatusError);
98
+ }
99
+
100
+ - (void)testTheSameSpanIsOneHandle {
101
+ BGSRNSpanHandles *handles = [BGSRNSpanHandles new];
102
+ BGSRNFakeSpan *span = [BGSRNFakeSpan new];
103
+ NSString *first = [handles retainSpan:span adapter:span];
104
+ NSString *second = [handles retainSpan:span adapter:[BGSRNFakeSpan new]];
105
+ XCTAssertEqualObjects(first, second);
106
+ XCTAssertEqual(handles.liveCount, 1u);
107
+ }
108
+
109
+ /// `finish` runs, and `isFinished` stays false. A no-op span can do that.
110
+ - (void)testASpanThatStaysUnfinishedIsStillReleased {
111
+ BGSRNSpanHandles *handles = [BGSRNSpanHandles new];
112
+ BGSRNStickySpan *span = [BGSRNStickySpan new];
113
+ NSString *handle = [handles retainSpan:span adapter:span];
114
+ NSArray<NSString *> *released = [handles finishHandle:handle status:nil];
115
+ XCTAssertEqualObjects(released, @[handle]);
116
+ XCTAssertTrue(span.finishCalled);
117
+ XCTAssertFalse(span.bgsrnIsFinished);
118
+ XCTAssertFalse([handles containsHandle:handle]);
119
+ XCTAssertEqual(handles.liveCount, 0u);
120
+ }
121
+
122
+ - (void)testANilSpanIsNotRetained {
123
+ BGSRNSpanHandles *handles = [BGSRNSpanHandles new];
124
+ XCTAssertEqualObjects([handles retainSpan:nil adapter:[BGSRNFakeSpan new]], @"");
125
+ XCTAssertEqual(handles.liveCount, 0u);
126
+ }
127
+
128
+ /// The object `invalidate` returns. A later retain must not store anything.
129
+ - (void)testAClosedRegistryAdoptsNothing {
130
+ BGSRNSpanHandles *handles = [BGSRNSpanHandles closedRegistry];
131
+ BGSRNFakeSpan *span = [BGSRNFakeSpan new];
132
+ XCTAssertEqualObjects([handles retainSpan:span adapter:span], @"");
133
+ XCTAssertEqual(handles.liveCount, 0u);
134
+ XCTAssertEqualObjects([handles finishHandle:@"sp-1" status:nil], @[]);
135
+ }
136
+
137
+ - (void)testAnUnknownHandleReleasesNothing {
138
+ BGSRNSpanHandles *handles = [BGSRNSpanHandles new];
139
+ XCTAssertEqualObjects([handles finishHandle:@"sp-nope" status:nil], @[]);
140
+ XCTAssertEqual(handles.liveCount, 0u);
141
+ }
142
+
143
+ /// The wire integer is the SDK enum, not a second numbering.
144
+ - (void)testSpanStatusValuesMatchTheWire {
145
+ XCTAssertEqual((NSInteger)BGSSpanStatusOK, 0);
146
+ XCTAssertEqual((NSInteger)BGSSpanStatusError, 1);
147
+ XCTAssertEqual((NSInteger)BGSSpanStatusTimeout, 2);
148
+ XCTAssertEqual((NSInteger)BGSSpanStatusCancelled, 3);
149
+ XCTAssertEqual((NSInteger)BGSSpanStatusDeadlineExceeded, 4);
150
+ XCTAssertEqual((NSInteger)BGSSpanStatusUnknown, 5);
151
+ }
152
+
153
+ @end
@@ -0,0 +1,81 @@
1
+ @import XCTest;
2
+ @import Bugsee;
3
+ @import BugseeRNSupport;
4
+
5
+ /// The JS side has its own Status constants; these pin the mapping between
6
+ /// them and the SDK's enum. Getting it wrong is silent — a caller polling for
7
+ /// "launched" simply never sees it.
8
+ @interface BGSRNStatusMapperTests : XCTestCase
9
+ @end
10
+
11
+ @implementation BGSRNStatusMapperTests
12
+
13
+ - (void)testMapsEveryStatusToItsWireNumber {
14
+ XCTAssertEqual(0, BGSRNStatusToWire(BugseeStatusStopped));
15
+ XCTAssertEqual(1, BGSRNStatusToWire(BugseeStatusLaunching));
16
+ XCTAssertEqual(2, BGSRNStatusToWire(BugseeStatusLaunched));
17
+ XCTAssertEqual(3, BGSRNStatusToWire(BugseeStatusStopping));
18
+ }
19
+
20
+ /// An unrecognised status means "we could not tell", which is far closer to
21
+ /// stopped than launched: a caller waiting to start should keep waiting.
22
+ - (void)testMapsAnUnknownStatusToStopped {
23
+ XCTAssertEqual(0, BGSRNStatusToWire((BugseeStatus)99));
24
+ }
25
+
26
+ /// Distinct states must stay distinguishable — collapsing two onto one wire
27
+ /// number leaves a caller unable to tell launching from launched.
28
+ - (void)testGivesEveryStatusADistinctWireNumber {
29
+ NSMutableSet *seen = [NSMutableSet set];
30
+ BugseeStatus all[] = {BugseeStatusStopped, BugseeStatusLaunching,
31
+ BugseeStatusLaunched, BugseeStatusStopping};
32
+ for (NSUInteger i = 0; i < sizeof(all) / sizeof(all[0]); i++) {
33
+ NSNumber *wire = @(BGSRNStatusToWire(all[i]));
34
+ XCTAssertFalse([seen containsObject:wire], @"duplicate wire number %@", wire);
35
+ [seen addObject:wire];
36
+ }
37
+ }
38
+
39
+ /// The wire numbers are shared with the Android bridge, which pins the same
40
+ /// four in BugseeStatusMapper. They are API, not an implementation detail.
41
+ - (void)testWireNumbersMatchTheSharedContract {
42
+ XCTAssertEqual(0, BGSRNStatusWireStopped);
43
+ XCTAssertEqual(1, BGSRNStatusWireLaunching);
44
+ XCTAssertEqual(2, BGSRNStatusWireLaunched);
45
+ XCTAssertEqual(3, BGSRNStatusWireStopping);
46
+ }
47
+
48
+ @end
49
+
50
+ @interface BGSRNTokensTests : XCTestCase
51
+ @end
52
+
53
+ @implementation BGSRNTokensTests
54
+
55
+ - (void)testRejectsBlankTokens {
56
+ XCTAssertFalse(BGSRNTokenIsUsable(nil));
57
+ XCTAssertFalse(BGSRNTokenIsUsable(@""));
58
+ XCTAssertFalse(BGSRNTokenIsUsable(@" "));
59
+ XCTAssertFalse(BGSRNTokenIsUsable(@"\t\n"));
60
+ }
61
+
62
+ - (void)testAcceptsARealToken {
63
+ XCTAssertTrue(BGSRNTokenIsUsable(@"00000000-0000-4000-8000-000000000000"));
64
+ }
65
+
66
+ /// Surrounding whitespace is a copy-paste artefact, not a different token.
67
+ - (void)testAcceptsATokenPaddedWithWhitespace {
68
+ XCTAssertTrue(BGSRNTokenIsUsable(@" tok "));
69
+ }
70
+
71
+ /// JavaScript is not typed, and a TurboModule declaring `string` can still be
72
+ /// handed a number. Objective-C will not stop it: the pointer arrives typed as
73
+ /// NSString* and only blows up when a string selector is sent to it. Reject it
74
+ /// here instead of crashing inside the SDK.
75
+ - (void)testRejectsAValueThatIsNotAString {
76
+ XCTAssertFalse(BGSRNTokenIsUsable((NSString *)(id)@42));
77
+ XCTAssertFalse(BGSRNTokenIsUsable((NSString *)(id)@[ @"tok" ]));
78
+ XCTAssertFalse(BGSRNTokenIsUsable((NSString *)(id)[NSNull null]));
79
+ }
80
+
81
+ @end
@@ -0,0 +1,32 @@
1
+ @import XCTest;
2
+ @import BugseeRNSupport;
3
+
4
+ /// `+[Bugsee trace:value:]` boxed booleans must serialise as JSON booleans,
5
+ /// not as `0`/`1` numbers -- the SDK's JSON writer decides that by object
6
+ /// identity (`CFGetTypeID`), not by value, so these pin identity rather than
7
+ /// just the boolean value.
8
+ @interface BGSRNValuesTests : XCTestCase
9
+ @end
10
+
11
+ @implementation BGSRNValuesTests
12
+
13
+ - (void)testTrueIsTheCFBooleanSingleton {
14
+ NSNumber *value = BGSRNBoolNumber(YES);
15
+ XCTAssertEqual((__bridge CFBooleanRef)value, kCFBooleanTrue);
16
+ }
17
+
18
+ - (void)testFalseIsTheCFBooleanSingleton {
19
+ NSNumber *value = BGSRNBoolNumber(NO);
20
+ XCTAssertEqual((__bridge CFBooleanRef)value, kCFBooleanFalse);
21
+ }
22
+
23
+ /// The failure mode a plain `@((int)value)` boxing produces: a `Boolean`
24
+ /// number is indistinguishable from an `NSCFNumber`/integer to anything that
25
+ /// only checks value, which is exactly what the SDK's writer does not do --
26
+ /// it checks the CoreFoundation type ID.
27
+ - (void)testABoolNumberIsNotAnInteger {
28
+ NSNumber *value = BGSRNBoolNumber(YES);
29
+ XCTAssertEqual(CFGetTypeID((__bridge CFTypeRef)value), CFBooleanGetTypeID());
30
+ }
31
+
32
+ @end
@@ -0,0 +1,205 @@
1
+ @import XCTest;
2
+ @import Bugsee;
3
+ @import BugseeRNSupport;
4
+
5
+ /// Records every call it receives. Implements every optional channel method,
6
+ /// standing in for a live SDK channel.
7
+ @interface BGSRNFullWrapperChannel : NSObject <BGSWrapperChannel>
8
+ @property (nonatomic, strong, readonly) NSMutableArray<NSDictionary *> *lines;
9
+ @property (nonatomic, strong, readonly) NSMutableArray *events;
10
+ @property (nonatomic, strong, readonly) NSMutableArray<NSNumber *> *requiresFilteringCalls;
11
+ @end
12
+
13
+ @implementation BGSRNFullWrapperChannel
14
+
15
+ - (instancetype)init {
16
+ self = [super init];
17
+ if (self) {
18
+ _lines = [NSMutableArray array];
19
+ _events = [NSMutableArray array];
20
+ _requiresFilteringCalls = [NSMutableArray array];
21
+ }
22
+ return self;
23
+ }
24
+
25
+ - (void)logWithTag:(nullable NSString *)tag
26
+ message:(nullable NSString *)message
27
+ level:(BugseeLogLevel)level
28
+ source:(BGSLogEventSource)source {
29
+ [self.lines addObject:@{
30
+ @"tag" : tag ?: [NSNull null],
31
+ @"message" : message ?: [NSNull null],
32
+ @"level" : @(level),
33
+ @"source" : @(source),
34
+ }];
35
+ }
36
+
37
+ - (void)addNetworkEvent:(nullable BugseeNetworkEvent *)event
38
+ requiresFiltering:(BOOL)requiresFiltering {
39
+ [self.events addObject:event ?: [NSNull null]];
40
+ [self.requiresFilteringCalls addObject:@(requiresFiltering)];
41
+ }
42
+
43
+ @end
44
+
45
+ /// Conforms to the protocol but implements none of its @optional methods --
46
+ /// a channel shaped like one built against a newer SDK contract than this
47
+ /// wrapper compiles selectors for, or simply an incomplete test double.
48
+ @interface BGSRNChannelWithoutTheSelector : NSObject <BGSWrapperChannel>
49
+ @end
50
+
51
+ @implementation BGSRNChannelWithoutTheSelector
52
+ @end
53
+
54
+ @interface BGSRNWrapperChannelHolderTests : XCTestCase
55
+ @end
56
+
57
+ @implementation BGSRNWrapperChannelHolderTests
58
+
59
+ - (BugseeNetworkEvent *)networkEvent {
60
+ return [BugseeNetworkEvent eventWithID:@"1"
61
+ HTTPmethod:@"GET"
62
+ type:BugseeNetwork
63
+ bugseeEventType:nil
64
+ url:@"https://example.com"
65
+ redirectedUrl:nil
66
+ body:nil
67
+ error:nil
68
+ headers:nil
69
+ noBodyReason:nil
70
+ dataSize:0
71
+ responseCode:200];
72
+ }
73
+
74
+ /**
75
+ * Custom is the only honest attribution for a JS line; leaving it to the SDK
76
+ * reads as Unknown on iOS. The tag is nil because iOS has nowhere to put one.
77
+ */
78
+ - (void)testLogsWithSourceCustomAndNilTag {
79
+ BGSRNWrapperChannelHolder *holder = [BGSRNWrapperChannelHolder new];
80
+ BGSRNFullWrapperChannel *channel = [BGSRNFullWrapperChannel new];
81
+ holder.channel = channel;
82
+
83
+ [holder logMessage:@"hello" level:3];
84
+
85
+ XCTAssertEqual(channel.lines.count, (NSUInteger)1);
86
+ NSDictionary *line = channel.lines[0];
87
+ XCTAssertEqualObjects(line[@"tag"], [NSNull null]);
88
+ XCTAssertEqualObjects(line[@"message"], @"hello");
89
+ XCTAssertEqual([line[@"source"] integerValue], (NSInteger)BGSLogEventSourceCustom);
90
+ }
91
+
92
+ /**
93
+ * By value, never by ordinal: BugseeLogLevelInvalid is 0 at ordinal 0, so
94
+ * Error sits at ordinal 1 -- a bare `values()`-style walk would shift every
95
+ * level.
96
+ */
97
+ - (void)testMapsLevelsByValue {
98
+ BGSRNWrapperChannelHolder *holder = [BGSRNWrapperChannelHolder new];
99
+ BGSRNFullWrapperChannel *channel = [BGSRNFullWrapperChannel new];
100
+ holder.channel = channel;
101
+
102
+ const BugseeLogLevel expected[] = {
103
+ BugseeLogLevelError, BugseeLogLevelWarning, BugseeLogLevelInfo,
104
+ BugseeLogLevelDebug, BugseeLogLevelVerbose,
105
+ };
106
+ for (NSInteger wire = 1; wire <= 5; wire++) {
107
+ [holder logMessage:[NSString stringWithFormat:@"level %ld", (long)wire] level:wire];
108
+ }
109
+
110
+ XCTAssertEqual(channel.lines.count, (NSUInteger)5);
111
+ for (NSInteger i = 0; i < 5; i++) {
112
+ XCTAssertEqual([channel.lines[i][@"level"] integerValue], (NSInteger)expected[i],
113
+ @"wire %ld", (long)(i + 1));
114
+ }
115
+ }
116
+
117
+ /**
118
+ * JS rejects these before they cross, so reaching here is a bridge bug; the
119
+ * line is still worth keeping, at the neutral level -- never
120
+ * BugseeLogLevelInvalid, which is not a level a log line can honestly carry.
121
+ */
122
+ - (void)testOutOfRangeLevelBecomesInfo {
123
+ BGSRNWrapperChannelHolder *holder = [BGSRNWrapperChannelHolder new];
124
+ BGSRNFullWrapperChannel *channel = [BGSRNFullWrapperChannel new];
125
+ holder.channel = channel;
126
+
127
+ const NSInteger wires[] = { 0, 6 };
128
+ for (size_t i = 0; i < sizeof(wires) / sizeof(wires[0]); i++) {
129
+ [holder logMessage:[NSString stringWithFormat:@"level %ld", (long)wires[i]] level:wires[i]];
130
+ }
131
+
132
+ XCTAssertEqual(channel.lines.count, (NSUInteger)2);
133
+ for (NSDictionary *line in channel.lines) {
134
+ XCTAssertEqual([line[@"level"] integerValue], (NSInteger)BugseeLogLevelInfo);
135
+ XCTAssertNotEqual([line[@"level"] integerValue], (NSInteger)BugseeLogLevelInvalid);
136
+ }
137
+ }
138
+
139
+ /**
140
+ * The same table, exported for the app's own `Bugsee.log` lines, which the
141
+ * module sends to the SDK directly rather than through the channel.
142
+ */
143
+ - (void)testExportedLevelTableMatchesTheChannel {
144
+ XCTAssertEqual(BGSRNLogLevelForWireValue(1), BugseeLogLevelError);
145
+ XCTAssertEqual(BGSRNLogLevelForWireValue(2), BugseeLogLevelWarning);
146
+ XCTAssertEqual(BGSRNLogLevelForWireValue(3), BugseeLogLevelInfo);
147
+ XCTAssertEqual(BGSRNLogLevelForWireValue(4), BugseeLogLevelDebug);
148
+ XCTAssertEqual(BGSRNLogLevelForWireValue(5), BugseeLogLevelVerbose);
149
+ XCTAssertEqual(BGSRNLogLevelForWireValue(0), BugseeLogLevelInfo);
150
+ XCTAssertEqual(BGSRNLogLevelForWireValue(6), BugseeLogLevelInfo);
151
+ }
152
+
153
+ /**
154
+ * `NO` would also skip the SDK's own network sanitizer, not only the app's
155
+ * filter -- there is no case where this wrapper wants that.
156
+ */
157
+ - (void)testNetworkEventsAlwaysRequireFiltering {
158
+ BGSRNWrapperChannelHolder *holder = [BGSRNWrapperChannelHolder new];
159
+ BGSRNFullWrapperChannel *channel = [BGSRNFullWrapperChannel new];
160
+ holder.channel = channel;
161
+ BugseeNetworkEvent *event = [self networkEvent];
162
+
163
+ [holder addNetworkEvent:event];
164
+
165
+ XCTAssertEqual(channel.events.count, (NSUInteger)1);
166
+ XCTAssertEqualObjects(channel.events[0], event);
167
+ XCTAssertEqual(channel.requiresFilteringCalls.count, (NSUInteger)1);
168
+ XCTAssertTrue(channel.requiresFilteringCalls[0].boolValue);
169
+ }
170
+
171
+ /** Before registration delivers a channel there is nowhere to send anything. */
172
+ - (void)testNoChannelIsANoOp {
173
+ BGSRNWrapperChannelHolder *holder = [BGSRNWrapperChannelHolder new];
174
+
175
+ XCTAssertNoThrow([holder logMessage:@"nobody listening" level:3]);
176
+ XCTAssertNoThrow([holder addNetworkEvent:[self networkEvent]]);
177
+ }
178
+
179
+ /**
180
+ * Every channel method is @optional; a channel that implements neither must
181
+ * not crash the caller.
182
+ */
183
+ - (void)testAChannelWithoutTheSelectorIsANoOp {
184
+ BGSRNWrapperChannelHolder *holder = [BGSRNWrapperChannelHolder new];
185
+ holder.channel = [BGSRNChannelWithoutTheSelector new];
186
+
187
+ XCTAssertNoThrow([holder logMessage:@"nobody home" level:3]);
188
+ XCTAssertNoThrow([holder addNetworkEvent:[self networkEvent]]);
189
+ }
190
+
191
+ /** Clearing the channel retires it: nothing sent afterwards reaches it. */
192
+ - (void)testClearingRetiresTheChannel {
193
+ BGSRNWrapperChannelHolder *holder = [BGSRNWrapperChannelHolder new];
194
+ BGSRNFullWrapperChannel *channel = [BGSRNFullWrapperChannel new];
195
+ holder.channel = channel;
196
+
197
+ holder.channel = nil;
198
+ [holder logMessage:@"after clear" level:3];
199
+ [holder addNetworkEvent:[self networkEvent]];
200
+
201
+ XCTAssertEqual(channel.lines.count, (NSUInteger)0);
202
+ XCTAssertEqual(channel.events.count, (NSUInteger)0);
203
+ }
204
+
205
+ @end
@@ -0,0 +1,66 @@
1
+ @import XCTest;
2
+ @import BugseeRNSupport;
3
+
4
+ @interface BGSRNWrapperTests : XCTestCase
5
+ @end
6
+
7
+ @implementation BGSRNWrapperTests
8
+
9
+ - (void)testReportsWhatItWasGiven {
10
+ BGSRNWrapper *wrapper = [BGSRNWrapper wrapperWithIdentity:@{
11
+ @"type" : @"react_native",
12
+ @"version" : @"1.2.3",
13
+ @"build" : @"42",
14
+ @"context" : @{@"react-native" : @"0.87.1"},
15
+ }];
16
+
17
+ XCTAssertEqualObjects(wrapper.wrapperType, @"react_native");
18
+ XCTAssertEqualObjects(wrapper.wrapperVersion, @"1.2.3");
19
+ XCTAssertEqualObjects(wrapper.wrapperBuild, @"42");
20
+ XCTAssertEqualObjects(wrapper.context[@"react-native"], @"0.87.1");
21
+ }
22
+
23
+ /// The SDK declares these non-null. Reporting "unknown" is honest; an empty
24
+ /// string reads in a report as "this wrapper has no version".
25
+ - (void)testFallsBackToUnknownRatherThanEmpty {
26
+ BGSRNWrapper *wrapper = [BGSRNWrapper wrapperWithIdentity:@{@"version" : @""}];
27
+ XCTAssertEqualObjects(wrapper.wrapperType, @"unknown");
28
+ XCTAssertEqualObjects(wrapper.wrapperVersion, @"unknown");
29
+ }
30
+
31
+ - (void)testSurvivesAnIdentityThatIsNotADictionary {
32
+ BGSRNWrapper *wrapper = [BGSRNWrapper wrapperWithIdentity:(id) @"nonsense"];
33
+ XCTAssertEqualObjects(wrapper.wrapperType, @"unknown");
34
+ XCTAssertNil(wrapper.wrapperBuild);
35
+ }
36
+
37
+ - (void)testAllowsNoBuild {
38
+ XCTAssertNil([BGSRNWrapper wrapperWithIdentity:@{@"type" : @"react_native"}].wrapperBuild);
39
+ }
40
+
41
+ /// A number rendered as "1" cannot be told apart from a version the wrapper
42
+ /// actually reported, so a non-string value is dropped instead.
43
+ - (void)testDropsNonStringContextValues {
44
+ BGSRNWrapper *wrapper = [BGSRNWrapper wrapperWithIdentity:@{
45
+ @"context" : @{@"good" : @"yes", @"bad" : @1, @"worse" : [NSNull null]},
46
+ }];
47
+ XCTAssertEqualObjects(wrapper.context[@"good"], @"yes");
48
+ XCTAssertNil(wrapper.context[@"bad"]);
49
+ XCTAssertEqual(wrapper.context.count, (NSUInteger)1);
50
+ }
51
+
52
+ - (void)testHasNoContextWhenNoneWasSupplied {
53
+ XCTAssertNil([BGSRNWrapper wrapperWithIdentity:@{@"type" : @"x"}].context);
54
+ }
55
+
56
+ /// What module init registers, before JS exists to describe the runtime.
57
+ /// Anything else here would be a second, disagreeing answer.
58
+ - (void)testWithoutJsRuntimeCarriesOnlyTypeAndVersion {
59
+ BGSRNWrapper *wrapper = [BGSRNWrapper wrapperWithoutJsRuntime];
60
+ XCTAssertEqualObjects(wrapper.wrapperType, @"react_native");
61
+ XCTAssertEqualObjects(wrapper.wrapperVersion, @"7.0.0-beta2");
62
+ XCTAssertNil(wrapper.wrapperBuild);
63
+ XCTAssertEqual(wrapper.context.count, (NSUInteger)0);
64
+ }
65
+
66
+ @end
@@ -0,0 +1,10 @@
1
+ // CocoaPods injects an implicit Foundation/UIKit import through a generated
2
+ // .pch. SPM has no equivalent, so this is force-included instead via
3
+ // -include in Package.swift's cSettings and cxxSettings. Without it, any
4
+ // source relying on those ambient imports fails to compile under SPM while
5
+ // still building fine under CocoaPods — a difference that only shows up on
6
+ // whichever delivery path you test second.
7
+ #ifdef __OBJC__
8
+ #import <Foundation/Foundation.h>
9
+ #import <UIKit/UIKit.h>
10
+ #endif