Skip to content

Commit 8413f0f

Browse files
committed
test: improve coverage of lib/fs.js
1 parent 52e4fb5 commit 8413f0f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,16 @@ 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+
const readOnlyOption = { mode: fs.constants.O_RDONLY, flag: 'r' };
105+
// TODO: Correct the error type
106+
fs.writeFile(filename, s, readOnlyOption, common.expectsError({
107+
code: 'EBADF',
108+
message: 'EBADF: bad file descriptor, write'
109+
}));
110+
}

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

+26
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,29 @@ tmpdir.refresh();
5555
}));
5656
}));
5757
}
58+
59+
// Test read-only file descriptor
60+
{
61+
const file = join(tmpdir.path, 'test.txt');
62+
fs.open(file, 'r', common.mustSucceed((fd) => {
63+
fs.writeFile(fd, 'World', common.expectsError({
64+
code: 'EBADF',
65+
message: 'EBADF: bad file descriptor, write'
66+
}));
67+
}));
68+
}
69+
70+
// Test with an AbortSignal
71+
{
72+
const controller = new AbortController();
73+
const signal = controller.signal;
74+
const file = join(tmpdir.path, 'test.txt');
75+
76+
fs.open(file, 'w', common.mustSucceed((fd) => {
77+
fs.writeFile(fd, 'World', { signal }, common.expectsError({
78+
name: 'AbortError'
79+
}));
80+
}));
81+
82+
controller.abort();
83+
}

0 commit comments

Comments
 (0)