From b8ab46594da8d2626c59ba36f76264ad980c533d Mon Sep 17 00:00:00 2001 From: kgarg1 <31365353+kgarg1@users.noreply.github.com> Date: Thu, 29 May 2025 05:56:16 +0530 Subject: [PATCH] test: add coverage for app.listen() variants (#6476) * test: add coverage for app.listen() variants - verify alternate signatures (port+host+backlog) - verify server.address() shape * fix linter issue --------- Co-authored-by: kuldeep --- test/app.listen.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/app.listen.js b/test/app.listen.js index 180162a0..3ef94ff1 100644 --- a/test/app.listen.js +++ b/test/app.listen.js @@ -24,4 +24,32 @@ describe('app.listen()', function(){ }) }) }) + it('accepts port + hostname + backlog + callback', function (done) { + const app = express(); + const server = app.listen(0, '127.0.0.1', 5, function () { + const { address, port } = server.address(); + assert.strictEqual(address, '127.0.0.1'); + assert(Number.isInteger(port) && port > 0); + // backlog isn’t directly inspectable, but if no error was thrown + // we know it was accepted. + server.close(done); + }); + }); + it('accepts just a callback (no args)', function (done) { + const app = express(); + // same as app.listen(0, done) + const server = app.listen(); + server.close(done); + }); + it('server.address() gives a { address, port, family } object', function (done) { + const app = express(); + const server = app.listen(0, () => { + const addr = server.address(); + assert(addr && typeof addr === 'object'); + assert.strictEqual(typeof addr.address, 'string'); + assert(Number.isInteger(addr.port) && addr.port > 0); + assert(typeof addr.family === 'string'); + server.close(done); + }); + }); })