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

route-shorthand.test.js — fastify Source File

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

Entity Profile

Source Code

'use strict'

const { describe, test } = require('node:test')
const { Client } = require('undici')
const Fastify = require('..')

describe('route-shorthand', () => {
  const methodsReader = new Fastify()
  const supportedMethods = methodsReader.supportedMethods

  for (const method of supportedMethods) {
    test(`route-shorthand - ${method.toLowerCase()}`, async (t) => {
      t.plan(2)
      const fastify = new Fastify()
      fastify[method.toLowerCase()]('/', (req, reply) => {
        t.assert.strictEqual(req.method, method)
        reply.send()
      })
      await fastify.listen({ port: 0 })
      t.after(() => fastify.close())

      const instance = new Client(`http://localhost:${fastify.server.address().port}`)

      const response = await instance.request({ path: '/', method })
      t.assert.strictEqual(response.statusCode, 200)
    })
  }

  test('route-shorthand - all', async (t) => {
    t.plan(2 * supportedMethods.length)
    const fastify = new Fastify()
    let currentMethod = ''
    fastify.all('/', function (req, reply) {
      t.assert.strictEqual(req.method, currentMethod)
      reply.send()
    })
    await fastify.listen({ port: 0 })
    t.after(() => fastify.close())

    for (const method of supportedMethods) {
      currentMethod = method
      const instance = new Client(`http://localhost:${fastify.server.address().port}`)

      const response = await instance.request({ path: '/', method })
      t.assert.strictEqual(response.statusCode, 200)
    }
  })
})

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free