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 695e982

Browse filesBrowse files
pd4d10danielleadams
authored andcommitted
test: improve coverage of lib/fs.js
PR-URL: #38604 Refs: https://coverage.nodejs.org/coverage-29f1b609ba5d12d3/lib/fs.js.html#L2045 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent 11ac9c6 commit 695e982
Copy full SHA for 695e982

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

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

‎test/parallel/test-fs-write-file.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-write-file.js
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,13 @@ fs.open(filename4, 'w+', common.mustSucceed((fd) => {
9595

9696
process.nextTick(() => controller.abort());
9797
}
98+
99+
{
100+
// Test read-only mode
101+
const filename = join(tmpdir.path, 'test6.txt');
102+
fs.writeFileSync(filename, '');
103+
104+
// TODO: Correct the error type
105+
const expectedError = common.isWindows ? /EPERM/ : /EBADF/;
106+
fs.writeFile(filename, s, { flag: 'r' }, common.expectsError(expectedError));
107+
}
Collapse file

‎test/parallel/test-fs-writefile-with-fd.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-writefile-with-fd.js
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,31 @@ tmpdir.refresh();
5555
}));
5656
}));
5757
}
58+
59+
60+
// Test read-only file descriptor
61+
{
62+
// TODO(pd4d10): https://github.com/nodejs/node/issues/38607
63+
const expectedError = common.isWindows ? /EPERM/ : /EBADF/;
64+
65+
const file = join(tmpdir.path, 'test.txt');
66+
67+
fs.open(file, 'r', common.mustSucceed((fd) => {
68+
fs.writeFile(fd, 'World', common.expectsError(expectedError));
69+
}));
70+
}
71+
72+
// Test with an AbortSignal
73+
{
74+
const controller = new AbortController();
75+
const signal = controller.signal;
76+
const file = join(tmpdir.path, 'test.txt');
77+
78+
fs.open(file, 'w', common.mustSucceed((fd) => {
79+
fs.writeFile(fd, 'World', { signal }, common.expectsError({
80+
name: 'AbortError'
81+
}));
82+
}));
83+
84+
controller.abort();
85+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.