test: improve fs coverage

PR-URL: https://github.com/nodejs/node/pull/38517
Refs: https://coverage.nodejs.org/coverage-68e6673224365120/lib/fs.js.html#L330
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
Rongjian Zhang authored and Michaël Zasso committed 2021-05-17 09:11:30 +02:00
1 parent 47080bcfc8
commit 95db7d5afc
2 files changed
+32 -7

No files matched your search

+15 -7
View File
@@ -78,13 +78,21 @@ assert.throws(
}
);
['buffer', 'offset', 'length'].forEach((option) =>
assert.throws(
() => fs.read(fd, {
[option]: null
}),
`not throws when options.${option} is null`
));
assert.throws(
() => fs.read(fd, { buffer: null }, common.mustNotCall()),
/TypeError: Cannot read property 'byteLength' of null/,
'throws when options.buffer is null'
);
assert.throws(
() => fs.readSync(fd, { buffer: null }),
{
name: 'TypeError',
message: 'The "buffer" argument must be an instance of Buffer, ' +
'TypedArray, or DataView. Received an instance of Object',
},
'throws when options.buffer is null'
);
assert.throws(
() => fs.read(null, Buffer.alloc(1), 0, 1, 0),
+17
View File
@@ -52,6 +52,23 @@ for (const e of fileInfo) {
assert.deepStrictEqual(buf, e.contents);
}));
}
// Test readFile size too large
{
const kIoMaxLength = 2 ** 31 - 1;
const file = path.join(tmpdir.path, `${prefix}-too-large.txt`);
fs.writeFileSync(file, Buffer.from('0'));
fs.truncateSync(file, kIoMaxLength + 1);
fs.readFile(file, common.expectsError({
code: 'ERR_FS_FILE_TOO_LARGE',
name: 'RangeError',
}));
assert.throws(() => {
fs.readFileSync(file);
}, { code: 'ERR_FS_FILE_TOO_LARGE', name: 'RangeError' });
}
{
// Test cancellation, before
const signal = AbortSignal.abort();