logging.test.js — fastify Source File
Architecture documentation for logging.test.js, a javascript file in the fastify codebase.
Entity Profile
Source Code
'use strict'
const stream = require('node:stream')
const t = require('node:test')
const split = require('split2')
const pino = require('pino')
const Fastify = require('../../fastify')
const helper = require('../helper')
const { once, on } = stream
const { request } = require('./logger-test-utils')
const { partialDeepStrictEqual } = require('../toolkit')
t.test('logging', { timeout: 60000 }, async (t) => {
let localhost
let localhostForURL
t.plan(14)
t.before(async function () {
[localhost, localhostForURL] = await helper.getLoopbackHost()
})
await t.test('The default 404 handler logs the incoming request', async (t) => {
const lines = ['incoming request', 'Route GET:/not-found not found', 'request completed']
t.plan(lines.length + 1)
const stream = split(JSON.parse)
const loggerInstance = pino({ level: 'trace' }, stream)
const fastify = Fastify({
loggerInstance
})
t.after(() => fastify.close())
await fastify.ready()
{
const response = await fastify.inject({ method: 'GET', url: '/not-found' })
t.assert.strictEqual(response.statusCode, 404)
}
for await (const [line] of on(stream, 'data')) {
t.assert.strictEqual(line.msg, lines.shift())
if (lines.length === 0) break
}
})
await t.test('should not rely on raw request to log errors', async (t) => {
const stream = split(JSON.parse)
const fastify = Fastify({
logger: {
stream,
level: 'info'
}
})
t.after(() => fastify.close())
fastify.get('/error', function (req, reply) {
// ... (401 more lines)
Source
Frequently Asked Questions
What does logging.test.js do?
logging.test.js is a source file in the fastify codebase, written in javascript.
Where is logging.test.js in the architecture?
logging.test.js is located at test/logger/logging.test.js (directory: test/logger).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free