11import type { Exception } from '@sentry/browser' ;
22import { defaultStackParser , eventFromException } from '@sentry/browser' ;
3+ import { Platform } from 'react-native' ;
34
45import { createReactNativeRewriteFrames } from '../../src/js/integrations/rewriteframes' ;
6+ import { isExpo } from '../../src/js/utils/environment' ;
7+ import { mockFunction } from '../testutils' ;
8+
9+ jest . mock ( '../../src/js/utils/environment' ) ;
10+ jest . mock ( 'react-native' , ( ) => ( { Platform : { OS : 'ios' } } ) ) ;
511
612describe ( 'RewriteFrames' , ( ) => {
713 const HINT = { } ;
@@ -20,6 +26,11 @@ describe('RewriteFrames', () => {
2026 return exception ;
2127 } ;
2228
29+ beforeEach ( ( ) => {
30+ mockFunction ( isExpo ) . mockReturnValue ( false ) ;
31+ jest . resetAllMocks ( ) ;
32+ } ) ;
33+
2334 it ( 'should parse exceptions for react-native-v8' , async ( ) => {
2435 const REACT_NATIVE_V8_EXCEPTION = {
2536 message : 'Manually triggered crash to test Sentry reporting' ,
@@ -98,7 +109,10 @@ describe('RewriteFrames', () => {
98109 } ) ;
99110 } ) ;
100111
101- it ( 'should parse exceptions for react-native Expo bundles' , async ( ) => {
112+ it ( 'should parse exceptions for react-native Expo bundles on ios' , async ( ) => {
113+ mockFunction ( isExpo ) . mockReturnValue ( true ) ;
114+ Platform . OS = 'ios' ;
115+
102116 const REACT_NATIVE_EXPO_EXCEPTION = {
103117 message : 'Test Error Expo' ,
104118 name : 'Error' ,
@@ -121,28 +135,86 @@ describe('RewriteFrames', () => {
121135 frames : [
122136 { filename : '[native code]' , function : 'forEach' , in_app : true } ,
123137 {
124- filename : 'app:///bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3 ' ,
138+ filename : 'app:///main.jsbundle ' ,
125139 function : 'p' ,
126140 lineno : 96 ,
127141 colno : 385 ,
128142 in_app : true ,
129143 } ,
130144 {
131- filename : 'app:///bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3 ' ,
145+ filename : 'app:///main.jsbundle ' ,
132146 function : 'onResponderRelease' ,
133147 lineno : 221 ,
134148 colno : 5666 ,
135149 in_app : true ,
136150 } ,
137151 {
138- filename : 'app:///bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3 ' ,
152+ filename : 'app:///main.jsbundle ' ,
139153 function : 'value' ,
140154 lineno : 221 ,
141155 colno : 7656 ,
142156 in_app : true ,
143157 } ,
144158 {
145- filename : 'app:///bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3' ,
159+ filename : 'app:///main.jsbundle' ,
160+ function : 'onPress' ,
161+ lineno : 595 ,
162+ colno : 658 ,
163+ in_app : true ,
164+ } ,
165+ ] ,
166+ } ,
167+ } ) ;
168+ } ) ;
169+
170+ it ( 'should parse exceptions for react-native Expo bundles on android' , async ( ) => {
171+ mockFunction ( isExpo ) . mockReturnValue ( true ) ;
172+ Platform . OS = 'android' ;
173+
174+ const REACT_NATIVE_EXPO_EXCEPTION = {
175+ message : 'Test Error Expo' ,
176+ name : 'Error' ,
177+ stack : `onPress@/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3:595:658
178+ value@/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3:221:7656
179+ onResponderRelease@/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3:221:5666
180+ p@/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3:96:385
181+ forEach@[native code]` ,
182+ } ;
183+ const exception = await exceptionFromError ( REACT_NATIVE_EXPO_EXCEPTION ) ;
184+
185+ expect ( exception ) . toEqual ( {
186+ value : 'Test Error Expo' ,
187+ type : 'Error' ,
188+ mechanism : {
189+ handled : true ,
190+ type : 'generic' ,
191+ } ,
192+ stacktrace : {
193+ frames : [
194+ { filename : '[native code]' , function : 'forEach' , in_app : true } ,
195+ {
196+ filename : 'app:///index.android.bundle' ,
197+ function : 'p' ,
198+ lineno : 96 ,
199+ colno : 385 ,
200+ in_app : true ,
201+ } ,
202+ {
203+ filename : 'app:///index.android.bundle' ,
204+ function : 'onResponderRelease' ,
205+ lineno : 221 ,
206+ colno : 5666 ,
207+ in_app : true ,
208+ } ,
209+ {
210+ filename : 'app:///index.android.bundle' ,
211+ function : 'value' ,
212+ lineno : 221 ,
213+ colno : 7656 ,
214+ in_app : true ,
215+ } ,
216+ {
217+ filename : 'app:///index.android.bundle' ,
146218 function : 'onPress' ,
147219 lineno : 595 ,
148220 colno : 658 ,
0 commit comments