@@ -589,30 +589,128 @@ describe('BSON e2e', function () {
589589 } ) ;
590590 } ) ;
591591 describe ( 'inspect nesting depth' , function ( ) {
592- it ( 'inspects a full bson document when it is read from the server' , async function ( ) {
592+ const deepAndNestedDefinition = `({
593+ a: { b: { c: { d: { e: { f: { g: { h: "foundme" } } } } } } },
594+ array: [...Array(100000).keys()].map(i => ({ num: i })),
595+ str: 'All work and no playmakes Jack a dull boy'.repeat(4096) + 'The End'
596+ })` ;
597+ const checkForDeepOutput = ( output : string , wantFullOutput : boolean ) => {
598+ if ( wantFullOutput ) {
599+ expect ( output ) . not . to . include ( '[Object' ) ;
600+ expect ( output ) . not . to . include ( 'more items' ) ;
601+ expect ( output ) . to . include ( 'foundme' ) ;
602+ expect ( output ) . to . include ( 'num: 99999' ) ;
603+ expect ( output ) . to . include ( 'The End' ) ;
604+ } else {
605+ expect ( output ) . to . include ( '[Object' ) ;
606+ expect ( output ) . to . include ( 'more items' ) ;
607+ expect ( output ) . not . to . include ( 'foundme' ) ;
608+ expect ( output ) . not . to . include ( 'num: 99999' ) ;
609+ expect ( output ) . not . to . include ( 'The End' ) ;
610+ }
611+ } ;
612+
613+ beforeEach ( async function ( ) {
593614 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- });` ) ;
615+ await shell . executeLine ( `deepAndNested = ${ deepAndNestedDefinition } ` ) ;
599616 await shell . executeLine ( `db.coll.insertOne(deepAndNested)` ) ;
617+ } ) ;
618+
619+ it ( 'inspects a full bson document when it is read from the server (interactive mode)' , async function ( ) {
600620 // Deeply nested object from the server should be fully printed
601621 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' ) ;
622+ checkForDeepOutput ( output , true ) ;
607623 // Same object doesn't need to be fully printed if created by the user
608624 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' ) ;
625+ checkForDeepOutput ( output2 , false ) ;
626+ shell . assertNoErrors ( ) ;
627+ } ) ;
628+
629+ it ( 'can explicitly disable full-depth nesting (interactive mode)' , async function ( ) {
630+ shell . kill ( ) ;
631+ shell = this . startTestShell ( {
632+ args : [ await testServer . connectionString ( ) , '--deepInspect=false' ] ,
633+ } ) ;
634+ await shell . executeLine ( `use ${ dbName } ` ) ;
635+ const output = await shell . executeLine ( 'db.coll.findOne()' ) ;
636+ checkForDeepOutput ( output , false ) ;
637+ shell . assertNoErrors ( ) ;
638+ } ) ;
639+
640+ it ( 'does not deeply inspect objects in non-interactive mode for intermediate output' , async function ( ) {
641+ shell . kill ( ) ;
642+ shell = this . startTestShell ( {
643+ args : [
644+ await testServer . connectionString ( ) ,
645+ '--eval' ,
646+ `use(${ JSON . stringify ( dbName ) } ); print(db.coll.findOne()); 0` ,
647+ ] ,
648+ } ) ;
649+ await shell . waitForSuccessfulExit ( ) ;
650+ checkForDeepOutput ( shell . output , false ) ;
651+ shell . assertNoErrors ( ) ;
652+ shell = this . startTestShell ( {
653+ args : [
654+ await testServer . connectionString ( ) ,
655+ '--eval' ,
656+ `print(${ deepAndNestedDefinition } ); 0` ,
657+ ] ,
658+ } ) ;
659+ await shell . waitForSuccessfulExit ( ) ;
660+ checkForDeepOutput ( shell . output , false ) ;
661+ shell . assertNoErrors ( ) ;
662+ } ) ;
663+
664+ it ( 'inspect full objects in non-interactive mode for final output' , async function ( ) {
665+ shell . kill ( ) ;
666+ shell = this . startTestShell ( {
667+ args : [
668+ await testServer . connectionString ( ) ,
669+ '--eval' ,
670+ `use(${ JSON . stringify ( dbName ) } ); db.coll.findOne();` ,
671+ ] ,
672+ } ) ;
673+ await shell . waitForSuccessfulExit ( ) ;
674+ checkForDeepOutput ( shell . output , true ) ;
675+ shell . assertNoErrors ( ) ;
676+ shell = this . startTestShell ( {
677+ args : [
678+ await testServer . connectionString ( ) ,
679+ '--eval' ,
680+ deepAndNestedDefinition ,
681+ ] ,
682+ } ) ;
683+ await shell . waitForSuccessfulExit ( ) ;
684+ checkForDeepOutput ( shell . output , true ) ;
614685 shell . assertNoErrors ( ) ;
615686 } ) ;
687+
688+ it ( 'can explicitly disable full-depth nesting (non-interactive mode)' , async function ( ) {
689+ shell . kill ( ) ;
690+ shell = this . startTestShell ( {
691+ args : [
692+ await testServer . connectionString ( ) ,
693+ '--deepInspect=false' ,
694+ '--eval' ,
695+ `use(${ JSON . stringify ( dbName ) } ); db.coll.findOne();` ,
696+ ] ,
697+ } ) ;
698+ await shell . waitForSuccessfulExit ( ) ;
699+ checkForDeepOutput ( shell . output , false ) ;
700+ shell . assertNoErrors ( ) ;
701+ shell = this . startTestShell ( {
702+ args : [
703+ await testServer . connectionString ( ) ,
704+ '--deepInspect=false' ,
705+ '--eval' ,
706+ deepAndNestedDefinition ,
707+ ] ,
708+ } ) ;
709+ await shell . waitForSuccessfulExit ( ) ;
710+ checkForDeepOutput ( shell . output , false ) ;
711+ shell . assertNoErrors ( ) ;
712+ } ) ;
713+
616714 it ( 'can parse serverStatus back to its original form' , async function ( ) {
617715 // Dates get special treatment but that doesn't currently apply
618716 // to mongosh's util.inspect that's available to users
0 commit comments