async_hooks.test.js — fastify Source File
Architecture documentation for async_hooks.test.js, a javascript file in the fastify codebase.
Entity Profile
Source Code
'use strict'
const { createHook } = require('node:async_hooks')
const { test } = require('node:test')
const Fastify = require('..')
const remainingIds = new Set()
createHook({
init (asyncId, type, triggerAsyncId, resource) {
if (type === 'content-type-parser:run') {
remainingIds.add(asyncId)
}
},
destroy (asyncId) {
remainingIds.delete(asyncId)
}
})
const app = Fastify({ logger: false })
test('test async hooks', async (t) => {
app.get('/', function (request, reply) {
reply.send({ id: 42 })
})
app.post('/', function (request, reply) {
reply.send({ id: 42 })
})
t.after(() => app.close())
const fastifyServer = await app.listen({ port: 0 })
const result1 = await fetch(fastifyServer, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ hello: 'world' })
})
t.assert.strictEqual(result1.status, 200)
const result2 = await fetch(fastifyServer, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ hello: 'world' })
})
t.assert.strictEqual(result2.status, 200)
const result3 = await fetch(fastifyServer)
t.assert.strictEqual(result3.status, 200)
t.assert.strictEqual(remainingIds.size, 0)
})
Source
Frequently Asked Questions
What does async_hooks.test.js do?
async_hooks.test.js is a source file in the fastify codebase, written in javascript.
Where is async_hooks.test.js in the architecture?
async_hooks.test.js is located at test/async_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