From 52499de3cda8d75b58a1b8a56f5d1a3d7adbe983 Mon Sep 17 00:00:00 2001 From: Artem Maksimov Date: Wed, 6 Nov 2019 17:24:29 +0300 Subject: [PATCH 1/2] test: cover 'close' method (in Dir class) with tests Add 2 tests for full covering of method 'close' in class Dir 1. If pass smth that not string as a callback - throw an exception 2. If do .close() on already closed directory - throw an exception --- test/parallel/test-fs-opendir.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/parallel/test-fs-opendir.js b/test/parallel/test-fs-opendir.js index 05fded527fe7f1..a2299f86b9d31f 100644 --- a/test/parallel/test-fs-opendir.js +++ b/test/parallel/test-fs-opendir.js @@ -33,6 +33,11 @@ const dirclosedError = { code: 'ERR_DIR_CLOSED' }; +const invalidCallbackObj = { + code: 'ERR_INVALID_CALLBACK', + name: 'TypeError' +}; + // Check the opendir Sync version { const dir = fs.opendirSync(testDir); @@ -205,3 +210,20 @@ for (const bufferSize of ['', '1', null]) { assertDirent(dir.readSync()); dir.close(); } + +// Check that when passing a string instead of function - throw an exception +async function doAsyncIterInvalidCallbackTest() { + const dir = await fs.promises.opendir(testDir); +`` + assert.throws(() => dir.close('not function'), invalidCallbackObj); +} +doAsyncIterInvalidCallbackTest().then(common.mustCall()); + +// Check if directory already closed - throw an exception +async function doAsyncIterDirClosedTest() { + const dir = await fs.promises.opendir(testDir); + await dir.close(); + + assert.throws(() => dir.close(), dirclosedError); +} +doAsyncIterDirClosedTest().then(common.mustCall()); From b3e84a67b176febc061cc2b34dfd7c5b25a32220 Mon Sep 17 00:00:00 2001 From: Artem Maksimov Date: Wed, 6 Nov 2019 18:23:09 +0300 Subject: [PATCH 2/2] test: fix a typo --- test/parallel/test-fs-opendir.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-fs-opendir.js b/test/parallel/test-fs-opendir.js index a2299f86b9d31f..7ae6186b28518a 100644 --- a/test/parallel/test-fs-opendir.js +++ b/test/parallel/test-fs-opendir.js @@ -214,7 +214,6 @@ for (const bufferSize of ['', '1', null]) { // Check that when passing a string instead of function - throw an exception async function doAsyncIterInvalidCallbackTest() { const dir = await fs.promises.opendir(testDir); -`` assert.throws(() => dir.close('not function'), invalidCallbackObj); } doAsyncIterInvalidCallbackTest().then(common.mustCall());