Skip to content

Commit efeb49d

Browse files
ratracegradtargos
authored andcommitted
test: increase test coverage for fs.promises read
PR-URL: #22800 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Coe <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent c40e2dd commit efeb49d

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

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

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ function verifyStatObject(stat){
6464
assert.strictEqual(typeofstat.mode,'number');
6565
}
6666

67+
asyncfunctiongetHandle(dest){
68+
awaitcopyFile(fixtures.path('baz.js'),dest);
69+
awaitaccess(dest,'r');
70+
71+
returnopen(dest,'r+');
72+
}
73+
6774
{
6875
asyncfunctiondoTest(){
6976
tmpdir.refresh();
@@ -93,6 +100,19 @@ function verifyStatObject(stat){
93100
awaithandle.datasync();
94101
awaithandle.sync();
95102

103+
// test fs.read promises when length to read is zero bytes
104+
{
105+
constdest=path.resolve(tmpDir,'test1.js');
106+
consthandle=awaitgetHandle(dest);
107+
constbuf=Buffer.from('DAWGS WIN');
108+
constbufLen=buf.length;
109+
awaithandle.write(buf);
110+
constret=awaithandle.read(Buffer.alloc(bufLen),0,0,0);
111+
assert.strictEqual(ret.bytesRead,0);
112+
113+
awaitunlink(dest);
114+
}
115+
96116
constbuf=Buffer.from('hello fsPromises');
97117
constbufLen=buf.length;
98118
awaithandle.write(buf);
@@ -203,13 +223,22 @@ function verifyStatObject(stat){
203223

204224
awaitunlink(newLink2);
205225

206-
constnewdir=path.resolve(tmpDir,'dir');
207-
awaitmkdir(newdir);
208-
stats=awaitstat(newdir);
209-
assert(stats.isDirectory());
210-
constlist=awaitreaddir(tmpDir);
211-
assert.deepStrictEqual(list,['baz2.js','dir']);
212-
awaitrmdir(newdir);
226+
// testing readdir lists both files and directories
227+
{
228+
constnewDir=path.resolve(tmpDir,'dir');
229+
constnewFile=path.resolve(tmpDir,'foo.js');
230+
231+
awaitmkdir(newDir);
232+
awaitwriteFile(newFile,'DAWGS WIN!','utf8');
233+
234+
stats=awaitstat(newDir);
235+
assert(stats.isDirectory());
236+
constlist=awaitreaddir(tmpDir);
237+
assert.notStrictEqual(list.indexOf('dir'),-1);
238+
assert.notStrictEqual(list.indexOf('foo.js'),-1);
239+
awaitrmdir(newDir);
240+
awaitunlink(newFile);
241+
}
213242

214243
// mkdir when options is number.
215244
{

0 commit comments

Comments
(0)