11
11
'use strict' ;
12
12
13
13
const fs = require ( 'fs' ) ;
14
+ const path = require ( 'path' ) ;
14
15
15
16
const capturedErrorDefaults = {
16
17
componentName : 'A' ,
@@ -87,7 +88,7 @@ describe('ExceptionsManager', () => {
87
88
expect ( console . error ) . toBeCalledWith ( formattedMessage ) ;
88
89
} ) ;
89
90
90
- test ( 'pops frames off the stack with framesToPop' , ( ) => {
91
+ test ( 'does not pop frames off the stack with framesToPop' , ( ) => {
91
92
function createError ( ) {
92
93
const error = new Error ( 'Some error happened' ) ;
93
94
error . framesToPop = 1 ;
@@ -103,7 +104,7 @@ describe('ExceptionsManager', () => {
103
104
expect ( nativeReportException . mock . calls . length ) . toBe ( 1 ) ;
104
105
const exceptionData = nativeReportException . mock . calls [ 0 ] [ 0 ] ;
105
106
expect ( getLineFromFrame ( exceptionData . stack [ 0 ] ) ) . toBe (
106
- ' const error = createError();' ,
107
+ " const error = new Error('Some error happened');" ,
107
108
) ;
108
109
} ) ;
109
110
@@ -305,9 +306,9 @@ describe('ExceptionsManager', () => {
305
306
) ;
306
307
expect ( exceptionData . originalMessage ) . toBe ( '"Some error happened"' ) ;
307
308
expect ( exceptionData . name ) . toBe ( 'console.error' ) ;
308
- expect ( getLineFromFrame ( exceptionData . stack [ 0 ] ) ) . toBe (
309
- 'console.error(message);' ,
310
- ) ;
309
+ expect (
310
+ getLineFromFrame ( getFirstFrameInThisFile ( exceptionData . stack ) ) ,
311
+ ) . toBe ( 'console.error(message);' ) ;
311
312
expect ( exceptionData . isFatal ) . toBe ( false ) ;
312
313
expect ( mockError . mock . calls [ 0 ] ) . toEqual ( [ message ] ) ;
313
314
} ) ;
@@ -326,9 +327,9 @@ describe('ExceptionsManager', () => {
326
327
'42, true, ["symbol" failed to stringify], {"y":null}' ,
327
328
) ;
328
329
expect ( exceptionData . name ) . toBe ( 'console.error' ) ;
329
- expect ( getLineFromFrame ( exceptionData . stack [ 0 ] ) ) . toBe (
330
- 'console.error(...args);' ,
331
- ) ;
330
+ expect (
331
+ getLineFromFrame ( getFirstFrameInThisFile ( exceptionData . stack ) ) ,
332
+ ) . toBe ( 'console.error(...args);' ) ;
332
333
expect ( exceptionData . isFatal ) . toBe ( false ) ;
333
334
334
335
expect ( mockError ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -367,7 +368,7 @@ describe('ExceptionsManager', () => {
367
368
expect ( mockError . mock . calls [ 0 ] ) . toEqual ( [ message ] ) ;
368
369
} ) ;
369
370
370
- test ( 'pops frames off the stack with framesToPop' , ( ) => {
371
+ test ( 'does not pop frames off the stack with framesToPop' , ( ) => {
371
372
function createError ( ) {
372
373
const error = new Error ( 'Some error happened' ) ;
373
374
error . framesToPop = 1 ;
@@ -380,7 +381,7 @@ describe('ExceptionsManager', () => {
380
381
expect ( nativeReportException . mock . calls . length ) . toBe ( 1 ) ;
381
382
const exceptionData = nativeReportException . mock . calls [ 0 ] [ 0 ] ;
382
383
expect ( getLineFromFrame ( exceptionData . stack [ 0 ] ) ) . toBe (
383
- ' const error = createError();' ,
384
+ " const error = new Error('Some error happened');" ,
384
385
) ;
385
386
} ) ;
386
387
} ) ;
@@ -441,7 +442,7 @@ describe('ExceptionsManager', () => {
441
442
expect ( console . error . mock . calls [ 0 ] ) . toEqual ( [ message ] ) ;
442
443
} ) ;
443
444
444
- test ( 'pops frames off the stack with framesToPop' , ( ) => {
445
+ test ( 'does not pop frames off the stack with framesToPop' , ( ) => {
445
446
function createError ( ) {
446
447
const error = new Error ( 'Some error happened' ) ;
447
448
error . framesToPop = 1 ;
@@ -454,7 +455,7 @@ describe('ExceptionsManager', () => {
454
455
expect ( nativeReportException . mock . calls . length ) . toBe ( 1 ) ;
455
456
const exceptionData = nativeReportException . mock . calls [ 0 ] [ 0 ] ;
456
457
expect ( getLineFromFrame ( exceptionData . stack [ 0 ] ) ) . toBe (
457
- ' const error = createError();' ,
458
+ " const error = new Error('Some error happened');" ,
458
459
) ;
459
460
} ) ;
460
461
} ) ;
@@ -550,6 +551,10 @@ function getLineFromFrame({lineNumber /* 1-based */, file}) {
550
551
return ( lines [ lineNumber - 1 ] || '' ) . trim ( ) ;
551
552
}
552
553
554
+ function getFirstFrameInThisFile ( stack ) {
555
+ return stack . find ( ( { file} ) => file . endsWith ( path . basename ( module . filename ) ) ) ;
556
+ }
557
+
553
558
// Works around a parseErrorStack bug involving `new X` stack frames.
554
559
function cleanFileName ( file ) {
555
560
return file . replace ( / ^ .+ ? \( (? = \/ ) / , '' ) ;
0 commit comments