Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Fix test running output truncation on async STDIO

Douglas Christopher Wilson1b2e9bc5ae4b
diff --git a/bin/_mocha b/bin/_mocha
index 3032690e..2aa69620 100755
--- a/bin/_mocha
+++ b/bin/_mocha
@@ -377,12 +377,32 @@ if (program.watch) {
// load
mocha.files = files;
-runner = mocha.run(program.exit ? process.exit : exitLater);
+runner = mocha.run(program.exit ? exit : exitLater);
function exitLater(code) {
process.on('exit', function() { process.exit(code) })
}
+function exit(code) {
+ // flush output for Node.js Windows pipe bug
+ // https://github.com/joyent/node/issues/6247 is just one bug example
+ // https://github.com/visionmedia/mocha/issues/333 has a good discussion
+ function done() {
+ if (!(draining--)) process.exit(code);
+ }
+
+ var draining = 0;
+ var streams = [process.stdout, process.stderr];
+
+ streams.forEach(function(stream){
+ // submit empty write request and wait for completion
+ draining += 1;
+ stream.write('', done);
+ });
+
+ done();
+}
+
process.on('SIGINT', function() { runner.abort(); })
// enable growl notifications