download
raw
1.91 kB
'use strict'
const test = require('node:test')
const assert = require('node:assert')
const os = require('node:os')
const { join } = require('node:path')
const { readFile } = require('node:fs').promises
const { promisify } = require('node:util')
const pino = require('../..')
const { watchFileCreated, watchForWrite, file } = require('../helper')
const { pid } = process
const hostname = os.hostname()
test('thread-stream async flush', async () => {
const destination = file()
const transport = pino.transport({
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
options: { destination }
})
const instance = pino(transport)
instance.info('hello')
assert.equal(instance.flush(), undefined)
await watchFileCreated(destination)
const result = JSON.parse(await readFile(destination))
delete result.time
assert.deepEqual(result, {
pid,
hostname,
level: 30,
msg: 'hello'
})
})
test('thread-stream async flush should call the passed callback', async () => {
const outputPath = file()
async function getOutputLogLines () {
return (await readFile(outputPath)).toString().trim().split('\n').map(JSON.parse)
}
const transport = pino.transport({
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
options: { destination: outputPath }
})
const instance = pino(transport)
const flushPromise = promisify(instance.flush).bind(instance)
instance.info('hello')
await flushPromise()
await watchFileCreated(outputPath)
const [firstFlushData] = await getOutputLogLines()
assert.equal(firstFlushData.msg, 'hello')
instance.info('world')
await flushPromise()
await watchForWrite(outputPath, 'world')
// After flush, both messages should be present
const afterSecondFlush = await getOutputLogLines()
assert.equal(afterSecondFlush.length, 2)
assert.equal(afterSecondFlush[1].msg, 'world')
})

Xet Storage Details

Size:
1.91 kB
·
Xet hash:
bee8c20a3a89b39a23766d779913df343b8a2e3b83adc233308106e5770f5d11

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.