mirror of
https://github.com/nodejs/node.git
synced 2025-05-21 08:27:49 +00:00

This commit adds a mustNotCall() helper for testing. This provides an alternative to using common.fail() as a callback, or creating a callback function for the sole purpose of calling common.fail(). PR-URL: https://github.com/nodejs/node/pull/11152 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
31 lines
905 B
JavaScript
31 lines
905 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
|
|
const invalidPort = -1 >>> 0;
|
|
const errorMessage = /"port" argument must be >= 0 and < 65536/;
|
|
|
|
net.Server().listen(common.PORT, function() {
|
|
const address = this.address();
|
|
const key = `${address.family.slice(-1)}:${address.address}:${common.PORT}`;
|
|
|
|
assert.strictEqual(this._connectionKey, key);
|
|
this.close();
|
|
});
|
|
|
|
// The first argument is a configuration object
|
|
assert.throws(() => {
|
|
net.Server().listen({ port: invalidPort }, common.mustNotCall());
|
|
}, errorMessage);
|
|
|
|
// The first argument is the port, no IP given.
|
|
assert.throws(() => {
|
|
net.Server().listen(invalidPort, common.mustNotCall());
|
|
}, errorMessage);
|
|
|
|
// The first argument is the port, the second an IP.
|
|
assert.throws(() => {
|
|
net.Server().listen(invalidPort, '0.0.0.0', common.mustNotCall());
|
|
}, errorMessage);
|