Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Add --no-exit flag to prevent process.exit() call (close #1018)

Brian M. Carlsonb43cb7fe27ee
diff --git a/bin/_mocha b/bin/_mocha
index 0244de02..79bd89ea 100644
--- a/bin/_mocha
+++ b/bin/_mocha
@@ -84,6 +84,7 @@ program
.option('--reporters', 'display available reporters')
.option('--compilers <ext>:<module>,...', 'use the given module(s) to compile files', list, [])
.option('--inline-diffs', 'display actual/expected differences inline within each string')
+ .option('--no-exit', 'require a clean shutdown of the event loop: mocha will not call process.exit')
program.name = 'mocha';
@@ -347,7 +348,7 @@ if (program.watch) {
// load
mocha.files = files;
-mocha.run(process.exit);
+mocha.run(program.exit ? process.exit : function() {});
// enable growl notifications
diff --git a/test/acceptance/misc/exit.js b/test/acceptance/misc/exit.js
new file mode 100644
index 00000000..4cace0b0
--- /dev/null
+++ b/test/acceptance/misc/exit.js
@@ -0,0 +1,13 @@
+describe('exit', function(){
+ //note --bail works nicely in that it still allows an 'early exit' in an error scenario
+ it('should not exit even in error scenario if called with --no-exit', function(done){
+ done(new Error('failure'));
+ })
+
+ it('should take a long time to exit if called with --no-exit', function(done){
+ done();
+ setTimeout(function() {
+ console.log('all done');
+ }, 2500)
+ })
+})