Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

resolves #1393: kill children with more effort on SIGINT

Christopher Hiller95606e4cb08a
diff --git a/bin/mocha b/bin/mocha
index ef5b1909..4ab29647 100755
--- a/bin/mocha
+++ b/bin/mocha
@@ -54,3 +54,10 @@ proc.on('exit', function (code, signal) {
}
});
});
+
+// terminate children.
+process.on('SIGINT', function () {
+ proc.kill('SIGINT'); // calls runner.abort()
+ proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
+ process.kill(process.pid, 'SIGINT');
+});
diff --git a/test/acceptance/misc/exit.js b/test/acceptance/misc/exit.js
index 4cace0b0..113e3923 100644
--- a/test/acceptance/misc/exit.js
+++ b/test/acceptance/misc/exit.js
@@ -10,4 +10,9 @@ describe('exit', function(){
console.log('all done');
}, 2500)
})
+
+ it('should kill all processes when SIGINT received', function () {
+ // uncomment to test
+ //while (true) {}
+ });
})