Skip to content

Commit b75148e

Browse files
Merge 1e5dbde into cb6b3a4
2 parents cb6b3a4 + 1e5dbde commit b75148e

File tree

27 files changed

+1567
-710
lines changed

27 files changed

+1567
-710
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222

2323
- Rename `navigation.processing` span to more expressive `Navigation dispatch to screen A mounted/navigation cancelled` ([#4423](https://github.com/getsentry/sentry-react-native/pull/4423))
2424
- Add RN SDK package to `sdk.packages` for Cocoa ([#4381](https://github.com/getsentry/sentry-react-native/pull/4381))
25+
- Add experimental version of `startWithConfigureOptions` for Apple platforms ([#4444](https://github.com/getsentry/sentry-react-native/pull/4444))
26+
- Add initialization using `sentry.options.json` for Apple platforms ([#4447](https://github.com/getsentry/sentry-react-native/pull/4447))
2527

2628
### Internal
2729

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

3034
### Dependencies
3135

packages/core/RNSentry.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Pod::Spec.new do |s|
3333
s.preserve_paths = '*.js'
3434

3535
s.source_files = 'ios/**/*.{h,m,mm}'
36-
s.public_header_files = 'ios/RNSentry.h'
36+
s.public_header_files = 'ios/RNSentry.h', 'ios/RNSentrySDK.h'
3737

3838
s.compiler_flags = other_cflags
3939

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package io.sentry.react
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import com.facebook.react.bridge.WritableArray
5+
import com.facebook.react.bridge.WritableMap
6+
import io.sentry.react.RNSentryJsonConverter.convertToWritable
7+
import org.json.JSONArray
8+
import org.json.JSONObject
9+
import org.junit.Assert.assertEquals
10+
import org.junit.Assert.assertNotNull
11+
import org.junit.Assert.assertNull
12+
import org.junit.Test
13+
import org.junit.runner.RunWith
14+
15+
@RunWith(AndroidJUnit4::class)
16+
class RNSentryJsonConverterTest {
17+
@Test
18+
fun testConvertToWritableWithSimpleJsonObject() {
19+
val jsonObject =
20+
JSONObject().apply {
21+
put("floatKey", 12.3f)
22+
put("doubleKey", 12.3)
23+
put("intKey", 123)
24+
put("stringKey", "test")
25+
put("nullKey", JSONObject.NULL)
26+
}
27+
28+
val result: WritableMap? = convertToWritable(jsonObject)
29+
30+
assertNotNull(result)
31+
assertEquals(12.3, result!!.getDouble("floatKey"), 0.0001)
32+
assertEquals(12.3, result.getDouble("doubleKey"), 0.0)
33+
assertEquals(123, result.getInt("intKey"))
34+
assertEquals("test", result.getString("stringKey"))
35+
assertNull(result.getString("nullKey"))
36+
}
37+
38+
@Test
39+
fun testConvertToWritableWithNestedJsonObject() {
40+
val jsonObject =
41+
JSONObject().apply {
42+
put(
43+
"nested",
44+
JSONObject().apply {
45+
put("key", "value")
46+
},
47+
)
48+
}
49+
50+
val result: WritableMap? = convertToWritable(jsonObject)
51+
52+
assertNotNull(result)
53+
val nestedMap = result!!.getMap("nested")
54+
assertNotNull(nestedMap)
55+
assertEquals("value", nestedMap!!.getString("key"))
56+
}
57+
58+
@Test
59+
fun testConvertToWritableWithJsonArray() {
60+
val jsonArray =
61+
JSONArray().apply {
62+
put(1)
63+
put(2.5)
64+
put("string")
65+
put(JSONObject.NULL)
66+
}
67+
68+
val result: WritableArray = convertToWritable(jsonArray)
69+
70+
assertEquals(1, result.getInt(0))
71+
assertEquals(2.5, result.getDouble(1), 0.0)
72+
assertEquals("string", result.getString(2))
73+
assertNull(result.getString(3))
74+
}
75+
76+
@Test
77+
fun testConvertToWritableWithNestedJsonArray() {
78+
val jsonObject =
79+
JSONObject().apply {
80+
put(
81+
"array",
82+
JSONArray().apply {
83+
put(
84+
JSONObject().apply {
85+
put("key1", "value1")
86+
},
87+
)
88+
put(
89+
JSONObject().apply {
90+
put("key2", "value2")
91+
},
92+
)
93+
},
94+
)
95+
}
96+
97+
val result: WritableMap? = convertToWritable(jsonObject)
98+
99+
val array = result?.getArray("array")
100+
assertEquals("value1", array?.getMap(0)?.getString("key1"))
101+
assertEquals("value2", array?.getMap(1)?.getString("key2"))
102+
}
103+
}

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://abc@def.ingest.sentry.io/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://abc@def.ingest.sentry.io/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://abc@def.ingest.sentry.io/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://abc@def.ingest.sentry.io/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
}

0 commit comments

Comments
 (0)