mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Pipe streams with the pump library
The library handles some edge cases we didn't yet. The GuardedStream was also updated to ignore error listeners already attached to the stream (since pump adds internal listeners).
This commit is contained in:
@@ -89,7 +89,7 @@ describe('GuardedStream', (): void => {
|
||||
expect(endListener).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('does not time out when a listener was already attached.', async(): Promise<void> => {
|
||||
it('ignores error listeners that were already attached.', async(): Promise<void> => {
|
||||
const stream = Readable.from([ 'data' ]);
|
||||
stream.addListener('error', jest.fn());
|
||||
guardStream(stream);
|
||||
@@ -97,7 +97,21 @@ describe('GuardedStream', (): void => {
|
||||
stream.emit('error', new Error('error'));
|
||||
|
||||
jest.advanceTimersByTime(1000);
|
||||
expect(logger.error).toHaveBeenCalledTimes(0);
|
||||
expect(logger.error).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('ignores error listeners after calling guardStream a second time.', async(): Promise<void> => {
|
||||
const stream = Readable.from([ 'data' ]);
|
||||
guardStream(stream);
|
||||
stream.addListener('error', jest.fn());
|
||||
|
||||
// This will cause the above error listener to be ignored for logging purposes
|
||||
guardStream(stream);
|
||||
|
||||
stream.emit('error', new Error('error'));
|
||||
|
||||
jest.advanceTimersByTime(1000);
|
||||
expect(logger.error).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('still works if error listeners get removed and added again.', async(): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user