Skip to content

Commit 1830406

Browse files
feat: introduce waitFor
1 parent 464e7ae commit 1830406

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pino-test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const nodeAssert = require('assert')
44
const os = require('os')
55
const split = require('split2')
66

7+
const DEFAULT_WAIT_FOR_TIMEOUT = 1000
8+
79
/**
810
* Create a Pino destination stream to easily inspect the logs processed by Pino.
911
*
@@ -129,4 +131,31 @@ async function consecutive (stream, expectedOrCallbacks, assert = nodeAssert.dee
129131
}
130132
}
131133

134+
/**
135+
* Assert a specific log is expected, ignoring the rest.
136+
*
137+
* @param {import('node:stream').Transform} stream The stream to be tested.
138+
* @param {Array<object | Function>} expectedsOrCallbacks The array of expected values to be tested or callback functions.
139+
* @param {Function} [assert=nodeAssert.deepStrictEqual] The assert function to be used when the expectedOrCallback parameter is an object.
140+
* @param {Number} [timeout=1000] The time in milliseconds to wait for the expected value.
141+
*
142+
* @returns A promise that resolves when the expected value is equal to the stream value.
143+
* @throws If the expected value is not equal to the stream value.
144+
* @throws If the callback function throws an error.
145+
* @throws If timeout is reached.
146+
*
147+
* @example
148+
* const stream = pinoTest.sink()
149+
* const logger = pino(stream)
150+
*
151+
* logger.debug('setting up server')
152+
* logger.info('server started')
153+
* logger.error('server crashed')
154+
*
155+
* await pinoTest.waitFor(stream, { msg: 'server started', level: 30 })
156+
*/
157+
async function waitFor (stream, expectedOrCallbacks, assert = nodeAssert.deepStrictEqual, timeout = DEFAULT_WAIT_FOR_TIMEOUT) {
158+
// TODO implementation
159+
}
160+
132161
module.exports = { sink, once, consecutive }

0 commit comments

Comments
 (0)