@@ -385,6 +385,17 @@ describe('run', () => {
385
385
kill = sinon . spy ( ( ) => { } ) ;
386
386
}
387
387
388
+ function loopExiter ( stdin ) {
389
+ return ( ) => stdin . emit ( 'keypress' , 'c' , { name : 'c' , ctrl : true } ) ;
390
+ }
391
+
392
+ function exitLoopOnError ( stdin ) {
393
+ return ( error ) => {
394
+ loopExiter ( stdin ) ;
395
+ throw error ;
396
+ } ;
397
+ }
398
+
388
399
function prepare ( ) {
389
400
const client = new RemoteFirefox ( fakeFirefoxClient ( ) ) ;
390
401
const watcher = {
@@ -403,6 +414,7 @@ describe('run', () => {
403
414
addonReload : sinon . spy ( ( ) => Promise . resolve ( ) ) ,
404
415
createWatcher : sinon . spy ( ( ) => watcher ) ,
405
416
stdin : new stream . Readable ( ) ,
417
+ kill : sinon . spy ( ( ) => Promise . resolve ( ) ) ,
406
418
} ;
407
419
return {
408
420
...args ,
@@ -462,19 +474,42 @@ describe('run', () => {
462
474
assert . ok ( addonReload . called ) ;
463
475
assert . equal ( addonReload . firstCall . args [ 0 ] . addonId ,
464
476
tempInstallResult . addon . id ) ;
465
- } ) ;
477
+ } )
478
+ . then ( loopExiter ( fakeStdin ) , exitLoopOnError ( fakeStdin ) ) ;
466
479
} ) ;
467
480
468
481
it ( 'shuts down firefox on user request (CTRL+C in shell console)' , ( ) => {
469
482
const { firefoxProcess, reloadStrategy} = prepare ( ) ;
470
483
const fakeStdin = new tty . ReadStream ( ) ;
484
+ sinon . spy ( fakeStdin , 'setRawMode' ) ;
471
485
472
486
return reloadStrategy ( { } , { stdin : fakeStdin } )
473
487
. then ( ( ) => {
474
488
fakeStdin . emit ( 'keypress' , 'c' , { name : 'c' , ctrl : true } ) ;
475
489
} ) . then ( ( ) => {
476
490
assert . ok ( firefoxProcess . kill . called ) ;
477
- } ) ;
491
+ } )
492
+ . then ( loopExiter ( fakeStdin ) , exitLoopOnError ( fakeStdin ) ) ;
493
+ } ) ;
494
+
495
+ it ( 'pauses the web-ext process (CTRL+Z in shell console)' , ( ) => {
496
+ const { reloadStrategy, kill} = prepare ( ) ;
497
+ const fakeStdin = new tty . ReadStream ( ) ;
498
+ const setRawMode = sinon . spy ( fakeStdin , 'setRawMode' ) ;
499
+
500
+ return reloadStrategy ( { } , { stdin : fakeStdin } )
501
+ . then ( ( ) => {
502
+ fakeStdin . emit ( 'keypress' , 'z' , { name : 'z' , ctrl : true } ) ;
503
+ } ) . then ( ( ) => {
504
+ assert . ok ( kill . called ) ;
505
+ assert . deepEqual ( kill . firstCall . args , [ process . pid , 'SIGTSTP' ] ) ;
506
+ sinon . assert . callOrder ( setRawMode , setRawMode , kill , setRawMode ) ;
507
+ sinon . assert . calledThrice ( setRawMode ) ;
508
+ assert . equal ( setRawMode . firstCall . args [ 0 ] , true ) ;
509
+ assert . equal ( setRawMode . secondCall . args [ 0 ] , false ) ;
510
+ assert . equal ( setRawMode . lastCall . args [ 0 ] , true ) ;
511
+ } )
512
+ . then ( loopExiter ( fakeStdin ) , exitLoopOnError ( fakeStdin ) ) ;
478
513
} ) ;
479
514
480
515
} ) ;
0 commit comments