1// Flags: --expose-internals --dns-result-order=ipv4first 2'use strict'; 3const common = require('../common'); 4const assert = require('assert'); 5const { internalBinding } = require('internal/test/binding'); 6const cares = internalBinding('cares_wrap'); 7const { promisify } = require('util'); 8 9// Test that --dns-result-order=ipv4first works as expected. 10 11const originalGetaddrinfo = cares.getaddrinfo; 12const calls = []; 13cares.getaddrinfo = common.mustCallAtLeast((...args) => { 14 calls.push(args); 15 originalGetaddrinfo(...args); 16}, 1); 17 18const dns = require('dns'); 19const dnsPromises = dns.promises; 20 21let verbatim; 22 23// We want to test the parameter of verbatim only so that we 24// ignore possible errors here. 25function allowFailed(fn) { 26 return fn.catch((_err) => { 27 // 28 }); 29} 30 31(async () => { 32 let callsLength = 0; 33 const checkParameter = (expected) => { 34 assert.strictEqual(calls.length, callsLength + 1); 35 verbatim = calls[callsLength][4]; 36 assert.strictEqual(verbatim, expected); 37 callsLength += 1; 38 }; 39 40 await allowFailed(promisify(dns.lookup)('example.org')); 41 checkParameter(false); 42 43 await allowFailed(dnsPromises.lookup('example.org')); 44 checkParameter(false); 45 46 await allowFailed(promisify(dns.lookup)('example.org', {})); 47 checkParameter(false); 48 49 await allowFailed(dnsPromises.lookup('example.org', {})); 50 checkParameter(false); 51})().then(common.mustCall()); 52