hooks.test.js — fastify Source File
Architecture documentation for hooks.test.js, a javascript file in the fastify codebase.
Entity Profile
Source Code
'use strict'
const { test } = require('node:test')
const stream = require('node:stream')
const Fastify = require('..')
const fp = require('fastify-plugin')
const fs = require('node:fs')
const split = require('split2')
const symbols = require('../lib/symbols.js')
const payload = { hello: 'world' }
const proxyquire = require('proxyquire')
const { connect } = require('node:net')
const { sleep } = require('./helper')
const { waitForCb } = require('./toolkit.js')
process.removeAllListeners('warning')
test('hooks', async t => {
t.plan(48)
const fastify = Fastify({ exposeHeadRoutes: false })
try {
fastify.addHook('preHandler', function (request, reply, done) {
t.assert.strictEqual(request.test, 'the request is coming')
t.assert.strictEqual(reply.test, 'the reply has come')
if (request.raw.method === 'HEAD') {
done(new Error('some error'))
} else {
done()
}
})
t.assert.ok('should pass')
} catch (e) {
t.assert.fail()
}
try {
fastify.addHook('preHandler', null)
} catch (e) {
t.assert.strictEqual(e.code, 'FST_ERR_HOOK_INVALID_HANDLER')
t.assert.strictEqual(e.message, 'preHandler hook should be a function, instead got null')
t.assert.ok('should pass')
}
try {
fastify.addHook('preParsing')
} catch (e) {
t.assert.strictEqual(e.code, 'FST_ERR_HOOK_INVALID_HANDLER')
t.assert.strictEqual(e.message, 'preParsing hook should be a function, instead got undefined')
t.assert.ok('should pass')
}
try {
fastify.addHook('preParsing', function (request, reply, payload, done) {
request.preParsing = true
t.assert.strictEqual(request.test, 'the request is coming')
t.assert.strictEqual(reply.test, 'the reply has come')
done()
})
t.assert.ok('should pass')
// ... (3519 more lines)
Source
Frequently Asked Questions
What does hooks.test.js do?
hooks.test.js is a source file in the fastify codebase, written in javascript.
Where is hooks.test.js in the architecture?
hooks.test.js is located at test/hooks.test.js (directory: test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free