Skip to content

Commit fb169eb

Browse files
authored
test: migrated reply-code.test.js from tap to node:test (fastify#5808)
1 parent 8a7f128 commit fb169eb

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

test/reply-code.test.js

+33-31
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const { test } = require('node:test')
44
const { Readable } = require('stream')
5-
const test = t.test
65
const Fastify = require('..')
76

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

1110
const fastify = Fastify()
@@ -26,9 +25,9 @@ test('code should handle null/undefined/float', t => {
2625
method: 'GET',
2726
url: '/null'
2827
}, (error, res) => {
29-
t.error(error)
30-
t.equal(res.statusCode, 500)
31-
t.same(res.json(), {
28+
t.assert.ifError(error)
29+
t.assert.strictEqual(res.statusCode, 500)
30+
t.assert.deepStrictEqual(res.json(), {
3231
statusCode: 500,
3332
code: 'FST_ERR_BAD_STATUS_CODE',
3433
error: 'Internal Server Error',
@@ -40,9 +39,9 @@ test('code should handle null/undefined/float', t => {
4039
method: 'GET',
4140
url: '/undefined'
4241
}, (error, res) => {
43-
t.error(error)
44-
t.equal(res.statusCode, 500)
45-
t.same(res.json(), {
42+
t.assert.ifError(error)
43+
t.assert.strictEqual(res.statusCode, 500)
44+
t.assert.deepStrictEqual(res.json(), {
4645
statusCode: 500,
4746
code: 'FST_ERR_BAD_STATUS_CODE',
4847
error: 'Internal Server Error',
@@ -54,12 +53,13 @@ test('code should handle null/undefined/float', t => {
5453
method: 'GET',
5554
url: '/404.5'
5655
}, (error, res) => {
57-
t.error(error)
58-
t.equal(res.statusCode, 404)
56+
t.assert.ifError(error)
57+
t.assert.strictEqual(res.statusCode, 404)
58+
done()
5959
})
6060
})
6161

62-
test('code should handle 204', t => {
62+
test('code should handle 204', (t, done) => {
6363
t.plan(13)
6464

6565
const fastify = Fastify()
@@ -80,7 +80,7 @@ test('code should handle 204', t => {
8080
}
8181
})
8282
stream.on('end', () => {
83-
t.pass('stream ended')
83+
t.assert.ok('stream ended')
8484
})
8585
reply.status(204).send(stream)
8686
})
@@ -89,34 +89,35 @@ test('code should handle 204', t => {
8989
method: 'GET',
9090
url: '/204'
9191
}, (error, res) => {
92-
t.error(error)
93-
t.equal(res.statusCode, 204)
94-
t.equal(res.payload, '')
95-
t.equal(res.headers['content-length'], undefined)
92+
t.assert.ifError(error)
93+
t.assert.strictEqual(res.statusCode, 204)
94+
t.assert.strictEqual(res.payload, '')
95+
t.assert.strictEqual(res.headers['content-length'], undefined)
9696
})
9797

9898
fastify.inject({
9999
method: 'GET',
100100
url: '/undefined/204'
101101
}, (error, res) => {
102-
t.error(error)
103-
t.equal(res.statusCode, 204)
104-
t.equal(res.payload, '')
105-
t.equal(res.headers['content-length'], undefined)
102+
t.assert.ifError(error)
103+
t.assert.strictEqual(res.statusCode, 204)
104+
t.assert.strictEqual(res.payload, '')
105+
t.assert.strictEqual(res.headers['content-length'], undefined)
106106
})
107107

108108
fastify.inject({
109109
method: 'GET',
110110
url: '/stream/204'
111111
}, (error, res) => {
112-
t.error(error)
113-
t.equal(res.statusCode, 204)
114-
t.equal(res.payload, '')
115-
t.equal(res.headers['content-length'], undefined)
112+
t.assert.ifError(error)
113+
t.assert.strictEqual(res.statusCode, 204)
114+
t.assert.strictEqual(res.payload, '')
115+
t.assert.strictEqual(res.headers['content-length'], undefined)
116+
done()
116117
})
117118
})
118119

119-
test('code should handle onSend hook on 204', t => {
120+
test('code should handle onSend hook on 204', (t, done) => {
120121
t.plan(5)
121122

122123
const fastify = Fastify()
@@ -137,10 +138,11 @@ test('code should handle onSend hook on 204', t => {
137138
method: 'GET',
138139
url: '/204'
139140
}, (error, res) => {
140-
t.error(error)
141-
t.equal(res.statusCode, 204)
142-
t.equal(res.payload, '')
143-
t.equal(res.headers['content-length'], undefined)
144-
t.equal(res.headers['content-type'], undefined)
141+
t.assert.ifError(error)
142+
t.assert.strictEqual(res.statusCode, 204)
143+
t.assert.strictEqual(res.payload, '')
144+
t.assert.strictEqual(res.headers['content-length'], undefined)
145+
t.assert.strictEqual(res.headers['content-type'], undefined)
146+
done()
145147
})
146148
})

0 commit comments

Comments
 (0)