Skip to content

Commit c4bd9bf

Browse files
authored
Merge 739ad30 into 800171e
2 parents 800171e + 739ad30 commit c4bd9bf

File tree

5 files changed

+509
-446
lines changed

5 files changed

+509
-446
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
- [changelog](https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md#8490)
2727
- [diff](https://github.com/getsentry/sentry-javascript/compare/8.47.0...8.49.0)
2828

29+
### Internal
30+
31+
- Extract Android native initialization to standalone structures ([#4445](https://github.com/getsentry/sentry-react-native/pull/4445))
32+
2933
## 6.5.0
3034

3135
### Features

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

Lines changed: 0 additions & 166 deletions
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
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
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 module: RNSentryStart
23+
private lateinit var logger: ILogger
24+
25+
private lateinit var activity: Activity
26+
27+
@Before
28+
fun setUp() {
29+
MockitoAnnotations.openMocks(this)
30+
logger = mock(ILogger::class.java)
31+
activity = mock(Activity::class.java)
32+
module = RNSentryStart()
33+
}
34+
35+
@Test
36+
fun `when the spotlight option is enabled, the spotlight SentryAndroidOption is set to true and the default url is used`() {
37+
val options =
38+
JavaOnlyMap.of(
39+
"spotlight",
40+
true,
41+
"defaultSidecarUrl",
42+
"http://localhost:8969/teststream",
43+
)
44+
val actualOptions = SentryAndroidOptions()
45+
module.getSentryAndroidOptions(actualOptions, options, activity, logger)
46+
assert(actualOptions.isEnableSpotlight)
47+
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
48+
}
49+
50+
@Test
51+
fun `when the spotlight url is passed, the spotlight is enabled for the given url`() {
52+
val options = JavaOnlyMap.of("spotlight", "http://localhost:8969/teststream")
53+
val actualOptions = SentryAndroidOptions()
54+
module.getSentryAndroidOptions(actualOptions, options, activity, logger)
55+
assert(actualOptions.isEnableSpotlight)
56+
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
57+
}
58+
59+
@Test
60+
fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false`() {
61+
val options = JavaOnlyMap.of("spotlight", false)
62+
val actualOptions = SentryAndroidOptions()
63+
module.getSentryAndroidOptions(actualOptions, options, activity, logger)
64+
assertFalse(actualOptions.isEnableSpotlight)
65+
}
66+
67+
@Test
68+
fun `the JavascriptException is added to the ignoredExceptionsForType list on initialisation`() {
69+
val actualOptions = SentryAndroidOptions()
70+
module.getSentryAndroidOptions(actualOptions, JavaOnlyMap.of(), activity, logger)
71+
assertTrue(actualOptions.ignoredExceptionsForType.contains(JavascriptException::class.java))
72+
}
73+
74+
@Test
75+
fun `beforeBreadcrumb callback filters out Sentry DSN requests breadcrumbs`() {
76+
val options = SentryAndroidOptions()
77+
val rnOptions =
78+
JavaOnlyMap.of(
79+
"dsn",
80+
"https://[email protected]/1234567",
81+
"devServerUrl",
82+
"http://localhost:8081",
83+
)
84+
module.getSentryAndroidOptions(options, rnOptions, activity, logger)
85+
86+
val breadcrumb =
87+
Breadcrumb().apply {
88+
type = "http"
89+
setData("url", "https://def.ingest.sentry.io/1234567")
90+
}
91+
92+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
93+
94+
assertNull("Breadcrumb should be filtered out", result)
95+
}
96+
97+
@Test
98+
fun `beforeBreadcrumb callback filters out dev server breadcrumbs`() {
99+
val mockDevServerUrl = "http://localhost:8081"
100+
val options = SentryAndroidOptions()
101+
val rnOptions =
102+
JavaOnlyMap.of(
103+
"dsn",
104+
"https://[email protected]/1234567",
105+
"devServerUrl",
106+
mockDevServerUrl,
107+
)
108+
module.getSentryAndroidOptions(options, rnOptions, activity, logger)
109+
110+
val breadcrumb =
111+
Breadcrumb().apply {
112+
type = "http"
113+
setData("url", mockDevServerUrl)
114+
}
115+
116+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
117+
118+
assertNull("Breadcrumb should be filtered out", result)
119+
}
120+
121+
@Test
122+
fun `beforeBreadcrumb callback does not filter out non dev server or dsn breadcrumbs`() {
123+
val options = SentryAndroidOptions()
124+
val rnOptions =
125+
JavaOnlyMap.of(
126+
"dsn",
127+
"https://[email protected]/1234567",
128+
"devServerUrl",
129+
"http://localhost:8081",
130+
)
131+
module.getSentryAndroidOptions(options, rnOptions, activity, logger)
132+
133+
val breadcrumb =
134+
Breadcrumb().apply {
135+
type = "http"
136+
setData("url", "http://testurl.com/service")
137+
}
138+
139+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
140+
141+
assertEquals(breadcrumb, result)
142+
}
143+
144+
@Test
145+
fun `the breadcrumb is not filtered out when the dev server url and dsn are not passed`() {
146+
val options = SentryAndroidOptions()
147+
module.getSentryAndroidOptions(options, JavaOnlyMap(), activity, logger)
148+
149+
val breadcrumb =
150+
Breadcrumb().apply {
151+
type = "http"
152+
setData("url", "http://testurl.com/service")
153+
}
154+
155+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
156+
157+
assertEquals(breadcrumb, result)
158+
}
159+
160+
@Test
161+
fun `the breadcrumb is not filtered out when the dev server url is not passed and the dsn does not match`() {
162+
val options = SentryAndroidOptions()
163+
val rnOptions = JavaOnlyMap.of("dsn", "https://[email protected]/1234567")
164+
module.getSentryAndroidOptions(options, rnOptions, activity, logger)
165+
166+
val breadcrumb =
167+
Breadcrumb().apply {
168+
type = "http"
169+
setData("url", "http://testurl.com/service")
170+
}
171+
172+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
173+
174+
assertEquals(breadcrumb, result)
175+
}
176+
177+
@Test
178+
fun `the breadcrumb is not filtered out when the dev server url does not match and the dsn is not passed`() {
179+
val options = SentryAndroidOptions()
180+
val rnOptions = JavaOnlyMap.of("devServerUrl", "http://localhost:8081")
181+
module.getSentryAndroidOptions(options, rnOptions, activity, logger)
182+
183+
val breadcrumb =
184+
Breadcrumb().apply {
185+
type = "http"
186+
setData("url", "http://testurl.com/service")
187+
}
188+
189+
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock())
190+
191+
assertEquals(breadcrumb, result)
192+
}
193+
}

0 commit comments

Comments
 (0)