Skip to content

Commit 4e99d70

Browse files
PR requested changes 0
1 parent c021660 commit 4e99d70

File tree

2 files changed

+76
-46
lines changed

2 files changed

+76
-46
lines changed

test/unit/connection_string.test.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -850,31 +850,37 @@ describe('Connection String', function () {
850850
sinon.restore();
851851
});
852852

853-
it('when option is `stderr`, it is accessible through mongoLogger.logDestination', function () {
854-
const client = new MongoClient('mongodb://a/?mongodbLogPath=stderr', {
855-
[loggerFeatureFlag]: true
853+
context('when option is `stderr`', function () {
854+
it('it is accessible through mongoLogger.logDestination', function () {
855+
const client = new MongoClient('mongodb://a/?mongodbLogPath=stderr', {
856+
[loggerFeatureFlag]: true
857+
});
858+
const log: Log = { t: new Date(), c: 'ConnectionStringStdErr', s: 'error' };
859+
client.options.mongoLoggerOptions.logDestination.write(log);
860+
expect(stderrStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
856861
});
857-
const log: Log = { t: new Date(), c: 'ConnectionStringStdErr', s: 'error' };
858-
client.options.mongoLoggerOptions.logDestination.write(log);
859-
expect(stderrStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
860862
});
861863

862-
it('when option is `stdout`, it is accessible through mongoLogger.logDestination', function () {
863-
const client = new MongoClient('mongodb://a/?mongodbLogPath=stdout', {
864-
[loggerFeatureFlag]: true
864+
context('when option is `stdout`', function () {
865+
it('it is accessible through mongoLogger.logDestination', function () {
866+
const client = new MongoClient('mongodb://a/?mongodbLogPath=stdout', {
867+
[loggerFeatureFlag]: true
868+
});
869+
const log: Log = { t: new Date(), c: 'ConnectionStringStdOut', s: 'error' };
870+
client.options.mongoLoggerOptions.logDestination.write(log);
871+
expect(stdoutStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
865872
});
866-
const log: Log = { t: new Date(), c: 'ConnectionStringStdOut', s: 'error' };
867-
client.options.mongoLoggerOptions.logDestination.write(log);
868-
expect(stdoutStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
869873
});
870874

871-
it('when option is invalid, it defaults to stderr', function () {
872-
const client = new MongoClient('mongodb://a/?mongodbLogPath=stdnothing', {
873-
[loggerFeatureFlag]: true
875+
context('when option is invalid', function () {
876+
it('it defaults to stderr', function () {
877+
const client = new MongoClient('mongodb://a/?mongodbLogPath=stdnothing', {
878+
[loggerFeatureFlag]: true
879+
});
880+
const log: Log = { t: new Date(), c: 'ConnectionStringInvalidOption', s: 'error' };
881+
client.options.mongoLoggerOptions.logDestination.write(log);
882+
expect(stderrStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
874883
});
875-
const log: Log = { t: new Date(), c: 'ConnectionStringInvalidOption', s: 'error' };
876-
client.options.mongoLoggerOptions.logDestination.write(log);
877-
expect(stderrStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
878884
});
879885
});
880886
});

test/unit/mongo_client.test.js

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -831,44 +831,68 @@ describe('MongoOptions', function () {
831831
sinon.restore();
832832
});
833833

834-
it('when option is `stderr`, it is accessible through mongoLogger.logDestination', function () {
835-
const client = new MongoClient('mongodb://a/', {
836-
[loggerFeatureFlag]: true,
837-
mongodbLogPath: 'stderr'
834+
context('when option is `stderr`', function () {
835+
it('it is accessible through mongoLogger.logDestination', function () {
836+
const client = new MongoClient('mongodb://a/', {
837+
[loggerFeatureFlag]: true,
838+
mongodbLogPath: 'stderr'
839+
});
840+
const log = { t: new Date(), c: 'constructorStdErr', s: 'error' };
841+
client.options.mongoLoggerOptions.logDestination.write(log);
842+
expect(stderrStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
843+
});
844+
});
845+
846+
context('when option is a Writable stream', function () {
847+
it('it is accessible through mongoLogger.logDestination', function () {
848+
const writable = new Writable();
849+
const client = new MongoClient('mongodb://a/', {
850+
[loggerFeatureFlag]: true,
851+
mongodbLogPath: writable
852+
});
853+
expect(client.options.mongoLoggerOptions.logDestination).to.deep.equal(writable);
838854
});
839-
const log = { t: new Date(), c: 'constructorStdErr', s: 'error' };
840-
client.options.mongoLoggerOptions.logDestination.write(log);
841-
expect(stderrStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
842855
});
843856

844-
it('when option is a Writable stream, it is accessible through mongoLogger.logDestination', function () {
845-
const writable = new Writable();
846-
const client = new MongoClient('mongodb://a/', {
847-
[loggerFeatureFlag]: true,
848-
mongodbLogPath: writable
857+
context('when option is a MongoDBLogWritable stream', function () {
858+
it('it is accessible through mongoLogger.logDestination', function () {
859+
const writable = {
860+
buffer: [],
861+
write(log) {
862+
this.buffer.push(log);
863+
}
864+
};
865+
const client = new MongoClient('mongodb://a/', {
866+
[loggerFeatureFlag]: true,
867+
mongodbLogPath: writable
868+
});
869+
expect(client.options.mongoLoggerOptions.logDestination).to.deep.equal(writable);
849870
});
850-
expect(client.options.mongoLoggerOptions.logDestination).to.deep.equal(writable);
851871
});
852872

853-
it('when option is `stdout`, it is accessible through mongoLogger.logDestination', function () {
854-
const client = new MongoClient('mongodb://a/', {
855-
[loggerFeatureFlag]: true,
856-
mongodbLogPath: 'stdout'
873+
context('when option is `stdout`', function () {
874+
it('it is accessible through mongoLogger.logDestination', function () {
875+
const client = new MongoClient('mongodb://a/', {
876+
[loggerFeatureFlag]: true,
877+
mongodbLogPath: 'stdout'
878+
});
879+
const log = { t: new Date(), c: 'constructorStdOut', s: 'error' };
880+
client.options.mongoLoggerOptions.logDestination.write(log);
881+
expect(stdoutStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
857882
});
858-
const log = { t: new Date(), c: 'constructorStdOut', s: 'error' };
859-
client.options.mongoLoggerOptions.logDestination.write(log);
860-
expect(stdoutStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
861883
});
862884

863-
it('when option is invalid, it defaults to stderr', function () {
864-
const invalidOption = 'stdnothing';
865-
const client = new MongoClient('mongodb://a/', {
866-
[loggerFeatureFlag]: true,
867-
mongodbLogPath: invalidOption
885+
context('when option is invalid', function () {
886+
it('it defaults to stderr', function () {
887+
const invalidOption = 'stdnothing';
888+
const client = new MongoClient('mongodb://a/', {
889+
[loggerFeatureFlag]: true,
890+
mongodbLogPath: invalidOption
891+
});
892+
const log = { t: new Date(), c: 'constructorInvalidOption', s: 'error' };
893+
client.options.mongoLoggerOptions.logDestination.write(log);
894+
expect(stderrStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
868895
});
869-
const log = { t: new Date(), c: 'constructorInvalidOption', s: 'error' };
870-
client.options.mongoLoggerOptions.logDestination.write(log);
871-
expect(stderrStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
872896
});
873897
});
874898
});

0 commit comments

Comments
 (0)