From 5e23869d1f936aa16c7e82e01a8684f6c54af910 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sun, 18 Sep 2022 18:48:01 +0800 Subject: [PATCH] feat(TestAgent): decoupled TestAgent and superagent's Agent to support more than `ca`, `key`, `cert` `options` object is now a direct passthrough, TestAgent can support whichever superagent's Agent is expecting i.e. `ca`, `key`, `cert`, `pfx`, `rejectUnauthorized` --- lib/agent.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/agent.js b/lib/agent.js index 8adf984..1b4aa27 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -20,12 +20,7 @@ const Test = require('./test.js'); function TestAgent(app, options) { if (!(this instanceof TestAgent)) return new TestAgent(app, options); if (typeof app === 'function') app = http.createServer(app); // eslint-disable-line no-param-reassign - if (options) { - this._ca = options.ca; - this._key = options.key; - this._cert = options.cert; - } - Agent.call(this); + Agent.call(this, options); this.app = app; } @@ -45,9 +40,7 @@ TestAgent.prototype.host = function(host) { methods.forEach(function(method) { TestAgent.prototype[method] = function(url, fn) { // eslint-disable-line no-unused-vars const req = new Test(this.app, method.toUpperCase(), url, this._host); - req.ca(this._ca); - req.cert(this._cert); - req.key(this._key); + if (this._host) { req.set('host', this._host); }