Skip to content

Commit 2919d57

Browse files
authored
test: remove tap (#418)
* feat: base assertion migration * chore: other assertions and imports * chore: fix promises * fix: test await and assertions * fix: disable request logging permissions * feat: configure c8 * fix: multipart assertions * fix: assertions * fix: assertions and plans * fix: close callback * fix: http2 https assertions * fix: parsedLength assertion * fix: onError assertions * fix: header assertions * fix: unix related tests * fix: strictEqual --------- Signed-off-by: Matteo Pietro Dazzi <[email protected]>
1 parent 3d24fec commit 2919d57

File tree

92 files changed

+889
-907
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+889
-907
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "eslint",
1010
"lint:fix": "eslint --fix",
1111
"test": "npm run test:unit && npm run test:typescript",
12-
"test:unit": "tap",
12+
"test:unit": "c8 node --test",
1313
"test:typescript": "tsd"
1414
},
1515
"repository": {
@@ -64,6 +64,7 @@
6464
"@sinonjs/fake-timers": "^14.0.0",
6565
"@types/node": "^22.0.0",
6666
"@types/tap": "^18.0.0",
67+
"c8": "^10.1.3",
6768
"eslint": "^9.17.0",
6869
"fastify": "^5.0.0",
6970
"form-data": "^4.0.0",
@@ -73,7 +74,6 @@
7374
"proxy": "^2.1.1",
7475
"proxyquire": "^2.1.3",
7576
"split2": "^4.2.0",
76-
"tap": "^18.7.2",
7777
"tsd": "^0.32.0"
7878
},
7979
"dependencies": {

test/async-route-handler.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const t = require('node:test')
44
const Fastify = require('fastify')
55
const From = require('..')
66
const http = require('node:http')
@@ -10,12 +10,12 @@ const instance = Fastify()
1010

1111
t.test('async route handler', async (t) => {
1212
t.plan(8)
13-
t.teardown(instance.close.bind(instance))
13+
t.after(() => instance.close())
1414

1515
const target = http.createServer((req, res) => {
16-
t.pass('request proxied')
17-
t.equal(req.method, 'GET')
18-
t.equal(req.url, '/')
16+
t.assert.ok('request proxied')
17+
t.assert.strictEqual(req.method, 'GET')
18+
t.assert.strictEqual(req.url, '/')
1919
res.statusCode = 205
2020
res.setHeader('Content-Type', 'text/plain')
2121
res.setHeader('x-my-header', 'hello!')
@@ -24,11 +24,11 @@ t.test('async route handler', async (t) => {
2424

2525
instance.get('/', async (_request, reply) => {
2626
const p = reply.from()
27-
t.equal(p, reply)
27+
t.assert.strictEqual(p, reply)
2828
return p
2929
})
3030

31-
t.teardown(target.close.bind(target))
31+
t.after(() => target.close())
3232

3333
await new Promise(resolve => target.listen({ port: 0 }, resolve))
3434

@@ -40,8 +40,8 @@ t.test('async route handler', async (t) => {
4040

4141
const result = await request(`http://localhost:${instance.server.address().port}`)
4242

43-
t.equal(result.headers['content-type'], 'text/plain')
44-
t.equal(result.headers['x-my-header'], 'hello!')
45-
t.equal(result.statusCode, 205)
46-
t.equal(await result.body.text(), 'hello world')
43+
t.assert.strictEqual(result.headers['content-type'], 'text/plain')
44+
t.assert.strictEqual(result.headers['x-my-header'], 'hello!')
45+
t.assert.strictEqual(result.statusCode, 205)
46+
t.assert.strictEqual(await result.body.text(), 'hello world')
4747
})

test/base-get.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const t = require('node:test')
44
const Fastify = require('fastify')
55
const { request } = require('undici')
66
const From = require('..')
@@ -10,12 +10,12 @@ const instance = Fastify()
1010

1111
t.test('base get', async (t) => {
1212
t.plan(7)
13-
t.teardown(instance.close.bind(instance))
13+
t.after(() => instance.close())
1414

1515
const target = http.createServer((req, res) => {
16-
t.pass('request proxied')
17-
t.equal(req.method, 'GET')
18-
t.equal(req.url, '/')
16+
t.assert.ok('request proxied')
17+
t.assert.strictEqual(req.method, 'GET')
18+
t.assert.strictEqual(req.url, '/')
1919
res.statusCode = 205
2020
res.setHeader('Content-Type', 'text/plain')
2121
res.setHeader('x-my-header', 'hello!')
@@ -26,7 +26,7 @@ t.test('base get', async (t) => {
2626
reply.from()
2727
})
2828

29-
t.teardown(target.close.bind(target))
29+
t.after(() => target.close())
3030

3131
await new Promise((resolve) => target.listen({ port: 0 }, resolve))
3232

@@ -38,8 +38,8 @@ t.test('base get', async (t) => {
3838

3939
const result = await request(`http://localhost:${instance.server.address().port}`)
4040

41-
t.equal(result.headers['content-type'], 'text/plain')
42-
t.equal(result.headers['x-my-header'], 'hello!')
43-
t.equal(result.statusCode, 205)
44-
t.equal(await result.body.text(), 'hello world')
41+
t.assert.strictEqual(result.headers['content-type'], 'text/plain')
42+
t.assert.strictEqual(result.headers['x-my-header'], 'hello!')
43+
t.assert.strictEqual(result.statusCode, 205)
44+
t.assert.strictEqual(await result.body.text(), 'hello world')
4545
})

test/base-path.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const t = require('node:test')
44
const Fastify = require('fastify')
55
const { request, Agent } = require('undici')
66
const From = require('..')
@@ -12,12 +12,12 @@ t.test('base path', async (t) => {
1212
nock('http://httpbin.org')
1313
.get('/ip')
1414
.reply(200, function () {
15-
t.equal(this.req.headers.host, 'httpbin.org')
15+
t.assert.strictEqual(this.req.headers.host, 'httpbin.org')
1616
return { origin: '127.0.0.1' }
1717
})
1818

1919
t.plan(4)
20-
t.teardown(instance.close.bind(instance))
20+
t.after(() => instance.close())
2121

2222
instance.get('/', (_request, reply) => {
2323
reply.from('http://httpbin.org/ip')
@@ -35,7 +35,7 @@ t.test('base path', async (t) => {
3535
})
3636
})
3737

38-
t.equal(result.statusCode, 200)
39-
t.equal(result.headers['content-type'], 'application/json')
40-
t.equal(typeof (await result.body.json()).origin, 'string')
38+
t.assert.strictEqual(result.statusCode, 200)
39+
t.assert.strictEqual(result.headers['content-type'], 'application/json')
40+
t.assert.strictEqual(typeof (await result.body.json()).origin, 'string')
4141
})

test/base-querystring.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const t = require('node:test')
44
const Fastify = require('fastify')
55
const { request } = require('undici')
66
const From = require('..')
@@ -10,12 +10,12 @@ const instance = Fastify()
1010

1111
t.test('base querystring', async (t) => {
1212
t.plan(7)
13-
t.teardown(instance.close.bind(instance))
13+
t.after(() => instance.close())
1414

1515
const target = http.createServer((req, res) => {
16-
t.pass('request proxied')
17-
t.equal(req.method, 'GET')
18-
t.equal(req.url, '/hello?a=b')
16+
t.assert.ok('request proxied')
17+
t.assert.strictEqual(req.method, 'GET')
18+
t.assert.strictEqual(req.url, '/hello?a=b')
1919
res.statusCode = 205
2020
res.setHeader('Content-Type', 'text/plain')
2121
res.setHeader('x-my-header', 'hello!')
@@ -26,7 +26,7 @@ t.test('base querystring', async (t) => {
2626
reply.from()
2727
})
2828

29-
t.teardown(target.close.bind(target))
29+
t.after(() => target.close())
3030

3131
await new Promise(resolve => target.listen({ port: 0 }, resolve))
3232

@@ -38,8 +38,8 @@ t.test('base querystring', async (t) => {
3838

3939
const result = await request(`http://localhost:${instance.server.address().port}/hello?a=b`)
4040

41-
t.equal(result.headers['content-type'], 'text/plain')
42-
t.equal(result.headers['x-my-header'], 'hello!')
43-
t.equal(result.statusCode, 205)
44-
t.equal(await result.body.text(), 'hello world')
41+
t.assert.strictEqual(result.headers['content-type'], 'text/plain')
42+
t.assert.strictEqual(result.headers['x-my-header'], 'hello!')
43+
t.assert.strictEqual(result.statusCode, 205)
44+
t.assert.strictEqual(await result.body.text(), 'hello world')
4545
})

test/build-url.test.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44
const { buildURL } = require('../lib/utils')
55

66
test('should produce valid URL', (t) => {
77
t.plan(1)
88
const url = buildURL('/hi', 'http://localhost')
9-
t.equal(url.href, 'http://localhost/hi')
9+
t.assert.strictEqual(url.href, 'http://localhost/hi')
1010
})
1111

1212
test('should produce valid URL', (t) => {
1313
t.plan(1)
1414
const url = buildURL('http://localhost/hi', 'http://localhost')
15-
t.equal(url.href, 'http://localhost/hi')
15+
t.assert.strictEqual(url.href, 'http://localhost/hi')
1616
})
1717

1818
test('should return same source when base is not specified', (t) => {
1919
t.plan(1)
2020
const url = buildURL('http://localhost/hi')
21-
t.equal(url.href, 'http://localhost/hi')
21+
t.assert.strictEqual(url.href, 'http://localhost/hi')
2222
})
2323

2424
test('should handle lack of trailing slash in base', (t) => {
2525
t.plan(3)
2626
let url = buildURL('hi', 'http://localhost/hi')
27-
t.equal(url.href, 'http://localhost/hi')
27+
t.assert.strictEqual(url.href, 'http://localhost/hi')
2828

2929
url = buildURL('hi/', 'http://localhost/hi')
30-
t.equal(url.href, 'http://localhost/hi/')
30+
t.assert.strictEqual(url.href, 'http://localhost/hi/')
3131

3232
url = buildURL('hi/more', 'http://localhost/hi')
33-
t.equal(url.href, 'http://localhost/hi/more')
33+
t.assert.strictEqual(url.href, 'http://localhost/hi/more')
3434
})
3535

3636
test('should handle default port in base', (t) => {
3737
t.plan(2)
3838
let url = buildURL('/hi', 'http://localhost:80/hi')
39-
t.equal(url.href, 'http://localhost/hi')
39+
t.assert.strictEqual(url.href, 'http://localhost/hi')
4040

4141
url = buildURL('/hi', 'https://localhost:443/hi')
42-
t.equal(url.href, 'https://localhost/hi')
42+
t.assert.strictEqual(url.href, 'https://localhost/hi')
4343
})
4444

4545
test('should append instead of override base', (t) => {
4646
t.plan(2)
4747
let url = buildURL('//10.0.0.10/hi', 'http://localhost')
48-
t.equal(url.href, 'http://localhost//10.0.0.10/hi')
48+
t.assert.strictEqual(url.href, 'http://localhost//10.0.0.10/hi')
4949

5050
url = buildURL('//httpbin.org/hi', 'http://localhost')
51-
t.equal(url.href, 'http://localhost//httpbin.org/hi')
51+
t.assert.strictEqual(url.href, 'http://localhost//httpbin.org/hi')
5252
})
5353

5454
const errorInputs = [
@@ -64,13 +64,15 @@ const errorInputs = [
6464
{ source: 'exposed-extra', base: 'http://localhost/exposed' }
6565
]
6666

67-
test('should throw when trying to override base', (t) => {
67+
test('should throw when trying to override base', async (t) => {
6868
t.plan(errorInputs.length)
6969

70-
errorInputs.forEach(({ source, base }) => {
71-
t.test(source, (t) => {
70+
const promises = errorInputs.map(({ source, base }) => {
71+
return t.test(source, (t) => {
7272
t.plan(1)
73-
t.throws(() => buildURL(source, base))
73+
t.assert.throws(() => buildURL(source, base))
7474
})
7575
})
76+
77+
await Promise.all(promises)
7678
})

test/core-with-path-in-base.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const t = require('tap')
3+
const t = require('node:test')
44
const Fastify = require('fastify')
55
const { request, Agent } = require('undici')
66
const From = require('..')
@@ -10,13 +10,13 @@ const instance = Fastify()
1010

1111
t.test('core with path in base', async (t) => {
1212
t.plan(8)
13-
t.teardown(instance.close.bind(instance))
13+
t.after(() => instance.close())
1414

1515
const target = http.createServer((req, res) => {
16-
t.pass('request proxied')
17-
t.equal(req.method, 'GET')
18-
t.equal(req.url, '/hello')
19-
t.equal(req.headers.connection, 'close')
16+
t.assert.ok('request proxied')
17+
t.assert.strictEqual(req.method, 'GET')
18+
t.assert.strictEqual(req.url, '/hello')
19+
t.assert.strictEqual(req.headers.connection, 'close')
2020
res.statusCode = 205
2121
res.setHeader('Content-Type', 'text/plain')
2222
res.setHeader('x-my-header', 'hello!')
@@ -27,7 +27,7 @@ t.test('core with path in base', async (t) => {
2727
reply.from('/hello')
2828
})
2929

30-
t.teardown(target.close.bind(target))
30+
t.after(() => target.close())
3131

3232
await new Promise(resolve => target.listen({ port: 0 }, resolve))
3333

@@ -43,8 +43,8 @@ t.test('core with path in base', async (t) => {
4343
pipelining: 0
4444
})
4545
})
46-
t.equal(result.headers['content-type'], 'text/plain')
47-
t.equal(result.headers['x-my-header'], 'hello!')
48-
t.equal(result.statusCode, 205)
49-
t.equal(await result.body.text(), 'hello world')
46+
t.assert.strictEqual(result.headers['content-type'], 'text/plain')
47+
t.assert.strictEqual(result.headers['x-my-header'], 'hello!')
48+
t.assert.strictEqual(result.statusCode, 205)
49+
t.assert.strictEqual(await result.body.text(), 'hello world')
5050
})

0 commit comments

Comments
 (0)