Skip to content

Commit

Permalink
add createReadStream test
Browse files Browse the repository at this point in the history
  • Loading branch information
graue committed Nov 30, 2024
1 parent 3dbf3ba commit 5734a60
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/__tests__/volume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
});

0 comments on commit 5734a60

Please sign in to comment.