node/test/parallel/test-net-socket-connect-without-cb.js
Antoine du Hamel 70b516e4db dns: accept 'IPv4' and 'IPv6' for family
Refs: https://github.com/nodejs/node/issues/43014

PR-URL: https://github.com/nodejs/node/pull/43054
Fixes: https://github.com/nodejs/node/issues/43014
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2022-06-15 18:02:01 -04:00

27 lines
658 B
JavaScript

'use strict';
const common = require('../common');
// This test ensures that socket.connect can be called without callback
// which is optional.
const net = require('net');
const server = net.createServer(common.mustCall(function(conn) {
conn.end();
server.close();
})).listen(0, common.mustCall(function() {
const client = new net.Socket();
client.on('connect', common.mustCall(function() {
client.end();
}));
const address = server.address();
if (!common.hasIPv6 && address.family === 'IPv6') {
// Necessary to pass CI running inside containers.
client.connect(address.port);
} else {
client.connect(address);
}
}));