{"library":"pino-test","title":"Pino Test Utilities","description":"pino-test is a utility library designed to simplify the process of testing applications that use the Pino logger. It provides a `sink()` method to create a transform stream that captures Pino's JSON log output, allowing for easy inspection and assertion within test suites. The library also offers `once()` and `consecutive()` helpers to assert single or multiple log entries against expected values, optionally with custom assertion functions. The current stable version is 2.0.0, which includes code modernization and drops support for older Node.js versions. While its release cadence isn't strictly fixed, major versions appear to be released as significant updates or breaking changes warrant, with v2.0.0 following v1.0.0 after some time. It differentiates itself by tightly integrating with Pino's stream-based logging for efficient and precise log verification without complex mock setups.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pino-test"],"cli":null},"imports":["const pinoTest = require('pino-test');","import { sink } from 'pino-test';","import { once } from 'pino-test';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import test from 'node:test';\nimport pino from 'pino';\nimport { sink, once } from 'pino-test';\n\ntest('pino should log an info message', async () => {\n  const pinoSink = sink();\n  const logger = pino(pinoSink);\n\n  logger.info('hello world');\n\n  const expected = { msg: 'hello world', level: 30 };\n  await once(pinoSink, expected);\n});\n\n// Example with a custom assertion function\nfunction customAssert (received, expected, msg) {\n  if (received.msg !== expected.msg) {\n    throw new Error(`Expected msg '${expected.msg}' but received '${received.msg}'`);\n  }\n}\n\ntest('pino should log an info message using a custom assert function', async () => {\n  const pinoSink = sink();\n  const logger = pino(pinoSink);\n\n  logger.info('hello world from custom');\n\n  const expected = { msg: 'hello world from custom', level: 30 };\n  await once(pinoSink, expected, customAssert);\n});","lang":"typescript","description":"Demonstrates how to create a `pino-test` sink, configure a Pino logger to use it, and assert single log messages using `pinoTest.once`, including an example with a custom assertion function.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}