summaryrefslogtreecommitdiffstats
path: root/test/diagnostics-channel/connect-error.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/diagnostics-channel/connect-error.js')
-rw-r--r--test/diagnostics-channel/connect-error.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/diagnostics-channel/connect-error.js b/test/diagnostics-channel/connect-error.js
new file mode 100644
index 0000000..f7e842d
--- /dev/null
+++ b/test/diagnostics-channel/connect-error.js
@@ -0,0 +1,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)
+})