Skip to content

Commit

Permalink
test: cover 'close' method in Dir class
Browse files Browse the repository at this point in the history
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: #30310
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
artmaks authored and MylesBorins committed Nov 21, 2019
1 parent 7e0f90e commit a5f25ec
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/parallel/test-fs-opendir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());

0 comments on commit a5f25ec

Please sign in to comment.