From 21f729de1b1d3845a9f1038be5a8765272c350a5 Mon Sep 17 00:00:00 2001 From: Scott Feeney Date: Wed, 27 Nov 2024 16:19:08 -0800 Subject: [PATCH] add test for createWriteStream accepting fh as fd --- src/__tests__/volume.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/__tests__/volume.test.ts b/src/__tests__/volume.test.ts index bc5ba0ff0..5f132e8e1 100644 --- a/src/__tests__/volume.test.ts +++ b/src/__tests__/volume.test.ts @@ -1,3 +1,4 @@ +import { promisify } from 'util'; import { URL } from 'url'; import { Link } from '../node'; import Stats from '../Stats'; @@ -1431,4 +1432,16 @@ describe('volume', () => { expect(new StatWatcher(vol).vol).toBe(vol); }); }); + describe('.createWriteStream', () => { + it('accepts filehandle as fd option', async () => { + const vol = new Volume(); + const fh = await vol.promises.open('/test.txt', 'wx', 0o600); + const writeStream = vol.createWriteStream('', { fd: fh }); + await promisify(writeStream.write.bind(writeStream))(Buffer.from('Hello')); + await promisify(writeStream.close.bind(writeStream))(); + expect(vol.toJSON()).toEqual({ + '/test.txt': 'Hello', + }); + }); + }); });