-
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: change equal to strictEqual and var to const #9941
test: change equal to strictEqual and var to const #9941
Conversation
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.
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')); |
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.
Why the addition of 'utf8'
? We should still test the case where the encoding is not provided. If anything, maybe add another assertion.
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.
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.
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.
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 (inreadFileSync()
) that is being tested. Instead, applytoString()
to the result so we can compare it to a string.
Aside: If you (or someone else) wants a good second PR after this lands: Merge this and |
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.
Ping! @jhwohlgemuth Any chance you can address the make the change requested in https://github.com/nodejs/node/pull/9941/files#r92760787?
@Trott Updated with requested changes. |
Landed 5c85ae6 |
change equal to strictEqual and var to const PR-URL: #9941 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
change equal to strictEqual and var to const PR-URL: #9941 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
change equal to strictEqual and var to const PR-URL: #9941 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
change equal to strictEqual and var to const PR-URL: #9941 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
change equal to strictEqual and var to const PR-URL: #9941 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
change equal to strictEqual and var to const PR-URL: #9941 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
change equal to strictEqual and var to const PR-URL: #9941 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
make -j8 test
Affected core subsystem(s)
Description of change
equal
tostrictEqual
(required addition ofencoding="utf"
parameter forreadFileSync
call)var
toconst