@@ -64,6 +64,13 @@ function verifyStatObject(stat) { |
64 | 64 | assert.strictEqual(typeof stat.mode, 'number'); |
65 | 65 | } |
66 | 66 |
|
| 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 | + |
67 | 74 | { |
68 | 75 | async function doTest() { |
69 | 76 | tmpdir.refresh(); |
@@ -93,6 +100,19 @@ function verifyStatObject(stat) { |
93 | 100 | await handle.datasync(); |
94 | 101 | await handle.sync(); |
95 | 102 |
|
| 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 | + |
96 | 116 | const buf = Buffer.from('hello fsPromises'); |
97 | 117 | const bufLen = buf.length; |
98 | 118 | await handle.write(buf); |
@@ -203,13 +223,22 @@ function verifyStatObject(stat) { |
203 | 223 |
|
204 | 224 | await unlink(newLink2); |
205 | 225 |
|
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 | + } |
213 | 242 |
|
214 | 243 | // mkdir when options is number. |
215 | 244 | { |
|