Skip to content

Commit

Permalink
fix(MockSTDIN): reset endEmitted flag on reset()
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
caitp committed Oct 12, 2014
1 parent 5c431f4 commit bad5737
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/mock/stdin.js
Expand Up @@ -134,6 +134,7 @@ MockSTDIN.prototype.restore = function MockSTDINRestore() {
MockSTDIN.prototype.reset = function MockSTDINReset() {
var state = this._readableState;
state.ended = false;
state.endEmitted = false;
return this;
};

Expand Down
5 changes: 5 additions & 0 deletions test/stdin.spec.js
Expand Up @@ -205,8 +205,13 @@ module.exports.stdin = {
received += data;
});
process.stdin.end();
test.ok(process.stdin._readableState.ended, "stream should be 'ended'.");
test.ok(process.stdin._readableState.endEmitted, "'end' event should be dispatched.");
process.stdin.reset();

test.ok(!process.stdin._readableState.ended, "'ended' flag should be reset.");
test.ok(!process.stdin._readableState.endEmitted, "'endEmitted' flag should be reset.");

test.doesNotThrow(function() {
process.stdin.send("Please don't throw, little lamb!");
}, "should not throw when sending data after end when reset() called");
Expand Down

0 comments on commit bad5737

Please sign in to comment.