Home / File/ route-prefix.test.js — fastify Source File

route-prefix.test.js — fastify Source File

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

Entity Profile

Source Code

'use strict'

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

test('Prefix options should add a prefix for all the routes inside a register / 1', (t, testDone) => {
  t.plan(6)
  const fastify = Fastify()

  fastify.get('/first', (req, reply) => {
    reply.send({ route: '/first' })
  })

  fastify.register(function (fastify, opts, done) {
    fastify.get('/first', (req, reply) => {
      reply.send({ route: '/v1/first' })
    })

    fastify.register(function (fastify, opts, done) {
      fastify.get('/first', (req, reply) => {
        reply.send({ route: '/v1/v2/first' })
      })
      done()
    }, { prefix: '/v2' })

    done()
  }, { prefix: '/v1' })

  const completion = waitForCb({ steps: 3 })
  fastify.inject({
    method: 'GET',
    url: '/first'
  }, (err, res) => {
    t.assert.ifError(err)
    t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/first' })
    completion.stepIn()
  })

  fastify.inject({
    method: 'GET',
    url: '/v1/first'
  }, (err, res) => {
    t.assert.ifError(err)
    t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/first' })
    completion.stepIn()
  })

  fastify.inject({
    method: 'GET',
    url: '/v1/v2/first'
  }, (err, res) => {
    t.assert.ifError(err)
    t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/v2/first' })
    completion.stepIn()
  })
  completion.patience.then(testDone)
})

test('Prefix options should add a prefix for all the routes inside a register / 2', (t, testDone) => {
// ... (845 more lines)

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free