summaryrefslogtreecommitdiff
path: root/tests/node_compat
diff options
context:
space:
mode:
authorhaturau <135221985+haturatu@users.noreply.github.com>2024-11-20 01:20:47 +0900
committerGitHub <noreply@github.com>2024-11-20 01:20:47 +0900
commit85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch)
treeface0aecaac53e93ce2f23b53c48859bcf1a36ec /tests/node_compat
parent67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff)
parent186b52731c6bb326c4d32905c5e732d082e83465 (diff)
Merge branch 'denoland:main' into main
Diffstat (limited to 'tests/node_compat')
-rw-r--r--tests/node_compat/config.jsonc28
-rw-r--r--tests/node_compat/package.json3
-rw-r--r--tests/node_compat/runner/TODO.md8
-rw-r--r--tests/node_compat/test.ts4
-rw-r--r--tests/node_compat/test/common/index.js1
-rw-r--r--tests/node_compat/test/common/package.json1
-rw-r--r--tests/node_compat/test/fixtures/child-process-spawn-node.js1
-rw-r--r--tests/node_compat/test/fixtures/package.json1
-rw-r--r--tests/node_compat/test/internet/package.json1
-rw-r--r--tests/node_compat/test/internet/test-dns-any.js194
-rw-r--r--tests/node_compat/test/internet/test-dns-ipv4.js257
-rw-r--r--tests/node_compat/test/internet/test-dns-ipv6.js250
-rw-r--r--tests/node_compat/test/internet/test-dns.js766
-rw-r--r--tests/node_compat/test/parallel/package.json1
-rw-r--r--tests/node_compat/test/parallel/test-child-process-ipc-next-tick.js46
-rw-r--r--tests/node_compat/test/parallel/test-net-autoselectfamily.js312
-rw-r--r--tests/node_compat/test/parallel/test-net-socket-setnodelay.js63
-rw-r--r--tests/node_compat/test/parallel/test-os.js286
-rw-r--r--tests/node_compat/test/pseudo-tty/package.json1
-rw-r--r--tests/node_compat/test/pummel/package.json1
-rw-r--r--tests/node_compat/test/sequential/package.json1
21 files changed, 735 insertions, 1491 deletions
diff --git a/tests/node_compat/config.jsonc b/tests/node_compat/config.jsonc
index bc9bf476b..31b184505 100644
--- a/tests/node_compat/config.jsonc
+++ b/tests/node_compat/config.jsonc
@@ -13,10 +13,12 @@
"x.txt"
],
"internet": [
- "test-dns-any.js",
- "test-dns-ipv4.js",
- "test-dns-ipv6.js",
- "test-dns.js"
+ // TODO(bartlomieju): temporarily disabled as these tests were hitting nodejs.org
+ // server. We should have a setup that hits a local server instead.
+ // "test-dns-any.js",
+ // "test-dns-ipv4.js",
+ // "test-dns-ipv6.js",
+ // "test-dns.js"
],
"parallel": [
"test-assert.js",
@@ -43,9 +45,6 @@
// TODO(littledivy): windows ipc streams not yet implemented
"test-child-process-fork-ref.js",
"test-child-process-fork-ref2.js",
- // TODO(bartlomieju): this test is very flaky on CI
- // https://github.com/denoland/deno/issues/25855
- // "test-child-process-ipc-next-tick.js",
"test-child-process-ipc.js",
"test-child-process-spawnsync-env.js",
"test-child-process-stdio-inherit.js",
@@ -80,6 +79,7 @@
"test-fs-rmdir-recursive.js",
"test-fs-write-file.js",
"test-http-url.parse-https.request.js",
+ "test-net-autoselectfamily.js",
"test-net-better-error-messages-path.js",
"test-net-connect-buffer.js",
"test-net-connect-buffer2.js",
@@ -90,8 +90,6 @@
"test-net-server-try-ports.js",
"test-net-socket-timeout.js",
"test-net-write-arguments.js",
- // TODO(nathanwhit): Disable os.userInfo is slightly incorrect
- // "test-os.js",
"test-path-resolve.js",
"test-querystring.js",
"test-readline-interface.js",
@@ -153,15 +151,15 @@
],
"fixtures/keys": ["agent1-cert.pem", "agent1-key.pem", "ca1-cert.pem"],
"internet": [
- "test-dns-any.js",
+ // "test-dns-any.js",
"test-dns-idna2008.js",
- "test-dns-ipv4.js",
- "test-dns-ipv6.js",
+ // "test-dns-ipv4.js",
+ // "test-dns-ipv6.js",
"test-dns-lookup.js",
"test-dns-promises-resolve.js",
"test-dns-regress-6244.js",
"test-dns-setserver-in-callback-of-resolve4.js",
- "test-dns.js",
+ // "test-dns.js",
"test-http-https-default-ports.js"
],
"parallel": [
@@ -240,6 +238,7 @@
"test-child-process-execfilesync-maxbuf.js",
"test-child-process-execsync-maxbuf.js",
"test-child-process-flush-stdio.js",
+ "test-child-process-ipc-next-tick.js",
"test-child-process-kill.js",
"test-child-process-set-blocking.js",
"test-child-process-spawn-args.js",
@@ -408,6 +407,7 @@
"test-http-url.parse-only-support-http-https-protocol.js",
"test-icu-transcode.js",
"test-net-access-byteswritten.js",
+ "test-net-autoselectfamily.js",
"test-net-better-error-messages-listen-path.js",
"test-net-better-error-messages-path.js",
"test-net-better-error-messages-port-hostname.js",
@@ -439,6 +439,7 @@
"test-net-server-unref.js",
"test-net-socket-destroy-twice.js",
"test-net-socket-no-halfopen-enforcer.js",
+ "test-net-socket-setnodelay.js",
"test-net-timeout-no-handle.js",
"test-net-write-arguments.js",
"test-next-tick-doesnt-hang.js",
@@ -449,6 +450,7 @@
"test-next-tick-when-exiting.js",
"test-next-tick.js",
"test-nodeeventtarget.js",
+ "test-os.js",
"test-outgoing-message-destroy.js",
"test-outgoing-message-pipe.js",
"test-parse-args.mjs",
diff --git a/tests/node_compat/package.json b/tests/node_compat/package.json
new file mode 100644
index 000000000..5bbefffba
--- /dev/null
+++ b/tests/node_compat/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "commonjs"
+}
diff --git a/tests/node_compat/runner/TODO.md b/tests/node_compat/runner/TODO.md
index 99258f5a5..cb7e6034b 100644
--- a/tests/node_compat/runner/TODO.md
+++ b/tests/node_compat/runner/TODO.md
@@ -105,9 +105,13 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co
- [internet/test-dgram-multicast-set-interface-lo.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dgram-multicast-set-interface-lo.js)
- [internet/test-dgram-multicast-ssm-multi-process.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dgram-multicast-ssm-multi-process.js)
- [internet/test-dgram-multicast-ssmv6-multi-process.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dgram-multicast-ssmv6-multi-process.js)
+- [internet/test-dns-any.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-any.js)
- [internet/test-dns-cares-domains.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-cares-domains.js)
- [internet/test-dns-getDefaultResultOrder.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-getDefaultResultOrder.js)
+- [internet/test-dns-ipv4.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-ipv4.js)
+- [internet/test-dns-ipv6.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-ipv6.js)
- [internet/test-dns-txt-sigsegv.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns-txt-sigsegv.js)
+- [internet/test-dns.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-dns.js)
- [internet/test-http-dns-fail.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-http-dns-fail.js)
- [internet/test-http2-issue-32922.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-http2-issue-32922.js)
- [internet/test-https-autoselectfamily-slow-timeout.js](https://github.com/nodejs/node/tree/v18.12.1/test/internet/test-https-autoselectfamily-slow-timeout.js)
@@ -280,7 +284,6 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co
- [parallel/test-child-process-fork3.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-fork3.js)
- [parallel/test-child-process-http-socket-leak.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-http-socket-leak.js)
- [parallel/test-child-process-internal.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-internal.js)
-- [parallel/test-child-process-ipc-next-tick.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-ipc-next-tick.js)
- [parallel/test-child-process-ipc.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-ipc.js)
- [parallel/test-child-process-no-deprecation.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-no-deprecation.js)
- [parallel/test-child-process-pipe-dataflow.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-pipe-dataflow.js)
@@ -1768,7 +1771,6 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co
- [parallel/test-net-autoselectfamily-commandline-option.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-autoselectfamily-commandline-option.js)
- [parallel/test-net-autoselectfamily-default.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-autoselectfamily-default.js)
- [parallel/test-net-autoselectfamily-ipv4first.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-autoselectfamily-ipv4first.js)
-- [parallel/test-net-autoselectfamily.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-autoselectfamily.js)
- [parallel/test-net-better-error-messages-listen.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-better-error-messages-listen.js)
- [parallel/test-net-binary.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-binary.js)
- [parallel/test-net-bind-twice.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-bind-twice.js)
@@ -1851,7 +1853,6 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co
- [parallel/test-net-socket-ready-without-cb.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-socket-ready-without-cb.js)
- [parallel/test-net-socket-reset-send.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-socket-reset-send.js)
- [parallel/test-net-socket-reset-twice.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-socket-reset-twice.js)
-- [parallel/test-net-socket-setnodelay.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-socket-setnodelay.js)
- [parallel/test-net-socket-timeout-unref.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-socket-timeout-unref.js)
- [parallel/test-net-socket-timeout.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-socket-timeout.js)
- [parallel/test-net-socket-write-after-close.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-net-socket-write-after-close.js)
@@ -1880,7 +1881,6 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co
- [parallel/test-os-homedir-no-envvar.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-os-homedir-no-envvar.js)
- [parallel/test-os-process-priority.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-os-process-priority.js)
- [parallel/test-os-userinfo-handles-getter-errors.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-os-userinfo-handles-getter-errors.js)
-- [parallel/test-os.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-os.js)
- [parallel/test-path-posix-relative-on-windows.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-path-posix-relative-on-windows.js)
- [parallel/test-pending-deprecation.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-pending-deprecation.js)
- [parallel/test-perf-gc-crash.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-perf-gc-crash.js)
diff --git a/tests/node_compat/test.ts b/tests/node_compat/test.ts
index f6db4ee1a..6cb41d2e4 100644
--- a/tests/node_compat/test.ts
+++ b/tests/node_compat/test.ts
@@ -19,6 +19,7 @@ import { magenta } from "@std/fmt/colors";
import { pooledMap } from "@std/async/pool";
import { dirname, fromFileUrl, join } from "@std/path";
import { assertEquals, fail } from "@std/assert";
+import { distinct } from "@std/collections";
import {
config,
getPathsFromTestSuites,
@@ -36,6 +37,9 @@ const testPaths = partitionParallelTestPaths(
getPathsFromTestSuites(config.ignore),
),
);
+testPaths.sequential = distinct(testPaths.sequential);
+testPaths.parallel = distinct(testPaths.parallel);
+
const cwd = new URL(".", import.meta.url);
const windowsIgnorePaths = new Set(
getPathsFromTestSuites(config.windowsIgnore),
diff --git a/tests/node_compat/test/common/index.js b/tests/node_compat/test/common/index.js
index d2165aecd..d358ffce5 100644
--- a/tests/node_compat/test/common/index.js
+++ b/tests/node_compat/test/common/index.js
@@ -473,6 +473,7 @@ const pwdCommand = isWindows ?
module.exports = {
allowGlobals,
+ defaultAutoSelectFamilyAttemptTimeout: 2500,
expectsError,
expectWarning,
getArrayBufferViews,
diff --git a/tests/node_compat/test/common/package.json b/tests/node_compat/test/common/package.json
deleted file mode 100644
index 0967ef424..000000000
--- a/tests/node_compat/test/common/package.json
+++ /dev/null
@@ -1 +0,0 @@
-{}
diff --git a/tests/node_compat/test/fixtures/child-process-spawn-node.js b/tests/node_compat/test/fixtures/child-process-spawn-node.js
index d403aabf9..7112567e0 100644
--- a/tests/node_compat/test/fixtures/child-process-spawn-node.js
+++ b/tests/node_compat/test/fixtures/child-process-spawn-node.js
@@ -1,5 +1,6 @@
const assert = require("assert");
const debug = require('util').debuglog('test');
+const process = require("process");
function onmessage(m) {
debug("CHILD got message:", m);
diff --git a/tests/node_compat/test/fixtures/package.json b/tests/node_compat/test/fixtures/package.json
deleted file mode 100644
index 0967ef424..000000000
--- a/tests/node_compat/test/fixtures/package.json
+++ /dev/null
@@ -1 +0,0 @@
-{}
diff --git a/tests/node_compat/test/internet/package.json b/tests/node_compat/test/internet/package.json
deleted file mode 100644
index 0967ef424..000000000
--- a/tests/node_compat/test/internet/package.json
+++ /dev/null
@@ -1 +0,0 @@
-{}
diff --git a/tests/node_compat/test/internet/test-dns-any.js b/tests/node_compat/test/internet/test-dns-any.js
deleted file mode 100644
index b8a70b8e2..000000000
--- a/tests/node_compat/test/internet/test-dns-any.js
+++ /dev/null
@@ -1,194 +0,0 @@
-// deno-fmt-ignore-file
-// deno-lint-ignore-file
-
-// Copyright Joyent and Node contributors. All rights reserved. MIT license.
-// Taken from Node 16.13.0
-// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
-
-// TODO(cmorten): enable remaining tests once functionality is implemented.
-
-'use strict';
-
-const common = require('../common');
-
-const assert = require('assert');
-const dns = require('dns');
-const net = require('net');
-
-let running = false;
-const queue = [];
-
-const dnsPromises = dns.promises;
-const isIPv4 = net.isIPv4;
-const isIPv6 = net.isIPv6;
-
-dns.setServers([ '8.8.8.8', '8.8.4.4' ]);
-
-function checkWrap(req) {
- assert.ok(typeof req === 'object');
-}
-
-const checkers = {
- checkA(r) {
- assert.ok(isIPv4(r.address));
- // assert.strictEqual(typeof r.ttl, 'number');
- assert.strictEqual(r.type, 'A');
- },
- checkAAAA(r) {
- assert.ok(isIPv6(r.address));
- // assert.strictEqual(typeof r.ttl, 'number');
- assert.strictEqual(r.type, 'AAAA');
- },
- checkCNAME(r) {
- assert.ok(r.value);
- assert.strictEqual(typeof r.value, 'string');
- assert.strictEqual(r.type, 'CNAME');
- },
- checkMX(r) {
- assert.strictEqual(typeof r.exchange, 'string');
- assert.strictEqual(typeof r.priority, 'number');
- assert.strictEqual(r.type, 'MX');
- },
- checkNAPTR(r) {
- assert.strictEqual(typeof r.flags, 'string');
- assert.strictEqual(typeof r.service, 'string');
- assert.strictEqual(typeof r.regexp, 'string');
- assert.strictEqual(typeof r.replacement, 'string');
- assert.strictEqual(typeof r.order, 'number');
- assert.strictEqual(typeof r.preference, 'number');
- assert.strictEqual(r.type, 'NAPTR');
- },
- checkNS(r) {
- assert.strictEqual(typeof r.value, 'string');
- assert.strictEqual(r.type, 'NS');
- },
- checkPTR(r) {
- assert.strictEqual(typeof r.value, 'string');
- assert.strictEqual(r.type, 'PTR');
- },
- checkTXT(r) {
- assert.ok(Array.isArray(r.entries));
- assert.ok(r.entries.length > 0);
- assert.strictEqual(r.type, 'TXT');
- },
- checkSOA(r) {
- assert.strictEqual(typeof r.nsname, 'string');
- assert.strictEqual(typeof r.hostmaster, 'string');
- assert.strictEqual(typeof r.serial, 'number');
- assert.strictEqual(typeof r.refresh, 'number');
- assert.strictEqual(typeof r.retry, 'number');
- assert.strictEqual(typeof r.expire, 'number');
- assert.strictEqual(typeof r.minttl, 'number');
- assert.strictEqual(r.type, 'SOA');
- },
- checkSRV(r) {
- assert.strictEqual(typeof r.name, 'string');
- assert.strictEqual(typeof r.port, 'number');
- assert.strictEqual(typeof r.priority, 'number');
- assert.strictEqual(typeof r.weight, 'number');
- assert.strictEqual(r.type, 'SRV');
- }
-};
-
-function TEST(f) {
- function next() {
- const f = queue.shift();
- if (f) {
- running = true;
- f(done);
- }
- }
-
- function done() {
- running = false;
- process.nextTick(next);
- }
-
- queue.push(f);
-
- if (!running) {
- next();
- }
-}
-
-function processResult(res) {
- assert.ok(Array.isArray(res));
- assert.ok(res.length > 0);
-
- const types = {};
- res.forEach((obj) => {
- types[obj.type] = true;
- checkers[`check${obj.type}`](obj);
- });
-
- return types;
-}
-
-TEST(async function test_sip2sip_for_naptr(done) {
- function validateResult(res) {
- const types = processResult(res);
- assert.ok(
- types.A && types.NS && types.NAPTR && types.SOA,
- `Missing record type, found ${Object.keys(types)}`
- );
- }
-
- validateResult(await dnsPromises.resolve('sip2sip.info', 'ANY'));
-
- const req = dns.resolve(
- 'sip2sip.info',
- 'ANY',
- common.mustSucceed((ret) => {
- validateResult(ret);
- done();
- }));
-
- checkWrap(req);
-});
-
-TEST(async function test_google_for_cname_and_srv(done) {
- function validateResult(res) {
- const types = processResult(res);
- assert.ok(types.SRV);
- }
-
- // TODO(kt3k): Temporarily use _caldav._tcp.google.com instead of
- // _jabber._tcp.google.com, which currently doesn't respond
- // validateResult(await dnsPromises.resolve('_jabber._tcp.google.com', 'ANY'));
- validateResult(await dnsPromises.resolve('_caldav._tcp.google.com', 'ANY'));
-
-
- // TODO(kt3k): Temporarily use _caldav._tcp.google.com instead of
- // _jabber._tcp.google.com, which currently doesn't respond
- const req = dns.resolve(
- // '_jabber._tcp.google.com',
- '_caldav._tcp.google.com',
- 'ANY',
- common.mustSucceed((ret) => {
- validateResult(ret);
- done();
- }));
-
- checkWrap(req);
-});
-
-// TODO(bartlomieju): this test started failing on CI on Dec 28th, 2023 returning
-// ENOTFOUND. It's unclear what's going on, since `dig -x 8.8.8.8.in-addr.arpa`
-// TEST(async function test_ptr(done) {
-// function validateResult(res) {
-// const types = processResult(res);
-// assert.ok(types.PTR);
-// }
-
-// validateResult(await dnsPromises.resolve('8.8.8.8.in-addr.arpa', 'ANY'));
-
-// const req = dns.resolve(
-// '8.8.8.8.in-addr.arpa',
-// 'ANY',
-// common.mustSucceed((ret) => {
-// validateResult(ret);
-// done();
-// }));
-
-// checkWrap(req);
-// });
diff --git a/tests/node_compat/test/internet/test-dns-ipv4.js b/tests/node_compat/test/internet/test-dns-ipv4.js
deleted file mode 100644
index 43b60950a..000000000
--- a/tests/node_compat/test/internet/test-dns-ipv4.js
+++ /dev/null
@@ -1,257 +0,0 @@
-// deno-fmt-ignore-file
-// deno-lint-ignore-file
-
-// Copyright Joyent and Node contributors. All rights reserved. MIT license.
-// Taken from Node 16.13.0
-// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
-
-'use strict';
-
-// TODO: enable remaining tests once functionality is implemented.
-
-const common = require('../common');
-const { addresses } = require('../common/internet');
-const assert = require('assert');
-const dns = require('dns');
-const net = require('net');
-// const util = require('util');
-const isIPv4 = net.isIPv4;
-
-const dnsPromises = dns.promises;
-let running = false;
-const queue = [];
-
-function TEST(f) {
- function next() {
- const f = queue.shift();
- if (f) {
- running = true;
- console.log(f.name);
- f(done);
- }
- }
-
- function done() {
- running = false;
- process.nextTick(next);
- }
-
- queue.push(f);
-
- if (!running) {
- next();
- }
-}
-
-function checkWrap(req) {
- assert.ok(typeof req === 'object');
-}
-
-TEST(async function test_resolve4(done) {
- function validateResult(res) {
- assert.ok(res.length > 0);
-
- for (let i = 0; i < res.length; i++) {
- assert.ok(isIPv4(res[i]));
- }
- }
-
- validateResult(await dnsPromises.resolve4(addresses.INET4_HOST));
-
- const req = dns.resolve4(
- addresses.INET4_HOST,
- common.mustSucceed((ips) => {
- validateResult(ips);
- done();
- }));
-
- checkWrap(req);
-});
-
-// TEST(async function test_reverse_ipv4(done) {
-// function validateResult(res) {
-// assert.ok(res.length > 0);
-
-// for (let i = 0; i < res.length; i++) {
-// assert.ok(res[i]);
-// assert.ok(typeof res[i] === 'string');
-// }
-// }
-
-// validateResult(await dnsPromises.reverse(addresses.INET4_IP));
-
-// const req = dns.reverse(
-// addresses.INET4_IP,
-// common.mustSucceed((domains) => {
-// validateResult(domains);
-// done();
-// }));
-
-// checkWrap(req);
-// });
-
-TEST(async function test_lookup_ipv4_explicit(done) {
- function validateResult(res) {
- assert.ok(net.isIPv4(res.address));
- assert.strictEqual(res.family, 4);
- }
-
- validateResult(await dnsPromises.lookup(addresses.INET4_HOST, 4));
-
- const req = dns.lookup(
- addresses.INET4_HOST, 4,
- common.mustSucceed((ip, family) => {
- validateResult({ address: ip, family });
- done();
- }));
-
- checkWrap(req);
-});
-
-TEST(async function test_lookup_ipv4_implicit(done) {
- function validateResult(res) {
- assert.ok(net.isIPv4(res.address));
- assert.strictEqual(res.family, 4);
- }
-
- validateResult(await dnsPromises.lookup(addresses.INET4_HOST));
-
- const req = dns.lookup(
- addresses.INET4_HOST,
- common.mustSucceed((ip, family) => {
- validateResult({ address: ip, family });
- done();
- }));
-
- checkWrap(req);
-});
-
-TEST(async function test_lookup_ipv4_explicit_object(done) {
- function validateResult(res) {
- assert.ok(net.isIPv4(res.address));
- assert.strictEqual(res.family, 4);
- }
-
- validateResult(await dnsPromises.lookup(addresses.INET4_HOST, { family: 4 }));
-
- const req = dns.lookup(addresses.INET4_HOST, {
- family: 4
- }, common.mustSucceed((ip, family) => {
- validateResult({ address: ip, family });
- done();
- }));
-
- checkWrap(req);
-});
-
-TEST(async function test_lookup_ipv4_hint_addrconfig(done) {
- function validateResult(res) {
- assert.ok(net.isIPv4(res.address));
- assert.strictEqual(res.family, 4);
- }
-
- validateResult(await dnsPromises.lookup(addresses.INET4_HOST, {
- hints: dns.ADDRCONFIG
- }));
-
- const req = dns.lookup(addresses.INET4_HOST, {
- hints: dns.ADDRCONFIG
- }, common.mustSucceed((ip, family) => {
- validateResult({ address: ip, family });
- done();
- }));
-
- checkWrap(req);
-});
-
-TEST(async function test_lookup_ip_ipv4(done) {
- function validateResult(res) {
- assert.strictEqual(res.address, '127.0.0.1');
- assert.strictEqual(res.family, 4);
- }
-
- validateResult(await dnsPromises.lookup('127.0.0.1'));
-
- const req = dns.lookup('127.0.0.1',
- common.mustSucceed((ip, family) => {
- validateResult({ address: ip, family });
- done();
- }));
-
- checkWrap(req);
-});
-
-TEST(async function test_lookup_localhost_ipv4(done) {
- function validateResult(res) {
- assert.strictEqual(res.address, '127.0.0.1');
- assert.strictEqual(res.family, 4);
- }
-
- validateResult(await dnsPromises.lookup('localhost', 4));
-
- const req = dns.lookup('localhost', 4,
- common.mustSucceed((ip, family) => {
- validateResult({ address: ip, family });
- done();
- }));
-
- checkWrap(req);
-});
-
-TEST(async function test_lookup_all_ipv4(done) {
- function validateResult(res) {
- assert.ok(Array.isArray(res));
- assert.ok(res.length > 0);
-
- res.forEach((ip) => {
- assert.ok(isIPv4(ip.address));
- assert.strictEqual(ip.family, 4);
- });
- }
-
- validateResult(await dnsPromises.lookup(addresses.INET4_HOST, {
- all: true,
- family: 4
- }));
-
- const req = dns.lookup(
- addresses.INET4_HOST,
- { all: true, family: 4 },
- common.mustSucceed((ips) => {
- validateResult(ips);
- done();
- })
- );
-
- checkWrap(req);
-});
-
-// TEST(async function test_lookupservice_ip_ipv4(done) {
-// function validateResult(res) {
-// assert.strictEqual(typeof res.hostname, 'string');
-// assert(res.hostname);
-// assert(['http', 'www', '80'].includes(res.service));
-// }
-
-// validateResult(await dnsPromises.lookupService('127.0.0.1', 80));
-
-// const req = dns.lookupService(
-// '127.0.0.1', 80,
-// common.mustSucceed((hostname, service) => {
-// validateResult({ hostname, service });
-// done();
-// })
-// );
-
-// checkWrap(req);
-// });
-
-// TEST(function test_lookupservice_ip_ipv4_promise(done) {
-// util.promisify(dns.lookupService)('127.0.0.1', 80)
-// .then(common.mustCall(({ hostname, service }) => {
-// assert.strictEqual(typeof hostname, 'string');
-// assert(hostname.length > 0);
-// assert(['http', 'www', '80'].includes(service));
-// done();
-// }));
-// });
diff --git a/tests/node_compat/test/internet/test-dns-ipv6.js b/tests/node_compat/test/internet/test-dns-ipv6.js
deleted file mode 100644
index 4b94d6041..000000000
--- a/tests/node_compat/test/internet/test-dns-ipv6.js
+++ /dev/null
@@ -1,250 +0,0 @@
-// deno-fmt-ignore-file
-// deno-lint-ignore-file
-
-// Copyright Joyent and Node contributors. All rights reserved. MIT license.
-// Taken from Node 16.13.0
-// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
-
-'use strict';
-
-// TODO: enable remaining tests once functionality is implemented.
-
-const common = require('../common');
-const { addresses } = require('../common/internet');
-if (!common.hasIPv6)
- common.skip('this test, no IPv6 support');
-
-const assert = require('assert');
-const dns = require('dns');
-const net = require('net');
-const dnsPromises = dns.promises;
-const isIPv6 = net.isIPv6;
-
-let running = false;
-const queue = [];
-
-function TEST(f) {
- function next() {
- const f = queue.shift();
- if (f) {
- running = true;
- console.log(f.name);
- f(done);
- }
- }
-
- function done() {
- running = false;
- process.nextTick(next);
- }
-
- queue.push(f);
-
- if (!running) {
- next();
- }
-}
-
-function checkWrap(req) {
- assert.ok(typeof req === 'object');
-}
-
-TEST(async function test_resolve6(done) {
- function validateResult(res) {
- assert.ok(res.length > 0);
-
- for (let i = 0; i < res.length; i++) {
- assert.ok(isIPv6(res[i]));
- }
- }
-
- validateResult(await dnsPromises.resolve6(addresses.INET6_HOST));
-
- const req = dns.resolve6(
- addresses.INET6_HOST,
- common.mustSucceed((ips) => {
- validateResult(ips);
- done();
- }));
-
- checkWrap(req);
-});
-
-// TEST(async function test_reverse_ipv6(done) {
-// function validateResult(res) {
-// assert.ok(res.length > 0);
-
-// for (let i = 0; i < res.length; i++) {
-// assert.ok(typeof res[i] === 'string');
-// }
-// }
-
-// validateResult(await dnsPromises.reverse(addresses.INET6_IP));
-
-// const req = dns.reverse(
-// addresses.INET6_IP,
-// common.mustSucceed((domains) => {
-// validateResult(domains);
-// done();
-// }));
-
-// checkWrap(req);
-// });
-
-TEST(async function test_lookup_ipv6_explicit(done) {
- function validateResult(res) {
- assert.ok(isIPv6(res.address));
- assert.strictEqual(res.family, 6);
- }
-
- validateResult(await dnsPromises.lookup(addresses.INET6_HOST, 6));
-
- const req = dns.lookup(
- addresses.INET6_HOST,
- 6,
- common.mustSucceed((ip, family) => {
- validateResult({ address: ip, family });
- done();
- }));
-
- checkWrap(req);
-});
-
-// This ends up just being too problematic to test
-// TEST(function test_lookup_ipv6_implicit(done) {
-// var req = dns.lookup(addresses.INET6_HOST, function(err, ip, family) {
-// assert.ifError(err);
-// assert.ok(net.isIPv6(ip));
-// assert.strictEqual(family, 6);
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-TEST(async function test_lookup_ipv6_explicit_object(done) {
- function validateResult(res) {
- assert.ok(isIPv6(res.address));
- assert.strictEqual(res.family, 6);
- }
-
- validateResult(await dnsPromises.lookup(addresses.INET6_HOST, { family: 6 }));
-
- const req = dns.lookup(addresses.INET6_HOST, {
- family: 6
- }, common.mustSucceed((ip, family) => {
- validateResult({ address: ip, family });
- done();
- }));
-
- checkWrap(req);
-});
-
-TEST(function test_lookup_ipv6_hint(done) {
- const req = dns.lookup(addresses.INET6_HOST, {
- family: 6,
- hints: dns.V4MAPPED
- }, common.mustCall((err, ip, family) => {
- if (err) {
- // FreeBSD does not support V4MAPPED
- if (common.isFreeBSD) {
- assert(err instanceof Error);
- assert.strictEqual(err.code, 'EAI_BADFLAGS');
- assert.strictEqual(err.hostname, addresses.INET_HOST);
- assert.match(err.message, /getaddrinfo EAI_BADFLAGS/);
- done();
- return;
- }
-
- assert.ifError(err);
- }
-
- assert.ok(isIPv6(ip));
- assert.strictEqual(family, 6);
-
- done();
- }));
-
- checkWrap(req);
-});
-
-TEST(async function test_lookup_ip_ipv6(done) {
- function validateResult(res) {
- assert.ok(isIPv6(res.address));
- assert.strictEqual(res.family, 6);
- }
-
- validateResult(await dnsPromises.lookup('::1'));
-
- const req = dns.lookup(
- '::1',
- common.mustSucceed((ip, family) => {
- validateResult({ address: ip, family });
- done();
- }));
-
- checkWrap(req);
-});
-
-TEST(async function test_lookup_all_ipv6(done) {
- function validateResult(res) {
- assert.ok(Array.isArray(res));
- assert.ok(res.length > 0);
-
- res.forEach((ip) => {
- assert.ok(isIPv6(ip.address),
- `Invalid IPv6: ${ip.address.toString()}`);
- assert.strictEqual(ip.family, 6);
- });
- }
-
- validateResult(await dnsPromises.lookup(addresses.INET6_HOST, {
- all: true,
- family: 6
- }));
-
- const req = dns.lookup(
- addresses.INET6_HOST,
- { all: true, family: 6 },
- common.mustSucceed((ips) => {
- validateResult(ips);
- done();
- })
- );
-
- checkWrap(req);
-});
-
-// TEST(function test_lookupservice_ip_ipv6(done) {
-// const req = dns.lookupService(
-// '::1', 80,
-// common.mustCall((err, host, service) => {
-// if (err) {
-// // Not skipping the test, rather checking an alternative result,
-// // i.e. that ::1 may not be configured (e.g. in /etc/hosts)
-// assert.strictEqual(err.code, 'ENOTFOUND');
-// return done();
-// }
-// assert.strictEqual(typeof host, 'string');
-// assert(host);
-// assert(['http', 'www', '80'].includes(service));
-// done();
-// })
-// );
-
-// checkWrap(req);
-// });
-
-// Disabled because it appears to be not working on Linux.
-// TEST(function test_lookup_localhost_ipv6(done) {
-// var req = dns.lookup('localhost', 6, function(err, ip, family) {
-// assert.ifError(err);
-// assert.ok(net.isIPv6(ip));
-// assert.strictEqual(family, 6);
-//
-// done();
-// });
-//
-// checkWrap(req);
-// });
diff --git a/tests/node_compat/test/internet/test-dns.js b/tests/node_compat/test/internet/test-dns.js
deleted file mode 100644
index 8aaeb728d..000000000
--- a/tests/node_compat/test/internet/test-dns.js
+++ /dev/null
@@ -1,766 +0,0 @@
-// deno-fmt-ignore-file
-// deno-lint-ignore-file
-
-// Copyright Joyent and Node contributors. All rights reserved. MIT license.
-// Taken from Node 16.13.0
-// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
-
-// Flags: --expose-internals
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-'use strict';
-
-// TODO(cmorten): enable remaining tests once functionality is implemented.
-
-const common = require('../common');
-const { addresses } = require('../common/internet');
-const { internalBinding } = require('internal/test/binding');
-// const { getSystemErrorName } = require('util');
-const assert = require('assert');
-const dns = require('dns');
-const net = require('net');
-const isIPv4 = net.isIPv4;
-const isIPv6 = net.isIPv6;
-const util = require('util');
-const dnsPromises = dns.promises;
-
-let expected = 0;
-let completed = 0;
-let running = false;
-const queue = [];
-
-
-function TEST(f) {
- function next() {
- const f = queue.shift();
- if (f) {
- running = true;
- console.log(f.name);
- f(done);
- }
- }
-
- function done() {
- running = false;
- completed++;
- process.nextTick(next);
- }
-
- expected++;
- queue.push(f);
-
- if (!running) {
- next();
- }
-}
-
-
-function checkWrap(req) {
- assert.strictEqual(typeof req, 'object');
-}
-
-
-// TEST(function test_reverse_bogus(done) {
-// dnsPromises.reverse('bogus ip')
-// .then(common.mustNotCall())
-// .catch(common.mustCall((err) => {
-// assert.strictEqual(err.code, 'EINVAL');
-// assert.strictEqual(getSystemErrorName(err.errno), 'EINVAL');
-// }));
-
-// assert.throws(() => {
-// dns.reverse('bogus ip', common.mustNotCall());
-// }, /^Error: getHostByAddr EINVAL bogus ip$/);
-// done();
-// });
-
-// TEST(async function test_resolve4_ttl(done) {
-// function validateResult(result) {
-// assert.ok(result.length > 0);
-
-// for (const item of result) {
-// assert.strictEqual(typeof item, 'object');
-// assert.strictEqual(typeof item.ttl, 'number');
-// assert.strictEqual(typeof item.address, 'string');
-// assert.ok(item.ttl >= 0);
-// assert.ok(isIPv4(item.address));
-// }
-// }
-
-// validateResult(await dnsPromises.resolve4(addresses.INET4_HOST, {
-// ttl: true
-// }));
-
-// const req = dns.resolve4(addresses.INET4_HOST, {
-// ttl: true
-// }, function(err, result) {
-// assert.ifError(err);
-// validateResult(result);
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-// TEST(async function test_resolve6_ttl(done) {
-// function validateResult(result) {
-// assert.ok(result.length > 0);
-
-// for (const item of result) {
-// assert.strictEqual(typeof item, 'object');
-// assert.strictEqual(typeof item.ttl, 'number');
-// assert.strictEqual(typeof item.address, 'string');
-// assert.ok(item.ttl >= 0);
-// assert.ok(isIPv6(item.address));
-// }
-// }
-
-// validateResult(await dnsPromises.resolve6(addresses.INET6_HOST, {
-// ttl: true
-// }));
-
-// const req = dns.resolve6(addresses.INET6_HOST, {
-// ttl: true
-// }, function(err, result) {
-// assert.ifError(err);
-// validateResult(result);
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-TEST(async function test_resolveMx(done) {
- function validateResult(result) {
- assert.ok(result.length > 0);
-
- for (const item of result) {
- assert.strictEqual(typeof item, 'object');
- assert.ok(item.exchange);
- assert.strictEqual(typeof item.exchange, 'string');
- assert.strictEqual(typeof item.priority, 'number');
- }
- }
-
- validateResult(await dnsPromises.resolveMx(addresses.MX_HOST));
-
- const req = dns.resolveMx(addresses.MX_HOST, function(err, result) {
- assert.ifError(err);
- validateResult(result);
- done();
- });
-
- checkWrap(req);
-});
-
-// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN`
-// instead of `ENOTFOUND`.
-// TEST(function test_resolveMx_failure(done) {
-// dnsPromises.resolveMx(addresses.NOT_FOUND)
-// .then(common.mustNotCall())
-// .catch(common.mustCall((err) => {
-// assert.strictEqual(err.code, 'ENOTFOUND');
-// }));
-
-// const req = dns.resolveMx(addresses.NOT_FOUND, function(err, result) {
-// assert.ok(err instanceof Error);
-// assert.strictEqual(err.code, 'ENOTFOUND');
-
-// assert.strictEqual(result, undefined);
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-TEST(async function test_resolveNs(done) {
- function validateResult(result) {
- assert.ok(result.length > 0);
-
- for (const item of result) {
- assert.ok(item);
- assert.strictEqual(typeof item, 'string');
- }
- }
-
- validateResult(await dnsPromises.resolveNs(addresses.NS_HOST));
-
- const req = dns.resolveNs(addresses.NS_HOST, function(err, names) {
- assert.ifError(err);
- validateResult(names);
- done();
- });
-
- checkWrap(req);
-});
-
-// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN`
-// instead of `ENOTFOUND`.
-// TEST(function test_resolveNs_failure(done) {
-// dnsPromises.resolveNs(addresses.NOT_FOUND)
-// .then(common.mustNotCall())
-// .catch(common.mustCall((err) => {
-// assert.strictEqual(err.code, 'ENOTFOUND');
-// }));
-
-// const req = dns.resolveNs(addresses.NOT_FOUND, function(err, result) {
-// assert.ok(err instanceof Error);
-// assert.strictEqual(err.code, 'ENOTFOUND');
-
-// assert.strictEqual(result, undefined);
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-TEST(async function test_resolveSrv(done) {
- function validateResult(result) {
- assert.ok(result.length > 0);
-
- for (const item of result) {
- assert.strictEqual(typeof item, 'object');
- assert.ok(item.name);
- assert.strictEqual(typeof item.name, 'string');
- assert.strictEqual(typeof item.port, 'number');
- assert.strictEqual(typeof item.priority, 'number');
- assert.strictEqual(typeof item.weight, 'number');
- }
- }
-
- validateResult(await dnsPromises.resolveSrv(addresses.SRV_HOST));
-
- const req = dns.resolveSrv(addresses.SRV_HOST, function(err, result) {
- assert.ifError(err);
- validateResult(result);
- done();
- });
-
- checkWrap(req);
-});
-
-// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN`
-// instead of `ENOTFOUND`.
-// TEST(function test_resolveSrv_failure(done) {
-// dnsPromises.resolveSrv(addresses.NOT_FOUND)
-// .then(common.mustNotCall())
-// .catch(common.mustCall((err) => {
-// assert.strictEqual(err.code, 'ENOTFOUND');
-// }));
-
-// const req = dns.resolveSrv(addresses.NOT_FOUND, function(err, result) {
-// assert.ok(err instanceof Error);
-// assert.strictEqual(err.code, 'ENOTFOUND');
-
-// assert.strictEqual(result, undefined);
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-// TODO(bartlomieju): this test started failing on CI on Dec 28th, 2023 returning
-// ENOTFOUND. It's unclear what's going on, since `dig -x 8.8.8.8.in-addr.arpa`
-// returns correct PTR record.
-// TEST(async function test_resolvePtr(done) {
-// function validateResult(result) {
-// assert.ok(result.length > 0);
-
-// for (const item of result) {
-// assert.ok(item);
-// assert.strictEqual(typeof item, 'string');
-// }
-// }
-
-// validateResult(await dnsPromises.resolvePtr(addresses.PTR_HOST));
-
-// const req = dns.resolvePtr(addresses.PTR_HOST, function(err, result) {
-// assert.ifError(err);
-// validateResult(result);
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN`
-// instead of `ENOTFOUND`.
-// TEST(function test_resolvePtr_failure(done) {
-// dnsPromises.resolvePtr(addresses.NOT_FOUND)
-// .then(common.mustNotCall())
-// .catch(common.mustCall((err) => {
-// assert.strictEqual(err.code, 'ENOTFOUND');
-// }));
-
-// const req = dns.resolvePtr(addresses.NOT_FOUND, function(err, result) {
-// assert.ok(err instanceof Error);
-// assert.strictEqual(err.code, 'ENOTFOUND');
-
-// assert.strictEqual(result, undefined);
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-TEST(async function test_resolveNaptr(done) {
- function validateResult(result) {
- assert.ok(result.length > 0);
-
- for (const item of result) {
- assert.strictEqual(typeof item, 'object');
- assert.strictEqual(typeof item.flags, 'string');
- assert.strictEqual(typeof item.service, 'string');
- assert.strictEqual(typeof item.regexp, 'string');
- assert.strictEqual(typeof item.replacement, 'string');
- assert.strictEqual(typeof item.order, 'number');
- assert.strictEqual(typeof item.preference, 'number');
- }
- }
-
- validateResult(await dnsPromises.resolveNaptr(addresses.NAPTR_HOST));
-
- const req = dns.resolveNaptr(addresses.NAPTR_HOST, function(err, result) {
- assert.ifError(err);
- validateResult(result);
- done();
- });
-
- checkWrap(req);
-});
-
-// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN`
-// instead of `ENOTFOUND`.
-// TEST(function test_resolveNaptr_failure(done) {
-// dnsPromises.resolveNaptr(addresses.NOT_FOUND)
-// .then(common.mustNotCall())
-// .catch(common.mustCall((err) => {
-// assert.strictEqual(err.code, 'ENOTFOUND');
-// }));
-
-// const req = dns.resolveNaptr(addresses.NOT_FOUND, function(err, result) {
-// assert.ok(err instanceof Error);
-// assert.strictEqual(err.code, 'ENOTFOUND');
-
-// assert.strictEqual(result, undefined);
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-TEST(async function test_resolveSoa(done) {
- function validateResult(result) {
- assert.strictEqual(typeof result, 'object');
- assert.strictEqual(typeof result.nsname, 'string');
- assert.ok(result.nsname.length > 0);
- assert.strictEqual(typeof result.hostmaster, 'string');
- assert.ok(result.hostmaster.length > 0);
- assert.strictEqual(typeof result.serial, 'number');
- assert.ok((result.serial > 0) && (result.serial < 4294967295));
- assert.strictEqual(typeof result.refresh, 'number');
- assert.ok((result.refresh > 0) && (result.refresh < 2147483647));
- assert.strictEqual(typeof result.retry, 'number');
- assert.ok((result.retry > 0) && (result.retry < 2147483647));
- assert.strictEqual(typeof result.expire, 'number');
- assert.ok((result.expire > 0) && (result.expire < 2147483647));
- assert.strictEqual(typeof result.minttl, 'number');
- assert.ok((result.minttl >= 0) && (result.minttl < 2147483647));
- }
-
- validateResult(await dnsPromises.resolveSoa(addresses.SOA_HOST));
-
- const req = dns.resolveSoa(addresses.SOA_HOST, function(err, result) {
- assert.ifError(err);
- validateResult(result);
- done();
- });
-
- checkWrap(req);
-});
-
-// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN`
-// instead of `ENOTFOUND`.
-// TEST(function test_resolveSoa_failure(done) {
-// dnsPromises.resolveSoa(addresses.NOT_FOUND)
-// .then(common.mustNotCall())
-// .catch(common.mustCall((err) => {
-// assert.strictEqual(err.code, 'ENOTFOUND');
-// }));
-
-// const req = dns.resolveSoa(addresses.NOT_FOUND, function(err, result) {
-// assert.ok(err instanceof Error);
-// assert.strictEqual(err.code, 'ENOTFOUND');
-
-// assert.strictEqual(result, undefined);
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-TEST(async function test_resolveCaa(done) {
- function validateResult(result) {
- assert.ok(Array.isArray(result),
- `expected array, got ${util.inspect(result)}`);
- assert.strictEqual(result.length, 1);
- assert.strictEqual(typeof result[0].critical, 'number');
- assert.strictEqual(result[0].critical, 0);
- assert.strictEqual(result[0].issue, 'pki.goog');
- }
-
- validateResult(await dnsPromises.resolveCaa(addresses.CAA_HOST));
-
- const req = dns.resolveCaa(addresses.CAA_HOST, function(err, records) {
- assert.ifError(err);
- validateResult(records);
- done();
- });
-
- checkWrap(req);
-});
-
-// NOTE(bartlomieju): this test started failing around July 11th, 2023.
-// TEST(async function test_resolveCname(done) {
-// function validateResult(result) {
-// assert.ok(result.length > 0);
-//
-// for (const item of result) {
-// assert.ok(item);
-// assert.strictEqual(typeof item, 'string');
-// }
-// }
-//
-// validateResult(await dnsPromises.resolveCname(addresses.CNAME_HOST));
-//
-// const req = dns.resolveCname(addresses.CNAME_HOST, function(err, names) {
-// assert.ifError(err);
-// validateResult(names);
-// done();
-// });
-//
-// checkWrap(req);
-// });
-
-// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN`
-// instead of `ENOTFOUND`.
-// TEST(function test_resolveCname_failure(done) {
-// dnsPromises.resolveCname(addresses.NOT_FOUND)
-// .then(common.mustNotCall())
-// .catch(common.mustCall((err) => {
-// assert.strictEqual(err.code, 'ENOTFOUND');
-// }));
-
-// const req = dns.resolveCname(addresses.NOT_FOUND, function(err, result) {
-// assert.ok(err instanceof Error);
-// assert.strictEqual(err.code, 'ENOTFOUND');
-
-// assert.strictEqual(result, undefined);
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-
-TEST(async function test_resolveTxt(done) {
- function validateResult(result) {
- assert.ok(Array.isArray(result[0]));
- assert.strictEqual(result.length, 1);
- assert(result[0][0].startsWith('v=spf1'));
- }
-
- validateResult(await dnsPromises.resolveTxt(addresses.TXT_HOST));
-
- const req = dns.resolveTxt(addresses.TXT_HOST, function(err, records) {
- assert.ifError(err);
- validateResult(records);
- done();
- });
-
- checkWrap(req);
-});
-
-// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN`
-// instead of `ENOTFOUND`.
-// TEST(function test_resolveTxt_failure(done) {
-// dnsPromises.resolveTxt(addresses.NOT_FOUND)
-// .then(common.mustNotCall())
-// .catch(common.mustCall((err) => {
-// assert.strictEqual(err.code, 'ENOTFOUND');
-// }));
-
-// const req = dns.resolveTxt(addresses.NOT_FOUND, function(err, result) {
-// assert.ok(err instanceof Error);
-// assert.strictEqual(err.code, 'ENOTFOUND');
-
-// assert.strictEqual(result, undefined);
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-
-TEST(function test_lookup_failure(done) {
- dnsPromises.lookup(addresses.NOT_FOUND, 4)
- .then(common.mustNotCall())
- .catch(common.expectsError({ code: dns.NOTFOUND }));
-
- const req = dns.lookup(addresses.NOT_FOUND, 4, (err) => {
- assert.ok(err instanceof Error);
- assert.strictEqual(err.code, dns.NOTFOUND);
- assert.strictEqual(err.code, 'ENOTFOUND');
- assert.doesNotMatch(err.message, /ENOENT/);
- assert.ok(err.message.includes(addresses.NOT_FOUND));
-
- done();
- });
-
- checkWrap(req);
-});
-
-
-TEST(async function test_lookup_ip_all(done) {
- function validateResult(result) {
- assert.ok(Array.isArray(result));
- assert.ok(result.length > 0);
- assert.strictEqual(result[0].address, '127.0.0.1');
- assert.strictEqual(result[0].family, 4);
- }
-
- validateResult(await dnsPromises.lookup('127.0.0.1', { all: true }));
-
- const req = dns.lookup(
- '127.0.0.1',
- { all: true },
- function(err, ips, family) {
- assert.ifError(err);
- assert.strictEqual(family, undefined);
- validateResult(ips);
- done();
- }
- );
-
- checkWrap(req);
-});
-
-
-TEST(function test_lookup_ip_all_promise(done) {
- const req = util.promisify(dns.lookup)('127.0.0.1', { all: true })
- .then(function(ips) {
- assert.ok(Array.isArray(ips));
- assert.ok(ips.length > 0);
- assert.strictEqual(ips[0].address, '127.0.0.1');
- assert.strictEqual(ips[0].family, 4);
-
- done();
- });
-
- checkWrap(req);
-});
-
-
-TEST(function test_lookup_ip_promise(done) {
- util.promisify(dns.lookup)('127.0.0.1')
- .then(function({ address, family }) {
- assert.strictEqual(address, '127.0.0.1');
- assert.strictEqual(family, 4);
-
- done();
- });
-});
-
-
-TEST(async function test_lookup_null_all(done) {
- assert.deepStrictEqual(await dnsPromises.lookup(null, { all: true }), []);
-
- const req = dns.lookup(null, { all: true }, (err, ips) => {
- assert.ifError(err);
- assert.ok(Array.isArray(ips));
- assert.strictEqual(ips.length, 0);
-
- done();
- });
-
- checkWrap(req);
-});
-
-
-TEST(async function test_lookup_all_mixed(done) {
- function validateResult(result) {
- assert.ok(Array.isArray(result));
- assert.ok(result.length > 0);
-
- result.forEach(function(ip) {
- if (isIPv4(ip.address))
- assert.strictEqual(ip.family, 4);
- else if (isIPv6(ip.address))
- assert.strictEqual(ip.family, 6);
- else
- assert.fail('unexpected IP address');
- });
- }
-
- validateResult(await dnsPromises.lookup(addresses.INET_HOST, { all: true }));
-
- const req = dns.lookup(addresses.INET_HOST, {
- all: true
- }, function(err, ips) {
- assert.ifError(err);
- validateResult(ips);
- done();
- });
-
- checkWrap(req);
-});
-
-
-// TEST(function test_lookupservice_invalid(done) {
-// dnsPromises.lookupService('1.2.3.4', 80)
-// .then(common.mustNotCall())
-// .catch(common.expectsError({ code: 'ENOTFOUND' }));
-
-// const req = dns.lookupService('1.2.3.4', 80, (err) => {
-// assert(err instanceof Error);
-// assert.strictEqual(err.code, 'ENOTFOUND');
-// assert.match(err.message, /1\.2\.3\.4/);
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-
-// TEST(function test_reverse_failure(done) {
-// dnsPromises.reverse('203.0.113.0')
-// .then(common.mustNotCall())
-// .catch(common.expectsError({
-// code: 'ENOTFOUND',
-// hostname: '203.0.113.0'
-// }));
-
-// // 203.0.113.0/24 are addresses reserved for (RFC) documentation use only
-// const req = dns.reverse('203.0.113.0', function(err) {
-// assert(err instanceof Error);
-// assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
-// assert.strictEqual(err.hostname, '203.0.113.0');
-// assert.match(err.message, /203\.0\.113\.0/);
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-
-// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN`
-// instead of `ENOTFOUND`.
-// TEST(function test_lookup_failure(done) {
-// dnsPromises.lookup(addresses.NOT_FOUND)
-// .then(common.mustNotCall())
-// .catch(common.expectsError({
-// code: 'ENOTFOUND',
-// hostname: addresses.NOT_FOUND
-// }));
-
-// const req = dns.lookup(addresses.NOT_FOUND, (err) => {
-// assert(err instanceof Error);
-// assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
-// assert.strictEqual(err.hostname, addresses.NOT_FOUND);
-// assert.ok(err.message.includes(addresses.NOT_FOUND));
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-
-// TODO(bartlomieju): this test became very flaky on CI, returning `UNKNOWN`
-// instead of `ENOTFOUND`.
-// TEST(function test_resolve_failure(done) {
-// const req = dns.resolve4(addresses.NOT_FOUND, (err) => {
-// assert(err instanceof Error);
-
-// switch (err.code) {
-// case 'ENOTFOUND':
-// case 'ESERVFAIL':
-// break;
-// default:
-// assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
-// break;
-// }
-
-// assert.strictEqual(err.hostname, addresses.NOT_FOUND);
-// assert.ok(err.message.includes(addresses.NOT_FOUND));
-
-// done();
-// });
-
-// checkWrap(req);
-// });
-
-
-let getaddrinfoCallbackCalled = false;
-
-console.log(`looking up ${addresses.INET4_HOST}..`);
-
-const cares = internalBinding('cares_wrap');
-const req = new cares.GetAddrInfoReqWrap();
-cares.getaddrinfo(req, addresses.INET4_HOST, 4,
- /* hints */ 0, /* verbatim */ true);
-
-req.oncomplete = function(err, domains) {
- assert.strictEqual(err, 0);
- console.log(`${addresses.INET4_HOST} = ${domains}`);
- assert.ok(Array.isArray(domains));
- assert.ok(domains.length >= 1);
- assert.strictEqual(typeof domains[0], 'string');
- getaddrinfoCallbackCalled = true;
-};
-
-process.on('exit', function() {
- console.log(`${completed} tests completed`);
- assert.strictEqual(running, false);
- assert.strictEqual(completed, expected);
- assert.ok(getaddrinfoCallbackCalled);
-});
-
-// Should not throw.
-dns.lookup(addresses.INET6_HOST, 6, common.mustCall());
-dns.lookup(addresses.INET_HOST, {}, common.mustCall());
-// dns.lookupService('0.0.0.0', '0', common.mustCall());
-// dns.lookupService('0.0.0.0', 0, common.mustCall());
-(async function() {
- await dnsPromises.lookup(addresses.INET6_HOST, 6);
- await dnsPromises.lookup(addresses.INET_HOST, {});
-})().then(common.mustCall());
diff --git a/tests/node_compat/test/parallel/package.json b/tests/node_compat/test/parallel/package.json
deleted file mode 100644
index 0967ef424..000000000
--- a/tests/node_compat/test/parallel/package.json
+++ /dev/null
@@ -1 +0,0 @@
-{}
diff --git a/tests/node_compat/test/parallel/test-child-process-ipc-next-tick.js b/tests/node_compat/test/parallel/test-child-process-ipc-next-tick.js
new file mode 100644
index 000000000..f511d2500
--- /dev/null
+++ b/tests/node_compat/test/parallel/test-child-process-ipc-next-tick.js
@@ -0,0 +1,46 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 18.12.1
+// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
+
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const cp = require('child_process');
+const NUM_MESSAGES = 10;
+const values = [];
+
+for (let i = 0; i < NUM_MESSAGES; ++i) {
+ values[i] = i;
+}
+
+if (process.argv[2] === 'child') {
+ const received = values.map(() => { return false; });
+
+ process.on('uncaughtException', common.mustCall((err) => {
+ received[err] = true;
+ const done = received.every((element) => { return element === true; });
+
+ if (done)
+ process.disconnect();
+ }, NUM_MESSAGES));
+
+ process.on('message', (msg) => {
+ // If messages are handled synchronously, throwing should break the IPC
+ // message processing.
+ throw msg;
+ });
+
+ process.send('ready');
+} else {
+ const child = cp.fork(__filename, ['child']);
+
+ child.on('message', common.mustCall((msg) => {
+ assert.strictEqual(msg, 'ready');
+ values.forEach((value) => {
+ child.send(value);
+ });
+ }));
+}
diff --git a/tests/node_compat/test/parallel/test-net-autoselectfamily.js b/tests/node_compat/test/parallel/test-net-autoselectfamily.js
new file mode 100644
index 000000000..3b520e6c8
--- /dev/null
+++ b/tests/node_compat/test/parallel/test-net-autoselectfamily.js
@@ -0,0 +1,312 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 18.12.1
+// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
+
+'use strict';
+
+const common = require('../common');
+const { parseDNSPacket, writeDNSPacket } = require('../common/dns');
+
+const assert = require('assert');
+const dgram = require('dgram');
+const { Resolver } = require('dns');
+const { createConnection, createServer } = require('net');
+
+// Test that happy eyeballs algorithm is properly implemented.
+
+// Purposely not using setDefaultAutoSelectFamilyAttemptTimeout here to test the
+// parameter is correctly used in options.
+//
+// Some of the machines in the CI need more time to establish connection
+const autoSelectFamilyAttemptTimeout = common.defaultAutoSelectFamilyAttemptTimeout;
+
+function _lookup(resolver, hostname, options, cb) {
+ resolver.resolve(hostname, 'ANY', (err, replies) => {
+ assert.notStrictEqual(options.family, 4);
+
+ if (err) {
+ return cb(err);
+ }
+
+ const hosts = replies
+ .map((r) => ({ address: r.address, family: r.type === 'AAAA' ? 6 : 4 }))
+ .sort((a, b) => b.family - a.family);
+
+ if (options.all === true) {
+ return cb(null, hosts);
+ }
+
+ return cb(null, hosts[0].address, hosts[0].family);
+ });
+}
+
+function createDnsServer(ipv6Addrs, ipv4Addrs, cb) {
+ if (!Array.isArray(ipv6Addrs)) {
+ ipv6Addrs = [ipv6Addrs];
+ }
+
+ if (!Array.isArray(ipv4Addrs)) {
+ ipv4Addrs = [ipv4Addrs];
+ }
+
+ // Create a DNS server which replies with a AAAA and a A record for the same host
+ const socket = dgram.createSocket('udp4');
+
+ // TODO(kt3k): We use common.mustCallAtLeast instead of common.mustCall
+ // because Deno sends multiple requests to the DNS server.
+ // This can be addressed if Deno.resolveDns supports ANY record type.
+ // See https://github.com/denoland/deno/issues/14492
+ socket.on('message', common.mustCallAtLeast((msg, { address, port }) => {
+ const parsed = parseDNSPacket(msg);
+ const domain = parsed.questions[0].domain;
+ assert.strictEqual(domain, 'example.org');
+
+ socket.send(writeDNSPacket({
+ id: parsed.id,
+ questions: parsed.questions,
+ answers: [
+ ...ipv6Addrs.map((address) => ({ type: 'AAAA', address, ttl: 123, domain: 'example.org' })),
+ ...ipv4Addrs.map((address) => ({ type: 'A', address, ttl: 123, domain: 'example.org' })),
+ ]
+ }), port, address);
+ }));
+
+ socket.bind(0, () => {
+ const resolver = new Resolver();
+ resolver.setServers([`127.0.0.1:${socket.address().port}`]);
+
+ cb({ dnsServer: socket, lookup: _lookup.bind(null, resolver) });
+ });
+}
+
+// Test that IPV4 is reached if IPV6 is not reachable
+{
+ createDnsServer('::1', '127.0.0.1', common.mustCall(function({ dnsServer, lookup }) {
+ const ipv4Server = createServer((socket) => {
+ socket.on('data', common.mustCall(() => {
+ socket.write('response-ipv4');
+ socket.end();
+ }));
+ });
+
+ ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
+ const port = ipv4Server.address().port;
+
+ const connection = createConnection({
+ host: 'example.org',
+ port: port,
+ lookup,
+ autoSelectFamily: true,
+ autoSelectFamilyAttemptTimeout,
+ });
+
+ let response = '';
+ connection.setEncoding('utf-8');
+
+ connection.on('ready', common.mustCall(() => {
+ assert.deepStrictEqual(connection.autoSelectFamilyAttemptedAddresses, [`::1:${port}`, `127.0.0.1:${port}`]);
+ }));
+
+ connection.on('data', (chunk) => {
+ response += chunk;
+ });
+
+ connection.on('end', common.mustCall(() => {
+ assert.strictEqual(response, 'response-ipv4');
+ ipv4Server.close();
+ dnsServer.close();
+ }));
+
+ connection.write('request');
+ }));
+ }));
+}
+
+// Test that only the last successful connection is established.
+{
+ createDnsServer(
+ ['2606:4700::6810:85e5', '2606:4700::6810:84e5', "::1"],
+ // TODO(kt3k): Comment out ipv4 addresses to make the test pass faster.
+ // Enable this when Deno.connect() call becomes cancellable.
+ // See https://github.com/denoland/deno/issues/26819
+ // ['104.20.22.46', '104.20.23.46', '127.0.0.1'],
+ ['127.0.0.1'],
+ common.mustCall(function({ dnsServer, lookup }) {
+ const ipv4Server = createServer((socket) => {
+ socket.on('data', common.mustCall(() => {
+ socket.write('response-ipv4');
+ socket.end();
+ }));
+ });
+
+ ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
+ const port = ipv4Server.address().port;
+
+ const connection = createConnection({
+ host: 'example.org',
+ port: port,
+ lookup,
+ autoSelectFamily: true,
+ autoSelectFamilyAttemptTimeout,
+ });
+
+ let response = '';
+ connection.setEncoding('utf-8');
+
+ connection.on('ready', common.mustCall(() => {
+ assert.deepStrictEqual(
+ connection.autoSelectFamilyAttemptedAddresses,
+ [
+ `2606:4700::6810:85e5:${port}`,
+ `104.20.22.46:${port}`,
+ `2606:4700::6810:84e5:${port}`,
+ `104.20.23.46:${port}`,
+ `::1:${port}`,
+ `127.0.0.1:${port}`,
+ ]
+ );
+ }));
+
+ connection.on('data', (chunk) => {
+ response += chunk;
+ });
+
+ connection.on('end', common.mustCall(() => {
+ assert.strictEqual(response, 'response-ipv4');
+ ipv4Server.close();
+ dnsServer.close();
+ }));
+
+ connection.write('request');
+ }));
+ })
+ );
+}
+
+// Test that IPV4 is NOT reached if IPV6 is reachable
+if (common.hasIPv6) {
+ createDnsServer('::1', '127.0.0.1', common.mustCall(function({ dnsServer, lookup }) {
+ const ipv4Server = createServer((socket) => {
+ socket.on('data', common.mustNotCall(() => {
+ socket.write('response-ipv4');
+ socket.end();
+ }));
+ });
+
+ const ipv6Server = createServer((socket) => {
+ socket.on('data', common.mustCall(() => {
+ socket.write('response-ipv6');
+ socket.end();
+ }));
+ });
+
+ ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
+ const port = ipv4Server.address().port;
+
+ ipv6Server.listen(port, '::1', common.mustCall(() => {
+ const connection = createConnection({
+ host: 'example.org',
+ port,
+ lookup,
+ autoSelectFamily: true,
+ autoSelectFamilyAttemptTimeout,
+ });
+
+ let response = '';
+ connection.setEncoding('utf-8');
+
+ connection.on('ready', common.mustCall(() => {
+ assert.deepStrictEqual(connection.autoSelectFamilyAttemptedAddresses, [`::1:${port}`]);
+ }));
+
+ connection.on('data', (chunk) => {
+ response += chunk;
+ });
+
+ connection.on('end', common.mustCall(() => {
+ assert.strictEqual(response, 'response-ipv6');
+ ipv4Server.close();
+ ipv6Server.close();
+ dnsServer.close();
+ }));
+
+ connection.write('request');
+ }));
+ }));
+ }));
+}
+
+// Test that when all errors are returned when no connections succeeded
+{
+ createDnsServer('::1', '127.0.0.1', common.mustCall(function({ dnsServer, lookup }) {
+ const connection = createConnection({
+ host: 'example.org',
+ port: 10,
+ lookup,
+ autoSelectFamily: true,
+ autoSelectFamilyAttemptTimeout,
+ });
+
+ connection.on('ready', common.mustNotCall());
+ connection.on('error', common.mustCall((error) => {
+ assert.deepStrictEqual(connection.autoSelectFamilyAttemptedAddresses, ['::1:10', '127.0.0.1:10']);
+ assert.strictEqual(error.constructor.name, 'AggregateError');
+ assert.strictEqual(error.errors.length, 2);
+
+ const errors = error.errors.map((e) => e.message);
+ assert.ok(errors.includes('connect ECONNREFUSED 127.0.0.1:10'));
+
+ if (common.hasIPv6) {
+ assert.ok(errors.includes('connect ECONNREFUSED ::1:10'));
+ }
+
+ dnsServer.close();
+ }));
+ }));
+}
+
+// Test that the option can be disabled
+{
+ createDnsServer('::1', '127.0.0.1', common.mustCall(function({ dnsServer, lookup }) {
+ const ipv4Server = createServer((socket) => {
+ socket.on('data', common.mustCall(() => {
+ socket.write('response-ipv4');
+ socket.end();
+ }));
+ });
+
+ ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
+ const port = ipv4Server.address().port;
+
+ const connection = createConnection({
+ host: 'example.org',
+ port,
+ lookup,
+ autoSelectFamily: false,
+ });
+
+ connection.on('ready', common.mustNotCall());
+ connection.on('error', common.mustCall((error) => {
+ assert.strictEqual(connection.autoSelectFamilyAttemptedAddresses, undefined);
+
+ if (common.hasIPv6) {
+ assert.strictEqual(error.code, 'ECONNREFUSED');
+ assert.strictEqual(error.message, `connect ECONNREFUSED ::1:${port}`);
+ } else if (error.code === 'EAFNOSUPPORT') {
+ assert.strictEqual(error.message, `connect EAFNOSUPPORT ::1:${port} - Local (undefined:undefined)`);
+ } else if (error.code === 'EUNATCH') {
+ assert.strictEqual(error.message, `connect EUNATCH ::1:${port} - Local (:::0)`);
+ } else {
+ assert.strictEqual(error.code, 'EADDRNOTAVAIL');
+ assert.strictEqual(error.message, `connect EADDRNOTAVAIL ::1:${port} - Local (:::0)`);
+ }
+
+ ipv4Server.close();
+ dnsServer.close();
+ }));
+ }));
+ }));
+}
diff --git a/tests/node_compat/test/parallel/test-net-socket-setnodelay.js b/tests/node_compat/test/parallel/test-net-socket-setnodelay.js
new file mode 100644
index 000000000..3d11b8452
--- /dev/null
+++ b/tests/node_compat/test/parallel/test-net-socket-setnodelay.js
@@ -0,0 +1,63 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 18.12.1
+// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
+
+'use strict';
+
+const common = require('../common');
+const assert = require('assert');
+const net = require('net');
+
+const truthyValues = [true, 1, 'true', {}, []];
+const falseyValues = [false, 0, ''];
+const genSetNoDelay = (desiredArg) => (enable) => {
+ assert.strictEqual(enable, desiredArg);
+};
+
+// setNoDelay should default to true
+let socket = new net.Socket({
+ handle: {
+ setNoDelay: common.mustCall(genSetNoDelay(true)),
+ readStart() {}
+ }
+});
+socket.setNoDelay();
+
+socket = new net.Socket({
+ handle: {
+ setNoDelay: common.mustCall(genSetNoDelay(true), 1),
+ readStart() {}
+ }
+});
+truthyValues.forEach((testVal) => socket.setNoDelay(testVal));
+
+socket = new net.Socket({
+ handle: {
+ setNoDelay: common.mustNotCall(),
+ readStart() {}
+ }
+});
+falseyValues.forEach((testVal) => socket.setNoDelay(testVal));
+
+socket = new net.Socket({
+ handle: {
+ setNoDelay: common.mustCall(3),
+ readStart() {}
+ }
+});
+truthyValues.concat(falseyValues).concat(truthyValues)
+ .forEach((testVal) => socket.setNoDelay(testVal));
+
+// If a handler doesn't have a setNoDelay function it shouldn't be called.
+// In the case below, if it is called an exception will be thrown
+socket = new net.Socket({
+ handle: {
+ setNoDelay: null,
+ readStart() {}
+ }
+});
+const returned = socket.setNoDelay(true);
+assert.ok(returned instanceof net.Socket);
diff --git a/tests/node_compat/test/parallel/test-os.js b/tests/node_compat/test/parallel/test-os.js
new file mode 100644
index 000000000..f7c24342a
--- /dev/null
+++ b/tests/node_compat/test/parallel/test-os.js
@@ -0,0 +1,286 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 18.12.1
+// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
+
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const os = require('os');
+const path = require('path');
+const { inspect } = require('util');
+
+const is = {
+ number: (value, key) => {
+ assert(!Number.isNaN(value), `${key} should not be NaN`);
+ assert.strictEqual(typeof value, 'number');
+ },
+ string: (value) => { assert.strictEqual(typeof value, 'string'); },
+ array: (value) => { assert.ok(Array.isArray(value)); },
+ object: (value) => {
+ assert.strictEqual(typeof value, 'object');
+ assert.notStrictEqual(value, null);
+ }
+};
+
+process.env.TMPDIR = '/tmpdir';
+process.env.TMP = '/tmp';
+process.env.TEMP = '/temp';
+if (common.isWindows) {
+ assert.strictEqual(os.tmpdir(), '/temp');
+ process.env.TEMP = '';
+ assert.strictEqual(os.tmpdir(), '/tmp');
+ process.env.TMP = '';
+ const expected = `${process.env.SystemRoot || process.env.windir}\\temp`;
+ assert.strictEqual(os.tmpdir(), expected);
+ process.env.TEMP = '\\temp\\';
+ assert.strictEqual(os.tmpdir(), '\\temp');
+ process.env.TEMP = '\\tmpdir/';
+ assert.strictEqual(os.tmpdir(), '\\tmpdir/');
+ process.env.TEMP = '\\';
+ assert.strictEqual(os.tmpdir(), '\\');
+ process.env.TEMP = 'C:\\';
+ assert.strictEqual(os.tmpdir(), 'C:\\');
+} else {
+ assert.strictEqual(os.tmpdir(), '/tmpdir');
+ process.env.TMPDIR = '';
+ assert.strictEqual(os.tmpdir(), '/tmp');
+ process.env.TMP = '';
+ assert.strictEqual(os.tmpdir(), '/temp');
+ process.env.TEMP = '';
+ assert.strictEqual(os.tmpdir(), '/tmp');
+ process.env.TMPDIR = '/tmpdir/';
+ assert.strictEqual(os.tmpdir(), '/tmpdir');
+ process.env.TMPDIR = '/tmpdir\\';
+ assert.strictEqual(os.tmpdir(), '/tmpdir\\');
+ process.env.TMPDIR = '/';
+ assert.strictEqual(os.tmpdir(), '/');
+}
+
+const endianness = os.endianness();
+is.string(endianness);
+assert.match(endianness, /[BL]E/);
+
+const hostname = os.hostname();
+is.string(hostname);
+assert.ok(hostname.length > 0);
+
+// IBMi process priority is different.
+if (!common.isIBMi) {
+ const DUMMY_PRIORITY = 10;
+ os.setPriority(DUMMY_PRIORITY);
+ const priority = os.getPriority();
+ is.number(priority);
+ assert.strictEqual(priority, DUMMY_PRIORITY);
+}
+
+// On IBMi, os.uptime() returns 'undefined'
+if (!common.isIBMi) {
+ const uptime = os.uptime();
+ is.number(uptime);
+ assert.ok(uptime > 0);
+}
+
+const cpus = os.cpus();
+is.array(cpus);
+assert.ok(cpus.length > 0);
+for (const cpu of cpus) {
+ assert.strictEqual(typeof cpu.model, 'string');
+ assert.strictEqual(typeof cpu.speed, 'number');
+ assert.strictEqual(typeof cpu.times.user, 'number');
+ assert.strictEqual(typeof cpu.times.nice, 'number');
+ assert.strictEqual(typeof cpu.times.sys, 'number');
+ assert.strictEqual(typeof cpu.times.idle, 'number');
+ assert.strictEqual(typeof cpu.times.irq, 'number');
+}
+
+const type = os.type();
+is.string(type);
+assert.ok(type.length > 0);
+
+const release = os.release();
+is.string(release);
+assert.ok(release.length > 0);
+// TODO: Check format on more than just AIX
+if (common.isAIX)
+ assert.match(release, /^\d+\.\d+$/);
+
+const platform = os.platform();
+is.string(platform);
+assert.ok(platform.length > 0);
+
+const arch = os.arch();
+is.string(arch);
+assert.ok(arch.length > 0);
+
+if (!common.isSunOS) {
+ // not implemented yet
+ assert.ok(os.loadavg().length > 0);
+ assert.ok(os.freemem() > 0);
+ assert.ok(os.totalmem() > 0);
+}
+
+const interfaces = os.networkInterfaces();
+switch (platform) {
+ case 'linux': {
+ const filter = (e) =>
+ e.address === '127.0.0.1' &&
+ e.netmask === '255.0.0.0';
+
+ const actual = interfaces.lo.filter(filter);
+ const expected = [{
+ address: '127.0.0.1',
+ netmask: '255.0.0.0',
+ family: 'IPv4',
+ mac: '00:00:00:00:00:00',
+ internal: true,
+ cidr: '127.0.0.1/8'
+ }];
+ assert.deepStrictEqual(actual, expected);
+ break;
+ }
+ case 'win32': {
+ const filter = (e) =>
+ e.address === '127.0.0.1';
+
+ const actual = interfaces['Loopback Pseudo-Interface 1'].filter(filter);
+ const expected = [{
+ address: '127.0.0.1',
+ netmask: '255.0.0.0',
+ family: 'IPv4',
+ mac: '00:00:00:00:00:00',
+ internal: true,
+ cidr: '127.0.0.1/8'
+ }];
+ assert.deepStrictEqual(actual, expected);
+ break;
+ }
+}
+const netmaskToCIDRSuffixMap = new Map(Object.entries({
+ '255.0.0.0': 8,
+ '255.255.255.0': 24,
+ 'ffff:ffff:ffff:ffff::': 64,
+ 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff': 128
+}));
+
+Object.values(interfaces)
+ .flat(Infinity)
+ .map((v) => ({ v, mask: netmaskToCIDRSuffixMap.get(v.netmask) }))
+ .forEach(({ v, mask }) => {
+ assert.ok('cidr' in v, `"cidr" prop not found in ${inspect(v)}`);
+ if (mask) {
+ assert.strictEqual(v.cidr, `${v.address}/${mask}`);
+ }
+ });
+
+const EOL = os.EOL;
+if (common.isWindows) {
+ assert.strictEqual(EOL, '\r\n');
+} else {
+ assert.strictEqual(EOL, '\n');
+}
+
+const home = os.homedir();
+is.string(home);
+assert.ok(home.includes(path.sep));
+
+const version = os.version();
+assert.strictEqual(typeof version, 'string');
+assert(version);
+
+if (common.isWindows && process.env.USERPROFILE) {
+ assert.strictEqual(home, process.env.USERPROFILE);
+ delete process.env.USERPROFILE;
+ assert.ok(os.homedir().includes(path.sep));
+ process.env.USERPROFILE = home;
+} else if (!common.isWindows && process.env.HOME) {
+ assert.strictEqual(home, process.env.HOME);
+ delete process.env.HOME;
+ assert.ok(os.homedir().includes(path.sep));
+ process.env.HOME = home;
+}
+
+const pwd = os.userInfo();
+is.object(pwd);
+const pwdBuf = os.userInfo({ encoding: 'buffer' });
+
+if (common.isWindows) {
+ assert.strictEqual(pwd.uid, -1);
+ assert.strictEqual(pwd.gid, -1);
+ assert.strictEqual(pwd.shell, null);
+ assert.strictEqual(pwdBuf.uid, -1);
+ assert.strictEqual(pwdBuf.gid, -1);
+ assert.strictEqual(pwdBuf.shell, null);
+} else {
+ is.number(pwd.uid);
+ is.number(pwd.gid);
+ assert.strictEqual(typeof pwd.shell, 'string');
+ // It's possible for /etc/passwd to leave the user's shell blank.
+ if (pwd.shell.length > 0) {
+ assert(pwd.shell.includes(path.sep));
+ }
+ assert.strictEqual(pwd.uid, pwdBuf.uid);
+ assert.strictEqual(pwd.gid, pwdBuf.gid);
+ assert.strictEqual(pwd.shell, pwdBuf.shell.toString('utf8'));
+}
+
+is.string(pwd.username);
+assert.ok(pwd.homedir.includes(path.sep));
+assert.strictEqual(pwd.username, pwdBuf.username.toString('utf8'));
+assert.strictEqual(pwd.homedir, pwdBuf.homedir.toString('utf8'));
+
+assert.strictEqual(`${os.hostname}`, os.hostname());
+assert.strictEqual(`${os.homedir}`, os.homedir());
+assert.strictEqual(`${os.release}`, os.release());
+assert.strictEqual(`${os.type}`, os.type());
+assert.strictEqual(`${os.endianness}`, os.endianness());
+assert.strictEqual(`${os.tmpdir}`, os.tmpdir());
+assert.strictEqual(`${os.arch}`, os.arch());
+assert.strictEqual(`${os.platform}`, os.platform());
+assert.strictEqual(`${os.version}`, os.version());
+assert.strictEqual(`${os.machine}`, os.machine());
+assert.strictEqual(+os.totalmem, os.totalmem());
+
+// Assert that the following values are coercible to numbers.
+// On IBMi, os.uptime() returns 'undefined'
+if (!common.isIBMi) {
+ is.number(+os.uptime, 'uptime');
+ is.number(os.uptime(), 'uptime');
+}
+
+is.number(+os.availableParallelism, 'availableParallelism');
+is.number(os.availableParallelism(), 'availableParallelism');
+is.number(+os.freemem, 'freemem');
+is.number(os.freemem(), 'freemem');
+
+const devNull = os.devNull;
+if (common.isWindows) {
+ assert.strictEqual(devNull, '\\\\.\\nul');
+} else {
+ assert.strictEqual(devNull, '/dev/null');
+}
+
+assert.ok(os.availableParallelism() > 0);
diff --git a/tests/node_compat/test/pseudo-tty/package.json b/tests/node_compat/test/pseudo-tty/package.json
deleted file mode 100644
index 0967ef424..000000000
--- a/tests/node_compat/test/pseudo-tty/package.json
+++ /dev/null
@@ -1 +0,0 @@
-{}
diff --git a/tests/node_compat/test/pummel/package.json b/tests/node_compat/test/pummel/package.json
deleted file mode 100644
index 0967ef424..000000000
--- a/tests/node_compat/test/pummel/package.json
+++ /dev/null
@@ -1 +0,0 @@
-{}
diff --git a/tests/node_compat/test/sequential/package.json b/tests/node_compat/test/sequential/package.json
deleted file mode 100644
index 0967ef424..000000000
--- a/tests/node_compat/test/sequential/package.json
+++ /dev/null
@@ -1 +0,0 @@
-{}