Skip to content

Commit c5f22cb

Browse files
artmakstargos
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 f8d3ea9 commit c5f22cb

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);
@@ -209,3 +214,19 @@ for (const bufferSize of ['', '1', null]) {
209214
assertDirent(dir.readSync());
210215
dir.close();
211216
}
217+
218+
// Check that when passing a string instead of function - throw an exception
219+
async function doAsyncIterInvalidCallbackTest() {
220+
const dir = await fs.promises.opendir(testDir);
221+
assert.throws(() => dir.close('not function'), invalidCallbackObj);
222+
}
223+
doAsyncIterInvalidCallbackTest().then(common.mustCall());
224+
225+
// Check if directory already closed - throw an exception
226+
async function doAsyncIterDirClosedTest() {
227+
const dir = await fs.promises.opendir(testDir);
228+
await dir.close();
229+
230+
assert.throws(() => dir.close(), dirclosedError);
231+
}
232+
doAsyncIterDirClosedTest().then(common.mustCall());

0 commit comments

Comments
 (0)