11'use strict' ;
22
3- var helpers = require ( '../helpers' ) ;
4- var runMochaJSON = helpers . runMochaJSON ;
3+ var runMocha = require ( '../helpers' ) . runMocha ;
54
65describe ( '--exit' , function ( ) {
76 var behaviors = {
87 enabled : '--exit' ,
98 disabled : '--no-exit'
109 } ;
1110
11+ // subprocess
12+ var mocha ;
13+
14+ function killSubprocess ( ) {
15+ mocha . kill ( 'SIGKILL' ) ;
16+ }
17+
18+ // these two handlers deal with a ctrl-c on command-line
19+ before ( function ( ) {
20+ process . on ( 'SIGINT' , killSubprocess ) ;
21+ } ) ;
22+
23+ after ( function ( ) {
24+ process . removeListener ( 'SIGINT' , killSubprocess ) ;
25+ } ) ;
26+
1227 /**
1328 * Returns a test that executes Mocha in a subprocess with either
1429 * `--exit`, `--no-exit`, or default behavior.
1530 *
1631 * @param {boolean } shouldExit - Expected result; `true` if Mocha should
1732 * have force-killed the process.
18- * @param {string } [behavior] - 'enabled' or 'disabled'
33+ * @param {"enabled"|"disabled" } [behavior] - 'enabled' or 'disabled'; omit for default
1934 * @returns {Function } async function implementing the test
2035 */
2136 var runExit = function ( shouldExit , behavior ) {
@@ -28,8 +43,7 @@ describe('--exit', function() {
2843 var timeoutObj ;
2944 var fixture = 'exit.fixture.js' ;
3045 var args = behaviors [ behavior ] ? [ behaviors [ behavior ] ] : [ ] ;
31-
32- var mocha = runMochaJSON ( fixture , args , function postmortem ( err ) {
46+ mocha = runMocha ( fixture , args , function postmortem ( err ) {
3347 clearTimeout ( timeoutObj ) ;
3448 if ( err ) {
3549 return done ( err ) ;
@@ -41,15 +55,13 @@ describe('--exit', function() {
4155 // If this callback happens, then Mocha didn't automatically exit.
4256 timeoutObj = setTimeout ( function ( ) {
4357 didExit = false ;
44- // This is the only way to kill the child, afaik.
45- // After the process ends, the callback to `run()` above is handled.
46- mocha . kill ( 'SIGINT' ) ;
58+ killSubprocess ( ) ;
4759 } , timeout - 500 ) ;
4860 } ;
4961 } ;
5062
5163 describe ( 'default behavior' , function ( ) {
52- it ( 'should force exit after root suite completion' , runExit ( false ) ) ;
64+ it ( 'should not force exit after root suite completion' , runExit ( false ) ) ;
5365 } ) ;
5466
5567 describe ( 'when enabled' , function ( ) {
0 commit comments