Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flush thread-stream missing callback #1137

Merged
merged 3 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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