Skip to content

Commit 95db7d5

Browse files
pd4d10targos
authored andcommitted
test: improve fs coverage
PR-URL: #38517 Refs: https://coverage.nodejs.org/coverage-68e6673224365120/lib/fs.js.html#L330 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 47080bc commit 95db7d5

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

test/parallel/test-fs-read.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,21 @@ assert.throws(
7878
}
7979
);
8080

81-
['buffer', 'offset', 'length'].forEach((option) =>
82-
assert.throws(
83-
() => fs.read(fd, {
84-
[option]: null
85-
}),
86-
`not throws when options.${option} is null`
87-
));
81+
assert.throws(
82+
() => fs.read(fd, { buffer: null }, common.mustNotCall()),
83+
/TypeError: Cannot read property 'byteLength' of null/,
84+
'throws when options.buffer is null'
85+
);
86+
87+
assert.throws(
88+
() => fs.readSync(fd, { buffer: null }),
89+
{
90+
name: 'TypeError',
91+
message: 'The "buffer" argument must be an instance of Buffer, ' +
92+
'TypedArray, or DataView. Received an instance of Object',
93+
},
94+
'throws when options.buffer is null'
95+
);
8896

8997
assert.throws(
9098
() => fs.read(null, Buffer.alloc(1), 0, 1, 0),

test/parallel/test-fs-readfile.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ for (const e of fileInfo) {
5252
assert.deepStrictEqual(buf, e.contents);
5353
}));
5454
}
55+
// Test readFile size too large
56+
{
57+
const kIoMaxLength = 2 ** 31 - 1;
58+
59+
const file = path.join(tmpdir.path, `${prefix}-too-large.txt`);
60+
fs.writeFileSync(file, Buffer.from('0'));
61+
fs.truncateSync(file, kIoMaxLength + 1);
62+
63+
fs.readFile(file, common.expectsError({
64+
code: 'ERR_FS_FILE_TOO_LARGE',
65+
name: 'RangeError',
66+
}));
67+
assert.throws(() => {
68+
fs.readFileSync(file);
69+
}, { code: 'ERR_FS_FILE_TOO_LARGE', name: 'RangeError' });
70+
}
71+
5572
{
5673
// Test cancellation, before
5774
const signal = AbortSignal.abort();

0 commit comments

Comments
 (0)