From b818aa66d42c26aecf7821d8f78c54273fe88811 Mon Sep 17 00:00:00 2001 From: ssube Date: Fri, 15 Nov 2019 17:45:23 -0600 Subject: [PATCH] cover stream error handling --- test/TestSource.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/TestSource.ts b/test/TestSource.ts index fde8394..1e91093 100644 --- a/test/TestSource.ts +++ b/test/TestSource.ts @@ -1,6 +1,7 @@ import { expect } from 'chai'; import mockFs from 'mock-fs'; -import { spy } from 'sinon'; +import { BaseError } from 'noicejs'; +import { spy, stub } from 'sinon'; import { PassThrough } from 'stream'; import { readSource, writeSource } from '../src/source'; @@ -31,6 +32,14 @@ describeLeaks('load source helper', async () => { expect(source).to.equal(TEST_STRING); }); + + it('should handle errors reading from stdin', async () => { + const pt = new PassThrough(); + const futureSource = readSource('-', pt); + pt.emit('error', new BaseError('terribad!')); + + return expect(futureSource).to.eventually.be.rejectedWith(BaseError); + }); }); describeLeaks('write source helper', async () => { @@ -56,4 +65,11 @@ describeLeaks('write source helper', async () => { expect(writeSpy).to.have.been.calledWith(TEST_STRING); }); + + it('should handle errors writing to stdout', async () => { + const pt = new PassThrough(); + stub(pt, 'write').yields(new BaseError('terribad!')); + + return expect(writeSource('-', 'test', pt)).to.eventually.be.rejectedWith(BaseError); + }); });