Skip to content

Cleanup test file write stream - #8894

Closed
sudaraka wants to merge 5 commits into
nodejs:masterfrom
sudaraka:cleanup-test-file-write-stream
Closed

sudaraka wants to merge 5 commits into
nodejs:masterfrom
sudaraka:cleanup-test-file-write-stream

Conversation

@sudaraka

@sudaraka sudaraka commented Oct 2, 2016

Copy link
Copy Markdown
Contributor
Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)
  • test
Description of change

Some trivial changes to improve the test code in test/parallel/test-file-write-stream.js.

Submitting this as my first contribution as per instructions from NodeTodo.

This replace all `var` occurrences in test-file-write-stream.js with
`const` (where they are not being reassigned) and `let` (where they are
being reassigned).
This add strict comparison to the asserts and if statements:

  - Replace `assert.equal` with `assert.strictEqual` where:
    1. Result of `typeof` being compared to a string literal.
    2. Result of `fs.readFileSync` with UTF-8 encoding being compared to
       a string constant.

  - Replace `==` with `===` where integer values are being compared to
    integer literals.
@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to Node.js core tests and test infrastructure. label Oct 2, 2016
@mscdex mscdex added the fs Issues and PRs related to file-system APIs and the fs module. label Oct 2, 2016
Comment thread test/parallel/test-file-write-stream.js Outdated
for (let i = 0; i < 11; i++) {
(function(i) {
file.write('' + i);
})(i);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this can be simplified by removing the IIFE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the IIFE, Thanks for pointing it out.

Comment thread test/parallel/test-file-write-stream.js Outdated
process.on('exit', function() {
for (var k in callbacks) {
for (const k in callbacks) {
assert.equal(0, callbacks[k], k + ' count off by ' + callbacks[k]);

@lpinca lpinca Oct 2, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: how about using strictEqual and a template literal here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing it out. Updated it.

This replace a `assert.equal` with a `assert.strictEqual` which was
missed in previous commit.

@lpinca lpinca left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@lpinca

lpinca commented Oct 2, 2016

Copy link
Copy Markdown
Member

@Trott

Trott commented Oct 2, 2016

Copy link
Copy Markdown
Member

LGTM if CI doesn't reveal any issues with the test.

Looping in @thealphanerd in case they have an opinion about the introduction of for (let...) in one place in the test. I think for (let..) is fine in tests, but I won't push back if people think we should avoid it here like we often do in the lib directory due to performance issues.

@addaleax addaleax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, and fwiw I’m perfectly fine with let here.

@Trott

Trott commented Oct 5, 2016

Copy link
Copy Markdown
Member

CI failures are unrelated known flaky tests. Landing.

Trott pushed a commit to Trott/io.js that referenced this pull request Oct 5, 2016
Replace all `var` occurrences in test-file-write-stream.js with
`const` (where they are not being reassigned) and `let` (where they are
being reassigned).

Add strict comparison to the asserts and if statements:

  - Replace `assert.equal` with `assert.strictEqual` where:
    1. Result of `typeof` being compared to a string literal.
    2. Result of `fs.readFileSync` with UTF-8 encoding being compared to
       a string constant.

  - Replace `==` with `===` where integer values are being compared to
    integer literals.

Remove unnecessary very IIFE.

Use template literals.

PR-URL: nodejs#8894
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@Trott

Trott commented Oct 5, 2016

Copy link
Copy Markdown
Member

Landed in 1d4ba1b

@Trott Trott closed this Oct 5, 2016
jasnell pushed a commit that referenced this pull request Oct 6, 2016
Replace all `var` occurrences in test-file-write-stream.js with
`const` (where they are not being reassigned) and `let` (where they are
being reassigned).

Add strict comparison to the asserts and if statements:

  - Replace `assert.equal` with `assert.strictEqual` where:
    1. Result of `typeof` being compared to a string literal.
    2. Result of `fs.readFileSync` with UTF-8 encoding being compared to
       a string constant.

  - Replace `==` with `===` where integer values are being compared to
    integer literals.

Remove unnecessary very IIFE.

Use template literals.

PR-URL: #8894
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Fishrock123 pushed a commit that referenced this pull request Oct 11, 2016
Replace all `var` occurrences in test-file-write-stream.js with
`const` (where they are not being reassigned) and `let` (where they are
being reassigned).

Add strict comparison to the asserts and if statements:

  - Replace `assert.equal` with `assert.strictEqual` where:
    1. Result of `typeof` being compared to a string literal.
    2. Result of `fs.readFileSync` with UTF-8 encoding being compared to
       a string constant.

  - Replace `==` with `===` where integer values are being compared to
    integer literals.

Remove unnecessary very IIFE.

Use template literals.

PR-URL: #8894
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fs Issues and PRs related to file-system APIs and the fs module. test Issues and PRs related to Node.js core tests and test infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants