reply-error.test.js — fastify Source File
Architecture documentation for reply-error.test.js, a javascript file in the fastify codebase.
Entity Profile
Relationship Graph
Source Code
'use strict'
const { test, describe } = require('node:test')
const net = require('node:net')
const Fastify = require('..')
const statusCodes = require('node:http').STATUS_CODES
const split = require('split2')
const fs = require('node:fs')
const path = require('node:path')
const codes = Object.keys(statusCodes)
codes.forEach(code => {
if (Number(code) >= 400) helper(code)
})
function helper (code) {
test('Reply error handling - code: ' + code, (t, testDone) => {
t.plan(4)
const fastify = Fastify()
t.after(() => fastify.close())
const err = new Error('winter is coming')
fastify.get('/', (req, reply) => {
reply
.code(Number(code))
.send(err)
})
fastify.inject({
method: 'GET',
url: '/'
}, (error, res) => {
t.assert.ifError(error)
t.assert.strictEqual(res.statusCode, Number(code))
t.assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8')
t.assert.deepStrictEqual(
{
error: statusCodes[code],
message: err.message,
statusCode: Number(code)
},
JSON.parse(res.payload)
)
testDone()
})
})
}
test('preHandler hook error handling with external code', (t, testDone) => {
t.plan(3)
const fastify = Fastify()
t.after(() => fastify.close())
const err = new Error('winter is coming')
fastify.addHook('preHandler', (req, reply, done) => {
reply.code(400)
done(err)
})
fastify.get('/', () => {})
// ... (756 more lines)
Domain
Subdomains
Functions
Source
Frequently Asked Questions
What does reply-error.test.js do?
reply-error.test.js is a source file in the fastify codebase, written in javascript. It belongs to the CoreKernel domain, LifecycleManager subdomain.
What functions are defined in reply-error.test.js?
reply-error.test.js defines 1 function(s): helper.
Where is reply-error.test.js in the architecture?
reply-error.test.js is located at test/reply-error.test.js (domain: CoreKernel, subdomain: LifecycleManager, directory: test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free