Skip to content

Commit a4685d9

Browse files
committed
Merge branch 'NODE-5981-fix-applying-read-preference-to-command' of github.com:mongodb/node-mongodb-native into NODE-5981-fix-applying-read-preference-to-command
2 parents 1806f30 + 00978cb commit a4685d9

File tree

4 files changed

+25
-31
lines changed

4 files changed

+25
-31
lines changed

src/mongo_logger.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ export function createStdioLogger(stream: {
220220
}): MongoDBLogWritable {
221221
return {
222222
write: promisify((log: Log, cb: (error?: Error) => void): unknown => {
223-
stream.write(inspect(log, { compact: true, breakLength: Infinity }), 'utf-8', cb);
223+
const logLine = inspect(log, { compact: true, breakLength: Infinity });
224+
stream.write(`${logLine}\n`, 'utf-8', cb);
224225
return;
225226
})
226227
};

test/unit/connection_string.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,8 @@ describe('Connection String', function () {
896896
});
897897
const log: Log = { t: new Date(), c: 'ConnectionStringStdErr', s: 'error' };
898898
client.options.mongoLoggerOptions.logDestination.write(log);
899-
expect(stderrStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
899+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
900+
expect(stderrStub.write).calledWith(`${logLine}\n`);
900901
});
901902
});
902903

@@ -907,7 +908,8 @@ describe('Connection String', function () {
907908
});
908909
const log: Log = { t: new Date(), c: 'ConnectionStringStdOut', s: 'error' };
909910
client.options.mongoLoggerOptions.logDestination.write(log);
910-
expect(stdoutStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
911+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
912+
expect(stdoutStub.write).calledWith(`${logLine}\n`);
911913
});
912914
});
913915

test/unit/mongo_client.test.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,8 @@ describe('MongoClient', function () {
852852
});
853853
const log = { t: new Date(), c: 'constructorStdErr', s: 'error' };
854854
client.options.mongoLoggerOptions.logDestination.write(log);
855-
expect(stderrStub.write).calledWith(
856-
inspect(log, { breakLength: Infinity, compact: true })
857-
);
855+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
856+
expect(stderrStub.write).calledWith(`${logLine}\n`);
858857
});
859858
});
860859

@@ -882,9 +881,8 @@ describe('MongoClient', function () {
882881
});
883882
const log = { t: new Date(), c: 'constructorStdOut', s: 'error' };
884883
client.options.mongoLoggerOptions.logDestination.write(log);
885-
expect(stdoutStub.write).calledWith(
886-
inspect(log, { breakLength: Infinity, compact: true })
887-
);
884+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
885+
expect(stdoutStub.write).calledWith(`${logLine}\n`);
888886
});
889887
});
890888

@@ -939,9 +937,8 @@ describe('MongoClient', function () {
939937
});
940938
const log = { t: new Date(), c: 'constructorStdErr', s: 'error' };
941939
client.options.mongoLoggerOptions.logDestination.write(log);
942-
expect(stderrStub.write).calledWith(
943-
inspect(log, { breakLength: Infinity, compact: true })
944-
);
940+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
941+
expect(stderrStub.write).calledWith(`${logLine}\n`);
945942
});
946943
});
947944
});

test/unit/mongo_logger.test.ts

+13-19
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,8 @@ describe('class MongoLogger', async function () {
443443
const log: Log = { t: new Date(), c: 'command', s: 'error' };
444444
options.logDestination.write(log);
445445

446-
expect(stderrStub.write).to.have.been.calledOnceWith(
447-
inspect(log, { breakLength: Infinity, compact: true })
448-
);
446+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
447+
expect(stderrStub.write).to.have.been.calledOnceWith(`${logLine}\n`);
449448
});
450449
}
451450
}
@@ -465,9 +464,8 @@ describe('class MongoLogger', async function () {
465464
const log: Log = { t: new Date(), c: 'command', s: 'error' };
466465
options.logDestination.write(log);
467466

468-
expect(stderrStub.write).to.have.been.calledOnceWith(
469-
inspect(log, { breakLength: Infinity, compact: true })
470-
);
467+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
468+
expect(stderrStub.write).to.have.been.calledOnceWith(`${logLine}\n`);
471469
});
472470
}
473471
}
@@ -512,9 +510,8 @@ describe('class MongoLogger', async function () {
512510
const log: Log = { t: new Date(), c: 'command', s: 'error' };
513511
options.logDestination.write(log);
514512

515-
expect(stderrStub.write).to.have.been.calledOnceWith(
516-
inspect(log, { breakLength: Infinity, compact: true })
517-
);
513+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
514+
expect(stderrStub.write).to.have.been.calledOnceWith(`${logLine}\n`);
518515
});
519516
}
520517
}
@@ -536,9 +533,8 @@ describe('class MongoLogger', async function () {
536533
const log: Log = { t: new Date(), c: 'command', s: 'error' };
537534
options.logDestination.write(log);
538535

539-
expect(stderrStub.write).to.have.been.calledOnceWith(
540-
inspect(log, { breakLength: Infinity, compact: true })
541-
);
536+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
537+
expect(stderrStub.write).to.have.been.calledOnceWith(`${logLine}\n`);
542538
});
543539
}
544540
}
@@ -1399,9 +1395,8 @@ describe('class MongoLogger', async function () {
13991395
logger.debug('client', 'random message');
14001396
let stderrStubCall = stderrStub.write.getCall(0).args[0];
14011397
stderrStubCall = stderrStubCall.slice(stderrStubCall.search('c:'));
1402-
expect(stderrStubCall).to.equal(
1403-
`c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'This writable always throws' }`
1404-
);
1398+
const expectedLogLine1 = `c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'This writable always throws' }`;
1399+
expect(stderrStubCall).to.equal(`${expectedLogLine1}\n`);
14051400

14061401
// logging is halted
14071402
logger.debug('client', 'random message 2');
@@ -1450,9 +1445,8 @@ describe('class MongoLogger', async function () {
14501445
// stderr now contains the error message
14511446
let stderrStubCall = stderrStub.write.getCall(0).args[0];
14521447
stderrStubCall = stderrStubCall.slice(stderrStubCall.search('c:'));
1453-
expect(stderrStubCall).to.equal(
1454-
`c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'This writable always throws, but only after at least 500ms' }`
1455-
);
1448+
const expectedLogLine1 = `c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'This writable always throws, but only after at least 500ms' }`;
1449+
expect(stderrStubCall).to.equal(`${expectedLogLine1}\n`);
14561450

14571451
// no more logging in the future
14581452
logger.debug('client', 'random message 2');
@@ -1480,7 +1474,7 @@ describe('class MongoLogger', async function () {
14801474
let stderrStubCall = stderrStub.write.getCall(0).args[0];
14811475
stderrStubCall = stderrStubCall.slice(stderrStubCall.search('c:'));
14821476
expect(stderrStubCall).to.equal(
1483-
`c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'I am stdout and do not work' }`
1477+
`c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'I am stdout and do not work' }\n`
14841478
);
14851479

14861480
// logging is halted

0 commit comments

Comments
 (0)