Skip to content

Commit

Permalink
test: improve test-fs-access
Browse files Browse the repository at this point in the history
* use const and let instead of var
* use common.mustCall to control functions execution
* use assert.ifError instead of assert.strictEqual for errors
* use arrow functions

PR-URL: #10542
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
edsadr authored and MylesBorins committed Apr 13, 2017
1 parent a6ab9f2 commit b85d15f
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions test/parallel/test-fs-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,46 +63,46 @@ assert.strictEqual(typeof fs.R_OK, 'number');
assert.strictEqual(typeof fs.W_OK, 'number');
assert.strictEqual(typeof fs.X_OK, 'number');

fs.access(__filename, function(err) {
assert.strictEqual(err, null, 'error should not exist');
});
fs.access(__filename, common.mustCall((err) => {
assert.ifError(err);
}));

fs.access(__filename, fs.R_OK, function(err) {
assert.strictEqual(err, null, 'error should not exist');
});
fs.access(__filename, fs.R_OK, common.mustCall((err) => {
assert.ifError(err);
}));

fs.access(doesNotExist, function(err) {
fs.access(doesNotExist, common.mustCall((err) => {
assert.notEqual(err, null, 'error should exist');
assert.strictEqual(err.code, 'ENOENT');
assert.strictEqual(err.path, doesNotExist);
});
}));

fs.access(readOnlyFile, fs.F_OK | fs.R_OK, function(err) {
assert.strictEqual(err, null, 'error should not exist');
});
fs.access(readOnlyFile, fs.F_OK | fs.R_OK, common.mustCall((err) => {
assert.ifError(err);
}));

fs.access(readOnlyFile, fs.W_OK, function(err) {
fs.access(readOnlyFile, fs.W_OK, common.mustCall((err) => {
if (hasWriteAccessForReadonlyFile) {
assert.equal(err, null, 'error should not exist');
assert.ifError(err);
} else {
assert.notEqual(err, null, 'error should exist');
assert.strictEqual(err.path, readOnlyFile);
}
});
}));

assert.throws(function() {
fs.access(100, fs.F_OK, function(err) {});
assert.throws(() => {
fs.access(100, fs.F_OK, (err) => {});
}, /path must be a string or Buffer/);

assert.throws(function() {
assert.throws(() => {
fs.access(__filename, fs.F_OK);
}, /"callback" argument must be a function/);

assert.throws(function() {
assert.throws(() => {
fs.access(__filename, fs.F_OK, {});
}, /"callback" argument must be a function/);

assert.doesNotThrow(function() {
assert.doesNotThrow(() => {
fs.accessSync(__filename);
});

Expand All @@ -112,13 +112,13 @@ assert.doesNotThrow(function() {
fs.accessSync(readWriteFile, mode);
});

assert.throws(function() {
assert.throws(() => {
fs.accessSync(doesNotExist);
}, function(err) {
}, (err) => {
return err.code === 'ENOENT' && err.path === doesNotExist;
});

process.on('exit', function() {
process.on('exit', () => {
removeFile(readOnlyFile);
removeFile(readWriteFile);
});

0 comments on commit b85d15f

Please sign in to comment.