@@ -64,6 +64,13 @@ function verifyStatObject(stat) {
6464 assert . strictEqual ( typeof stat . mode , 'number' ) ;
6565}
6666
67+ async function getHandle ( dest ) {
68+ await copyFile ( fixtures . path ( 'baz.js' ) , dest ) ;
69+ await access ( dest , 'r' ) ;
70+
71+ return open ( dest , 'r+' ) ;
72+ }
73+
6774{
6875 async function doTest ( ) {
6976 tmpdir . refresh ( ) ;
@@ -93,6 +100,19 @@ function verifyStatObject(stat) {
93100 await handle . datasync ( ) ;
94101 await handle . sync ( ) ;
95102
103+ // test fs.read promises when length to read is zero bytes
104+ {
105+ const dest = path . resolve ( tmpDir , 'test1.js' ) ;
106+ const handle = await getHandle ( dest ) ;
107+ const buf = Buffer . from ( 'DAWGS WIN' ) ;
108+ const bufLen = buf . length ;
109+ await handle . write ( buf ) ;
110+ const ret = await handle . read ( Buffer . alloc ( bufLen ) , 0 , 0 , 0 ) ;
111+ assert . strictEqual ( ret . bytesRead , 0 ) ;
112+
113+ await unlink ( dest ) ;
114+ }
115+
96116 const buf = Buffer . from ( 'hello fsPromises' ) ;
97117 const bufLen = buf . length ;
98118 await handle . write ( buf ) ;
@@ -203,13 +223,22 @@ function verifyStatObject(stat) {
203223
204224 await unlink ( newLink2 ) ;
205225
206- const newdir = path . resolve ( tmpDir , 'dir' ) ;
207- await mkdir ( newdir ) ;
208- stats = await stat ( newdir ) ;
209- assert ( stats . isDirectory ( ) ) ;
210- const list = await readdir ( tmpDir ) ;
211- assert . deepStrictEqual ( list , [ 'baz2.js' , 'dir' ] ) ;
212- await rmdir ( newdir ) ;
226+ // testing readdir lists both files and directories
227+ {
228+ const newDir = path . resolve ( tmpDir , 'dir' ) ;
229+ const newFile = path . resolve ( tmpDir , 'foo.js' ) ;
230+
231+ await mkdir ( newDir ) ;
232+ await writeFile ( newFile , 'DAWGS WIN!' , 'utf8' ) ;
233+
234+ stats = await stat ( newDir ) ;
235+ assert ( stats . isDirectory ( ) ) ;
236+ const list = await readdir ( tmpDir ) ;
237+ assert . notStrictEqual ( list . indexOf ( 'dir' ) , - 1 ) ;
238+ assert . notStrictEqual ( list . indexOf ( 'foo.js' ) , - 1 ) ;
239+ await rmdir ( newDir ) ;
240+ await unlink ( newFile ) ;
241+ }
213242
214243 // mkdir when options is number.
215244 {
0 commit comments