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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
'use strict'
const t = require('tap')
let diagnosticsChannel
try {
diagnosticsChannel = require('diagnostics_channel')
} catch {
t.skip('missing diagnostics_channel')
process.exit(0)
}
const { Client } = require('../..')
t.plan(16)
const connectError = new Error('custom error')
let _connector
diagnosticsChannel.channel('undici:client:beforeConnect').subscribe(({ connectParams, connector }) => {
_connector = connector
t.equal(typeof _connector, 'function')
t.equal(Object.keys(connectParams).length, 6)
const { host, hostname, protocol, port, servername } = connectParams
t.equal(host, 'localhost:1234')
t.equal(hostname, 'localhost')
t.equal(port, '1234')
t.equal(protocol, 'http:')
t.equal(servername, null)
})
diagnosticsChannel.channel('undici:client:connectError').subscribe(({ error, connectParams, connector }) => {
t.equal(Object.keys(connectParams).length, 6)
t.equal(_connector, connector)
const { host, hostname, protocol, port, servername } = connectParams
t.equal(error, connectError)
t.equal(host, 'localhost:1234')
t.equal(hostname, 'localhost')
t.equal(port, '1234')
t.equal(protocol, 'http:')
t.equal(servername, null)
})
const client = new Client('http://localhost:1234', {
connect: (_, cb) => { cb(connectError, null) }
})
t.teardown(client.close.bind(client))
client.request({
path: '/',
method: 'GET'
}, (err, data) => {
t.equal(err, connectError)
})
|