@@ -6,42 +6,51 @@ var utils = require('../utils'),
6
6
appjs = path . relative ( process . cwd ( ) , path . resolve ( __dirname , '..' , 'fixtures' , 'sigint.js' ) ) ,
7
7
match = utils . match ,
8
8
cleanup = utils . cleanup ,
9
- run = utils . run ;
9
+ run = utils . run ,
10
+ isRunning = utils . isRunning ;
10
11
11
- describe ( 'terminal signals' , function ( ) {
12
- it ( 'should kill child with SIGINT (after ~10 seconds)' , function ( done ) {
13
- var childPID = null ;
12
+ function runAndKill ( done , cmdline , exitcb )
13
+ {
14
+ var childPID = null ;
14
15
15
- var p = run ( appjs , {
16
- output : function ( data ) {
17
- if ( match ( data , 'pid: ' ) ) {
18
- data . replace ( / p i d : ( \d + ) / , function ( m ) {
19
- childPID = m ;
20
- } ) ;
21
- }
22
- } ,
23
- error : function ( data ) {
24
- assert ( false , 'nodemon failed with ' + data ) ;
25
- cleanup ( p , done ) ;
16
+ var p = run ( cmdline , {
17
+ output : function ( data ) {
18
+ if ( match ( data , 'pid: ' ) ) {
19
+ data . replace ( / p i d : ( \d + ) / , function ( _ , p1 ) {
20
+ childPID = p1 ;
21
+ } ) ;
26
22
}
27
- } ) ;
23
+ } ,
24
+ error : function ( data ) {
25
+ assert ( false , 'nodemon failed with ' + data ) ;
26
+ cleanup ( p , done ) ;
27
+ }
28
+ } ) ;
28
29
29
- p . on ( 'message' , function ( event ) {
30
- if ( event . type === 'start' ) {
31
- setTimeout ( function ( ) {
32
- p . kill ( 'SIGINT' ) ;
33
- } , 1000 ) ;
34
- }
35
- } ) . on ( 'exit' , function ( ) {
36
- // check if the child process is still running
37
- try {
38
- process . kill ( childPID , 0 ) ;
39
- assert ( false , 'child is still running at ' + childPID ) ;
40
- } catch ( e ) {
41
- assert ( true , 'child process was not running' ) ;
42
- }
30
+ p . on ( 'message' , function ( event ) {
31
+ if ( event . type === 'start' ) {
32
+ setTimeout ( function ( ) {
33
+ p . kill ( 'SIGINT' ) ;
34
+ } , 1000 ) ;
35
+ }
36
+ } ) . on ( 'exit' , function ( ) {
37
+ exitcb ( childPID ) ;
38
+ } ) ;
39
+ }
40
+
41
+ describe ( 'terminal signals' , function ( ) {
42
+ it ( 'should kill child with SIGINT' , function ( done ) {
43
+ runAndKill ( done , appjs , function ( childPID ) {
44
+ assert ( ! isRunning ( childPID ) , 'child is still running at ' + childPID ) ;
43
45
done ( ) ;
44
46
} ) ;
45
47
} ) ;
46
48
49
+ it ( 'should terminate nodemon (after ~10 seconds)' , function ( done ) {
50
+ runAndKill ( done , appjs + ' --dont-exit' , function ( childPID ) {
51
+ // make sure we don't keep abandoned child
52
+ process . kill ( childPID , 'SIGTERM' ) ;
53
+ done ( ) ;
54
+ } ) ;
55
+ } ) ;
47
56
} ) ;
0 commit comments