Home / File/ route.5.test.js — fastify Source File

route.5.test.js — fastify Source File

Architecture documentation for route.5.test.js, a javascript file in the fastify codebase.

Entity Profile

Source Code

'use strict'

const { test } = require('node:test')
const Fastify = require('..')

test('route child logger factory does not affect other routes', async t => {
  t.plan(4)

  const fastify = Fastify()

  const customRouteChildLogger = (logger, bindings, opts, req) => {
    const child = logger.child(bindings, opts)
    child.customLog = function (message) {
      t.assert.strictEqual(message, 'custom')
    }
    return child
  }

  fastify.route({
    method: 'GET',
    path: '/coffee',
    handler: (req, res) => {
      req.log.customLog('custom')
      res.send()
    },
    childLoggerFactory: customRouteChildLogger
  })

  fastify.route({
    method: 'GET',
    path: '/tea',
    handler: (req, res) => {
      t.assert.ok(req.log.customLog instanceof Function)
      res.send()
    }
  })

  let res = await fastify.inject({
    method: 'GET',
    url: '/coffee'
  })
  t.assert.strictEqual(res.statusCode, 200)

  res = await fastify.inject({
    method: 'GET',
    url: '/tea'
  })
  t.assert.strictEqual(res.statusCode, 200)
})
test('route child logger factory overrides global custom error handler', async t => {
  t.plan(4)

  const fastify = Fastify()

  const customGlobalChildLogger = (logger, bindings, opts, req) => {
    const child = logger.child(bindings, opts)
    child.globalLog = function (message) {
      t.assert.strictEqual(message, 'global')
    }
    return child
// ... (152 more lines)

Frequently Asked Questions

What does route.5.test.js do?
route.5.test.js is a source file in the fastify codebase, written in javascript.
Where is route.5.test.js in the architecture?
route.5.test.js is located at test/route.5.test.js (directory: test).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free