-
Notifications
You must be signed in to change notification settings - Fork 30k
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 few stream utils to common #31968
Conversation
730ce77
to
23cbbbf
Compare
To maintain alphabetical order in the README, |
Optional suggestion: Since these utilities are only used by a few tests, maybe put them in their own |
63e1473
to
526e618
Compare
@Trott Sounds good, done. |
`collectStream` allows to collect arbitrary readable that supports async iteration (which should be almost all) with Promise and callback API support. `collectChildStreams` expands on `collectStream` for child processes as it's quite common to need the resulting output of the child and collects their `stdout`, `stderr` if avaialble and optionally waits for another promise (i.e `once(child, 'exit')` can be used).
526e618
to
c070ba9
Compare
Is there a precedent for combining promises with const assert = require('assert')
async function commonUtil () {
return 'nope'
}
commonUtil().then(function (res) {
assert.strictEqual(res, 'foo')
}) |
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.
I personally would rather keep the code as it is. Adding more Node.js specific helper functions is always a mental overhead for new collaborators and the benefit seems small to me. Currently it's straight forward to understand what the code does while it's somewhat less clear with the helper function.
@BridgeAR while I agree that mental overhead is an important consideration but in this particular use case every time I write a test related to Streams or any type of IO basically I look for such utility considering how widespread and used this pattern is in our tests. Also, this helper is imo easy to understand even from the name alone while adding benefits of properly handling data/errors in the |
So … I don’t know if we should move forward with this, but how would people feel about moving something alone these lines to |
I don't really have much to say except that I always think increasing Node's API surface area should be considered a bad thing without a strong case otherwise; performance being one of them ( Don't add something that's easy to do in userland, and is already done in userland, unless you want to be maintaining that standard library forever. Python anyone? How about Java? How long are you prepared for CI to take. How many tests do you want in your way when you want to change something in the future and how many people are you prepared to scream at you when you break their favourite thing? How many weird edge cases are you comfortable with users finding and relying on that aren't covered by the test suite? I'm sad that we never wrote this down clearly somewhere at a time when we all roughly agreed this was how Node's standard library was governed. |
I’m not convinced to move this to the stream module. They do not follow any of the good reasons to add them to core as their implementation is covered by our docs. I’m not really convinced to have them as test utilities, as they would likely make things harder to debug when a stream bug arises. |
8ae28ff
to
2935f72
Compare
test: add collectStream and collectChildStreams utilities
collectStream
allows to collect arbitrary readable that supports asynciteration (which should be almost all) with Promise and callback API support.
collectChildStreams
expands oncollectStream
for child processes asit's quite common to need the resulting output of the child and collects
their
stdout
,stderr
if avaialble and optionally waits for anotherpromise (i.e
once(child, 'exit')
can be used).test: refactor few tests with collectStream/collectChildStreams utils
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes/cc @nodejs/testing