Skip to content

Commit 215dfec

Browse files
edsadrandrew749
authored andcommitted
test: improve test-fs-access
* 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: nodejs/node#10542 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 71f2519 commit 215dfec

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

test/parallel/test-fs-access.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -63,46 +63,46 @@ assert.strictEqual(typeof fs.R_OK, 'number');
6363
assert.strictEqual(typeof fs.W_OK, 'number');
6464
assert.strictEqual(typeof fs.X_OK, 'number');
6565

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

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

74-
fs.access(doesNotExist, function(err) {
74+
fs.access(doesNotExist, common.mustCall((err) => {
7575
assert.notEqual(err, null, 'error should exist');
7676
assert.strictEqual(err.code, 'ENOENT');
7777
assert.strictEqual(err.path, doesNotExist);
78-
});
78+
}));
7979

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

84-
fs.access(readOnlyFile, fs.W_OK, function(err) {
84+
fs.access(readOnlyFile, fs.W_OK, common.mustCall((err) => {
8585
if (hasWriteAccessForReadonlyFile) {
86-
assert.equal(err, null, 'error should not exist');
86+
assert.ifError(err);
8787
} else {
8888
assert.notEqual(err, null, 'error should exist');
8989
assert.strictEqual(err.path, readOnlyFile);
9090
}
91-
});
91+
}));
9292

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

97-
assert.throws(function() {
97+
assert.throws(() => {
9898
fs.access(__filename, fs.F_OK);
9999
}, /"callback" argument must be a function/);
100100

101-
assert.throws(function() {
101+
assert.throws(() => {
102102
fs.access(__filename, fs.F_OK, {});
103103
}, /"callback" argument must be a function/);
104104

105-
assert.doesNotThrow(function() {
105+
assert.doesNotThrow(() => {
106106
fs.accessSync(__filename);
107107
});
108108

@@ -112,13 +112,13 @@ assert.doesNotThrow(function() {
112112
fs.accessSync(readWriteFile, mode);
113113
});
114114

115-
assert.throws(function() {
115+
assert.throws(() => {
116116
fs.accessSync(doesNotExist);
117-
}, function(err) {
117+
}, (err) => {
118118
return err.code === 'ENOENT' && err.path === doesNotExist;
119119
});
120120

121-
process.on('exit', function() {
121+
process.on('exit', () => {
122122
removeFile(readOnlyFile);
123123
removeFile(readWriteFile);
124124
});

0 commit comments

Comments
 (0)