-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathhttp-global-agent.test.js
44 lines (35 loc) · 1.05 KB
/
http-global-agent.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict'
const { test } = require('tap')
const Fastify = require('fastify')
const { request } = require('undici')
const From = require('..')
const http = require('node:http')
test('http global agent is used, but not destroyed', async (t) => {
http.globalAgent.destroy = () => {
t.fail()
}
const instance = Fastify()
t.teardown(instance.close.bind(instance))
instance.get('/', (_request, reply) => {
reply.from()
})
const target = http.createServer((req, res) => {
t.pass('request proxied')
t.equal(req.method, 'GET')
t.equal(req.url, '/')
res.statusCode = 200
res.end()
})
t.teardown(target.close.bind(target))
await new Promise(resolve => target.listen({ port: 0 }, resolve))
instance.register(From, {
base: `http://localhost:${target.address().port}`,
globalAgent: true,
http: {
}
})
await new Promise(resolve => instance.listen({ port: 0 }, resolve))
const result = await request(`http://localhost:${instance.server.address().port}`)
t.equal(result.statusCode, 200)
target.close()
})