Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
  • Loading branch information
artmaks committed Nov 6, 2019
commit 52499de3cda8d75b58a1b8a56f5d1a3d7adbe983
22 changes: 22 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,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);
``
Comment thread
trivikr marked this conversation as resolved.
Outdated
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());