mirror of
https://github.com/expressjs/express.git
synced 2026-02-26 02:54:58 +00:00
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 <kuldeep@wanclouds.net>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user