From ab66179b57d551c23d6e02c02522877371951a38 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Mon, 18 Jul 2022 11:11:32 +0200 Subject: [PATCH] resolves #1489 add test (#1496) --- test/fixtures/noop-transport.js | 10 +++++++++ test/multistream.test.js | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/fixtures/noop-transport.js diff --git a/test/fixtures/noop-transport.js b/test/fixtures/noop-transport.js new file mode 100644 index 000000000..5e36c4473 --- /dev/null +++ b/test/fixtures/noop-transport.js @@ -0,0 +1,10 @@ +const { Writable } = require('stream') + +module.exports = () => { + return new Writable({ + autoDestroy: true, + write (chunk, enc, cb) { + cb() + } + }) +} diff --git a/test/multistream.test.js b/test/multistream.test.js index abd1dba03..5b659096b 100644 --- a/test/multistream.test.js +++ b/test/multistream.test.js @@ -2,6 +2,7 @@ const writeStream = require('flush-write-stream') const { readFileSync } = require('fs') +const { join } = require('path') const test = require('tap').test const pino = require('../') const multistream = pino.multistream @@ -538,6 +539,42 @@ test('multistream throws if not a stream', function (t) { } }) +test('multistream.write should not throw if one stream fails', function (t) { + let messageCount = 0 + const stream = writeStream(function (data, enc, cb) { + messageCount += 1 + cb() + }) + const noopStream = pino.transport({ + target: join(__dirname, 'fixtures', 'noop-transport.js') + }) + // eslint-disable-next-line + noopStream.on('error', function (err) { + // something went wrong while writing to noop stream, ignoring! + }) + const log = pino({ + level: 'trace' + }, + multistream([ + { + level: 'trace', + stream + }, + { + level: 'debug', + stream: noopStream + } + ]) + ) + log.debug('0') + noopStream.end() + // noop stream is ending, should emit an error but not throw + log.debug('1') + log.debug('2') + t.equal(messageCount, 3) + t.end() +}) + test('flushSync', function (t) { const tmp = file() const destination = pino.destination({ dest: tmp, sync: false, minLength: 4096 })