-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathunix-http-undici-from.test.js
47 lines (35 loc) · 1.04 KB
/
unix-http-undici-from.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
45
46
47
'use strict'
const t = require('tap')
const Fastify = require('fastify')
const { request } = require('undici')
const From = require('..')
const fs = require('node:fs')
const querystring = require('node:querystring')
const http = require('node:http')
if (process.platform === 'win32') {
t.pass()
process.exit(0)
}
const instance = Fastify()
instance.register(From)
t.test('unix http undici from', async (t) => {
t.plan(1)
t.teardown(instance.close.bind(instance))
const socketPath = `${__filename}.socket`
try {
fs.unlinkSync(socketPath)
} catch (_) {
}
const target = http.createServer((_req, res) => {
t.fail('no response')
res.end()
})
instance.get('/', (_request, reply) => {
reply.from(`unix+http://${querystring.escape(socketPath)}/hello`)
})
t.teardown(target.close.bind(target))
await instance.listen({ port: 0 })
await new Promise(resolve => target.listen(socketPath, resolve))
const result = await request(`http://localhost:${instance.server.address().port}`)
t.equal(result.statusCode, 500)
})