CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
post-empty-body.test.js39 linesDownload Raw Back to test
1'use strict'2 3const { test } = require('node:test')4const Fastify = require('..')5const { request, setGlobalDispatcher, Agent } = require('undici')6 7setGlobalDispatcher(new Agent({8  keepAliveTimeout: 10,9  keepAliveMaxTimeout: 1010}))11 12test('post empty body', { timeout: 3_000 }, async t => {13  const fastify = Fastify({ forceCloseConnections: true })14  const abortController = new AbortController()15  const { signal } = abortController16  t.after(() => {17    fastify.close()18    abortController.abort()19  })20 21  fastify.post('/bug', async () => {22    // This function must be async and return nothing23  })24 25  await fastify.listen({ port: 0 })26 27  const res = await request(`http://localhost:${fastify.server.address().port}/bug`, {28    method: 'POST',29    headers: {30      'Content-Type': 'application/json'31    },32    body: JSON.stringify({ foo: 'bar' }),33    signal34  })35 36  t.assert.strictEqual(res.statusCode, 200)37  t.assert.strictEqual(await res.body.text(), '')38})39