@@ -5,9 +5,13 @@ import com.facebook.react.bridge.JavaOnlyMap
55import com.facebook.react.common.JavascriptException
66import io.sentry.Breadcrumb
77import io.sentry.ILogger
8+ import io.sentry.SentryEvent
9+ import io.sentry.android.core.CurrentActivityHolder
810import io.sentry.android.core.SentryAndroidOptions
11+ import io.sentry.protocol.SdkVersion
912import org.junit.Assert.assertEquals
1013import org.junit.Assert.assertFalse
14+ import org.junit.Assert.assertNotNull
1115import org.junit.Assert.assertNull
1216import org.junit.Assert.assertTrue
1317import org.junit.Before
@@ -40,7 +44,7 @@ class RNSentryStartTest {
4044 " http://localhost:8969/teststream" ,
4145 )
4246 val actualOptions = SentryAndroidOptions ()
43- RNSentryStart .getSentryAndroidOptions(actualOptions, options, activity, logger)
47+ RNSentryStart .getSentryAndroidOptions(actualOptions, options, logger)
4448 assert (actualOptions.isEnableSpotlight)
4549 assertEquals(" http://localhost:8969/teststream" , actualOptions.spotlightConnectionUrl)
4650 }
@@ -49,7 +53,7 @@ class RNSentryStartTest {
4953 fun `when the spotlight url is passed, the spotlight is enabled for the given url` () {
5054 val options = JavaOnlyMap .of(" spotlight" , " http://localhost:8969/teststream" )
5155 val actualOptions = SentryAndroidOptions ()
52- RNSentryStart .getSentryAndroidOptions(actualOptions, options, activity, logger)
56+ RNSentryStart .getSentryAndroidOptions(actualOptions, options, logger)
5357 assert (actualOptions.isEnableSpotlight)
5458 assertEquals(" http://localhost:8969/teststream" , actualOptions.spotlightConnectionUrl)
5559 }
@@ -58,17 +62,10 @@ class RNSentryStartTest {
5862 fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false` () {
5963 val options = JavaOnlyMap .of(" spotlight" , false )
6064 val actualOptions = SentryAndroidOptions ()
61- RNSentryStart .getSentryAndroidOptions(actualOptions, options, activity, logger)
65+ RNSentryStart .getSentryAndroidOptions(actualOptions, options, logger)
6266 assertFalse(actualOptions.isEnableSpotlight)
6367 }
6468
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-
7269 @Test
7370 fun `beforeBreadcrumb callback filters out Sentry DSN requests breadcrumbs` () {
7471 val options = SentryAndroidOptions ()
@@ -79,7 +76,7 @@ class RNSentryStartTest {
7976 " devServerUrl" ,
8077 " http://localhost:8081" ,
8178 )
82- RNSentryStart .getSentryAndroidOptions(options, rnOptions, activity, logger)
79+ RNSentryStart .getSentryAndroidOptions(options, rnOptions, logger)
8380
8481 val breadcrumb =
8582 Breadcrumb ().apply {
@@ -103,7 +100,7 @@ class RNSentryStartTest {
103100 " devServerUrl" ,
104101 mockDevServerUrl,
105102 )
106- RNSentryStart .getSentryAndroidOptions(options, rnOptions, activity, logger)
103+ RNSentryStart .getSentryAndroidOptions(options, rnOptions, logger)
107104
108105 val breadcrumb =
109106 Breadcrumb ().apply {
@@ -126,7 +123,7 @@ class RNSentryStartTest {
126123 " devServerUrl" ,
127124 " http://localhost:8081" ,
128125 )
129- RNSentryStart .getSentryAndroidOptions(options, rnOptions, activity, logger)
126+ RNSentryStart .getSentryAndroidOptions(options, rnOptions, logger)
130127
131128 val breadcrumb =
132129 Breadcrumb ().apply {
@@ -142,7 +139,7 @@ class RNSentryStartTest {
142139 @Test
143140 fun `the breadcrumb is not filtered out when the dev server url and dsn are not passed` () {
144141 val options = SentryAndroidOptions ()
145- RNSentryStart .getSentryAndroidOptions(options, JavaOnlyMap (), activity, logger)
142+ RNSentryStart .getSentryAndroidOptions(options, JavaOnlyMap (), logger)
146143
147144 val breadcrumb =
148145 Breadcrumb ().apply {
@@ -159,7 +156,7 @@ class RNSentryStartTest {
159156 fun `the breadcrumb is not filtered out when the dev server url is not passed and the dsn does not match` () {
160157 val options = SentryAndroidOptions ()
161158 val rnOptions
= JavaOnlyMap .of(
" dsn" ,
" https://[email protected] /1234567" )
162- RNSentryStart .getSentryAndroidOptions(options, rnOptions, activity, logger)
159+ RNSentryStart .getSentryAndroidOptions(options, rnOptions, logger)
163160
164161 val breadcrumb =
165162 Breadcrumb ().apply {
@@ -176,7 +173,7 @@ class RNSentryStartTest {
176173 fun `the breadcrumb is not filtered out when the dev server url does not match and the dsn is not passed` () {
177174 val options = SentryAndroidOptions ()
178175 val rnOptions = JavaOnlyMap .of(" devServerUrl" , " http://localhost:8081" )
179- RNSentryStart .getSentryAndroidOptions(options, rnOptions, activity, logger)
176+ RNSentryStart .getSentryAndroidOptions(options, rnOptions, logger)
180177
181178 val breadcrumb =
182179 Breadcrumb ().apply {
@@ -188,4 +185,67 @@ class RNSentryStartTest {
188185
189186 assertEquals(breadcrumb, result)
190187 }
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+ }
191251}
0 commit comments