Skip to content

Commit a5f25ec

Browse files
artmaksMylesBorins
authored andcommitted
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: #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]>
1 parent 7e0f90e commit a5f25ec

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/parallel/test-fs-opendir.js

+21
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ const dirclosedError = {
3333
code: 'ERR_DIR_CLOSED'
3434
};
3535

36+
const invalidCallbackObj = {
37+
code: 'ERR_INVALID_CALLBACK',
38+
name: 'TypeError'
39+
};
40+
3641
// Check the opendir Sync version
3742
{
3843
const dir = fs.opendirSync(testDir);
@@ -205,3 +210,19 @@ for (const bufferSize of ['', '1', null]) {
205210
assertDirent(dir.readSync());
206211
dir.close();
207212
}
213+
214+
// Check that when passing a string instead of function - throw an exception
215+
async function doAsyncIterInvalidCallbackTest() {
216+
const dir = await fs.promises.opendir(testDir);
217+
assert.throws(() => dir.close('not function'), invalidCallbackObj);
218+
}
219+
doAsyncIterInvalidCallbackTest().then(common.mustCall());
220+
221+
// Check if directory already closed - throw an exception
222+
async function doAsyncIterDirClosedTest() {
223+
const dir = await fs.promises.opendir(testDir);
224+
await dir.close();
225+
226+
assert.throws(() => dir.close(), dirclosedError);
227+
}
228+
doAsyncIterDirClosedTest().then(common.mustCall());

0 commit comments

Comments
 (0)