Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test of fs.promises write for non-string buffers #21708

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions test/parallel/test-fs-promises-file-handle-write.js
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());