Skip to content

Commit

Permalink
test: migrated post-empty-body.test.js from tap to node:test (fastify…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony133 authored Nov 6, 2024
1 parent 4eb2688 commit f89fd9e
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions test/post-empty-body.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { test } = require('tap')
const fastify = require('../')
const { test } = require('node:test')
const Fastify = require('..')
const { request, setGlobalDispatcher, Agent } = require('undici')

setGlobalDispatcher(new Agent({
Expand All @@ -10,22 +10,27 @@ setGlobalDispatcher(new Agent({
}))

test('post empty body', async t => {
const app = fastify()
t.teardown(app.close.bind(app))

app.post('/bug', async (request, reply) => {
const fastify = Fastify()
const abortController = new AbortController()
const { signal } = abortController
t.after(() => {
fastify.close()
abortController.abort()
})

await app.listen({ port: 0 })
fastify.post('/bug', async (request, reply) => {})

await fastify.listen({ port: 0 })

const res = await request(`http://127.0.0.1:${app.server.address().port}/bug`, {
const res = await request(`http://127.0.0.1:${fastify.server.address().port}/bug`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ foo: 'bar' })
body: JSON.stringify({ foo: 'bar' }),
signal
})

t.equal(res.statusCode, 200)
t.equal(await res.body.text(), '')
t.assert.strictEqual(res.statusCode, 200)
t.assert.strictEqual(await res.body.text(), '')
})

0 comments on commit f89fd9e

Please sign in to comment.