Skip to content

Commit 2b6e8cc

Browse files
humphdaddaleax
authored andcommitted
test: increase test coverage for fs/promises.js
PR-URL: #19811 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent e6c0bbe commit 2b6e8cc

1 file changed

Lines changed: 50 additions & 5 deletions

File tree

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

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,60 @@ function verifyStatObject(stat) {
8787
stats=awaitstat(dest);
8888
verifyStatObject(stats);
8989

90+
stats=awaithandle.stat();
91+
verifyStatObject(stats);
92+
9093
awaitfdatasync(handle);
94+
awaithandle.datasync();
9195
awaitfsync(handle);
96+
awaithandle.sync();
9297

93-
constbuf=Buffer.from('hello world');
94-
98+
constbuf=Buffer.from('hello fsPromises');
99+
constbufLen=buf.length;
95100
awaitwrite(handle,buf);
96-
97-
constret=awaitread(handle,Buffer.alloc(11),0,11,0);
98-
assert.strictEqual(ret.bytesRead,11);
101+
constret=awaitread(handle,Buffer.alloc(bufLen),0,bufLen,0);
102+
assert.strictEqual(ret.bytesRead,bufLen);
99103
assert.deepStrictEqual(ret.buffer,buf);
100104

105+
constbuf2=Buffer.from('hello FileHandle');
106+
constbuf2Len=buf2.length;
107+
awaithandle.write(buf2,0,buf2Len,0);
108+
constret2=awaithandle.read(Buffer.alloc(buf2Len),0,buf2Len,0);
109+
assert.strictEqual(ret2.bytesRead,buf2Len);
110+
assert.deepStrictEqual(ret2.buffer,buf2);
111+
101112
awaitchmod(dest,0o666);
102113
awaitfchmod(handle,0o666);
114+
awaithandle.chmod(0o666);
115+
116+
// `mode` can't be > 0o777
117+
assert.rejects(
118+
async()=>chmod(handle,(0o777+1)),
119+
{
120+
code: 'ERR_INVALID_ARG_TYPE',
121+
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
122+
}
123+
);
124+
assert.rejects(
125+
async()=>fchmod(handle,(0o777+1)),
126+
{
127+
code: 'ERR_OUT_OF_RANGE',
128+
name: 'RangeError [ERR_OUT_OF_RANGE]'
129+
}
130+
);
131+
assert.rejects(
132+
async()=>handle.chmod(handle,(0o777+1)),
133+
{
134+
code: 'ERR_INVALID_ARG_TYPE',
135+
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
136+
}
137+
);
103138

104139
awaitutimes(dest,newDate(),newDate());
105140

106141
try{
107142
awaitfutimes(handle,newDate(),newDate());
143+
awaithandle.utimes(newDate(),newDate());
108144
}catch(err){
109145
// Some systems do not have futimes. If there is an error,
110146
// expect it to be ENOSYS
@@ -152,6 +188,15 @@ function verifyStatObject(stat) {
152188
awaitrmdir(newdir);
153189

154190
awaitmkdtemp(path.resolve(tmpDir,'FOO'));
191+
assert.rejects(
192+
// mkdtemp() expects to get a string prefix.
193+
async()=>mkdtemp(1),
194+
{
195+
code: 'ERR_INVALID_ARG_TYPE',
196+
name: 'TypeError [ERR_INVALID_ARG_TYPE]'
197+
}
198+
);
199+
155200
}
156201

157202
doTest().then(common.mustCall());

0 commit comments

Comments
 (0)