From c596eb2673180d7ffbc75a4835eb1be40aa689c9 Mon Sep 17 00:00:00 2001 From: Ryuichi Sakagami Date: Sun, 8 Jul 2018 19:09:18 +0900 Subject: [PATCH] test: add test of fs.promises write for non-string buffers PR-URL: https://github.com/nodejs/node/pull/21708 Reviewed-By: Franziska Hinkelmann Reviewed-By: Shingo Inoue Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- .../test-fs-promises-file-handle-write.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-fs-promises-file-handle-write.js b/test/parallel/test-fs-promises-file-handle-write.js index d7812745c5439e..3cff69f48dfb72 100644 --- a/test/parallel/test-fs-promises-file-handle-write.js +++ b/test/parallel/test-fs-promises-file-handle-write.js @@ -45,8 +45,22 @@ async function validateNonUint8ArrayWrite() { assert.deepStrictEqual(Buffer.from(buffer, 'utf8'), readFileData); } +async function validateNonStringValuesWrite() { + const filePathForHandle = path.resolve(tmpDir, 'tmp-non-string-write.txt'); + const fileHandle = await open(filePathForHandle, 'w+'); + const nonStringValues = [123, {}, new Map()]; + for (const nonStringValue of nonStringValues) { + await fileHandle.write(nonStringValue); + } + + const readFileData = fs.readFileSync(filePathForHandle); + const expected = ['123', '[object Object]', '[object Map]'].join(''); + assert.deepStrictEqual(Buffer.from(expected, 'utf8'), readFileData); +} + Promise.all([ validateWrite(), validateEmptyWrite(), - validateNonUint8ArrayWrite() + validateNonUint8ArrayWrite(), + validateNonStringValuesWrite() ]).then(common.mustCall());