@@ -831,44 +831,68 @@ describe('MongoOptions', function () {
831
831
sinon . restore ( ) ;
832
832
} ) ;
833
833
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 ) ;
838
854
} ) ;
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 } ) ) ;
842
855
} ) ;
843
856
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 ) ;
849
870
} ) ;
850
- expect ( client . options . mongoLoggerOptions . logDestination ) . to . deep . equal ( writable ) ;
851
871
} ) ;
852
872
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 } ) ) ;
857
882
} ) ;
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 } ) ) ;
861
883
} ) ;
862
884
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 } ) ) ;
868
895
} ) ;
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 } ) ) ;
872
896
} ) ;
873
897
} ) ;
874
898
} ) ;
0 commit comments