Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test running output truncation on async STDIO #1440

Merged
merged 1 commit into from
Jan 13, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down