-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: remove unnecessary .toString() calls in HTTP tests #43731
test: remove unnecessary .toString() calls in HTTP tests #43731
Conversation
Let’s not have bad examples in our test suite and instead use the proper way of converting stream data to UTF-8 (i.e. `stream.setEncoding('utf8')`) in all places.
@@ -26,7 +26,7 @@ server.listen(0, common.mustSucceed(() => { | |||
let response = ''; | |||
|
|||
client.on('data', common.mustCall((chunk) => { | |||
response += chunk.toString('utf-8'); | |||
response += chunk; | |||
})); | |||
|
|||
client.setEncoding('utf8'); |
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(feel free to ignore): would be better to move client.setEncoding('utf8');
before client.on('data'
?
Reason:
- keep consistent with other use cases
- don't make us guess if
client.setEncoding('utf8')
after attachdata
listener would cause problem.
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.
Fwiw, my preferred way is client.setEncoding('utf8').on('data', ...')
😄
Ultimately, it doesn't matter. If we do clean this up, it might also be a good idea to do so across all tests for consistency.
Maybe it is time to doc-deprecate buffer.toString() params at all? |
I don't think that that's practical or meaningful. We should just push really hard to avoid examples like these so that people know not to do it this way 🙂 Also, this is something that TypeScript would have caught at least in the cases where |
Landed in febb539 |
Let’s not have bad examples in our test suite and instead use the proper way of converting stream data to UTF-8 (i.e. `stream.setEncoding('utf8')`) in all places. PR-URL: #43731 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Let’s not have bad examples in our test suite and instead use the
proper way of converting stream data to UTF-8
(i.e.
stream.setEncoding('utf8')
) in all places.