@@ -32,6 +32,34 @@ describe('Stacktrace', () => {
3232 expect ( frames [ 0 ] . function ) . toBe ( 'bar' ) ;
3333 expect ( frames [ 1 ] . function ) . toBe ( 'foo' ) ;
3434 } ) ;
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+ } ) ;
3563 } ) ;
3664
3765 describe ( 'removed bottom frame if its internally reserved word (internal API)' , ( ) => {
@@ -53,6 +81,7 @@ describe('Stacktrace', () => {
5381
5482 it ( 'removed top and bottom frame if they are internally reserved words' , ( ) => {
5583 const stack = [
84+ { colno : 1 , lineno : 4 , filename : 'anything.js' , function : 'captureMessage' } ,
5685 { colno : 1 , lineno : 4 , filename : 'anything.js' , function : 'captureMessage' } ,
5786 { colno : 1 , lineno : 3 , filename : 'anything.js' , function : 'foo' } ,
5887 { colno : 1 , lineno : 2 , filename : 'anything.js' , function : 'bar' } ,
@@ -66,6 +95,25 @@ describe('Stacktrace', () => {
6695 expect ( frames [ 0 ] . function ) . toBe ( 'bar' ) ;
6796 expect ( frames [ 1 ] . function ) . toBe ( 'foo' ) ;
6897 } ) ;
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+ } ) ;
69117 } ) ;
70118} ) ;
71119
0 commit comments