Home / File/ 404s.test.js — fastify Source File

404s.test.js — fastify Source File

Architecture documentation for 404s.test.js, a javascript file in the fastify codebase.

Entity Profile

Source Code

'use strict'

const { test } = require('node:test')
const fp = require('fastify-plugin')
const errors = require('http-errors')
const split = require('split2')
const Fastify = require('..')
const { getServerUrl } = require('./helper')

test('default 404', async t => {
  t.plan(4)

  const fastify = Fastify()

  fastify.get('/', function (req, reply) {
    reply.send({ hello: 'world' })
  })

  t.after(() => { fastify.close() })

  await fastify.listen({ port: 0 })

  await t.test('unsupported method', async (t) => {
    t.plan(3)
    const result = await fetch(getServerUrl(fastify), {
      method: 'PUT'
    })

    t.assert.ok(!result.ok)
    t.assert.strictEqual(result.status, 404)
    t.assert.strictEqual(result.headers.get('content-type'), 'application/json; charset=utf-8')
  })

  // Return 404 instead of 405 see https://github.com/fastify/fastify/pull/862 for discussion
  await t.test('framework-unsupported method', async (t) => {
    t.plan(3)
    const result = await fetch(getServerUrl(fastify), {
      method: 'PROPFIND'
    })

    t.assert.ok(!result.ok)
    t.assert.strictEqual(result.status, 404)
    t.assert.strictEqual(result.headers.get('content-type'), 'application/json; charset=utf-8')
  })

  await t.test('unsupported route', async (t) => {
    t.plan(3)
    const response = await fetch(getServerUrl(fastify) + '/notSupported')

    t.assert.ok(!response.ok)
    t.assert.strictEqual(response.status, 404)
    t.assert.strictEqual(response.headers.get('content-type'), 'application/json; charset=utf-8')
  })

  await t.test('using post method and multipart/formdata', async t => {
    t.plan(3)
    const form = new FormData()
    form.set('test-field', 'just some field')

    const response = await fetch(getServerUrl(fastify) + '/notSupported', {
// ... (1976 more lines)

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free