test: add test of fs.promises write for non-string buffers
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
8babbc5e45
commit
c596eb2673
@ -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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user