@@ -32,6 +32,34 @@ describe('Stacktrace', () => {
32
32
expect ( frames [ 0 ] . function ) . toBe ( 'bar' ) ;
33
33
expect ( frames [ 1 ] . function ) . toBe ( 'foo' ) ;
34
34
} ) ;
35
+
36
+ it ( 'remove two occurences if they are present' , ( ) => {
37
+ const exceptionStack = [
38
+ { colno : 1 , lineno : 4 , filename : 'anything.js' , function : 'captureException' } ,
39
+ { colno : 1 , lineno : 4 , filename : 'anything.js' , function : 'captureException' } ,
40
+ { colno : 1 , lineno : 3 , filename : 'anything.js' , function : 'foo' } ,
41
+ { colno : 1 , lineno : 2 , filename : 'anything.js' , function : 'bar' } ,
42
+ ] ;
43
+
44
+ const exceptionFrames = stripSentryFramesAndReverse ( exceptionStack ) ;
45
+
46
+ expect ( exceptionFrames . length ) . toBe ( 2 ) ;
47
+ expect ( exceptionFrames [ 0 ] . function ) . toBe ( 'bar' ) ;
48
+ expect ( exceptionFrames [ 1 ] . function ) . toBe ( 'foo' ) ;
49
+
50
+ const messageStack = [
51
+ { colno : 1 , lineno : 4 , filename : 'anything.js' , function : 'captureMessage' } ,
52
+ { colno : 1 , lineno : 4 , filename : 'anything.js' , function : 'captureMessage' } ,
53
+ { colno : 1 , lineno : 3 , filename : 'anything.js' , function : 'foo' } ,
54
+ { colno : 1 , lineno : 2 , filename : 'anything.js' , function : 'bar' } ,
55
+ ] ;
56
+
57
+ const messageFrames = stripSentryFramesAndReverse ( messageStack ) ;
58
+
59
+ expect ( messageFrames . length ) . toBe ( 2 ) ;
60
+ expect ( messageFrames [ 0 ] . function ) . toBe ( 'bar' ) ;
61
+ expect ( messageFrames [ 1 ] . function ) . toBe ( 'foo' ) ;
62
+ } ) ;
35
63
} ) ;
36
64
37
65
describe ( 'removed bottom frame if its internally reserved word (internal API)' , ( ) => {
@@ -53,6 +81,7 @@ describe('Stacktrace', () => {
53
81
54
82
it ( 'removed top and bottom frame if they are internally reserved words' , ( ) => {
55
83
const stack = [
84
+ { colno : 1 , lineno : 4 , filename : 'anything.js' , function : 'captureMessage' } ,
56
85
{ colno : 1 , lineno : 4 , filename : 'anything.js' , function : 'captureMessage' } ,
57
86
{ colno : 1 , lineno : 3 , filename : 'anything.js' , function : 'foo' } ,
58
87
{ colno : 1 , lineno : 2 , filename : 'anything.js' , function : 'bar' } ,
@@ -66,6 +95,25 @@ describe('Stacktrace', () => {
66
95
expect ( frames [ 0 ] . function ) . toBe ( 'bar' ) ;
67
96
expect ( frames [ 1 ] . function ) . toBe ( 'foo' ) ;
68
97
} ) ;
98
+
99
+ it ( 'applies frames limit after the stripping, not before' , ( ) => {
100
+ const stack = Array . from ( { length : 55 } ) . map ( ( _ , i ) => {
101
+ return { colno : 1 , lineno : 4 , filename : 'anything.js' , function : `${ i } ` } ;
102
+ } ) ;
103
+
104
+ stack . unshift ( { colno : 1 , lineno : 4 , filename : 'anything.js' , function : 'captureMessage' } ) ;
105
+ stack . unshift ( { colno : 1 , lineno : 4 , filename : 'anything.js' , function : 'captureMessage' } ) ;
106
+ stack . push ( { colno : 1 , lineno : 4 , filename : 'anything.js' , function : 'sentryWrapped' } ) ;
107
+
108
+ // Should remove 2x `captureMessage`, `sentryWrapped`, and then limit frames to default 50.
109
+ const frames = stripSentryFramesAndReverse ( stack ) ;
110
+
111
+ expect ( frames . length ) . toBe ( 50 ) ;
112
+
113
+ // Frames are named 0-54, thus after reversal and trimming, we should have frames 54-5, 50 in total.
114
+ expect ( frames [ 0 ] . function ) . toBe ( '54' ) ;
115
+ expect ( frames [ 49 ] . function ) . toBe ( '5' ) ;
116
+ } ) ;
69
117
} ) ;
70
118
} ) ;
71
119
0 commit comments