@@ -51,16 +51,28 @@ class Helper {
51
51
if ( ! isAsync && ! log . enabled )
52
52
continue ;
53
53
Reflect . set ( classType . prototype , methodName , function ( this : any , ...args : any [ ] ) {
54
+ const syncStack : any = { } ;
55
+ Error . captureStackTrace ( syncStack ) ;
54
56
if ( log . enabled ) {
55
- if ( args . length )
56
- log ( `${ className } .${ methodName } %o` , args ) ;
57
- else
58
- log ( `${ className } .${ methodName } ` ) ;
57
+ const frames = syncStack . stack . substring ( 'Error\n' . length )
58
+ . split ( '\n' )
59
+ . map ( ( f : string ) => f . replace ( / \s + a t \s / , '' ) . trim ( ) ) ;
60
+ const userCall = frames . length <= 1 || ! frames [ 1 ] . includes ( 'playwright/lib' ) ;
61
+ if ( userCall ) {
62
+ const match = / ( [ ^ / \\ ] + ) ( : \d + : \d + ) [ ) ] ? $ / . exec ( frames [ 1 ] ) ;
63
+ let location = '' ;
64
+ if ( match ) {
65
+ const fileName = helper . trimMiddle ( match [ 1 ] , 20 - match [ 2 ] . length ) ;
66
+ location = `\u001b[33m[${ fileName } ${ match [ 2 ] } ]\u001b[39m ` ;
67
+ }
68
+ if ( args . length )
69
+ log ( `${ location } ${ className } .${ methodName } %o` , args ) ;
70
+ else
71
+ log ( `${ location } ${ className } .${ methodName } ` ) ;
72
+ }
59
73
}
60
74
if ( ! isAsync )
61
75
return method . call ( this , ...args ) ;
62
- const syncStack : any = { } ;
63
- Error . captureStackTrace ( syncStack ) ;
64
76
return method . call ( this , ...args ) . catch ( ( e : any ) => {
65
77
const stack = syncStack . stack . substring ( syncStack . stack . indexOf ( '\n' ) + 1 ) ;
66
78
const clientStack = stack . substring ( stack . indexOf ( '\n' ) ) ;
@@ -225,6 +237,15 @@ class Helper {
225
237
urlString = 'http://' + urlString ;
226
238
return urlString ;
227
239
}
240
+
241
+ static trimMiddle ( string : string , maxLength : number ) {
242
+ if ( string . length <= maxLength )
243
+ return string ;
244
+
245
+ const leftHalf = maxLength >> 1 ;
246
+ const rightHalf = maxLength - leftHalf - 1 ;
247
+ return string . substr ( 0 , leftHalf ) + '\u2026' + string . substr ( this . length - rightHalf , rightHalf ) ;
248
+ }
228
249
}
229
250
230
251
export function assert ( value : any , message ?: string ) : asserts value {
0 commit comments