-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Make tests more clear #8999
Make tests more clear #8999
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.
LGTM
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.
LGTM
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.
LGTM. Left a bunch of nits, but they aren't necessary for this to land. Would simply prefer them.
const common = require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
var filename = path.join(common.fixturesDir, 'does_not_exist.txt'); |
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: Since you're in here already, can you make filename
a constant too?
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.
Done
const common = require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
var filename = path.join(common.fixturesDir, 'does_not_exist.txt'); | ||
fs.readFile(filename, 'latin1', common.mustCall(function(err, content) { |
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: Can we add a line after assert.ok(err)
like assert.strictEqual(err.code, 'ENOENT')
or whatever the right error code is? I assume it will be the same across platform, but correction welcome.
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.
Done
var path = require('path'); | ||
var fs = require('fs'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
|
||
var filepath = path.join(common.tmpDir, 'write.txt'); |
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: Can we make this filepath
a constant too?
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: I think the var
in line 84 can also be a const
, no?
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: While we're in here refactoring anyway, maybe line 79 can be converted from assert.ok(err.message.indexOf('write after end') >= 0);
to something more like assert.ok(err.message.includes('write after end'))
?
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.
Done
LGTM if CI is OK. |
Add `assert.strictEqual(err.code, 'ENOENT')` and changed the last `var` to `const` for clarity
Refactor line 79 to use `includes()` instead of `indexOf() >= 0` for better readability. Change `var` to `const` for clarity
Thx for all the tips! @Trott |
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.
Thanks! LGTM.
* var to const * add check that expected error is ENOENT * indexOf() to includes() PR-URL: nodejs#8999 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Landed in a7970c0. Thanks! |
* var to const * add check that expected error is ENOENT * indexOf() to includes() PR-URL: #8999 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
* var to const * add check that expected error is ENOENT * indexOf() to includes() PR-URL: #8999 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Checklist
Affected core subsystem(s)
tests
Description of change
change 'var' to 'const' for clarity