improve stream testing

Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
This commit is contained in:
Diogenes Fernandes 2025-12-17 12:09:05 -03:00
parent 6951ef3b10
commit e09aa99a0d
No known key found for this signature in database
GPG key ID: C9F5DF287AF42A48

View file

@ -7,11 +7,15 @@ const OutputListener = require('../lib/output-listener');
const { PassThrough } = require('stream');
describe('output-listener', () => {
it('receives and exposes data', () => {
const listener = new OutputListener(new PassThrough());
const stream = new PassThrough();
const listener = new OutputListener(stream);
const listen = listener.listener;
listen(Buffer.from('foo'));
expect(stream.read()).toEqual(Buffer.from('foo'));
listen(Buffer.from('bar'));
expect(stream.read()).toEqual(Buffer.from('bar'));
listen(Buffer.from('baz'));
expect(stream.read()).toEqual(Buffer.from('baz'));
expect(listener.contents).toEqual('foobarbaz');
});
});