Skip to content

Commit 886116f

Browse files
Trottaddaleax
authored andcommitted
test: apply test-fs-access to promises API
Add tests for `fs.promises.access()` in all test cases in `test-fs-access` that are relevant to the Promises-based API. PR-URL: #20667 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent a66aad4 commit 886116f

1 file changed

Lines changed: 52 additions & 25 deletions

File tree

‎test/parallel/test-fs-access.js‎

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,64 @@ assert.strictEqual(typeof fs.R_OK, 'number');
6262
assert.strictEqual(typeoffs.W_OK,'number');
6363
assert.strictEqual(typeoffs.X_OK,'number');
6464

65+
constthrowNextTick=(e)=>{process.nextTick(()=>{throwe;});};
66+
6567
fs.access(__filename,common.mustCall(assert.ifError));
68+
fs.promises.access(__filename)
69+
.then(common.mustCall())
70+
.catch(throwNextTick);
6671
fs.access(__filename,fs.R_OK,common.mustCall(assert.ifError));
72+
fs.promises.access(__filename,fs.R_OK)
73+
.then(common.mustCall())
74+
.catch(throwNextTick);
6775
fs.access(readOnlyFile,fs.F_OK|fs.R_OK,common.mustCall(assert.ifError));
76+
fs.promises.access(readOnlyFile,fs.F_OK|fs.R_OK)
77+
.then(common.mustCall())
78+
.catch(throwNextTick);
6879

69-
fs.access(doesNotExist,common.mustCall((err)=>{
70-
assert.notStrictEqual(err,null,'error should exist');
71-
assert.strictEqual(err.code,'ENOENT');
72-
assert.strictEqual(err.path,doesNotExist);
73-
}));
74-
75-
fs.access(readOnlyFile,fs.W_OK,common.mustCall(function(err){
76-
assert.strictEqual(this,undefined);
77-
if(hasWriteAccessForReadonlyFile){
78-
assert.ifError(err);
79-
}else{
80-
assert.notStrictEqual(err,null,'error should exist');
81-
assert.strictEqual(err.path,readOnlyFile);
82-
}
83-
}));
80+
{
81+
constexpectedError=(err)=>{
82+
assert.notStrictEqual(err,null);
83+
assert.strictEqual(err.code,'ENOENT');
84+
assert.strictEqual(err.path,doesNotExist);
85+
};
86+
fs.access(doesNotExist,common.mustCall(expectedError));
87+
fs.promises.access(doesNotExist)
88+
.then(common.mustNotCall(),common.mustCall(expectedError))
89+
.catch(throwNextTick);
90+
}
8491

85-
common.expectsError(
86-
()=>{
87-
fs.access(100,fs.F_OK,common.mustNotCall());
88-
},
89-
{
90-
code: 'ERR_INVALID_ARG_TYPE',
91-
type: TypeError,
92-
message: 'The "path" argument must be one of type string, Buffer, or URL.'+
93-
' Received type number'
92+
{
93+
functionexpectedError(err){
94+
assert.strictEqual(this,undefined);
95+
if(hasWriteAccessForReadonlyFile){
96+
assert.ifError(err);
97+
}else{
98+
assert.notStrictEqual(err,null);
99+
assert.strictEqual(err.path,readOnlyFile);
100+
}
94101
}
95-
);
102+
fs.access(readOnlyFile,fs.W_OK,common.mustCall(expectedError));
103+
fs.promises.access(readOnlyFile,fs.W_OK)
104+
.then(common.mustNotCall(),common.mustCall(expectedError))
105+
.catch(throwNextTick);
106+
}
107+
108+
{
109+
constexpectedError=(err)=>{
110+
assert.strictEqual(err.code,'ERR_INVALID_ARG_TYPE');
111+
assert.ok(errinstanceofTypeError);
112+
returntrue;
113+
};
114+
assert.throws(
115+
()=>{fs.access(100,fs.F_OK,common.mustNotCall());},
116+
expectedError
117+
);
118+
119+
fs.promises.access(100,fs.F_OK)
120+
.then(common.mustNotCall(),common.mustCall(expectedError))
121+
.catch(throwNextTick);
122+
}
96123

97124
common.expectsError(
98125
()=>{

0 commit comments

Comments
 (0)