Files
klz-cables.com/.pnpm-store/v10/files/ef/6709cfbdfc1d047ebcb8cc1167abe5502d093c75016adc2f45c464acaaa35ffe19aedffdfd10298925d1d9a597ecd022f6e9fc4151e417399209654256ec12
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

108 lines
2.9 KiB
Plaintext

'use strict'
const test = require('node:test')
const os = require('node:os')
const diagChan = require('node:diagnostics_channel')
const { AsyncLocalStorage } = require('node:async_hooks')
const { Writable } = require('node:stream')
const tspl = require('@matteo.collina/tspl')
const pino = require('../pino')
const hostname = os.hostname()
const { pid } = process
const AS_JSON_START = 'tracing:pino_asJson:start'
const AS_JSON_END = 'tracing:pino_asJson:end'
// Skip tests if diagnostics_channel.tracingChannel is not available (Node < 18.19)
const skip = typeof diagChan.tracingChannel !== 'function'
test.beforeEach(ctx => {
ctx.pino = {
ts: 1757512800000, // 2025-09-10T10:00:00.000-05:00
now: Date.now
}
Date.now = () => ctx.pino.ts
ctx.pino.dest = new Writable({
objectMode: true,
write (data, enc, cb) {
cb()
}
})
})
test.afterEach(ctx => {
Date.now = ctx.pino.now
})
test('asJson emits events', { skip }, async (t) => {
const plan = tspl(t, { plan: 8 })
const { dest } = t.pino
const logger = pino({}, dest)
const expectedArguments = [
{},
'testing',
30,
`,"time":${t.pino.ts}`
]
let startEvent
diagChan.subscribe(AS_JSON_START, startHandler)
diagChan.subscribe(AS_JSON_END, endHandler)
logger.info('testing')
await plan
diagChan.unsubscribe(AS_JSON_START, startHandler)
diagChan.unsubscribe(AS_JSON_END, endHandler)
function startHandler (event) {
startEvent = event
plan.equal(Object.prototype.toString.call(event.instance), '[object Pino]')
plan.equal(event.instance === logger, true)
plan.deepStrictEqual(Array.from(event.arguments ?? []), expectedArguments)
}
function endHandler (event) {
plan.equal(Object.prototype.toString.call(event.instance), '[object Pino]')
plan.equal(event.instance === logger, true)
plan.deepStrictEqual(Array.from(event.arguments ?? []), expectedArguments)
plan.equal(
event.result,
`{"level":30,"time":${t.pino.ts},"pid":${pid},"hostname":"${hostname}","msg":"testing"}\n`
)
plan.equal(event.arguments === startEvent.arguments, true, 'same event object is supplied to both events')
}
})
test('asJson context is not lost', { skip }, async (t) => {
const plan = tspl(t, { plan: 2 })
const { dest } = t.pino
const logger = pino({}, dest)
const asyncLocalStorage = new AsyncLocalStorage()
const localStore = { foo: 'bar' }
diagChan.subscribe(AS_JSON_START, startHandler)
diagChan.subscribe(AS_JSON_END, endHandler)
asyncLocalStorage.run(localStore, () => {
logger.info('testing')
})
await plan
diagChan.unsubscribe(AS_JSON_START, startHandler)
diagChan.unsubscribe(AS_JSON_END, endHandler)
function startHandler () {
const store = asyncLocalStorage.getStore()
plan.equal(store === localStore, true)
}
function endHandler () {
const store = asyncLocalStorage.getStore()
plan.equal(store === localStore, true)
}
})