File tree 1 file changed +19
-7
lines changed
1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change 1
1
import * as util from 'node:util' ;
2
+ import * as types from 'node:util/types' ;
2
3
3
4
import { expect } from 'chai' ;
4
5
import { type Context } from 'mocha' ;
@@ -9,6 +10,7 @@ import * as url from 'url';
9
10
import {
10
11
type AuthMechanism ,
11
12
HostAddress ,
13
+ Long ,
12
14
MongoClient ,
13
15
type MongoClientOptions ,
14
16
ObjectId ,
@@ -466,13 +468,23 @@ export class TestConfiguration {
466
468
afterEachLogging ( ctx : Context ) {
467
469
if ( this . loggingEnabled && ctx . currentTest . state === 'failed' ) {
468
470
for ( const log of this . logs ) {
469
- const logLine = util . inspect ( log , {
470
- compact : true ,
471
- breakLength : Infinity ,
472
- colors : true ,
473
- depth : 1000
474
- } ) ;
475
- console . error ( logLine ) ;
471
+ console . error (
472
+ JSON . stringify (
473
+ log ,
474
+ function ( _ , value ) {
475
+ if ( types . isMap ( value ) ) return { Map : Array . from ( value . entries ( ) ) } ;
476
+ if ( types . isSet ( value ) ) return { Set : Array . from ( value . values ( ) ) } ;
477
+ if ( types . isNativeError ( value ) ) return { [ value . name ] : util . inspect ( value ) } ;
478
+ if ( typeof value === 'bigint' ) return new Long ( value ) . toExtendedJSON ( ) ;
479
+ if ( typeof value === 'symbol' ) return `Symbol(${ value . description } )` ;
480
+ if ( Buffer . isBuffer ( value ) )
481
+ return { [ value . constructor . name ] : Buffer . prototype . base64Slice . call ( value ) } ;
482
+ if ( value === undefined ) return { undefined : 'key was set but equal to undefined' } ;
483
+ return value ;
484
+ } ,
485
+ 0
486
+ )
487
+ ) ;
476
488
}
477
489
}
478
490
this . loggingEnabled = false ;
You can’t perform that action at this time.
0 commit comments