mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Make piping consistent
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
||||
decodeUriPathComponents,
|
||||
encodeUriPathComponents,
|
||||
ensureTrailingSlash,
|
||||
matchingMediaType, pipeStreamsAndErrors, pushQuad,
|
||||
matchingMediaType, pipeSafe, pushQuad,
|
||||
readableToString,
|
||||
toCanonicalUriPath,
|
||||
} from '../../../src/util/Util';
|
||||
@@ -48,19 +48,19 @@ describe('Util function', (): void => {
|
||||
it('pipes data from one stream to the other.', async(): Promise<void> => {
|
||||
const input = streamifyArray([ 'data' ]);
|
||||
const output = new PassThrough();
|
||||
pipeStreamsAndErrors(input, output);
|
||||
await expect(readableToString(output)).resolves.toEqual('data');
|
||||
const piped = pipeSafe(input, output);
|
||||
await expect(readableToString(piped)).resolves.toEqual('data');
|
||||
});
|
||||
|
||||
it('pipes errors from one stream to the other.', async(): Promise<void> => {
|
||||
const input = streamifyArray([ 'data' ]);
|
||||
const input = new PassThrough();
|
||||
input.read = (): any => {
|
||||
input.emit('error', new Error('error'));
|
||||
return null;
|
||||
};
|
||||
const output = new PassThrough();
|
||||
pipeStreamsAndErrors(input, output);
|
||||
await expect(readableToString(output)).rejects.toThrow(new Error('error'));
|
||||
const piped = pipeSafe(input, output);
|
||||
await expect(readableToString(piped)).rejects.toThrow(new Error('error'));
|
||||
});
|
||||
|
||||
it('supports mapping errors to something else.', async(): Promise<void> => {
|
||||
@@ -70,8 +70,8 @@ describe('Util function', (): void => {
|
||||
return null;
|
||||
};
|
||||
const output = new PassThrough();
|
||||
pipeStreamsAndErrors(input, output, (): any => new Error('other error'));
|
||||
await expect(readableToString(output)).rejects.toThrow(new Error('other error'));
|
||||
const piped = pipeSafe(input, output, (): any => new Error('other error'));
|
||||
await expect(readableToString(piped)).rejects.toThrow(new Error('other error'));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user