Skip to content

Commit

Permalink
fix: flush thread-stream missing callback (#1137)
Browse files Browse the repository at this point in the history
* fix: flush thread-stream missing callback

* test: fix file.js import

* fix: console transport
  • Loading branch information
climba03003 authored Sep 21, 2021
1 parent 21ee5e2 commit 0e8ecd6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion file.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { Transform, pipeline } = require('stream')
const pino = require('../pino')
const pino = require('./pino')
const { once } = require('events')

module.exports = async function (opts = {}) {
Expand Down
4 changes: 3 additions & 1 deletion lib/proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ function write (_obj, msg, num) {
stream.write(s)
}

function noop () {}

function flush () {
const stream = this[streamSym]
if ('flush' in stream) stream.flush()
if ('flush' in stream) stream.flush(noop)
}
12 changes: 12 additions & 0 deletions test/fixtures/console-transport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { Writable } = require('stream')

module.exports = (options) => {
const myTransportStream = new Writable({
write (chunk, enc, cb) {
// apply a transform and send to stdout
console.log(chunk.toString().toUpperCase())
cb()
}
})
return myTransportStream
}
10 changes: 10 additions & 0 deletions test/syncfalse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,13 @@ test('flush does nothing with sync true (default)', async () => {
const instance = require('..')()
instance.flush()
})

test('thread-stream async flush', async () => {
const pino = require('..')
const transport = pino.transport({
target: join(__dirname, 'fixtures', 'console-transport.js')
})
const instance = pino(transport)
instance.info('hello')
instance.flush()
})
2 changes: 1 addition & 1 deletion test/targets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('file-target mocked', async function ({ equal, same, plan, pass }) {
plan(1)
let ret
const fileTarget = proxyquire('../file', {
'../pino': {
'./pino': {
destination (opts) {
same(opts, { dest: 1, sync: false })

Expand Down

0 comments on commit 0e8ecd6

Please sign in to comment.