From 26ebedc256842e8f754b26faa1e9bd5fe3999a72 Mon Sep 17 00:00:00 2001 From: Trevor Robinson Date: Wed, 19 Jun 2019 17:05:49 -0700 Subject: [PATCH] Compose urls in `Test.serverAddress` using Node's `url` library --- lib/test.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/test.js b/lib/test.js index f87a3273..a2ba0cbc 100644 --- a/lib/test.js +++ b/lib/test.js @@ -3,6 +3,7 @@ */ var request = require('superagent'); +var url = require('url'); var util = require('util'); var http = require('http'); var https = require('https'); @@ -51,7 +52,7 @@ Object.setPrototypeOf(Test.prototype, Request.prototype); * @api private */ -Test.prototype.serverAddress = function(app, path, host) { +Test.prototype.serverAddress = function(app, pathname, hostname = '127.0.0.1') { var addr = app.address(); var port; var protocol; @@ -59,7 +60,13 @@ Test.prototype.serverAddress = function(app, path, host) { if (!addr) this._server = app.listen(0); port = app.address().port; protocol = app instanceof https.Server ? 'https' : 'http'; - return protocol + '://' + (host || '127.0.0.1') + ':' + port + path; + + return url.format({ + protocol, + hostname, + port, + pathname + }); }; /**