mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
dns: add dns/promises alias
PR-URL: https://github.com/nodejs/node/pull/32953 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
7a094dc505
commit
039cd00a9a
@ -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
|
||||
|
5
lib/dns/promises.js
Normal file
5
lib/dns/promises.js
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const dnsPromises = require('internal/dns/promises');
|
||||
dnsPromises.setServers = require('dns').setServers;
|
||||
module.exports = dnsPromises;
|
1
node.gyp
1
node.gyp
@ -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',
|
||||
|
14
test/es-module/test-esm-dns-promises.mjs
Normal file
14
test/es-module/test-esm-dns-promises.mjs
Normal file
@ -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
test/parallel/test-dns-promises-exists.js
Normal file
6
test/parallel/test-dns-promises-exists.js
Normal file
@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
assert.strictEqual(require('dns/promises'), require('dns').promises);
|
@ -85,3 +85,36 @@ const promiseResolver = new dns.promises.Resolver();
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// This test for 'dns/promises'
|
||||
{
|
||||
const {
|
||||
setServers
|
||||
} = require('dns/promises');
|
||||
|
||||
// This should not throw any error.
|
||||
(async () => {
|
||||
setServers([ '127.0.0.1' ]);
|
||||
})();
|
||||
|
||||
[
|
||||
[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);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user