summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorArtem Maksimov <temamaksimov@gmail.com>2019-11-06 17:24:29 +0300
committerGireesh Punathil <gpunathi@in.ibm.com>2019-11-21 18:10:49 +0530
commit9fbad51c8a6afdaf7d24d57a1712319346efe28e (patch)
tree47063d5452af63cc972d4ac8d7361011002c1af8 /test
parent8c1cb4365d359687fff5435df5409e0ed9d91531 (diff)
downloadandroid-node-v8-9fbad51c8a6afdaf7d24d57a1712319346efe28e.tar.gz
android-node-v8-9fbad51c8a6afdaf7d24d57a1712319346efe28e.tar.bz2
android-node-v8-9fbad51c8a6afdaf7d24d57a1712319346efe28e.zip
test: cover 'close' method in Dir class
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 PR-URL: https://github.com/nodejs/node/pull/30310 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-fs-opendir.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/parallel/test-fs-opendir.js b/test/parallel/test-fs-opendir.js
index 05fded527f..7ae6186b28 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,19 @@ 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());