Skip to content

Commit

Permalink
test: add test of fs.promises write for non-string buffers
Browse files Browse the repository at this point in the history
PR-URL: #21708
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
Shagamii authored and targos committed Jul 16, 2018
1 parent 238ef58 commit 32ad163
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/parallel/test-fs-promises-file-handle-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

0 comments on commit 32ad163

Please sign in to comment.