From dc9b914b707f10712782d51116d91dfa7e819689 Mon Sep 17 00:00:00 2001 From: Yoshiki Kurihara Date: Mon, 20 Dec 2021 07:41:02 +0900 Subject: [PATCH] test: improve test coverage of dns/promises PR-URL: https://github.com/nodejs/node/pull/41133 Refs: https://coverage.nodejs.org/coverage-18ff5832501b66b4/lib/internal/dns/promises.js.html#L116 Reviewed-By: Luigi Pinca Reviewed-By: Qingyu Deng --- ...-dns-lookup-promises-options-deprecated.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/parallel/test-dns-lookup-promises-options-deprecated.js diff --git a/test/parallel/test-dns-lookup-promises-options-deprecated.js b/test/parallel/test-dns-lookup-promises-options-deprecated.js new file mode 100644 index 00000000000000..6f3b9314b9db13 --- /dev/null +++ b/test/parallel/test-dns-lookup-promises-options-deprecated.js @@ -0,0 +1,32 @@ +// Flags: --expose-internals +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const { internalBinding } = require('internal/test/binding'); +const cares = internalBinding('cares_wrap'); +cares.getaddrinfo = () => internalBinding('uv').UV_ENOMEM; + +// This test ensures that dns.lookup issue a DeprecationWarning +// when invalid options type is given + +const dnsPromises = require('dns/promises'); + +common.expectWarning({ + 'internal/test/binding': [ + 'These APIs are for internal testing only. Do not use them.', + ], + 'DeprecationWarning': { + DEP0153: 'Type coercion of dns.lookup options is deprecated' + } +}); + +assert.throws(() => { + dnsPromises.lookup('127.0.0.1', { hints: '-1' }); +}, { + code: 'ERR_INVALID_ARG_VALUE', + name: 'TypeError' +}); +dnsPromises.lookup('127.0.0.1', { family: '6' }); +dnsPromises.lookup('127.0.0.1', { all: 'true' }); +dnsPromises.lookup('127.0.0.1', { verbatim: 'true' }); +dnsPromises.lookup('127.0.0.1', '6');