Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve test coverage of dns/promises #41133

Merged
merged 2 commits into from
Dec 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions test/parallel/test-dns-lookup-promises-options-deprecated.js
Original file line number Diff line number Diff line change
@@ -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' });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test only check whether DeprecationWarning is emitted when hints is not a number.
Since the valid string value of hints depends on the OS environment, give an invalid string value here and assert the error.

}, {
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');