@@ -5,9 +5,13 @@ import com.facebook.react.bridge.JavaOnlyMap
5
5
import com.facebook.react.common.JavascriptException
6
6
import io.sentry.Breadcrumb
7
7
import io.sentry.ILogger
8
+ import io.sentry.SentryEvent
9
+ import io.sentry.android.core.CurrentActivityHolder
8
10
import io.sentry.android.core.SentryAndroidOptions
11
+ import io.sentry.protocol.SdkVersion
9
12
import org.junit.Assert.assertEquals
10
13
import org.junit.Assert.assertFalse
14
+ import org.junit.Assert.assertNotNull
11
15
import org.junit.Assert.assertNull
12
16
import org.junit.Assert.assertTrue
13
17
import org.junit.Before
@@ -40,7 +44,7 @@ class RNSentryStartTest {
40
44
" http://localhost:8969/teststream" ,
41
45
)
42
46
val actualOptions = SentryAndroidOptions ()
43
- RNSentryStart .getSentryAndroidOptions(actualOptions, options, activity, logger)
47
+ RNSentryStart .getSentryAndroidOptions(actualOptions, options, logger)
44
48
assert (actualOptions.isEnableSpotlight)
45
49
assertEquals(" http://localhost:8969/teststream" , actualOptions.spotlightConnectionUrl)
46
50
}
@@ -49,7 +53,7 @@ class RNSentryStartTest {
49
53
fun `when the spotlight url is passed, the spotlight is enabled for the given url` () {
50
54
val options = JavaOnlyMap .of(" spotlight" , " http://localhost:8969/teststream" )
51
55
val actualOptions = SentryAndroidOptions ()
52
- RNSentryStart .getSentryAndroidOptions(actualOptions, options, activity, logger)
56
+ RNSentryStart .getSentryAndroidOptions(actualOptions, options, logger)
53
57
assert (actualOptions.isEnableSpotlight)
54
58
assertEquals(" http://localhost:8969/teststream" , actualOptions.spotlightConnectionUrl)
55
59
}
@@ -58,17 +62,10 @@ class RNSentryStartTest {
58
62
fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false` () {
59
63
val options = JavaOnlyMap .of(" spotlight" , false )
60
64
val actualOptions = SentryAndroidOptions ()
61
- RNSentryStart .getSentryAndroidOptions(actualOptions, options, activity, logger)
65
+ RNSentryStart .getSentryAndroidOptions(actualOptions, options, logger)
62
66
assertFalse(actualOptions.isEnableSpotlight)
63
67
}
64
68
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
69
@Test
73
70
fun `beforeBreadcrumb callback filters out Sentry DSN requests breadcrumbs` () {
74
71
val options = SentryAndroidOptions ()
@@ -79,7 +76,7 @@ class RNSentryStartTest {
79
76
" devServerUrl" ,
80
77
" http://localhost:8081" ,
81
78
)
82
- RNSentryStart .getSentryAndroidOptions(options, rnOptions, activity, logger)
79
+ RNSentryStart .getSentryAndroidOptions(options, rnOptions, logger)
83
80
84
81
val breadcrumb =
85
82
Breadcrumb ().apply {
@@ -103,7 +100,7 @@ class RNSentryStartTest {
103
100
" devServerUrl" ,
104
101
mockDevServerUrl,
105
102
)
106
- RNSentryStart .getSentryAndroidOptions(options, rnOptions, activity, logger)
103
+ RNSentryStart .getSentryAndroidOptions(options, rnOptions, logger)
107
104
108
105
val breadcrumb =
109
106
Breadcrumb ().apply {
@@ -126,7 +123,7 @@ class RNSentryStartTest {
126
123
" devServerUrl" ,
127
124
" http://localhost:8081" ,
128
125
)
129
- RNSentryStart .getSentryAndroidOptions(options, rnOptions, activity, logger)
126
+ RNSentryStart .getSentryAndroidOptions(options, rnOptions, logger)
130
127
131
128
val breadcrumb =
132
129
Breadcrumb ().apply {
@@ -142,7 +139,7 @@ class RNSentryStartTest {
142
139
@Test
143
140
fun `the breadcrumb is not filtered out when the dev server url and dsn are not passed` () {
144
141
val options = SentryAndroidOptions ()
145
- RNSentryStart .getSentryAndroidOptions(options, JavaOnlyMap (), activity, logger)
142
+ RNSentryStart .getSentryAndroidOptions(options, JavaOnlyMap (), logger)
146
143
147
144
val breadcrumb =
148
145
Breadcrumb ().apply {
@@ -159,7 +156,7 @@ class RNSentryStartTest {
159
156
fun `the breadcrumb is not filtered out when the dev server url is not passed and the dsn does not match` () {
160
157
val options = SentryAndroidOptions ()
161
158
val rnOptions
= JavaOnlyMap .of(
" dsn" ,
" https://[email protected] /1234567" )
162
- RNSentryStart .getSentryAndroidOptions(options, rnOptions, activity, logger)
159
+ RNSentryStart .getSentryAndroidOptions(options, rnOptions, logger)
163
160
164
161
val breadcrumb =
165
162
Breadcrumb ().apply {
@@ -176,7 +173,7 @@ class RNSentryStartTest {
176
173
fun `the breadcrumb is not filtered out when the dev server url does not match and the dsn is not passed` () {
177
174
val options = SentryAndroidOptions ()
178
175
val rnOptions = JavaOnlyMap .of(" devServerUrl" , " http://localhost:8081" )
179
- RNSentryStart .getSentryAndroidOptions(options, rnOptions, activity, logger)
176
+ RNSentryStart .getSentryAndroidOptions(options, rnOptions, logger)
180
177
181
178
val breadcrumb =
182
179
Breadcrumb ().apply {
@@ -188,4 +185,67 @@ class RNSentryStartTest {
188
185
189
186
assertEquals(breadcrumb, result)
190
187
}
188
+
189
+ @Test
190
+ fun `the JavascriptException is added to the ignoredExceptionsForType list on with react defaults` () {
191
+ val actualOptions = SentryAndroidOptions ()
192
+ RNSentryStart .updateWithReactDefaults(actualOptions, activity)
193
+ assertTrue(actualOptions.ignoredExceptionsForType.contains(JavascriptException ::class .java))
194
+ }
195
+
196
+ @Test
197
+ fun `the sdk version information is added to the initialisation options with react defaults` () {
198
+ val actualOptions = SentryAndroidOptions ()
199
+ RNSentryStart .updateWithReactDefaults(actualOptions, activity)
200
+ assertEquals(RNSentryVersion .ANDROID_SDK_NAME , actualOptions.sdkVersion?.name)
201
+ assertEquals(
202
+ io.sentry.android.core.BuildConfig .VERSION_NAME ,
203
+ actualOptions.sdkVersion?.version,
204
+ )
205
+ assertEquals(true , actualOptions.sdkVersion?.packages?.isNotEmpty())
206
+ assertEquals(
207
+ RNSentryVersion .REACT_NATIVE_SDK_PACKAGE_NAME ,
208
+ actualOptions.sdkVersion
209
+ ?.packages
210
+ ?.last()
211
+ ?.name,
212
+ )
213
+ assertEquals(
214
+ RNSentryVersion .REACT_NATIVE_SDK_PACKAGE_VERSION ,
215
+ actualOptions.sdkVersion
216
+ ?.packages
217
+ ?.last()
218
+ ?.version,
219
+ )
220
+ }
221
+
222
+ @Test
223
+ fun `the tracing options are added to the initialisation options with react defaults` () {
224
+ val actualOptions = SentryAndroidOptions ()
225
+ RNSentryStart .updateWithReactDefaults(actualOptions, activity)
226
+ assertNull(actualOptions.tracesSampleRate)
227
+ assertNull(actualOptions.tracesSampler)
228
+ assertEquals(false , actualOptions.enableTracing)
229
+ }
230
+
231
+ @Test
232
+ fun `the current activity is added to the initialisation options with react defaults` () {
233
+ val actualOptions = SentryAndroidOptions ()
234
+ RNSentryStart .updateWithReactDefaults(actualOptions, activity)
235
+ assertEquals(activity, CurrentActivityHolder .getInstance().activity)
236
+ }
237
+
238
+ @Test
239
+ fun `beforeSend callback that sets event tags is set with react finals` () {
240
+ val options = SentryAndroidOptions ()
241
+ val event =
242
+ SentryEvent ().apply { sdk = SdkVersion (RNSentryVersion .ANDROID_SDK_NAME , " 1.0" ) }
243
+
244
+ RNSentryStart .updateWithReactFinals(options)
245
+ val result = options.beforeSend?.execute(event, mock())
246
+
247
+ assertNotNull(result)
248
+ assertEquals(" android" , result?.getTag(" event.origin" ))
249
+ assertEquals(" java" , result?.getTag(" event.environment" ))
250
+ }
191
251
}
0 commit comments