@@ -705,47 +705,81 @@ describe('e2e', function() {
705705 }
706706 } ) ;
707707
708- let shell : TestShell ;
709- beforeEach ( async ( ) => {
710- shell = TestShell . start ( { args : [ '--nodb' ] , removeSigintListeners : true } ) ;
711- await shell . waitForPrompt ( ) ;
712- shell . assertNoErrors ( ) ;
708+ describe ( 'non-interactive' , function ( ) {
709+ it ( 'interrupts file execution' , async function ( ) {
710+ const filename = path . resolve (
711+ __dirname ,
712+ 'fixtures' ,
713+ 'load' ,
714+ 'long-sleep.js'
715+ ) ;
716+ const shell = TestShell . start ( {
717+ args : [ '--nodb' , filename ] ,
718+ removeSigintListeners : true ,
719+ forceTerminal : true
720+ } ) ;
721+
722+ await eventually ( ( ) => {
723+ if ( shell . output . includes ( 'Long sleep' ) ) {
724+ return ;
725+ }
726+ throw new Error ( 'Waiting for the file to load...' ) ;
727+ } ) ;
728+
729+ shell . kill ( 'SIGINT' ) ;
730+
731+ await eventually ( ( ) => {
732+ if ( shell . output . includes ( 'MongoshInterruptedError' ) ) {
733+ return ;
734+ }
735+ throw new Error ( 'Waiting for the interruption...' ) ;
736+ } ) ;
737+ } ) ;
713738 } ) ;
714739
715- it ( 'interrupts sync execution' , async ( ) => {
716- await shell . executeLine ( 'void process.removeAllListeners("SIGINT")' ) ;
717- const result = shell . executeLine ( 'while(true);' ) ;
718- setTimeout ( ( ) => shell . kill ( 'SIGINT' ) , 1000 ) ;
719- await result ;
720- shell . assertContainsError ( 'interrupted' ) ;
721- } ) ;
722- it ( 'interrupts async awaiting' , async ( ) => {
723- const result = shell . executeLine ( 'new Promise(() => {});' ) ;
724- setTimeout ( ( ) => shell . kill ( 'SIGINT' ) , 3000 ) ;
725- await result ;
726- shell . assertContainsOutput ( 'Stopping execution...' ) ;
727- } ) ;
728- it ( 'interrupts load()' , async ( ) => {
729- const filename = path . resolve ( __dirname , 'fixtures' , 'load' , 'infinite-loop.js' ) ;
730- const result = shell . executeLine ( `load(${ JSON . stringify ( filename ) } )` ) ;
731- setTimeout ( ( ) => shell . kill ( 'SIGINT' ) , 3000 ) ;
732- await result ;
733- // The while loop in the script is run as "sync" code
734- shell . assertContainsError ( 'interrupted' ) ;
735- } ) ;
736- it ( 'behaves normally after an exception' , async ( ) => {
737- await shell . executeLine ( 'throw new Error()' ) ;
738- await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
739- shell . kill ( 'SIGINT' ) ;
740- await shell . waitForPrompt ( ) ;
741- await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
742- shell . assertNotContainsOutput ( 'interrupted' ) ;
743- shell . assertNotContainsOutput ( 'Stopping execution' ) ;
744- } ) ;
745- it ( 'does not trigger MaxListenersExceededWarning' , async ( ) => {
746- await shell . executeLine ( 'for (let i = 0; i < 11; i++) { console.log("hi"); }\n' ) ;
747- await shell . executeLine ( 'for (let i = 0; i < 20; i++) (async() => { await sleep(0) })()' ) ;
748- shell . assertNotContainsOutput ( 'MaxListenersExceededWarning' ) ;
740+ describe ( 'interactive' , function ( ) {
741+ let shell : TestShell ;
742+ beforeEach ( async ( ) => {
743+ shell = TestShell . start ( { args : [ '--nodb' ] , removeSigintListeners : true } ) ;
744+ await shell . waitForPrompt ( ) ;
745+ shell . assertNoErrors ( ) ;
746+ } ) ;
747+
748+ it ( 'interrupts sync execution' , async ( ) => {
749+ await shell . executeLine ( 'void process.removeAllListeners("SIGINT")' ) ;
750+ const result = shell . executeLine ( 'while(true);' ) ;
751+ setTimeout ( ( ) => shell . kill ( 'SIGINT' ) , 1000 ) ;
752+ await result ;
753+ shell . assertContainsError ( 'interrupted' ) ;
754+ } ) ;
755+ it ( 'interrupts async awaiting' , async ( ) => {
756+ const result = shell . executeLine ( 'new Promise(() => {});' ) ;
757+ setTimeout ( ( ) => shell . kill ( 'SIGINT' ) , 3000 ) ;
758+ await result ;
759+ shell . assertContainsOutput ( 'Stopping execution...' ) ;
760+ } ) ;
761+ it ( 'interrupts load()' , async ( ) => {
762+ const filename = path . resolve ( __dirname , 'fixtures' , 'load' , 'infinite-loop.js' ) ;
763+ const result = shell . executeLine ( `load(${ JSON . stringify ( filename ) } )` ) ;
764+ setTimeout ( ( ) => shell . kill ( 'SIGINT' ) , 3000 ) ;
765+ await result ;
766+ // The while loop in the script is run as "sync" code
767+ shell . assertContainsError ( 'interrupted' ) ;
768+ } ) ;
769+ it ( 'behaves normally after an exception' , async ( ) => {
770+ await shell . executeLine ( 'throw new Error()' ) ;
771+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
772+ shell . kill ( 'SIGINT' ) ;
773+ await shell . waitForPrompt ( ) ;
774+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
775+ shell . assertNotContainsOutput ( 'interrupted' ) ;
776+ shell . assertNotContainsOutput ( 'Stopping execution' ) ;
777+ } ) ;
778+ it ( 'does not trigger MaxListenersExceededWarning' , async ( ) => {
779+ await shell . executeLine ( 'for (let i = 0; i < 11; i++) { console.log("hi"); }\n' ) ;
780+ await shell . executeLine ( 'for (let i = 0; i < 20; i++) (async() => { await sleep(0) })()' ) ;
781+ shell . assertNotContainsOutput ( 'MaxListenersExceededWarning' ) ;
782+ } ) ;
749783 } ) ;
750784 } ) ;
751785
0 commit comments