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

dns: Add dns/promises alias #32953

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/dns.md
Expand Up @@ -611,7 +611,7 @@ earlier ones time out or result in some other error.

The `dns.promises` API provides an alternative set of asynchronous DNS methods
that return `Promise` objects rather than using callbacks. The API is accessible
via `require('dns').promises`.
via `require('dns').promises` or `require('dns/promises')`.

### Class: `dnsPromises.Resolver`
<!-- YAML
Expand Down
5 changes: 5 additions & 0 deletions lib/dns/promises.js
@@ -0,0 +1,5 @@
'use strict';

const dnsPromises = require('internal/dns/promises');
dnsPromises.setServers = require('dns').setServers;
module.exports = dnsPromises;
1 change: 1 addition & 0 deletions node.gyp
Expand Up @@ -48,6 +48,7 @@
'lib/cluster.js',
'lib/dgram.js',
'lib/dns.js',
'lib/dns/promises.js',
'lib/domain.js',
'lib/events.js',
'lib/fs.js',
Expand Down
14 changes: 14 additions & 0 deletions test/es-module/test-esm-dns-promises.mjs
@@ -0,0 +1,14 @@
// Flags: --expose-internals
import '../common/index.mjs';
import assert from 'assert';
import { lookupService } from 'dns/promises';

const invalidAddress = 'fasdfdsaf';

assert.throws(() => {
lookupService(invalidAddress, 0);
}, {
code: 'ERR_INVALID_OPT_VALUE',
name: 'TypeError',
message: `The value "${invalidAddress}" is invalid for option "address"`
});
6 changes: 6 additions & 0 deletions test/parallel/test-dns-promises-exists.js
@@ -0,0 +1,6 @@
'use strict';

require('../common');
const assert = require('assert');

assert.strictEqual(require('dns/promises'), require('dns').promises);
35 changes: 35 additions & 0 deletions test/parallel/test-dns-setservers-type-check.js
Expand Up @@ -85,3 +85,38 @@ const promiseResolver = new dns.promises.Resolver();
);
});
}

// This test for 'dns/promises'
{
const {
setServers,
resolve
} = require('dns/promises');

// This should not throw any error.
(async () => {
const localhost = await resolve('localhost');
setServers(localhost);
})();

[
[null],
[undefined],
[Number(addresses.DNS4_SERVER)],
[
{
address: addresses.DNS4_SERVER
}
]
].forEach((val) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "servers[0]" argument must be of type string.' +
common.invalidArgTypeHelper(val[0])
};
assert.throws(() => {
setServers(val);
}, errObj);
});
}