File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -23,10 +23,18 @@ export class RewriteFrames implements Integration {
2323 /**
2424 * @inheritDoc
2525 */
26- public constructor ( options : { root ?: string ; iteratee ?: StackFrameIteratee } = { } ) {
26+ private readonly _prefix : string = 'app:///' ;
27+
28+ /**
29+ * @inheritDoc
30+ */
31+ public constructor ( options : { root ?: string ; prefix ?: string ; iteratee ?: StackFrameIteratee } = { } ) {
2732 if ( options . root ) {
2833 this . _root = options . root ;
2934 }
35+ if ( options . prefix ) {
36+ this . _prefix = options . prefix ;
37+ }
3038 if ( options . iteratee ) {
3139 this . _iteratee = options . iteratee ;
3240 }
@@ -75,7 +83,7 @@ export class RewriteFrames implements Integration {
7583 . replace ( / \\ / g, '/' ) // replace all `\\` instances with `/`
7684 : frame . filename ;
7785 const base = this . _root ? relative ( this . _root , filename ) : basename ( filename ) ;
78- frame . filename = `app:/// ${ base } ` ;
86+ frame . filename = `${ this . _prefix } ${ base } ` ;
7987 }
8088 return frame ;
8189 } ;
Original file line number Diff line number Diff line change @@ -78,12 +78,32 @@ describe('RewriteFrames', () => {
7878 } ) ;
7979 } ) ;
8080
81+ describe ( 'default iteratee prepends custom prefix to basename if frame starts with `/`' , ( ) => {
82+ beforeEach ( ( ) => {
83+ rewriteFrames = new RewriteFrames ( {
84+ prefix : 'foobar/' ,
85+ } ) ;
86+ } ) ;
87+
88+ it ( 'transforms messageEvent frames' , ( ) => {
89+ const event = rewriteFrames . process ( messageEvent ) ;
90+ expect ( event . stacktrace ! . frames ! [ 0 ] . filename ) . toEqual ( 'foobar/file1.js' ) ;
91+ expect ( event . stacktrace ! . frames ! [ 1 ] . filename ) . toEqual ( 'foobar/file2.js' ) ;
92+ } ) ;
93+
94+ it ( 'transforms exceptionEvent frames' , ( ) => {
95+ const event = rewriteFrames . process ( exceptionEvent ) ;
96+ expect ( event . exception ! . values ! [ 0 ] . stacktrace ! . frames ! [ 0 ] . filename ) . toEqual ( 'foobar/file1.js' ) ;
97+ expect ( event . exception ! . values ! [ 0 ] . stacktrace ! . frames ! [ 1 ] . filename ) . toEqual ( 'foobar/file2.js' ) ;
98+ } ) ;
99+ } ) ;
100+
81101 describe ( 'default iteratee appends basename to `app:///` if frame starts with `C:\\`' , ( ) => {
82102 beforeEach ( ( ) => {
83103 rewriteFrames = new RewriteFrames ( ) ;
84104 } ) ;
85105
86- it ( 'trasforms windowsExceptionEvent frames' , ( ) => {
106+ it ( 'transforms windowsExceptionEvent frames' , ( ) => {
87107 const event = rewriteFrames . process ( windowsExceptionEvent ) ;
88108 expect ( event . exception ! . values ! [ 0 ] . stacktrace ! . frames ! [ 0 ] . filename ) . toEqual ( 'app:///file1.js' ) ;
89109 expect ( event . exception ! . values ! [ 0 ] . stacktrace ! . frames ! [ 1 ] . filename ) . toEqual ( 'app:///file2.js' ) ;
You can’t perform that action at this time.
0 commit comments