Skip to content

Commit b5c75a3

Browse files
Masashi Hiranojasnell
Masashi Hirano
authored andcommitted
test: error when empty buffer is passed to filehandle.read()
Added tests to occur error when empty buffer is passed to filehandle.read() to increase coverage. PR-URL: #23250 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent a29631b commit b5c75a3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/parallel/test-fs-read-empty-buffer.js

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const assert = require('assert');
66
const fs = require('fs');
77
const filepath = fixtures.path('x.txt');
88
const fd = fs.openSync(filepath, 'r');
9+
const fsPromises = fs.promises;
910

1011
const buffer = new Uint8Array();
1112

@@ -26,3 +27,15 @@ assert.throws(
2627
'Received Uint8Array []'
2728
}
2829
);
30+
31+
(async () => {
32+
const filehandle = await fsPromises.open(filepath, 'r');
33+
assert.rejects(
34+
() => filehandle.read(buffer, 0, 1, 0),
35+
{
36+
code: 'ERR_INVALID_ARG_VALUE',
37+
message: 'The argument \'buffer\' is empty and cannot be written. ' +
38+
'Received Uint8Array []'
39+
}
40+
);
41+
})();

0 commit comments

Comments
 (0)