Skip to content

Commit

Permalink
Merge pull request #1440 from dougwilson/fix/async-stdio
Browse files Browse the repository at this point in the history
Fix test running output truncation on async STDIO
  • Loading branch information
Travis Jeffery committed Jan 13, 2015
2 parents 908d8db + 1b2e9bc commit cfe26ea
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,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
Expand Down

0 comments on commit cfe26ea

Please sign in to comment.