Skip to content

Commit a770fb3

Browse files
committed
chore: use json
1 parent d0100f7 commit a770fb3

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

test/tools/runner/config.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as util from 'node:util';
2+
import * as types from 'node:util/types';
23

34
import { expect } from 'chai';
45
import { type Context } from 'mocha';
@@ -9,6 +10,7 @@ import * as url from 'url';
910
import {
1011
type AuthMechanism,
1112
HostAddress,
13+
Long,
1214
MongoClient,
1315
type MongoClientOptions,
1416
ObjectId,
@@ -466,13 +468,23 @@ export class TestConfiguration {
466468
afterEachLogging(ctx: Context) {
467469
if (this.loggingEnabled && ctx.currentTest.state === 'failed') {
468470
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+
);
476488
}
477489
}
478490
this.loggingEnabled = false;

0 commit comments

Comments
 (0)