Skip to content

Commit

Permalink
test: migrated reply-code.test.js from tap to node:test (fastify#5808)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony133 authored Nov 1, 2024
1 parent 8a7f128 commit fb169eb
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions test/reply-code.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict'

const t = require('tap')
const { test } = require('node:test')
const { Readable } = require('stream')
const test = t.test
const Fastify = require('..')

test('code should handle null/undefined/float', t => {
test('code should handle null/undefined/float', (t, done) => {
t.plan(8)

const fastify = Fastify()
Expand All @@ -26,9 +25,9 @@ test('code should handle null/undefined/float', t => {
method: 'GET',
url: '/null'
}, (error, res) => {
t.error(error)
t.equal(res.statusCode, 500)
t.same(res.json(), {
t.assert.ifError(error)
t.assert.strictEqual(res.statusCode, 500)
t.assert.deepStrictEqual(res.json(), {
statusCode: 500,
code: 'FST_ERR_BAD_STATUS_CODE',
error: 'Internal Server Error',
Expand All @@ -40,9 +39,9 @@ test('code should handle null/undefined/float', t => {
method: 'GET',
url: '/undefined'
}, (error, res) => {
t.error(error)
t.equal(res.statusCode, 500)
t.same(res.json(), {
t.assert.ifError(error)
t.assert.strictEqual(res.statusCode, 500)
t.assert.deepStrictEqual(res.json(), {
statusCode: 500,
code: 'FST_ERR_BAD_STATUS_CODE',
error: 'Internal Server Error',
Expand All @@ -54,12 +53,13 @@ test('code should handle null/undefined/float', t => {
method: 'GET',
url: '/404.5'
}, (error, res) => {
t.error(error)
t.equal(res.statusCode, 404)
t.assert.ifError(error)
t.assert.strictEqual(res.statusCode, 404)
done()
})
})

test('code should handle 204', t => {
test('code should handle 204', (t, done) => {
t.plan(13)

const fastify = Fastify()
Expand All @@ -80,7 +80,7 @@ test('code should handle 204', t => {
}
})
stream.on('end', () => {
t.pass('stream ended')
t.assert.ok('stream ended')
})
reply.status(204).send(stream)
})
Expand All @@ -89,34 +89,35 @@ test('code should handle 204', t => {
method: 'GET',
url: '/204'
}, (error, res) => {
t.error(error)
t.equal(res.statusCode, 204)
t.equal(res.payload, '')
t.equal(res.headers['content-length'], undefined)
t.assert.ifError(error)
t.assert.strictEqual(res.statusCode, 204)
t.assert.strictEqual(res.payload, '')
t.assert.strictEqual(res.headers['content-length'], undefined)
})

fastify.inject({
method: 'GET',
url: '/undefined/204'
}, (error, res) => {
t.error(error)
t.equal(res.statusCode, 204)
t.equal(res.payload, '')
t.equal(res.headers['content-length'], undefined)
t.assert.ifError(error)
t.assert.strictEqual(res.statusCode, 204)
t.assert.strictEqual(res.payload, '')
t.assert.strictEqual(res.headers['content-length'], undefined)
})

fastify.inject({
method: 'GET',
url: '/stream/204'
}, (error, res) => {
t.error(error)
t.equal(res.statusCode, 204)
t.equal(res.payload, '')
t.equal(res.headers['content-length'], undefined)
t.assert.ifError(error)
t.assert.strictEqual(res.statusCode, 204)
t.assert.strictEqual(res.payload, '')
t.assert.strictEqual(res.headers['content-length'], undefined)
done()
})
})

test('code should handle onSend hook on 204', t => {
test('code should handle onSend hook on 204', (t, done) => {
t.plan(5)

const fastify = Fastify()
Expand All @@ -137,10 +138,11 @@ test('code should handle onSend hook on 204', t => {
method: 'GET',
url: '/204'
}, (error, res) => {
t.error(error)
t.equal(res.statusCode, 204)
t.equal(res.payload, '')
t.equal(res.headers['content-length'], undefined)
t.equal(res.headers['content-type'], undefined)
t.assert.ifError(error)
t.assert.strictEqual(res.statusCode, 204)
t.assert.strictEqual(res.payload, '')
t.assert.strictEqual(res.headers['content-length'], undefined)
t.assert.strictEqual(res.headers['content-type'], undefined)
done()
})
})

0 comments on commit fb169eb

Please sign in to comment.