From da984ed2ddd83a0e39a8700381e27cf3315903cc Mon Sep 17 00:00:00 2001 From: kuldeep Date: Tue, 22 Apr 2025 18:04:20 +0530 Subject: [PATCH 1/2] test: add coverage for app.listen() variants - verify alternate signatures (port+host+backlog) - verify server.address() shape --- test/app.listen.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/app.listen.js b/test/app.listen.js index 180162a0fa..331663fa0b 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, family } = 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); + }); + }); }) From d29e4ecc73f56d12907dad977c5f1e0fd21d8aa7 Mon Sep 17 00:00:00 2001 From: kuldeep Date: Tue, 22 Apr 2025 23:49:44 +0530 Subject: [PATCH 2/2] fix linter issue --- test/app.listen.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/app.listen.js b/test/app.listen.js index 331663fa0b..3ef94ff184 100644 --- a/test/app.listen.js +++ b/test/app.listen.js @@ -27,14 +27,14 @@ 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, family } = server.address(); + 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)