Skip to content

Commit 208f4af

Browse files
Merge 2cb7eb2 into 94b806c
2 parents 94b806c + 2cb7eb2 commit 208f4af

File tree

12 files changed

+772
-673
lines changed

12 files changed

+772
-673
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
### Internal
2323

2424
- Initialize `RNSentryTimeToDisplay` during native module `init` on iOS ([#4443](https://github.com/getsentry/sentry-react-native/pull/4443))
25+
- Extract iOS native initialization to standalone structures ([#4442](https://github.com/getsentry/sentry-react-native/pull/4442))
26+
- Extract Android native initialization to standalone structures ([#4445](https://github.com/getsentry/sentry-react-native/pull/4445))
2527

2628
### Dependencies
2729

packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/react/RNSentryModuleImplTest.kt

-166
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,13 @@ package io.sentry.react
33
import android.content.pm.PackageInfo
44
import android.content.pm.PackageManager
55
import com.facebook.react.bridge.Arguments
6-
import com.facebook.react.bridge.JavaOnlyMap
76
import com.facebook.react.bridge.Promise
87
import com.facebook.react.bridge.ReactApplicationContext
98
import com.facebook.react.bridge.WritableMap
10-
import com.facebook.react.common.JavascriptException
11-
import io.sentry.Breadcrumb
129
import io.sentry.ILogger
1310
import io.sentry.SentryLevel
14-
import io.sentry.android.core.SentryAndroidOptions
1511
import org.junit.After
1612
import org.junit.Assert.assertEquals
17-
import org.junit.Assert.assertFalse
18-
import org.junit.Assert.assertNull
19-
import org.junit.Assert.assertTrue
2013
import org.junit.Before
2114
import org.junit.Test
2215
import org.junit.runner.RunWith
@@ -103,163 +96,4 @@ class RNSentryModuleImplTest {
10396
val capturedMap = writableMapCaptor.value
10497
assertEquals(false, capturedMap.getBoolean("has_fetched"))
10598
}
106-
107-
@Test
108-
fun `when the spotlight option is enabled, the spotlight SentryAndroidOption is set to true and the default url is used`() {
109-
val options =
110-
JavaOnlyMap.of(
111-
"spotlight",
112-
true,
113-
"defaultSidecarUrl",
114-
"http://localhost:8969/teststream",
115-
)
116-
val actualOptions = SentryAndroidOptions()
117-
module.getSentryAndroidOptions(actualOptions, options, logger)
118-
assert(actualOptions.isEnableSpotlight)
119-
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
120-
}
121-
122-
@Test
123-
fun `when the spotlight url is passed, the spotlight is enabled for the given url`() {
124-
val options = JavaOnlyMap.of("spotlight", "http://localhost:8969/teststream")
125-
val actualOptions = SentryAndroidOptions()
126-
module.getSentryAndroidOptions(actualOptions, options, logger)
127-
assert(actualOptions.isEnableSpotlight)
128-
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
129-
}
130-
131-
@Test
132-
fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false`() {
133-
val options = JavaOnlyMap.of("spotlight", false)
134-
val actualOptions = SentryAndroidOptions()
135-
module.getSentryAndroidOptions(actualOptions, options, logger)
136-
assertFalse(actualOptions.isEnableSpotlight)
137-
}
138-
139-
@Test
140-
fun `the JavascriptException is added to the ignoredExceptionsForType list on initialisation`() {
141-
val actualOptions = SentryAndroidOptions()
142-
module.getSentryAndroidOptions(actualOptions, JavaOnlyMap.of(), logger)
143-
assertTrue(actualOptions.ignoredExceptionsForType.contains(JavascriptException::class.java))
144-
}
145-
146-
@Test
147-
fun `beforeBreadcrumb callback filters out Sentry DSN requests breadcrumbs`() {
148-
val options = SentryAndroidOptions()
149-
val rnOptions =
150-
JavaOnlyMap.of(
151-
"dsn",
152-
"https://[email protected]/1234567",
153-
"devServerUrl",
154-
"http://localhost:8081",
155-
)
156-
module.getSentryAndroidOptions(options, rnOptions, logger)
157-
158-
val breadcrumb =
159-
Breadcrumb().apply {
160-
type = "http"
161-
setData("url", "https://def.ingest.sentry.io/1234567")
162-
}
163-
164-
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
165-
166-
assertNull("Breadcrumb should be filtered out", result)
167-
}
168-
169-
@Test
170-
fun `beforeBreadcrumb callback filters out dev server breadcrumbs`() {
171-
val mockDevServerUrl = "http://localhost:8081"
172-
val options = SentryAndroidOptions()
173-
val rnOptions =
174-
JavaOnlyMap.of(
175-
"dsn",
176-
"https://[email protected]/1234567",
177-
"devServerUrl",
178-
mockDevServerUrl,
179-
)
180-
module.getSentryAndroidOptions(options, rnOptions, logger)
181-
182-
val breadcrumb =
183-
Breadcrumb().apply {
184-
type = "http"
185-
setData("url", mockDevServerUrl)
186-
}
187-
188-
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
189-
190-
assertNull("Breadcrumb should be filtered out", result)
191-
}
192-
193-
@Test
194-
fun `beforeBreadcrumb callback does not filter out non dev server or dsn breadcrumbs`() {
195-
val options = SentryAndroidOptions()
196-
val rnOptions =
197-
JavaOnlyMap.of(
198-
"dsn",
199-
"https://[email protected]/1234567",
200-
"devServerUrl",
201-
"http://localhost:8081",
202-
)
203-
module.getSentryAndroidOptions(options, rnOptions, logger)
204-
205-
val breadcrumb =
206-
Breadcrumb().apply {
207-
type = "http"
208-
setData("url", "http://testurl.com/service")
209-
}
210-
211-
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
212-
213-
assertEquals(breadcrumb, result)
214-
}
215-
216-
@Test
217-
fun `the breadcrumb is not filtered out when the dev server url and dsn are not passed`() {
218-
val options = SentryAndroidOptions()
219-
module.getSentryAndroidOptions(options, JavaOnlyMap(), logger)
220-
221-
val breadcrumb =
222-
Breadcrumb().apply {
223-
type = "http"
224-
setData("url", "http://testurl.com/service")
225-
}
226-
227-
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
228-
229-
assertEquals(breadcrumb, result)
230-
}
231-
232-
@Test
233-
fun `the breadcrumb is not filtered out when the dev server url is not passed and the dsn does not match`() {
234-
val options = SentryAndroidOptions()
235-
val rnOptions = JavaOnlyMap.of("dsn", "https://[email protected]/1234567")
236-
module.getSentryAndroidOptions(options, rnOptions, logger)
237-
238-
val breadcrumb =
239-
Breadcrumb().apply {
240-
type = "http"
241-
setData("url", "http://testurl.com/service")
242-
}
243-
244-
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
245-
246-
assertEquals(breadcrumb, result)
247-
}
248-
249-
@Test
250-
fun `the breadcrumb is not filtered out when the dev server url does not match and the dsn is not passed`() {
251-
val options = SentryAndroidOptions()
252-
val rnOptions = JavaOnlyMap.of("devServerUrl", "http://localhost:8081")
253-
module.getSentryAndroidOptions(options, rnOptions, logger)
254-
255-
val breadcrumb =
256-
Breadcrumb().apply {
257-
type = "http"
258-
setData("url", "http://testurl.com/service")
259-
}
260-
261-
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
262-
263-
assertEquals(breadcrumb, result)
264-
}
26599
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package io.sentry.react
2+
3+
import android.app.Activity
4+
import com.facebook.react.bridge.JavaOnlyMap
5+
import com.facebook.react.common.JavascriptException
6+
import io.sentry.Breadcrumb
7+
import io.sentry.ILogger
8+
import io.sentry.android.core.SentryAndroidOptions
9+
import org.junit.Assert.assertEquals
10+
import org.junit.Assert.assertFalse
11+
import org.junit.Assert.assertNull
12+
import org.junit.Assert.assertTrue
13+
import org.junit.Before
14+
import org.junit.Test
15+
import org.junit.runner.RunWith
16+
import org.junit.runners.JUnit4
17+
import org.mockito.Mockito.mock
18+
import org.mockito.MockitoAnnotations
19+
20+
@RunWith(JUnit4::class)
21+
class RNSentryStartTest {
22+
private lateinit var logger: ILogger
23+
24+
private lateinit var activity: Activity
25+
26+
@Before
27+
fun setUp() {
28+
MockitoAnnotations.openMocks(this)
29+
logger = mock(ILogger::class.java)
30+
activity = mock(Activity::class.java)
31+
}
32+
33+
@Test
34+
fun `when the spotlight option is enabled, the spotlight SentryAndroidOption is set to true and the default url is used`() {
35+
val options =
36+
JavaOnlyMap.of(
37+
"spotlight",
38+
true,
39+
"defaultSidecarUrl",
40+
"http://localhost:8969/teststream",
41+
)
42+
val actualOptions = SentryAndroidOptions()
43+
RNSentryStart.getSentryAndroidOptions(actualOptions, options, activity, logger)
44+
assert(actualOptions.isEnableSpotlight)
45+
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
46+
}
47+
48+
@Test
49+
fun `when the spotlight url is passed, the spotlight is enabled for the given url`() {
50+
val options = JavaOnlyMap.of("spotlight", "http://localhost:8969/teststream")
51+
val actualOptions = SentryAndroidOptions()
52+
RNSentryStart.getSentryAndroidOptions(actualOptions, options, activity, logger)
53+
assert(actualOptions.isEnableSpotlight)
54+
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
55+
}
56+
57+
@Test
58+
fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false`() {
59+
val options = JavaOnlyMap.of("spotlight", false)
60+
val actualOptions = SentryAndroidOptions()
61+
RNSentryStart.getSentryAndroidOptions(actualOptions, options, activity, logger)
62+
assertFalse(actualOptions.isEnableSpotlight)
63+
}
64+
65+
@Test
66+
fun `the JavascriptException is added to the ignoredExceptionsForType list on initialisation`() {
67+
val actualOptions = SentryAndroidOptions()
68+
RNSentryStart.getSentryAndroidOptions(actualOptions, JavaOnlyMap.of(), activity, logger)
69+
assertTrue(actualOptions.ignoredExceptionsForType.contains(JavascriptException::class.java))
70+
}
71+
72+
@Test
73+
fun `beforeBreadcrumb callback filters out Sentry DSN requests breadcrumbs`() {
74+
val options = SentryAndroidOptions()
75+
val rnOptions =
76+
JavaOnlyMap.of(
77+
"dsn",
78+
"https://[email protected]/1234567",
79+
"devServerUrl",
80+
"http://localhost:8081",
81+
)
82+
RNSentryStart.getSentryAndroidOptions(options, rnOptions, activity, logger)
83+
84+
val breadcrumb =
85+
Breadcrumb().apply {
86+
type = "http"
87+
setData("url", "https://def.ingest.sentry.io/1234567")
88+
}
89+
90+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
91+
92+
assertNull("Breadcrumb should be filtered out", result)
93+
}
94+
95+
@Test
96+
fun `beforeBreadcrumb callback filters out dev server breadcrumbs`() {
97+
val mockDevServerUrl = "http://localhost:8081"
98+
val options = SentryAndroidOptions()
99+
val rnOptions =
100+
JavaOnlyMap.of(
101+
"dsn",
102+
"https://[email protected]/1234567",
103+
"devServerUrl",
104+
mockDevServerUrl,
105+
)
106+
RNSentryStart.getSentryAndroidOptions(options, rnOptions, activity, logger)
107+
108+
val breadcrumb =
109+
Breadcrumb().apply {
110+
type = "http"
111+
setData("url", mockDevServerUrl)
112+
}
113+
114+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
115+
116+
assertNull("Breadcrumb should be filtered out", result)
117+
}
118+
119+
@Test
120+
fun `beforeBreadcrumb callback does not filter out non dev server or dsn breadcrumbs`() {
121+
val options = SentryAndroidOptions()
122+
val rnOptions =
123+
JavaOnlyMap.of(
124+
"dsn",
125+
"https://[email protected]/1234567",
126+
"devServerUrl",
127+
"http://localhost:8081",
128+
)
129+
RNSentryStart.getSentryAndroidOptions(options, rnOptions, activity, logger)
130+
131+
val breadcrumb =
132+
Breadcrumb().apply {
133+
type = "http"
134+
setData("url", "http://testurl.com/service")
135+
}
136+
137+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
138+
139+
assertEquals(breadcrumb, result)
140+
}
141+
142+
@Test
143+
fun `the breadcrumb is not filtered out when the dev server url and dsn are not passed`() {
144+
val options = SentryAndroidOptions()
145+
RNSentryStart.getSentryAndroidOptions(options, JavaOnlyMap(), activity, logger)
146+
147+
val breadcrumb =
148+
Breadcrumb().apply {
149+
type = "http"
150+
setData("url", "http://testurl.com/service")
151+
}
152+
153+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
154+
155+
assertEquals(breadcrumb, result)
156+
}
157+
158+
@Test
159+
fun `the breadcrumb is not filtered out when the dev server url is not passed and the dsn does not match`() {
160+
val options = SentryAndroidOptions()
161+
val rnOptions = JavaOnlyMap.of("dsn", "https://[email protected]/1234567")
162+
RNSentryStart.getSentryAndroidOptions(options, rnOptions, activity, logger)
163+
164+
val breadcrumb =
165+
Breadcrumb().apply {
166+
type = "http"
167+
setData("url", "http://testurl.com/service")
168+
}
169+
170+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
171+
172+
assertEquals(breadcrumb, result)
173+
}
174+
175+
@Test
176+
fun `the breadcrumb is not filtered out when the dev server url does not match and the dsn is not passed`() {
177+
val options = SentryAndroidOptions()
178+
val rnOptions = JavaOnlyMap.of("devServerUrl", "http://localhost:8081")
179+
RNSentryStart.getSentryAndroidOptions(options, rnOptions, activity, logger)
180+
181+
val breadcrumb =
182+
Breadcrumb().apply {
183+
type = "http"
184+
setData("url", "http://testurl.com/service")
185+
}
186+
187+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
188+
189+
assertEquals(breadcrumb, result)
190+
}
191+
}

0 commit comments

Comments
 (0)