Skip to content

Commit

Permalink
resolves #1489 add test (#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Jul 18, 2022
1 parent 7a0c925 commit ab66179
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 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()
}
})
}
37 changes: 37 additions & 0 deletions test/multistream.test.js
Expand Up @@ -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
Expand Down Expand Up @@ -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 })
Expand Down

0 comments on commit ab66179

Please sign in to comment.