Skip to content

Commit 9de3d45

Browse files
fix(ttd): Add TimeToDisplay integration to force fetch the data (#4669)
1 parent 7301787 commit 9de3d45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1143
-355
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
- Change `gradle.projectsEvaluated` to `project.afterEvaluate` in the Sentry Gradle Plugin to fix tasks not being created when using `--configure-on-demand` ([#4687](https://github.com/getsentry/sentry-react-native/pull/4687))
3232
- Remove `SENTRY_FORCE_FOREGROUND` from Xcode Scripts as the underlying `--force-foreground` Sentry CLI is no-op since v2.37.0 ([#4689](https://github.com/getsentry/sentry-react-native/pull/4689))
33+
- TTID and TTFD use native getters instead of events to pass timestamps to the JS layer ([#4669](https://github.com/getsentry/sentry-react-native/pull/4669))
3334

3435
## 6.10.0
3536

packages/core/RNSentryAndroidTester/app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dependencies {
4343
implementation 'androidx.core:core-ktx:1.7.0'
4444
implementation 'androidx.appcompat:appcompat:1.4.1'
4545
implementation 'com.google.android.material:material:1.5.0'
46+
implementation 'androidx.test:core-ktx:1.6.1'
4647
testImplementation 'junit:junit:4.13.2'
4748
testImplementation 'org.mockito:mockito-core:5.10.0'
4849
testImplementation 'org.mockito.kotlin:mockito-kotlin:5.2.1'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
package io.sentry.react
2+
3+
import android.app.Activity
4+
import android.content.Context
5+
import androidx.test.core.app.ApplicationProvider
6+
import com.facebook.react.bridge.ReactApplicationContext
7+
import io.sentry.android.core.BuildInfoProvider
8+
import org.junit.Assert.assertNotNull
9+
import org.junit.Assert.assertNull
10+
import org.junit.Before
11+
import org.junit.Test
12+
import org.junit.runner.RunWith
13+
import org.mockito.Mockito.mock
14+
import org.mockito.MockitoAnnotations
15+
import org.mockito.kotlin.whenever
16+
import org.robolectric.RobolectricTestRunner
17+
18+
@RunWith(RobolectricTestRunner::class)
19+
class RNSentryOnDrawReporterTest {
20+
companion object {
21+
private const val TTID_PREFIX = RNSentryOnDrawReporterManager.TTID_PREFIX
22+
private const val TTFD_PREFIX = RNSentryOnDrawReporterManager.TTFD_PREFIX
23+
private const val SPAN_ID = "test-span-id"
24+
private const val NEW_SPAN_ID = "new-test-span-id"
25+
}
26+
27+
@Before
28+
fun setUp() {
29+
MockitoAnnotations.openMocks(this)
30+
}
31+
32+
@Test
33+
fun `when parentSpanId and timeToFullDisplay are set the next render timestamp is saved`() {
34+
val reporter = createTestRNSentryOnDrawReporterView()
35+
reporter.setFullDisplay(true)
36+
reporter.setParentSpanId(SPAN_ID)
37+
38+
assertNotNull(RNSentryTimeToDisplay.popTimeToDisplayFor(TTFD_PREFIX + SPAN_ID))
39+
}
40+
41+
@Test
42+
fun `when parentSpanId and timeToInitialDisplay are set the next render timestamp is saved`() {
43+
val reporter = createTestRNSentryOnDrawReporterView()
44+
reporter.setInitialDisplay(true)
45+
reporter.setParentSpanId(SPAN_ID)
46+
47+
assertNotNull(RNSentryTimeToDisplay.popTimeToDisplayFor(TTID_PREFIX + SPAN_ID))
48+
}
49+
50+
@Test
51+
fun `when parentSpanId and timeToFullDisplay are set the next render timestamp is saved - reversed order`() {
52+
val reporter = createTestRNSentryOnDrawReporterView()
53+
reporter.setParentSpanId(SPAN_ID)
54+
reporter.setFullDisplay(true)
55+
56+
assertNotNull(RNSentryTimeToDisplay.popTimeToDisplayFor(TTFD_PREFIX + SPAN_ID))
57+
}
58+
59+
@Test
60+
fun `when parentSpanId and timeToInitialDisplay are set the next render timestamp is saved - reversed order`() {
61+
val reporter = createTestRNSentryOnDrawReporterView()
62+
reporter.setParentSpanId(SPAN_ID)
63+
reporter.setInitialDisplay(true)
64+
65+
assertNotNull(RNSentryTimeToDisplay.popTimeToDisplayFor(TTID_PREFIX + SPAN_ID))
66+
}
67+
68+
@Test
69+
fun `when display flag and parentSpanId changes the next full display render is saved`() {
70+
val reporter = createTestRNSentryOnDrawReporterView()
71+
reporter.setFullDisplay(true)
72+
reporter.setParentSpanId(SPAN_ID)
73+
RNSentryTimeToDisplay.popTimeToDisplayFor(TTFD_PREFIX + SPAN_ID)
74+
75+
reporter.setFullDisplay(false)
76+
reporter.setFullDisplay(true)
77+
reporter.setParentSpanId(NEW_SPAN_ID)
78+
assertNotNull(RNSentryTimeToDisplay.popTimeToDisplayFor(TTFD_PREFIX + NEW_SPAN_ID))
79+
}
80+
81+
@Test
82+
fun `when display flag and parentSpanId changes the next initial display render is saved`() {
83+
val reporter = createTestRNSentryOnDrawReporterView()
84+
reporter.setInitialDisplay(true)
85+
reporter.setParentSpanId(SPAN_ID)
86+
RNSentryTimeToDisplay.popTimeToDisplayFor(TTID_PREFIX + SPAN_ID)
87+
88+
reporter.setInitialDisplay(false)
89+
reporter.setInitialDisplay(true)
90+
reporter.setParentSpanId(NEW_SPAN_ID)
91+
assertNotNull(RNSentryTimeToDisplay.popTimeToDisplayFor(TTID_PREFIX + NEW_SPAN_ID))
92+
}
93+
94+
@Test
95+
fun `when parentSpanId doesn't change the next full display render is not saved`() {
96+
val reporter = createTestRNSentryOnDrawReporterView()
97+
reporter.setFullDisplay(true)
98+
reporter.setParentSpanId(SPAN_ID)
99+
RNSentryTimeToDisplay.popTimeToDisplayFor(TTFD_PREFIX + SPAN_ID)
100+
101+
reporter.setFullDisplay(false)
102+
reporter.setFullDisplay(true)
103+
reporter.setParentSpanId(SPAN_ID)
104+
assertNull(RNSentryTimeToDisplay.popTimeToDisplayFor(TTFD_PREFIX + SPAN_ID))
105+
}
106+
107+
@Test
108+
fun `when parentSpanId doesn't change the next initial display render is not saved`() {
109+
val reporter = createTestRNSentryOnDrawReporterView()
110+
reporter.setInitialDisplay(true)
111+
reporter.setParentSpanId(SPAN_ID)
112+
RNSentryTimeToDisplay.popTimeToDisplayFor(TTID_PREFIX + SPAN_ID)
113+
114+
reporter.setInitialDisplay(false)
115+
reporter.setInitialDisplay(true)
116+
reporter.setParentSpanId(SPAN_ID)
117+
assertNull(RNSentryTimeToDisplay.popTimeToDisplayFor(TTID_PREFIX + SPAN_ID))
118+
}
119+
120+
@Test
121+
fun `when display flag doesn't change the next full display render is not saved`() {
122+
val reporter = createTestRNSentryOnDrawReporterView()
123+
reporter.setFullDisplay(true)
124+
reporter.setParentSpanId(SPAN_ID)
125+
RNSentryTimeToDisplay.popTimeToDisplayFor(TTFD_PREFIX + SPAN_ID)
126+
127+
reporter.setFullDisplay(true)
128+
assertNull(RNSentryTimeToDisplay.popTimeToDisplayFor(TTFD_PREFIX + SPAN_ID))
129+
}
130+
131+
@Test
132+
fun `when display flag doesn't change the next initial display render is not saved`() {
133+
val reporter = createTestRNSentryOnDrawReporterView()
134+
reporter.setInitialDisplay(true)
135+
reporter.setParentSpanId(SPAN_ID)
136+
RNSentryTimeToDisplay.popTimeToDisplayFor(TTID_PREFIX + SPAN_ID)
137+
138+
reporter.setInitialDisplay(true)
139+
assertNull(RNSentryTimeToDisplay.popTimeToDisplayFor(TTID_PREFIX + SPAN_ID))
140+
}
141+
142+
class TestRNSentryOnDrawReporterView(
143+
context: Context,
144+
reactContext: ReactApplicationContext,
145+
buildInfo: BuildInfoProvider,
146+
) : RNSentryOnDrawReporterManager.RNSentryOnDrawReporterView(context, reactContext, buildInfo) {
147+
override fun registerForNextDraw(
148+
activity: Activity,
149+
callback: Runnable,
150+
buildInfo: BuildInfoProvider,
151+
) {
152+
callback.run()
153+
}
154+
}
155+
156+
private fun createTestRNSentryOnDrawReporterView(): TestRNSentryOnDrawReporterView =
157+
TestRNSentryOnDrawReporterView(ApplicationProvider.getApplicationContext(), mockReactContext(), mockBuildInfo())
158+
159+
private fun mockReactContext(): ReactApplicationContext {
160+
val reactContext = mock<ReactApplicationContext>()
161+
whenever(reactContext.getCurrentActivity()).thenReturn(mock<Activity>())
162+
return reactContext
163+
}
164+
165+
private fun mockBuildInfo(): BuildInfoProvider = mock()
166+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.sentry.react
2+
3+
import org.junit.Assert.assertEquals
4+
import org.junit.Assert.assertNotNull
5+
import org.junit.Assert.assertNull
6+
import org.junit.Before
7+
import org.junit.Test
8+
import org.junit.runner.RunWith
9+
import org.junit.runners.JUnit4
10+
11+
@RunWith(JUnit4::class)
12+
class RNSentryTimeToDisplayTest {
13+
companion object {
14+
val TEST_ID = "test-id"
15+
val TEST_VAL = 123.4
16+
}
17+
18+
@Before
19+
fun setUp() {
20+
}
21+
22+
@Test
23+
fun `puts and pops record`() {
24+
RNSentryTimeToDisplay.putTimeToDisplayFor(TEST_ID, TEST_VAL)
25+
26+
val firstPop = RNSentryTimeToDisplay.popTimeToDisplayFor(TEST_ID)
27+
val secondPop = RNSentryTimeToDisplay.popTimeToDisplayFor(TEST_ID)
28+
29+
assertEquals(firstPop, TEST_VAL, 0.0)
30+
assertNull(secondPop)
31+
}
32+
33+
@Test
34+
fun `removes oldes entry when full`() {
35+
val maxSize = RNSentryTimeToDisplay.ENTRIES_MAX_SIZE + 1
36+
for (i in 1..maxSize) {
37+
RNSentryTimeToDisplay.putTimeToDisplayFor("$TEST_ID-$i", i.toDouble())
38+
}
39+
40+
val oldestEntry = RNSentryTimeToDisplay.popTimeToDisplayFor("$TEST_ID-1")
41+
val secondOldestEntry = RNSentryTimeToDisplay.popTimeToDisplayFor("$TEST_ID-2")
42+
val newestEntry = RNSentryTimeToDisplay.popTimeToDisplayFor("$TEST_ID-$maxSize")
43+
44+
assertNull(oldestEntry)
45+
assertNotNull(secondOldestEntry)
46+
assertNotNull(newestEntry)
47+
}
48+
}

packages/core/RNSentryCocoaTester/RNSentryCocoaTester.xcodeproj/project.pbxproj

+16-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
3339C4812D6625570088EB3A /* RNSentryUserTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3339C4802D6625570088EB3A /* RNSentryUserTests.mm */; };
1212
336084392C32E382008CC412 /* RNSentryReplayBreadcrumbConverterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 336084382C32E382008CC412 /* RNSentryReplayBreadcrumbConverterTests.swift */; };
1313
3380C6C42CE25ECA0018B9B6 /* RNSentryReplayPostInitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3380C6C32CE25ECA0018B9B6 /* RNSentryReplayPostInitTests.swift */; };
14-
33958C692BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33958C682BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m */; };
1514
33AFDFED2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33AFDFEC2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m */; };
1615
33AFDFF12B8D15E500AAB120 /* RNSentryDependencyContainerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33AFDFF02B8D15E500AAB120 /* RNSentryDependencyContainerTests.m */; };
16+
33DEDFEA2D8DBE67006066E4 /* RNSentryOnDrawReporterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DEDFE92D8DBE5B006066E4 /* RNSentryOnDrawReporterTests.swift */; };
17+
33DEDFED2D8DC825006066E4 /* RNSentryOnDrawReporter+Test.mm in Sources */ = {isa = PBXBuildFile; fileRef = 33DEDFEC2D8DC820006066E4 /* RNSentryOnDrawReporter+Test.mm */; };
18+
33DEDFF02D9185EB006066E4 /* RNSentryTimeToDisplayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DEDFEF2D9185E3006066E4 /* RNSentryTimeToDisplayTests.swift */; };
1719
33F58AD02977037D008F60EA /* RNSentryTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 33F58ACF2977037D008F60EA /* RNSentryTests.mm */; };
1820
AEFB00422CC90C4B00EC8A9A /* RNSentryBreadcrumbTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3360843C2C340C76008CC412 /* RNSentryBreadcrumbTests.swift */; };
1921
B5859A50A3E865EF5E61465A /* libPods-RNSentryCocoaTesterTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 650CB718ACFBD05609BF2126 /* libPods-RNSentryCocoaTesterTests.a */; };
@@ -37,12 +39,16 @@
3739
3380C6C32CE25ECA0018B9B6 /* RNSentryReplayPostInitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNSentryReplayPostInitTests.swift; sourceTree = "<group>"; };
3840
338739072A7D7D2800950DDD /* RNSentryReplay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSentryReplay.h; path = ../ios/RNSentryReplay.h; sourceTree = "<group>"; };
3941
33958C672BFCEF5A00AD1FB6 /* RNSentryOnDrawReporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSentryOnDrawReporter.h; path = ../ios/RNSentryOnDrawReporter.h; sourceTree = "<group>"; };
40-
33958C682BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSentryOnDrawReporterTests.m; sourceTree = "<group>"; };
4142
33AFDFEC2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSentryFramesTrackerListenerTests.m; sourceTree = "<group>"; };
4243
33AFDFEE2B8D14C200AAB120 /* RNSentryFramesTrackerListenerTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSentryFramesTrackerListenerTests.h; sourceTree = "<group>"; };
4344
33AFDFF02B8D15E500AAB120 /* RNSentryDependencyContainerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSentryDependencyContainerTests.m; sourceTree = "<group>"; };
4445
33AFDFF22B8D15F600AAB120 /* RNSentryDependencyContainerTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSentryDependencyContainerTests.h; sourceTree = "<group>"; };
4546
33AFE0132B8F31AF00AAB120 /* RNSentryDependencyContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSentryDependencyContainer.h; path = ../ios/RNSentryDependencyContainer.h; sourceTree = "<group>"; };
47+
33DEDFE92D8DBE5B006066E4 /* RNSentryOnDrawReporterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNSentryOnDrawReporterTests.swift; sourceTree = "<group>"; };
48+
33DEDFEB2D8DC800006066E4 /* RNSentryOnDrawReporter+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNSentryOnDrawReporter+Test.h"; sourceTree = "<group>"; };
49+
33DEDFEC2D8DC820006066E4 /* RNSentryOnDrawReporter+Test.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "RNSentryOnDrawReporter+Test.mm"; sourceTree = "<group>"; };
50+
33DEDFEE2D8DD431006066E4 /* RNSentryTimeToDisplay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSentryTimeToDisplay.h; path = ../ios/RNSentryTimeToDisplay.h; sourceTree = SOURCE_ROOT; };
51+
33DEDFEF2D9185E3006066E4 /* RNSentryTimeToDisplayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNSentryTimeToDisplayTests.swift; sourceTree = "<group>"; };
4652
33F58ACF2977037D008F60EA /* RNSentryTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RNSentryTests.mm; sourceTree = "<group>"; };
4753
650CB718ACFBD05609BF2126 /* libPods-RNSentryCocoaTesterTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNSentryCocoaTesterTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4854
E2321E7CFA55AB617247098E /* Pods-RNSentryCocoaTesterTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNSentryCocoaTesterTests.debug.xcconfig"; path = "Target Support Files/Pods-RNSentryCocoaTesterTests/Pods-RNSentryCocoaTesterTests.debug.xcconfig"; sourceTree = "<group>"; };
@@ -91,6 +97,10 @@
9197
3360899029524164007C7730 /* RNSentryCocoaTesterTests */ = {
9298
isa = PBXGroup;
9399
children = (
100+
33DEDFEF2D9185E3006066E4 /* RNSentryTimeToDisplayTests.swift */,
101+
33DEDFEC2D8DC820006066E4 /* RNSentryOnDrawReporter+Test.mm */,
102+
33DEDFEB2D8DC800006066E4 /* RNSentryOnDrawReporter+Test.h */,
103+
33DEDFE92D8DBE5B006066E4 /* RNSentryOnDrawReporterTests.swift */,
94104
3339C47F2D6625260088EB3A /* RNSentry+Test.h */,
95105
332D334A2CDCC8EB00547D76 /* RNSentryCocoaTesterTests-Bridging-Header.h */,
96106
332D33492CDCC8E100547D76 /* RNSentryTests.h */,
@@ -101,7 +111,6 @@
101111
33AFDFEE2B8D14C200AAB120 /* RNSentryFramesTrackerListenerTests.h */,
102112
33AFDFF02B8D15E500AAB120 /* RNSentryDependencyContainerTests.m */,
103113
33AFDFF22B8D15F600AAB120 /* RNSentryDependencyContainerTests.h */,
104-
33958C682BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m */,
105114
3360843C2C340C76008CC412 /* RNSentryBreadcrumbTests.swift */,
106115
332D33462CDBDBB600547D76 /* RNSentryReplayOptionsTests.swift */,
107116
3380C6C32CE25ECA0018B9B6 /* RNSentryReplayPostInitTests.swift */,
@@ -121,6 +130,7 @@
121130
33AFE0122B8F319000AAB120 /* RNSentry */ = {
122131
isa = PBXGroup;
123132
children = (
133+
33DEDFEE2D8DD431006066E4 /* RNSentryTimeToDisplay.h */,
124134
3380C6C02CDEC56B0018B9B6 /* Replay */,
125135
332D33482CDBDC7300547D76 /* RNSentry.h */,
126136
3360843A2C32E3A8008CC412 /* RNSentryReplayBreadcrumbConverter.h */,
@@ -244,11 +254,13 @@
244254
files = (
245255
AEFB00422CC90C4B00EC8A9A /* RNSentryBreadcrumbTests.swift in Sources */,
246256
332D33472CDBDBB600547D76 /* RNSentryReplayOptionsTests.swift in Sources */,
257+
33DEDFEA2D8DBE67006066E4 /* RNSentryOnDrawReporterTests.swift in Sources */,
247258
33AFDFF12B8D15E500AAB120 /* RNSentryDependencyContainerTests.m in Sources */,
248259
336084392C32E382008CC412 /* RNSentryReplayBreadcrumbConverterTests.swift in Sources */,
260+
33DEDFED2D8DC825006066E4 /* RNSentryOnDrawReporter+Test.mm in Sources */,
249261
33F58AD02977037D008F60EA /* RNSentryTests.mm in Sources */,
250-
33958C692BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m in Sources */,
251262
3339C4812D6625570088EB3A /* RNSentryUserTests.mm in Sources */,
263+
33DEDFF02D9185EB006066E4 /* RNSentryTimeToDisplayTests.swift in Sources */,
252264
3380C6C42CE25ECA0018B9B6 /* RNSentryReplayPostInitTests.swift in Sources */,
253265
33AFDFED2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m in Sources */,
254266
);

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryCocoaTesterTests-Bridging-Header.h

+2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
//
44

55
#import "RNSentryBreadcrumb.h"
6+
#import "RNSentryOnDrawReporter+Test.h"
67
#import "RNSentryReplay.h"
78
#import "RNSentryReplayBreadcrumbConverter.h"
89
#import "RNSentryReplayMask.h"
910
#import "RNSentryReplayUnmask.h"
11+
#import "RNSentryTimeToDisplay.h"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#import "RNSentryOnDrawReporter.h"
2+
#import <Foundation/Foundation.h>
3+
4+
@interface
5+
RNSentryOnDrawReporterView (Testing)
6+
7+
+ (instancetype)createWithMockedListener;
8+
- (RNSentryEmitNewFrameEvent)createEmitNewFrameEvent;
9+
10+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#import "RNSentryOnDrawReporter+Test.h"
2+
3+
@interface MockedListener : NSObject <RNSentryFramesTrackerListenerProtocol>
4+
@property (strong, nonatomic) RNSentryEmitNewFrameEvent emitNewFrameEvent;
5+
- (instancetype)initWithMockedListener:(RNSentryEmitNewFrameEvent)emitNewFrameEvent;
6+
@end
7+
8+
@implementation MockedListener
9+
10+
- (instancetype)initWithMockedListener:(RNSentryEmitNewFrameEvent)emitNewFrameEvent
11+
{
12+
self = [super init];
13+
if (self) {
14+
_emitNewFrameEvent = [emitNewFrameEvent copy];
15+
}
16+
return self;
17+
}
18+
19+
- (void)startListening
20+
{
21+
self.emitNewFrameEvent(@([[NSDate date] timeIntervalSince1970]));
22+
}
23+
24+
- (void)framesTrackerHasNewFrame:(nonnull NSDate *)newFrameDate
25+
{
26+
NSLog(@"Not implemented in the test mock");
27+
}
28+
29+
@end
30+
31+
@implementation
32+
RNSentryOnDrawReporterView (Testing)
33+
34+
+ (instancetype)createWithMockedListener
35+
{
36+
return [[self alloc] initWithMockedListener];
37+
}
38+
39+
- (instancetype)initWithMockedListener
40+
{
41+
self = [super init];
42+
if (self) {
43+
self.framesListener =
44+
[[MockedListener alloc] initWithMockedListener:[self createEmitNewFrameEvent]];
45+
}
46+
return self;
47+
}
48+
49+
@end

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryOnDrawReporterTests.m

-16
This file was deleted.

0 commit comments

Comments
 (0)