@@ -588,4 +588,53 @@ describe('BSON e2e', function () {
588588 shell . assertNoErrors ( ) ;
589589 } ) ;
590590 } ) ;
591+ describe ( 'inspect nesting depth' , function ( ) {
592+ it ( 'inspects a full bson document when it is read from the server' , async function ( ) {
593+ await shell . executeLine ( `use ${ dbName } ` ) ;
594+ await shell . executeLine ( `deepAndNested = ({
595+ a: { b: { c: { d: { e: { f: { g: { h: "foundme" } } } } } } },
596+ array: [...Array(100000).keys()].map(i => ({ num: i })),
597+ str: 'All work and no play makes Jack a dull boy'.repeat(4096) + 'The End'
598+ });` ) ;
599+ await shell . executeLine ( `db.coll.insertOne(deepAndNested)` ) ;
600+ // Deeply nested object from the server should be fully printed
601+ const output = await shell . executeLine ( 'db.coll.findOne()' ) ;
602+ expect ( output ) . not . to . include ( '[Object' ) ;
603+ expect ( output ) . not . to . include ( 'more items' ) ;
604+ expect ( output ) . to . include ( 'foundme' ) ;
605+ expect ( output ) . to . include ( 'num: 99999' ) ;
606+ expect ( output ) . to . include ( 'The End' ) ;
607+ // Same object doesn't need to be fully printed if created by the user
608+ const output2 = await shell . executeLine ( 'deepAndNested' ) ;
609+ expect ( output2 ) . to . include ( '[Object' ) ;
610+ expect ( output2 ) . to . include ( 'more items' ) ;
611+ expect ( output2 ) . not . to . include ( 'foundme' ) ;
612+ expect ( output2 ) . not . to . include ( 'num: 99999' ) ;
613+ expect ( output2 ) . not . to . include ( 'The End' ) ;
614+ shell . assertNoErrors ( ) ;
615+ } ) ;
616+ it ( 'can parse serverStatus back to its original form' , async function ( ) {
617+ // Dates get special treatment but that doesn't currently apply
618+ // to mongosh's util.inspect that's available to users
619+ // (although maybe it should?).
620+ await shell . executeLine (
621+ `Date.prototype[Symbol.for('nodejs.util.inspect.custom')] = function(){ return 'ISODate("' + this.toISOString() + '")'; };`
622+ ) ;
623+ // 'void 0' to avoid large output in the shell from serverStatus
624+ await shell . executeLine (
625+ 'A = db.adminCommand({ serverStatus: 1 }); void 0'
626+ ) ;
627+ await shell . executeLine ( 'util.inspect(A)' ) ;
628+ await shell . executeLine ( `B = eval('(' + util.inspect(A) + ')'); void 0` ) ;
629+ shell . assertNoErrors ( ) ;
630+ const output1 = await shell . executeLineWithJSONResult ( 'A' , {
631+ parseAsEJSON : false ,
632+ } ) ;
633+ const output2 = await shell . executeLineWithJSONResult ( 'B' , {
634+ parseAsEJSON : false ,
635+ } ) ;
636+ expect ( output1 ) . to . deep . equal ( output2 ) ;
637+ shell . assertNoErrors ( ) ;
638+ } ) ;
639+ } ) ;
591640} ) ;
0 commit comments