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>
This commit is contained in:
Artem Maksimov authored and Myles Borins committed 2019-11-21 13:37:05 -05:00
1 parent 7e0f90e286
commit a5f25ecf07
1 file changed
+21
+21
View File
@@ -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());