Skip to content

Commit

Permalink
fix: pick ephemeral just port
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst committed Nov 9, 2024
1 parent 2ae1c36 commit 8ae2a31
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions test/supertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

Expand Down

0 comments on commit 8ae2a31

Please sign in to comment.