feat: Create function to wrap streams to not lose errors

This commit is contained in:
Joachim Van Herwegen
2020-11-17 11:44:48 +01:00
parent 9c78c4f9ad
commit 1a30b51461
4 changed files with 221 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
import { PassThrough } from 'stream';
import streamifyArray from 'streamify-array';
import { pipeSafely, readableToString } from '../../../src/util/StreamUtil';
import { guardedStreamFrom, pipeSafely, readableToString } from '../../../src/util/StreamUtil';
describe('StreamUtil', (): void => {
describe('#readableToString', (): void => {
@@ -40,4 +40,11 @@ describe('StreamUtil', (): void => {
await expect(readableToString(piped)).rejects.toThrow(new Error('other error'));
});
});
describe('#guardedStreamFrom', (): void => {
it('converts data to a guarded stream.', async(): Promise<void> => {
const data = [ 'a', 'b' ];
await expect(readableToString(guardedStreamFrom(data))).resolves.toBe('ab');
});
});
});