node/test/parallel/test-net-better-error-messages-port-hostname.js
Joyee Cheung da162278de
test: mock the lookup function in parallel tests
These tests should not make any DNS calls. The lookup would fail
when the DNS requests are hijacked and time out instead of erroring
out.

PR-URL: https://github.com/nodejs/node/pull/17296
Backport-PR-URL: https://github.com/nodejs/node/pull/19706
Refs: https://github.com/nodejs/help/issues/687
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-04-12 00:48:01 +01:00

31 lines
816 B
JavaScript

'use strict';
// This tests that the error thrown from net.createConnection
// comes with host and port properties.
// See https://github.com/nodejs/node-v0.x-archive/issues/7005
const common = require('../common');
const net = require('net');
const assert = require('assert');
const { addresses } = require('../common/internet');
const {
errorLookupMock,
mockedErrorCode
} = require('../common/dns');
// Using port 0 as hostname used is already invalid.
const c = net.createConnection({
port: 0,
host: addresses.INVALID_HOST,
lookup: common.mustCall(errorLookupMock())
});
c.on('connect', common.mustNotCall());
c.on('error', common.mustCall(function(e) {
assert.strictEqual(e.code, mockedErrorCode);
assert.strictEqual(e.port, 0);
assert.strictEqual(e.hostname, addresses.INVALID_HOST);
}));