From 5734a60c2bff80f6823a54c56b1de563529e5971 Mon Sep 17 00:00:00 2001 From: Scott Feeney Date: Fri, 29 Nov 2024 21:16:03 -0800 Subject: [PATCH] add createReadStream test --- src/__tests__/volume.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/__tests__/volume.test.ts b/src/__tests__/volume.test.ts index 5f132e8e..75abb2ae 100644 --- a/src/__tests__/volume.test.ts +++ b/src/__tests__/volume.test.ts @@ -1444,4 +1444,29 @@ describe('volume', () => { }); }); }); + describe('.createReadStream', () => { + it('accepts filehandle as fd option', done => { + const vol = Volume.fromJSON({ + '/test.txt': 'Hello', + }); + vol.promises.open('/test.txt', 'r').then(fh => { + const readStream = vol.createReadStream( + '/this/should/be/ignored', + { fd: fh }, + ); + readStream.setEncoding('utf8'); + let readData = ''; + readStream.on('readable', () => { + const chunk = readStream.read(); + if (chunk != null) readData += chunk; + }); + readStream.on('end', () => { + expect(readData).toEqual('Hello'); + done(); + }); + }).catch((err) => { + expect(err).toBeNull(); + }); + }); + }); });