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

test: remove unnecessary .toString() calls in HTTP tests #43731

Conversation

addaleax
Copy link
Member

@addaleax addaleax commented Jul 8, 2022

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.

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.
@addaleax addaleax added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 8, 2022
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Jul 8, 2022
@addaleax addaleax added http Issues or PRs related to the http subsystem. needs-ci PRs that need a full CI run. and removed needs-ci PRs that need a full CI run. labels Jul 8, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 8, 2022
@nodejs-github-bot
Copy link
Collaborator

@@ -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');
Copy link
Member

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:

  1. keep consistent with other use cases
  2. don't make us guess if client.setEncoding('utf8') after attach data listener would cause problem.

Copy link
Member Author

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.

@wa-Nadoo
Copy link

wa-Nadoo commented Jul 8, 2022

Maybe it is time to doc-deprecate buffer.toString() params at all?

@addaleax
Copy link
Member Author

addaleax commented Jul 8, 2022

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 .setEncoding() is already being used.

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jul 8, 2022
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 11, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 11, 2022
@nodejs-github-bot nodejs-github-bot merged commit febb539 into nodejs:main Jul 11, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in febb539

targos pushed a commit that referenced this pull request Jul 12, 2022
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. http Issues or PRs related to the http subsystem. needs-ci PRs that need a full CI run. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants