Skip to content

test: add coverage for app.listen() variants #6476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions test/app.listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
})