mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 20:40:03 +00:00

Covert lib/net.js over to using lib/internal/errors.js - Replace thrown errors in lib/net.js with errors from lib/internal/errors. The ERR_INVALID_OPT_VALUE error have been used in the Server.prototype.listen() method - Update tests according to the above modifications PR-URL: https://github.com/nodejs/node/pull/14782 Refs: https://github.com/nodejs/node/issues/11273 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
39 lines
1003 B
JavaScript
39 lines
1003 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
|
|
const invalidPort = -1 >>> 0;
|
|
|
|
net.Server().listen(0, function() {
|
|
const address = this.address();
|
|
const key = `${address.family.slice(-1)}:${address.address}:0`;
|
|
|
|
assert.strictEqual(this._connectionKey, key);
|
|
this.close();
|
|
});
|
|
|
|
// The first argument is a configuration object
|
|
assert.throws(() => {
|
|
net.Server().listen({ port: invalidPort }, common.mustNotCall());
|
|
}, common.expectsError({
|
|
code: 'ERR_SOCKET_BAD_PORT',
|
|
type: RangeError
|
|
}));
|
|
|
|
// The first argument is the port, no IP given.
|
|
assert.throws(() => {
|
|
net.Server().listen(invalidPort, common.mustNotCall());
|
|
}, common.expectsError({
|
|
code: 'ERR_SOCKET_BAD_PORT',
|
|
type: RangeError
|
|
}));
|
|
|
|
// The first argument is the port, the second an IP.
|
|
assert.throws(() => {
|
|
net.Server().listen(invalidPort, '0.0.0.0', common.mustNotCall());
|
|
}, common.expectsError({
|
|
code: 'ERR_SOCKET_BAD_PORT',
|
|
type: RangeError
|
|
}));
|