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

route.8.test.js — fastify Source File

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

Entity Profile

Source Code

'use strict'

const { test } = require('node:test')
const Fastify = require('..')
const {
  FST_ERR_INVALID_URL
} = require('../lib/errors')

test('Request and Reply share the route options', async t => {
  t.plan(3)

  const fastify = Fastify()

  const config = {
    this: 'is a string',
    thisIs: function aFunction () {}
  }

  fastify.route({
    method: 'GET',
    url: '/',
    config,
    handler: (req, reply) => {
      t.assert.deepStrictEqual(req.routeOptions, reply.routeOptions)
      t.assert.deepStrictEqual(req.routeOptions.config, reply.routeOptions.config)
      t.assert.match(req.routeOptions.config, config, 'there are url and method additional properties')

      reply.send({ hello: 'world' })
    }
  })

  await fastify.inject('/')
})

test('Will not try to re-createprefixed HEAD route if it already exists and exposeHeadRoutes is true', async (t) => {
  t.plan(1)

  const fastify = Fastify({ exposeHeadRoutes: true })

  fastify.register((scope, opts, next) => {
    scope.route({
      method: 'HEAD',
      path: '/route',
      handler: (req, reply) => {
        reply.header('content-type', 'text/plain')
        reply.send('custom HEAD response')
      }
    })
    scope.route({
      method: 'GET',
      path: '/route',
      handler: (req, reply) => {
        reply.send({ ok: true })
      }
    })

    next()
  }, { prefix: '/prefix' })

  await fastify.ready()
// ... (166 more lines)

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free