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

Use callback from empty write instead of drain event but don't prevent f... #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ console.error("yay");

// process.exit(5);
exit(5);

// These lines shouldn't appear in the output.
console.log("wtf");
console.error("bro");
```

## Don't believe me? Try it for yourself.
Expand Down
4 changes: 1 addition & 3 deletions lib/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ module.exports = function exit(exitCode, streams) {
}
}
streams.forEach(function(stream) {
// Prevent further writing.
stream.write = function() {};
// Count drained streams now, but monitor non-drained streams.
if (stream.bufferSize === 0) {
drainCount++;
} else {
stream.once('drain', function() {
stream.write('', 'utf-8', function() {
drainCount++;
tryToExit();
});
Expand Down
4 changes: 1 addition & 3 deletions test/exit_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,13 @@ function buildTests() {
pipes.forEach(function(pipe) {
var command = 'node log.js 0 ' + count + output + ' 2>&1' + pipe;
exports['exit']['output (' + command + ')'] = function(test) {
test.expect(2);
test.expect(1);
run(command, function(code, actual) {
var expected = fixture(count + output.replace(/ /g, '-') + '.txt');
// Sometimes, the actual file lines are out of order on Windows.
// But since the point of this lib is to drain the buffer and not
// guarantee output order, we only test the length.
test.equal(actual.length, expected.length, 'should be the same length.');
// The "fail" lines in log.js should NOT be output!
test.ok(actual.indexOf('fail') === -1, 'should not output after exit is called.');
test.done();
});
};
Expand Down
3 changes: 0 additions & 3 deletions test/fixtures/log-broken.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ for (var i = 0; i < max; i++) {
}

process.exit(errorCode);

stdout('fail');
stderr('fail');
3 changes: 0 additions & 3 deletions test/fixtures/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,3 @@ for (var i = 0; i < max; i++) {
}

exit(errorCode);

stdout('fail');
stderr('fail');