express/test/app.listen.js
kgarg1 b8ab46594d
Some checks failed
ci / Lint (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (18, ubuntu-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (18, windows-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (19, ubuntu-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (19, windows-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (20, ubuntu-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (20, windows-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (21, ubuntu-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (21, windows-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (22, ubuntu-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (22, windows-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (23, ubuntu-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (23, windows-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (24, ubuntu-latest) (push) Has been cancelled
ci / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (24, windows-latest) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
legacy / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (16, ubuntu-latest) (push) Has been cancelled
legacy / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (16, windows-latest) (push) Has been cancelled
legacy / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (17, ubuntu-latest) (push) Has been cancelled
legacy / Node.js ${{ matrix.node-version }} - ${{matrix.os}} (17, windows-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
ci / coverage (push) Has been cancelled
legacy / coverage (push) Has been cancelled
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>
2025-05-28 19:26:16 -05:00

56 lines
1.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict'
var express = require('../')
var assert = require('node:assert')
describe('app.listen()', function(){
it('should wrap with an HTTP server', function(done){
var app = express();
var server = app.listen(0, function () {
server.close(done)
});
})
it('should callback on HTTP server errors', function (done) {
var app1 = express()
var app2 = express()
var server1 = app1.listen(0, function (err) {
assert(!err)
app2.listen(server1.address().port, function (err) {
assert(err.code === 'EADDRINUSE')
server1.close()
done()
})
})
})
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 isnt 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);
});
});
})