Skip to content

Commit 695e982

Browse 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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 11ac9c6 commit 695e982

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

+10
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+
}

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

+28
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)