From 226d2498f89b45ed6471fa9a1c1ec5fc7ea802c0 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Wed, 27 Nov 2024 21:41:17 +0300 Subject: [PATCH] test: migrate tests to use node:test module for better test structure --- test/parallel/test-c-ares.js | 98 +++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 46 deletions(-) diff --git a/test/parallel/test-c-ares.js b/test/parallel/test-c-ares.js index 7576be0589e227..87fdaa3816447f 100644 --- a/test/parallel/test-c-ares.js +++ b/test/parallel/test-c-ares.js @@ -20,13 +20,15 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -const common = require('../common'); -const assert = require('assert'); -const dns = require('dns'); +require('../common'); + +const { test } = require('node:test'); +const assert = require('node:assert'); +const dns = require('node:dns'); const dnsPromises = dns.promises; -(async function() { +test('dns promises lookup', async (t) => { let res; res = await dnsPromises.lookup(null); @@ -40,54 +42,58 @@ const dnsPromises = dns.promises; res = await dnsPromises.lookup('::1'); assert.strictEqual(res.address, '::1'); assert.strictEqual(res.family, 6); -})().then(common.mustCall()); +}); -// Try resolution without hostname. -dns.lookup(null, common.mustSucceed((result, addressType) => { - assert.strictEqual(result, null); - assert.strictEqual(addressType, 4); -})); +test('dns callback lookup', (t) => { + dns.lookup(null, (err, result, addressType) => { + assert.strictEqual(err, null); + assert.strictEqual(result, null); + assert.strictEqual(addressType, 4); + }); -dns.lookup('127.0.0.1', common.mustSucceed((result, addressType) => { - assert.strictEqual(result, '127.0.0.1'); - assert.strictEqual(addressType, 4); -})); + dns.lookup('127.0.0.1', (err, result, addressType) => { + assert.strictEqual(err, null); + assert.strictEqual(result, '127.0.0.1'); + assert.strictEqual(addressType, 4); + }); -dns.lookup('::1', common.mustSucceed((result, addressType) => { - assert.strictEqual(result, '::1'); - assert.strictEqual(addressType, 6); -})); + dns.lookup('::1', (err, result, addressType) => { + assert.strictEqual(err, null); + assert.strictEqual(result, '::1'); + assert.strictEqual(addressType, 6); + }); +}); -[ - // Try calling resolve with an unsupported type. - 'HI', - // Try calling resolve with an unsupported type that's an object key - 'toString', -].forEach((val) => { - const err = { - code: 'ERR_INVALID_ARG_VALUE', - name: 'TypeError', - message: `The argument 'rrtype' is invalid. Received '${val}'`, - }; +test('unsupported rrtype resolves', (t) => { + [ + // Try calling resolve with an unsupported type. + 'HI', + // Try calling resolve with an unsupported type that's an object key + 'toString', + ].forEach((val) => { + const err = { + code: 'ERR_INVALID_ARG_VALUE', + name: 'TypeError', + message: `The argument 'rrtype' is invalid. Received '${val}'`, + }; - assert.throws( - () => dns.resolve('www.google.com', val), - err - ); + assert.throws( + () => dns.resolve('www.google.com', val), + err + ); - assert.throws(() => dnsPromises.resolve('www.google.com', val), err); + assert.throws(() => dnsPromises.resolve('www.google.com', val), err); + }); }); -// Windows doesn't usually have an entry for localhost 127.0.0.1 in -// C:\Windows\System32\drivers\etc\hosts -// so we disable this test on Windows. -// IBMi reports `ENOTFOUND` when get hostname by address 127.0.0.1 -if (!common.isWindows && !common.isIBMi) { - dns.reverse('127.0.0.1', common.mustSucceed((domains) => { - assert.ok(Array.isArray(domains)); - })); +test('reverse DNS lookup (non-Windows, non-IBMi)', async (t) => { + if (!process.platform.startsWith('win') && process.platform !== 'aix') { + dns.reverse('127.0.0.1', (err, domains) => { + assert.strictEqual(err, null); + assert.ok(Array.isArray(domains)); + }); - (async function() { - assert.ok(Array.isArray(await dnsPromises.reverse('127.0.0.1'))); - })().then(common.mustCall()); -} + const domains = await dnsPromises.reverse('127.0.0.1'); + assert.ok(Array.isArray(domains)); + } +});