From 4b192ae5f4423a4476b21b2456a50bc7b3cef4d8 Mon Sep 17 00:00:00 2001 From: Jennifer Bland Date: Mon, 10 Sep 2018 21:56:27 -0400 Subject: [PATCH 1/4] test: increase test coverage for fs.promises read --- test/parallel/test-fs-promises.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index 714f1db05d5494..9da7caae4ba5bf 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -93,6 +93,15 @@ function verifyStatObject(stat) { await handle.datasync(); await handle.sync(); + // test fs.read promises when length to read is zero bytes + { + const buf = Buffer.from('DAWGS WIN'); + const bufLen = buf.length; + await handle.write(buf); + const ret = await handle.read(Buffer.alloc(bufLen), 0, 0, 0); + assert.strictEqual(ret.bytesRead, 0); + } + const buf = Buffer.from('hello fsPromises'); const bufLen = buf.length; await handle.write(buf); From 630b9ae0f6edfd8ce97ba9811f8583c7940d8ca8 Mon Sep 17 00:00:00 2001 From: Jennifer Bland Date: Thu, 27 Sep 2018 21:45:13 -0400 Subject: [PATCH 2/4] test: increase test coverage for fs.promises read --- test/parallel/test-fs-promises.js | 36 +++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index 9da7caae4ba5bf..e0662dd2b02388 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -64,6 +64,14 @@ function verifyStatObject(stat) { assert.strictEqual(typeof stat.mode, 'number'); } +async function getHandle(dest) { + // const dest = path.resolve(tmpDir, filename); + await copyFile(fixtures.path('baz.js'), dest); + await access(dest, 'r'); + + return open(dest, 'r+'); +} + { async function doTest() { tmpdir.refresh(); @@ -95,11 +103,15 @@ function verifyStatObject(stat) { // test fs.read promises when length to read is zero bytes { + const dest = path.resolve(tmpDir, 'test1.js'); + const handle = await getHandle(dest); const buf = Buffer.from('DAWGS WIN'); const bufLen = buf.length; await handle.write(buf); const ret = await handle.read(Buffer.alloc(bufLen), 0, 0, 0); assert.strictEqual(ret.bytesRead, 0); + + await unlink(dest); } const buf = Buffer.from('hello fsPromises'); @@ -212,13 +224,22 @@ function verifyStatObject(stat) { await unlink(newLink2); - const newdir = path.resolve(tmpDir, 'dir'); - await mkdir(newdir); - stats = await stat(newdir); - assert(stats.isDirectory()); - const list = await readdir(tmpDir); - assert.deepStrictEqual(list, ['baz2.js', 'dir']); - await rmdir(newdir); + // testing readdir lists both files and directories + { + const newDir = path.resolve(tmpDir, 'dir'); + const newFile = path.resolve(tmpDir, 'foo.js'); + + await mkdir(newDir); + await writeFile(newFile, 'DAWGS WIN!', 'utf8'); + + stats = await stat(newDir); + assert(stats.isDirectory()); + const list = await readdir(tmpDir); + assert.notStrictEqual(list.indexOf('dir'), -1); + assert.notStrictEqual(list.indexOf('foo.js'), -1); + await rmdir(newDir); + await unlink(newFile); + } // mkdir when options is number. { @@ -307,3 +328,4 @@ function verifyStatObject(stat) { doTest().then(common.mustCall()); } + From 3b02cb3baf5b7ed48fd930fb8ec58f5cbaafa75f Mon Sep 17 00:00:00 2001 From: Jennifer Bland Date: Thu, 27 Sep 2018 21:46:32 -0400 Subject: [PATCH 3/4] test: increase test coverage for fs.promises read --- test/parallel/test-fs-promises.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index e0662dd2b02388..77799b7bfdad73 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -65,7 +65,6 @@ function verifyStatObject(stat) { } async function getHandle(dest) { - // const dest = path.resolve(tmpDir, filename); await copyFile(fixtures.path('baz.js'), dest); await access(dest, 'r'); From bfd56780f9a5013395170fbc0f865788274f1b2c Mon Sep 17 00:00:00 2001 From: Jennifer Bland Date: Thu, 27 Sep 2018 21:47:59 -0400 Subject: [PATCH 4/4] test: increase test coverage for fs.promises read --- test/parallel/test-fs-promises.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index 77799b7bfdad73..797f8e4ea269f8 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -327,4 +327,3 @@ async function getHandle(dest) { doTest().then(common.mustCall()); } -