-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
test: add tests for end event of stream.Duplex #21325
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const Duplex = require('stream').Duplex; | ||
{ | ||
const stream = new Duplex(); | ||
assert(stream.allowHalfOpen); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cjihrig Fixed it. Thank you for your comment. |
||
stream.on('finish', common.mustNotCall()); | ||
assert.strictEqual(stream.emit('end'), false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it's better to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lpinca Thanks for your review. Would you please tell me why it is better to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's how the If you switch the stream in flowing mode with const stream = new Duplex({ read() {} });
stream.resume();
stream.push(null); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed it and the codes you indicated emit |
||
} | ||
|
||
{ | ||
const stream = new Duplex({ | ||
allowHalfOpen: false | ||
}); | ||
assert.strictEqual(stream.allowHalfOpen, false); | ||
stream.on('finish', common.mustCall()); | ||
assert(stream.emit('end')); | ||
} | ||
|
||
{ | ||
const stream = new Duplex({ | ||
allowHalfOpen: false | ||
}); | ||
assert.strictEqual(stream.allowHalfOpen, false); | ||
stream._writableState.ended = true; | ||
stream.on('finish', common.mustNotCall()); | ||
assert(stream.emit('end')); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can please add a new line before this?