Skip to content

Commit 32ad163

Browse files
Shagamiitargos
authored andcommitted
test: add test of fs.promises write for non-string buffers
PR-URL: #21708 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Shingo Inoue <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 238ef58 commit 32ad163

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,22 @@ async function validateNonUint8ArrayWrite() {
4545
assert.deepStrictEqual(Buffer.from(buffer, 'utf8'), readFileData);
4646
}
4747

48+
async function validateNonStringValuesWrite() {
49+
const filePathForHandle = path.resolve(tmpDir, 'tmp-non-string-write.txt');
50+
const fileHandle = await open(filePathForHandle, 'w+');
51+
const nonStringValues = [123, {}, new Map()];
52+
for (const nonStringValue of nonStringValues) {
53+
await fileHandle.write(nonStringValue);
54+
}
55+
56+
const readFileData = fs.readFileSync(filePathForHandle);
57+
const expected = ['123', '[object Object]', '[object Map]'].join('');
58+
assert.deepStrictEqual(Buffer.from(expected, 'utf8'), readFileData);
59+
}
60+
4861
Promise.all([
4962
validateWrite(),
5063
validateEmptyWrite(),
51-
validateNonUint8ArrayWrite()
64+
validateNonUint8ArrayWrite(),
65+
validateNonStringValuesWrite()
5266
]).then(common.mustCall());

0 commit comments

Comments
 (0)