1'use strict'; 2 3// This tests that the error thrown from net.createConnection 4// comes with host and port properties. 5// See https://github.com/nodejs/node-v0.x-archive/issues/7005 6 7const common = require('../common'); 8const assert = require('assert'); 9const net = require('net'); 10 11const { addresses } = require('../common/internet'); 12const { 13 errorLookupMock, 14 mockedErrorCode 15} = require('../common/dns'); 16 17// Using port 0 as hostname used is already invalid. 18const c = net.createConnection({ 19 port: 0, 20 host: addresses.INVALID_HOST, 21 lookup: common.mustCall(errorLookupMock()) 22}); 23 24c.on('connect', common.mustNotCall()); 25 26c.on('error', common.mustCall((error) => { 27 assert.ok(!('port' in error)); 28 assert.ok(!('host' in error)); 29 assert.throws(() => { throw error; }, { 30 errno: mockedErrorCode, 31 code: mockedErrorCode, 32 name: 'Error', 33 message: 'getaddrinfo ENOTFOUND something.invalid', 34 hostname: addresses.INVALID_HOST, 35 syscall: 'getaddrinfo' 36 }); 37})); 38