1
1
import type { Exception } from '@sentry/browser' ;
2
2
import { defaultStackParser , eventFromException } from '@sentry/browser' ;
3
+ import { Platform } from 'react-native' ;
3
4
4
5
import { 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' } } ) ) ;
5
11
6
12
describe ( 'RewriteFrames' , ( ) => {
7
13
const HINT = { } ;
@@ -20,6 +26,11 @@ describe('RewriteFrames', () => {
20
26
return exception ;
21
27
} ;
22
28
29
+ beforeEach ( ( ) => {
30
+ mockFunction ( isExpo ) . mockReturnValue ( false ) ;
31
+ jest . resetAllMocks ( ) ;
32
+ } ) ;
33
+
23
34
it ( 'should parse exceptions for react-native-v8' , async ( ) => {
24
35
const REACT_NATIVE_V8_EXCEPTION = {
25
36
message : 'Manually triggered crash to test Sentry reporting' ,
@@ -98,7 +109,10 @@ describe('RewriteFrames', () => {
98
109
} ) ;
99
110
} ) ;
100
111
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
+
102
116
const REACT_NATIVE_EXPO_EXCEPTION = {
103
117
message : 'Test Error Expo' ,
104
118
name : 'Error' ,
@@ -121,28 +135,86 @@ describe('RewriteFrames', () => {
121
135
frames : [
122
136
{ filename : '[native code]' , function : 'forEach' , in_app : true } ,
123
137
{
124
- filename : 'app:///bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3 ' ,
138
+ filename : 'app:///main.jsbundle ' ,
125
139
function : 'p' ,
126
140
lineno : 96 ,
127
141
colno : 385 ,
128
142
in_app : true ,
129
143
} ,
130
144
{
131
- filename : 'app:///bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3 ' ,
145
+ filename : 'app:///main.jsbundle ' ,
132
146
function : 'onResponderRelease' ,
133
147
lineno : 221 ,
134
148
colno : 5666 ,
135
149
in_app : true ,
136
150
} ,
137
151
{
138
- filename : 'app:///bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3 ' ,
152
+ filename : 'app:///main.jsbundle ' ,
139
153
function : 'value' ,
140
154
lineno : 221 ,
141
155
colno : 7656 ,
142
156
in_app : true ,
143
157
} ,
144
158
{
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' ,
146
218
function : 'onPress' ,
147
219
lineno : 595 ,
148
220
colno : 658 ,
0 commit comments