Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions test/parallel/test-fs-promises-file-handle-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const common = require('../common');

// The following tests validate base functionality for the fs.promises
// FileHandle.read method.
// FileHandle.write method.

const fs = require('fs');
const { open } = fs.promises;
Expand Down 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());