Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c5f22cb

Browse filesBrowse 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 <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>
1 parent f8d3ea9 commit c5f22cb
Copy full SHA for c5f22cb

File tree

Expand file treeCollapse file tree

1 file changed

+21
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-0
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-fs-opendir.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-opendir.js
+21Lines changed: 21 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.