@@ -810,6 +810,61 @@ describe('CliRepl', () => {
810
810
expect ( output ) . to . include ( '--eval requires an argument, but no argument was given' ) ;
811
811
expect ( exitCode ) . to . equal ( 0 ) ;
812
812
} ) ;
813
+
814
+ it ( 'isInteractive() is false for --eval without --shell' , async ( ) => {
815
+ const filename1 = path . resolve ( __dirname , '..' , 'test' , 'fixtures' , 'load' , 'printisinteractive.js' ) ;
816
+ cliReplOptions . shellCliOptions . eval = await fs . readFile ( filename1 , 'utf8' ) ;
817
+ cliRepl = new CliRepl ( cliReplOptions ) ;
818
+ await startWithExpectedImmediateExit ( cliRepl , await testServer . connectionString ( ) ) ;
819
+ expect ( output ) . to . match ( / i s I n t e r a c t i v e = f a l s e / ) ;
820
+ expect ( exitCode ) . to . equal ( 0 ) ;
821
+ } ) ;
822
+
823
+ it ( 'isInteractive() is true for --eval with --shell' , async ( ) => {
824
+ const filename1 = path . resolve ( __dirname , '..' , 'test' , 'fixtures' , 'load' , 'printisinteractive.js' ) ;
825
+ cliReplOptions . shellCliOptions . eval = await fs . readFile ( filename1 , 'utf8' ) ;
826
+ cliReplOptions . shellCliOptions . shell = true ;
827
+ cliRepl = new CliRepl ( cliReplOptions ) ;
828
+ await cliRepl . start ( await testServer . connectionString ( ) , { } ) ;
829
+ expect ( output ) . to . match ( / i s I n t e r a c t i v e = t r u e / ) ;
830
+ expect ( exitCode ) . to . equal ( null ) ;
831
+
832
+ input . write ( 'exit\n' ) ;
833
+ await waitBus ( cliRepl . bus , 'mongosh:closed' ) ;
834
+ expect ( exitCode ) . to . equal ( 0 ) ;
835
+ } ) ;
836
+
837
+ it ( 'isInteractive() is false for loaded file without --shell' , async ( ) => {
838
+ const filename1 = path . resolve ( __dirname , '..' , 'test' , 'fixtures' , 'load' , 'printisinteractive.js' ) ;
839
+ cliReplOptions . shellCliOptions . _ . push ( filename1 ) ;
840
+ cliRepl = new CliRepl ( cliReplOptions ) ;
841
+ await startWithExpectedImmediateExit ( cliRepl , await testServer . connectionString ( ) ) ;
842
+ expect ( output ) . to . match ( / i s I n t e r a c t i v e = f a l s e / ) ;
843
+ expect ( exitCode ) . to . equal ( 0 ) ;
844
+ } ) ;
845
+
846
+ it ( 'isInteractive() is true for --eval with --shell' , async ( ) => {
847
+ const filename1 = path . resolve ( __dirname , '..' , 'test' , 'fixtures' , 'load' , 'printisinteractive.js' ) ;
848
+ cliReplOptions . shellCliOptions . _ . push ( filename1 ) ;
849
+ cliReplOptions . shellCliOptions . shell = true ;
850
+ cliRepl = new CliRepl ( cliReplOptions ) ;
851
+ await cliRepl . start ( await testServer . connectionString ( ) , { } ) ;
852
+ expect ( output ) . to . match ( / i s I n t e r a c t i v e = t r u e / ) ;
853
+ expect ( exitCode ) . to . equal ( null ) ;
854
+
855
+ input . write ( 'exit\n' ) ;
856
+ await waitBus ( cliRepl . bus , 'mongosh:closed' ) ;
857
+ expect ( exitCode ) . to . equal ( 0 ) ;
858
+ } ) ;
859
+
860
+ it ( 'isInteractive() is true for plain shell' , async ( ) => {
861
+ cliRepl = new CliRepl ( cliReplOptions ) ;
862
+ await cliRepl . start ( await testServer . connectionString ( ) , { } ) ;
863
+
864
+ input . write ( 'print("isInteractive=" + isInteractive())\n' ) ;
865
+ await waitEval ( cliRepl . bus ) ;
866
+ expect ( output ) . to . match ( / i s I n t e r a c t i v e = t r u e / ) ;
867
+ } ) ;
813
868
} ) ;
814
869
815
870
context ( 'with a user-provided prompt' , ( ) => {
0 commit comments