Skip to content

Commit ae95871

Browse files
authoredFeb 12, 2024
chore: migrate a batch of tests to node test runner (#2742)
1 parent 8218436 commit ae95871

11 files changed

+446
-347
lines changed
 

‎test/client-errors.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { test, after } = require('node:test')
45
const { Client } = require('..')
56
const net = require('node:net')
67

78
// TODO: move to test/node-test/client-connect.js
8-
test('parser error', (t) => {
9-
t.plan(2)
9+
test('parser error', async (t) => {
10+
t = tspl(t, { plan: 2 })
1011

1112
const server = net.createServer()
1213
server.once('connection', (socket) => {
1314
socket.write('asd\n\r213123')
1415
})
15-
t.teardown(server.close.bind(server))
16+
after(() => server.close())
1617

1718
server.listen(0, () => {
1819
const client = new Client(`http://localhost:${server.address().port}`)
19-
t.teardown(client.destroy.bind(client))
20+
after(() => client.destroy())
2021

2122
client.request({ path: '/', method: 'GET' }, (err) => {
2223
t.ok(err)
2324
client.close((err) => {
24-
t.error(err)
25+
t.ifError(err)
2526
})
2627
})
2728
})
29+
30+
await t.completed
2831
})

‎test/client-stream.js

+242-193
Large diffs are not rendered by default.

‎test/connect-abort.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { test } = require('node:test')
45
const { Client } = require('..')
56
const { PassThrough } = require('node:stream')
67

7-
test(t => {
8-
t.plan(2)
8+
test('connect-abort', async t => {
9+
t = tspl(t, { plan: 2 })
910

1011
const client = new Client('http://localhost:1234', {
1112
connect: (_, cb) => {
1213
client.destroy()
1314
cb(null, new PassThrough({
1415
destroy (err, cb) {
15-
t.same(err?.name, 'ClientDestroyedError')
16+
t.strictEqual(err.name, 'ClientDestroyedError')
1617
cb(null)
1718
}
1819
}))
@@ -23,6 +24,8 @@ test(t => {
2324
path: '/',
2425
method: 'GET'
2526
}, (err, data) => {
26-
t.same(err?.name, 'ClientDestroyedError')
27+
t.strictEqual(err.name, 'ClientDestroyedError')
2728
})
29+
30+
await t.completed
2831
})

‎test/http-req-destroy.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { test, after } = require('node:test')
45
const undici = require('..')
56
const { createServer } = require('node:http')
67
const { Readable } = require('node:stream')
78
const { maybeWrapStream, consts } = require('./utils/async-iterators')
89

910
function doNotKillReqSocket (bodyType) {
10-
test(`do not kill req socket ${bodyType}`, (t) => {
11-
t.plan(3)
11+
test(`do not kill req socket ${bodyType}`, async (t) => {
12+
t = tspl(t, { plan: 3 })
1213

1314
const server1 = createServer((req, res) => {
1415
const client = new undici.Client(`http://localhost:${server2.address().port}`)
15-
t.teardown(client.close.bind(client))
16+
after(() => client.close())
1617
client.request({
1718
path: '/',
1819
method: 'POST',
1920
body: req
2021
}, (err, response) => {
21-
t.error(err)
22+
t.ifError(err)
2223
setTimeout(() => {
2324
response.body.on('data', buf => {
2425
res.write(buf)
@@ -29,18 +30,18 @@ function doNotKillReqSocket (bodyType) {
2930
}, 100)
3031
})
3132
})
32-
t.teardown(server1.close.bind(server1))
33+
after(() => server1.close())
3334

3435
const server2 = createServer((req, res) => {
3536
setTimeout(() => {
3637
req.pipe(res)
3738
}, 100)
3839
})
39-
t.teardown(server2.close.bind(server2))
40+
after(() => server2.close())
4041

4142
server1.listen(0, () => {
4243
const client = new undici.Client(`http://localhost:${server1.address().port}`)
43-
t.teardown(client.close.bind(client))
44+
after(() => client.close())
4445

4546
const r = new Readable({ read () {} })
4647
r.push('hello')
@@ -49,19 +50,21 @@ function doNotKillReqSocket (bodyType) {
4950
method: 'POST',
5051
body: maybeWrapStream(r, bodyType)
5152
}, (err, response) => {
52-
t.error(err)
53+
t.ifError(err)
5354
const bufs = []
5455
response.body.on('data', (buf) => {
5556
bufs.push(buf)
5657
r.push(null)
5758
})
5859
response.body.on('end', () => {
59-
t.equal('hello', Buffer.concat(bufs).toString('utf8'))
60+
t.strictEqual('hello', Buffer.concat(bufs).toString('utf8'))
6061
})
6162
})
6263
})
6364

6465
server2.listen(0)
66+
67+
await t.completed
6568
})
6669
}
6770

‎test/https.js

+26-21
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,79 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { test, after } = require('node:test')
45
const { Client } = require('..')
56
const { createServer } = require('node:https')
67
const pem = require('https-pem')
78

8-
test('https get with tls opts', (t) => {
9-
t.plan(6)
9+
test('https get with tls opts', async (t) => {
10+
t = tspl(t, { plan: 6 })
1011

1112
const server = createServer(pem, (req, res) => {
12-
t.equal('/', req.url)
13-
t.equal('GET', req.method)
13+
t.strictEqual('/', req.url)
14+
t.strictEqual('GET', req.method)
1415
res.setHeader('content-type', 'text/plain')
1516
res.end('hello')
1617
})
17-
t.teardown(server.close.bind(server))
18+
after(() => server.close())
1819

1920
server.listen(0, () => {
2021
const client = new Client(`https://localhost:${server.address().port}`, {
2122
tls: {
2223
rejectUnauthorized: false
2324
}
2425
})
25-
t.teardown(client.close.bind(client))
26+
after(() => client.close())
2627

2728
client.request({ path: '/', method: 'GET' }, (err, { statusCode, headers, body }) => {
28-
t.error(err)
29-
t.equal(statusCode, 200)
30-
t.equal(headers['content-type'], 'text/plain')
29+
t.ifError(err)
30+
t.strictEqual(statusCode, 200)
31+
t.strictEqual(headers['content-type'], 'text/plain')
3132
const bufs = []
3233
body.on('data', (buf) => {
3334
bufs.push(buf)
3435
})
3536
body.on('end', () => {
36-
t.equal('hello', Buffer.concat(bufs).toString('utf8'))
37+
t.strictEqual('hello', Buffer.concat(bufs).toString('utf8'))
3738
})
3839
})
3940
})
41+
42+
await t.completed
4043
})
4144

42-
test('https get with tls opts ip', (t) => {
43-
t.plan(6)
45+
test('https get with tls opts ip', async (t) => {
46+
t = tspl(t, { plan: 6 })
4447

4548
const server = createServer(pem, (req, res) => {
46-
t.equal('/', req.url)
47-
t.equal('GET', req.method)
49+
t.strictEqual('/', req.url)
50+
t.strictEqual('GET', req.method)
4851
res.setHeader('content-type', 'text/plain')
4952
res.end('hello')
5053
})
51-
t.teardown(server.close.bind(server))
54+
after(() => server.close())
5255

5356
server.listen(0, () => {
5457
const client = new Client(`https://127.0.0.1:${server.address().port}`, {
5558
tls: {
5659
rejectUnauthorized: false
5760
}
5861
})
59-
t.teardown(client.close.bind(client))
62+
after(() => client.close())
6063

6164
client.request({ path: '/', method: 'GET' }, (err, { statusCode, headers, body }) => {
62-
t.error(err)
63-
t.equal(statusCode, 200)
64-
t.equal(headers['content-type'], 'text/plain')
65+
t.ifError(err)
66+
t.strictEqual(statusCode, 200)
67+
t.strictEqual(headers['content-type'], 'text/plain')
6568
const bufs = []
6669
body.on('data', (buf) => {
6770
bufs.push(buf)
6871
})
6972
body.on('end', () => {
70-
t.equal('hello', Buffer.concat(bufs).toString('utf8'))
73+
t.strictEqual('hello', Buffer.concat(bufs).toString('utf8'))
7174
})
7275
})
7376
})
77+
78+
await t.completed
7479
})

‎test/max-response-size.js

+32-25
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,76 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { test, after, describe } = require('node:test')
45
const { Client, errors } = require('..')
56
const { createServer } = require('node:http')
67

7-
test('max response size', (t) => {
8-
t.plan(4)
9-
10-
t.test('default max default size should allow all responses', (t) => {
11-
t.plan(3)
8+
describe('max response size', async (t) => {
9+
test('default max default size should allow all responses', async (t) => {
10+
t = tspl(t, { plan: 3 })
1211

1312
const server = createServer()
14-
t.teardown(server.close.bind(server))
13+
after(() => server.close())
1514

1615
server.on('request', (req, res) => {
1716
res.end('hello')
1817
})
1918

2019
server.listen(0, () => {
2120
const client = new Client(`http://localhost:${server.address().port}`, { maxResponseSize: -1 })
22-
t.teardown(client.close.bind(client))
21+
after(() => client.close())
2322

2423
client.request({ path: '/', method: 'GET' }, (err, { statusCode, body }) => {
25-
t.error(err)
26-
t.equal(statusCode, 200)
24+
t.ifError(err)
25+
t.strictEqual(statusCode, 200)
2726
const bufs = []
2827
body.on('data', (buf) => {
2928
bufs.push(buf)
3029
})
3130
body.on('end', () => {
32-
t.equal('hello', Buffer.concat(bufs).toString('utf8'))
31+
t.strictEqual('hello', Buffer.concat(bufs).toString('utf8'))
3332
})
3433
})
3534
})
35+
36+
await t.completed
3637
})
3738

38-
t.test('max response size set to zero should allow only empty responses', (t) => {
39-
t.plan(3)
39+
test('max response size set to zero should allow only empty responses', async (t) => {
40+
t = tspl(t, { plan: 3 })
4041

4142
const server = createServer()
42-
t.teardown(server.close.bind(server))
43+
after(() => server.close())
4344

4445
server.on('request', (req, res) => {
4546
res.end()
4647
})
4748

4849
server.listen(0, () => {
4950
const client = new Client(`http://localhost:${server.address().port}`, { maxResponseSize: 0 })
50-
t.teardown(client.close.bind(client))
51+
after(() => client.close())
5152

5253
client.request({ path: '/', method: 'GET' }, (err, { statusCode, body }) => {
53-
t.error(err)
54-
t.equal(statusCode, 200)
54+
t.ifError(err)
55+
t.strictEqual(statusCode, 200)
5556
const bufs = []
5657
body.on('data', (buf) => {
5758
bufs.push(buf)
5859
})
5960
body.on('end', () => {
60-
t.equal('', Buffer.concat(bufs).toString('utf8'))
61+
t.strictEqual('', Buffer.concat(bufs).toString('utf8'))
6162
})
6263
})
6364
})
65+
66+
await t.completed
6467
})
6568

66-
t.test('should throw an error if the response is too big', (t) => {
67-
t.plan(3)
69+
test('should throw an error if the response is too big', async (t) => {
70+
t = tspl(t, { plan: 3 })
6871

6972
const server = createServer()
70-
t.teardown(server.close.bind(server))
73+
after(() => server.close())
7174

7275
server.on('request', (req, res) => {
7376
res.end('hello')
@@ -78,20 +81,22 @@ test('max response size', (t) => {
7881
maxResponseSize: 1
7982
})
8083

81-
t.teardown(client.close.bind(client))
84+
after(() => client.close())
8285

8386
client.request({ path: '/', method: 'GET' }, (err, { body }) => {
84-
t.error(err)
87+
t.ifError(err)
8588
body.on('error', (err) => {
8689
t.ok(err)
8790
t.ok(err instanceof errors.ResponseExceededMaxSizeError)
8891
})
8992
})
9093
})
94+
95+
await t.completed
9196
})
9297

93-
t.test('invalid max response size should throw an error', (t) => {
94-
t.plan(2)
98+
test('invalid max response size should throw an error', async (t) => {
99+
t = tspl(t, { plan: 2 })
95100

96101
t.throws(() => {
97102
// eslint-disable-next-line no-new
@@ -102,4 +107,6 @@ test('max response size', (t) => {
102107
new Client('http://localhost:3000', { maxResponseSize: -2 })
103108
}, 'maxResponseSize must be greater than or equal to -1')
104109
})
110+
111+
await t.completed
105112
})

‎test/parser-issues.js

+31-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
'use strict'
2+
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { test, after } = require('node:test')
15
const net = require('node:net')
2-
const { test } = require('tap')
36
const { Client, errors } = require('..')
47

5-
test('https://github.com/mcollina/undici/issues/268', (t) => {
6-
t.plan(2)
8+
test('https://github.com/mcollina/undici/issues/268', async (t) => {
9+
t = tspl(t, { plan: 2 })
710

811
const server = net.createServer(socket => {
912
socket.write('HTTP/1.1 200 OK\r\n')
@@ -17,18 +20,18 @@ test('https://github.com/mcollina/undici/issues/268', (t) => {
1720
}, 500)
1821
}, 500)
1922
})
20-
t.teardown(server.close.bind(server))
23+
after(() => server.close())
2124

2225
server.listen(0, () => {
2326
const client = new Client(`http://localhost:${server.address().port}`)
24-
t.teardown(client.destroy.bind(client))
27+
after(() => client.destroy())
2528

2629
client.request({
2730
method: 'GET',
2831
path: '/nxt/_changes?feed=continuous&heartbeat=5000',
2932
headersTimeout: 1e3
3033
}, (err, data) => {
31-
t.error(err)
34+
t.ifError(err)
3235
data.body
3336
.resume()
3437
setTimeout(() => {
@@ -37,19 +40,21 @@ test('https://github.com/mcollina/undici/issues/268', (t) => {
3740
}, 2e3)
3841
})
3942
})
43+
44+
await t.completed
4045
})
4146

42-
test('parser fail', (t) => {
43-
t.plan(2)
47+
test('parser fail', async (t) => {
48+
t = tspl(t, { plan: 2 })
4449

4550
const server = net.createServer(socket => {
4651
socket.write('HTT/1.1 200 OK\r\n')
4752
})
48-
t.teardown(server.close.bind(server))
53+
after(() => server.close())
4954

5055
server.listen(0, () => {
5156
const client = new Client(`http://localhost:${server.address().port}`)
52-
t.teardown(client.destroy.bind(client))
57+
after(() => client.destroy())
5358

5459
client.request({
5560
method: 'GET',
@@ -59,56 +64,62 @@ test('parser fail', (t) => {
5964
t.ok(err instanceof errors.HTTPParserError)
6065
})
6166
})
67+
68+
await t.completed
6269
})
6370

64-
test('split header field', (t) => {
65-
t.plan(2)
71+
test('split header field', async (t) => {
72+
t = tspl(t, { plan: 2 })
6673

6774
const server = net.createServer(socket => {
6875
socket.write('HTTP/1.1 200 OK\r\nA')
6976
setTimeout(() => {
7077
socket.write('SD: asd,asd\r\n\r\n\r\n')
7178
}, 100)
7279
})
73-
t.teardown(server.close.bind(server))
80+
after(() => server.close())
7481

7582
server.listen(0, () => {
7683
const client = new Client(`http://localhost:${server.address().port}`)
77-
t.teardown(client.destroy.bind(client))
84+
after(() => client.destroy())
7885

7986
client.request({
8087
method: 'GET',
8188
path: '/'
8289
}, (err, data) => {
83-
t.error(err)
90+
t.ifError(err)
8491
t.equal(data.headers.asd, 'asd,asd')
8592
data.body.destroy().on('error', () => {})
8693
})
8794
})
95+
96+
await t.completed
8897
})
8998

90-
test('split header value', (t) => {
91-
t.plan(2)
99+
test('split header value', async (t) => {
100+
t = tspl(t, { plan: 2 })
92101

93102
const server = net.createServer(socket => {
94103
socket.write('HTTP/1.1 200 OK\r\nASD: asd')
95104
setTimeout(() => {
96105
socket.write(',asd\r\n\r\n\r\n')
97106
}, 100)
98107
})
99-
t.teardown(server.close.bind(server))
108+
after(() => server.close())
100109

101110
server.listen(0, () => {
102111
const client = new Client(`http://localhost:${server.address().port}`)
103-
t.teardown(client.destroy.bind(client))
112+
after(() => client.destroy())
104113

105114
client.request({
106115
method: 'GET',
107116
path: '/'
108117
}, (err, data) => {
109-
t.error(err)
118+
t.ifError(err)
110119
t.equal(data.headers.asd, 'asd,asd')
111120
data.body.destroy().on('error', () => {})
112121
})
113122
})
123+
124+
await t.completed
114125
})

‎test/pipeline-pipelining.js

+25-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { test, after } = require('node:test')
45
const { Client } = require('..')
56
const { createServer } = require('node:http')
67
const { kConnect } = require('../lib/core/symbols')
78
const { kBusy, kPending, kRunning } = require('../lib/core/symbols')
89

9-
test('pipeline pipelining', (t) => {
10-
t.plan(10)
10+
test('pipeline pipelining', async (t) => {
11+
t = tspl(t, { plan: 10 })
1112

1213
const server = createServer((req, res) => {
13-
t.strictSame(req.headers['transfer-encoding'], undefined)
14+
t.deepStrictEqual(req.headers['transfer-encoding'], undefined)
1415
res.end()
1516
})
1617

17-
t.teardown(server.close.bind(server))
18+
after(() => server.close())
1819
server.listen(0, () => {
1920
const client = new Client(`http://localhost:${server.address().port}`, {
2021
pipelining: 2
2122
})
22-
t.teardown(client.close.bind(client))
23+
after(() => client.close())
2324

2425
client[kConnect](() => {
2526
t.equal(client[kRunning], 0)
@@ -28,25 +29,27 @@ test('pipeline pipelining', (t) => {
2829
path: '/'
2930
}, ({ body }) => body).end().resume()
3031
t.equal(client[kBusy], true)
31-
t.strictSame(client[kRunning], 0)
32-
t.strictSame(client[kPending], 1)
32+
t.deepStrictEqual(client[kRunning], 0)
33+
t.deepStrictEqual(client[kPending], 1)
3334

3435
client.pipeline({
3536
method: 'GET',
3637
path: '/'
3738
}, ({ body }) => body).end().resume()
3839
t.equal(client[kBusy], true)
39-
t.strictSame(client[kRunning], 0)
40-
t.strictSame(client[kPending], 2)
40+
t.deepStrictEqual(client[kRunning], 0)
41+
t.deepStrictEqual(client[kPending], 2)
4142
process.nextTick(() => {
4243
t.equal(client[kRunning], 2)
4344
})
4445
})
4546
})
47+
48+
await t.completed
4649
})
4750

48-
test('pipeline pipelining retry', (t) => {
49-
t.plan(13)
51+
test('pipeline pipelining retry', async (t) => {
52+
t = tspl(t, { plan: 13 })
5053

5154
let count = 0
5255
const server = createServer((req, res) => {
@@ -57,12 +60,12 @@ test('pipeline pipelining retry', (t) => {
5760
}
5861
})
5962

60-
t.teardown(server.close.bind(server))
63+
after(() => server.close())
6164
server.listen(0, () => {
6265
const client = new Client(`http://localhost:${server.address().port}`, {
6366
pipelining: 3
6467
})
65-
t.teardown(client.destroy.bind(client))
68+
after(() => client.destroy())
6669

6770
client.once('disconnect', () => {
6871
t.ok(true, 'pass')
@@ -77,24 +80,24 @@ test('pipeline pipelining retry', (t) => {
7780
t.ok(err)
7881
})
7982
t.equal(client[kBusy], true)
80-
t.strictSame(client[kRunning], 0)
81-
t.strictSame(client[kPending], 1)
83+
t.deepStrictEqual(client[kRunning], 0)
84+
t.deepStrictEqual(client[kPending], 1)
8285

8386
client.pipeline({
8487
method: 'GET',
8588
path: '/'
8689
}, ({ body }) => body).end().resume()
8790
t.equal(client[kBusy], true)
88-
t.strictSame(client[kRunning], 0)
89-
t.strictSame(client[kPending], 2)
91+
t.deepStrictEqual(client[kRunning], 0)
92+
t.deepStrictEqual(client[kPending], 2)
9093

9194
client.pipeline({
9295
method: 'GET',
9396
path: '/'
9497
}, ({ body }) => body).end().resume()
9598
t.equal(client[kBusy], true)
96-
t.strictSame(client[kRunning], 0)
97-
t.strictSame(client[kPending], 3)
99+
t.deepStrictEqual(client[kRunning], 0)
100+
t.deepStrictEqual(client[kPending], 3)
98101

99102
process.nextTick(() => {
100103
t.equal(client[kRunning], 3)
@@ -105,4 +108,6 @@ test('pipeline pipelining retry', (t) => {
105108
})
106109
})
107110
})
111+
112+
await t.completed
108113
})

‎test/socket-timeout.js

+25-20
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,76 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { test, after } = require('node:test')
45
const { Client, errors } = require('..')
56
const timers = require('../lib/timers')
67
const { createServer } = require('node:http')
78
const FakeTimers = require('@sinonjs/fake-timers')
89

9-
test('timeout with pipelining 1', (t) => {
10-
t.plan(9)
10+
test('timeout with pipelining 1', async (t) => {
11+
t = tspl(t, { plan: 9 })
1112

1213
const server = createServer()
1314

1415
server.once('request', (req, res) => {
1516
t.ok(true, 'first request received, we are letting this timeout on the client')
1617

1718
server.once('request', (req, res) => {
18-
t.equal('/', req.url)
19-
t.equal('GET', req.method)
19+
t.strictEqual('/', req.url)
20+
t.strictEqual('GET', req.method)
2021
res.setHeader('content-type', 'text/plain')
2122
res.end('hello')
2223
})
2324
})
24-
t.teardown(server.close.bind(server))
25+
after(() => server.close())
2526

2627
server.listen(0, () => {
2728
const client = new Client(`http://localhost:${server.address().port}`, {
2829
pipelining: 1,
2930
headersTimeout: 500,
3031
bodyTimeout: 500
3132
})
32-
t.teardown(client.close.bind(client))
33+
after(() => client.close())
3334

3435
client.request({
3536
path: '/',
3637
method: 'GET',
3738
opaque: 'asd'
3839
}, (err, data) => {
3940
t.ok(err instanceof errors.HeadersTimeoutError) // we are expecting an error
40-
t.equal(data.opaque, 'asd')
41+
t.strictEqual(data.opaque, 'asd')
4142
})
4243

4344
client.request({
4445
path: '/',
4546
method: 'GET'
4647
}, (err, { statusCode, headers, body }) => {
47-
t.error(err)
48-
t.equal(statusCode, 200)
49-
t.equal(headers['content-type'], 'text/plain')
48+
t.ifError(err)
49+
t.strictEqual(statusCode, 200)
50+
t.strictEqual(headers['content-type'], 'text/plain')
5051
const bufs = []
5152
body.on('data', (buf) => {
5253
bufs.push(buf)
5354
})
5455
body.on('end', () => {
55-
t.equal('hello', Buffer.concat(bufs).toString('utf8'))
56+
t.strictEqual('hello', Buffer.concat(bufs).toString('utf8'))
5657
})
5758
})
5859
})
60+
61+
await t.completed
5962
})
6063

61-
test('Disable socket timeout', (t) => {
62-
t.plan(2)
64+
test('Disable socket timeout', async (t) => {
65+
t = tspl(t, { plan: 2 })
6366

6467
const server = createServer()
6568
const clock = FakeTimers.install()
66-
t.teardown(clock.uninstall.bind(clock))
69+
after(clock.uninstall.bind(clock))
6770

6871
const orgTimers = { ...timers }
6972
Object.assign(timers, { setTimeout, clearTimeout })
70-
t.teardown(() => {
73+
after(() => {
7174
Object.assign(timers, orgTimers)
7275
})
7376

@@ -77,24 +80,26 @@ test('Disable socket timeout', (t) => {
7780
}, 31e3)
7881
clock.tick(32e3)
7982
})
80-
t.teardown(server.close.bind(server))
83+
after(() => server.close())
8184

8285
server.listen(0, () => {
8386
const client = new Client(`http://localhost:${server.address().port}`, {
8487
bodyTimeout: 0,
8588
headersTimeout: 0
8689
})
87-
t.teardown(client.close.bind(client))
90+
after(() => client.close())
8891

8992
client.request({ path: '/', method: 'GET' }, (err, result) => {
90-
t.error(err)
93+
t.ifError(err)
9194
const bufs = []
9295
result.body.on('data', (buf) => {
9396
bufs.push(buf)
9497
})
9598
result.body.on('end', () => {
96-
t.equal('hello', Buffer.concat(bufs).toString('utf8'))
99+
t.strictEqual('hello', Buffer.concat(bufs).toString('utf8'))
97100
})
98101
})
99102
})
103+
104+
await t.completed
100105
})

‎test/stream-compat.js

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { test, after } = require('node:test')
45
const { Client } = require('..')
56
const { createServer } = require('node:http')
67
const { Readable } = require('node:stream')
78
const EE = require('node:events')
89

9-
test('stream body without destroy', (t) => {
10-
t.plan(2)
10+
test('stream body without destroy', async (t) => {
11+
t = tspl(t, { plan: 2 })
1112

1213
const server = createServer((req, res) => {
1314
res.end()
1415
})
15-
t.teardown(server.close.bind(server))
16+
after(() => server.close())
1617
server.listen(0, () => {
1718
const client = new Client(`http://localhost:${server.address().port}`)
18-
t.teardown(client.destroy.bind(client))
19+
after(() => client.destroy())
1920

2021
const signal = new EE()
2122
const body = new Readable({ read () {} })
@@ -33,43 +34,47 @@ test('stream body without destroy', (t) => {
3334
})
3435
signal.emit('abort')
3536
})
37+
38+
await t.completed
3639
})
3740

38-
test('IncomingMessage', (t) => {
39-
t.plan(2)
41+
test('IncomingMessage', async (t) => {
42+
t = tspl(t, { plan: 2 })
4043

4144
const server = createServer((req, res) => {
4245
res.end()
4346
})
44-
t.teardown(server.close.bind(server))
47+
after(() => server.close())
4548

4649
server.listen(0, () => {
4750
const proxyClient = new Client(`http://localhost:${server.address().port}`)
48-
t.teardown(proxyClient.destroy.bind(proxyClient))
51+
after(() => proxyClient.destroy())
4952

5053
const proxy = createServer((req, res) => {
5154
proxyClient.request({
5255
path: '/',
5356
method: 'PUT',
5457
body: req
5558
}, (err, data) => {
56-
t.error(err)
59+
t.ifError(err)
5760
data.body.pipe(res)
5861
})
5962
})
60-
t.teardown(proxy.close.bind(proxy))
63+
after(() => proxy.close())
6164

6265
proxy.listen(0, () => {
6366
const client = new Client(`http://localhost:${proxy.address().port}`)
64-
t.teardown(client.destroy.bind(client))
67+
after(() => client.destroy())
6568

6669
client.request({
6770
path: '/',
6871
method: 'PUT',
6972
body: 'hello world'
7073
}, (err, data) => {
71-
t.error(err)
74+
t.ifError(err)
7275
})
7376
})
7477
})
78+
79+
await t.completed
7580
})

‎test/trailers.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { test, after } = require('node:test')
45
const { Client } = require('..')
56
const { createServer } = require('node:http')
67

7-
test('response trailers missing is OK', (t) => {
8-
t.plan(1)
8+
test('response trailers missing is OK', async (t) => {
9+
t = tspl(t, { plan: 1 })
910

1011
const server = createServer((req, res) => {
1112
res.writeHead(200, {
1213
Trailer: 'content-length'
1314
})
1415
res.end('response')
1516
})
16-
t.teardown(server.close.bind(server))
17+
after(() => server.close())
1718
server.listen(0, async () => {
1819
const client = new Client(`http://localhost:${server.address().port}`)
19-
t.teardown(client.destroy.bind(client))
20-
20+
after(() => client.destroy())
2121
const { body } = await client.request({
2222
path: '/',
2323
method: 'GET',
2424
body: 'asd'
2525
})
2626

27-
t.equal(await body.text(), 'response')
27+
t.strictEqual(await body.text(), 'response')
2828
})
29+
30+
await t.completed
2931
})
3032

31-
test('response trailers missing w trailers is OK', (t) => {
32-
t.plan(2)
33+
test('response trailers missing w trailers is OK', async (t) => {
34+
t = tspl(t, { plan: 2 })
3335

3436
const server = createServer((req, res) => {
3537
res.writeHead(200, {
@@ -40,18 +42,19 @@ test('response trailers missing w trailers is OK', (t) => {
4042
})
4143
res.end('response')
4244
})
43-
t.teardown(server.close.bind(server))
45+
after(() => server.close())
4446
server.listen(0, async () => {
4547
const client = new Client(`http://localhost:${server.address().port}`)
46-
t.teardown(client.destroy.bind(client))
47-
48+
after(() => client.destroy())
4849
const { body, trailers } = await client.request({
4950
path: '/',
5051
method: 'GET',
5152
body: 'asd'
5253
})
5354

54-
t.equal(await body.text(), 'response')
55-
t.same(trailers, { asd: 'foo' })
55+
t.strictEqual(await body.text(), 'response')
56+
t.deepStrictEqual(trailers, { asd: 'foo' })
5657
})
58+
59+
await t.completed
5760
})

0 commit comments

Comments
 (0)
Please sign in to comment.