diff --git a/index.js b/index.js index 8db8e43..6e610f1 100644 --- a/index.js +++ b/index.js @@ -32,9 +32,9 @@ module.exports = function(app, options = {}) { 'supertest: this version of Node.js does not support http2' ); } - app = http2.createServer(app); // eslint-disable-line no-param-reassign + app = http2.createServer(app).listen(0); // eslint-disable-line no-param-reassign } else { - app = http.createServer(app); // eslint-disable-line no-param-reassign + app = http.createServer(app).listen(0); // eslint-disable-line no-param-reassign } } diff --git a/lib/agent.js b/lib/agent.js index 6e4e7d8..956c7ca 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -38,9 +38,9 @@ function TestAgent(app, options = {}) { 'supertest: this version of Node.js does not support http2' ); } - app = http2.createServer(app); // eslint-disable-line no-param-reassign + app = http2.createServer(app).listen(0); // eslint-disable-line no-param-reassign } else { - app = http.createServer(app); // eslint-disable-line no-param-reassign + app = http.createServer(app).listen(0); // eslint-disable-line no-param-reassign } } this.app = app; diff --git a/test/supertest.js b/test/supertest.js index 9eebf31..04a1e0c 100644 --- a/test/supertest.js +++ b/test/supertest.js @@ -1390,13 +1390,16 @@ describeHttp2('http2', function() { res.end('hey'); }; - it('should fire up the app on an ephemeral port', function (done) { - api(app, { http2: true }) + it('should fire up the app on a single ephemeral port', function (done) { + const agent = api(app, { http2: true }); + agent .get('/') - .end(function (err, res) { - res.status.should.equal(200); - res.text.should.equal('hey'); - done(); + .end(function (err1, res1) { + res1.request.url.should.match(/^http:\/\/127.0.0.1:(\d+)\/$/); + agent.get('/').end(function (err2, res2) { + res2.request.url.should.equal(res1.request.url); + done(); + }); }); });