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: change equal to strictEqual and var to const #9941

Closed
wants to merge 1 commit into from
Closed

test: change equal to strictEqual and var to const #9941

wants to merge 1 commit into from

Conversation

jhwohlgemuth
Copy link
Contributor

  • make -j8 test
  • commit message follows commit guidelines
Affected core subsystem(s)
  • test
Description of change
  • Change equal to strictEqual (required addition of encoding="utf" parameter for readFileSync call)
  • Change var to const

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Dec 1, 2016
@mscdex mscdex added the fs Issues and PRs related to the fs subsystem / file system. label Dec 1, 2016
@imyller imyller added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Dec 1, 2016
Copy link
Contributor

@princejwesley princejwesley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit message suggestion:
First line as test: refactor test-sync-fileread
and the description in subsequent line


assert.equal('xyz\n', fs.readFileSync(fixture));
assert.strictEqual('xyz\n', fs.readFileSync(fixture, 'utf8'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the addition of 'utf8'? We should still test the case where the encoding is not provided. If anything, maybe add another assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the documentation:

If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.

So, it seemed to me that the old test with just assert.equal was not actually doing much...although I could be wrong? In any case, I did not see much value in adding another test beyond what was added.

Perhaps I could add an assertion that compares Buffer content of a readFileSync call with no encoding? I am still new to the style and preferences of contributing to the Node.js project, but personally if I was to do such a thing, I would do so in a different PR in an effort to separate refactoring tests and adding tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR How about just change this line to this?:

assert.strictEqual(fs.readFileSync(fixture).toString(), 'xyz\n`);

The reasoning:

  • This line has the arguments reversed from the documentation. Let's switch them.

  • To address @cjihrig's comment, leave the fs.readFileSync() call as it was so that we're not altering the code path (in readFileSync()) that is being tested. Instead, apply toString() to the result so we can compare it to a string.

@Trott
Copy link
Member

Trott commented Dec 16, 2016

Aside: If you (or someone else) wants a good second PR after this lands: Merge this and test-fs-read-file-sync.js into a single file named test-fs-readfilesync.js.

Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping! @jhwohlgemuth Any chance you can address the make the change requested in https://github.com/nodejs/node/pull/9941/files#r92760787?

@jhwohlgemuth
Copy link
Contributor Author

@Trott Updated with requested changes.

@Trott
Copy link
Member

Trott commented Dec 22, 2016

@italoacasas
Copy link
Contributor

Landed 5c85ae6

targos pushed a commit that referenced this pull request Dec 26, 2016
change equal to strictEqual and var to const

PR-URL: #9941
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Dec 27, 2016
targos pushed a commit that referenced this pull request Dec 28, 2016
change equal to strictEqual and var to const

PR-URL: #9941
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
evanlucas pushed a commit that referenced this pull request Jan 3, 2017
change equal to strictEqual and var to const

PR-URL: #9941
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
evanlucas pushed a commit that referenced this pull request Jan 4, 2017
change equal to strictEqual and var to const

PR-URL: #9941
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
targos pushed a commit that referenced this pull request Jan 23, 2017
change equal to strictEqual and var to const

PR-URL: #9941
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 24, 2017
change equal to strictEqual and var to const

PR-URL: #9941
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Jan 24, 2017
MylesBorins pushed a commit that referenced this pull request Feb 1, 2017
change equal to strictEqual and var to const

PR-URL: #9941
Reviewed-By: Prince John Wesley <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. fs Issues and PRs related to the fs subsystem / file system. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.