deno/tests/unit_node
Nicholas R bc9d356059
Some checks are pending
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / build libs (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
fix(node/net): return string family in server.address() (#31465)
## Summary

Aligns Deno's Node.js compatibility layer (`node:net`, `node:http`,
`node:https`,
`node:http2`, `node:dns`) with Node.js v18.4.0+ behavior by returning
the `family`
property as a string (`"IPv4"` or `"IPv6"`) rather than a number in
`server.address()`
   and socket address methods.

Node.js briefly changed `family` from string to number in v18.0.0
(nodejs/node#41431),
   but reverted in v18.4.0 (nodejs/node#43054) due to ecosystem breakage
   (nodejs/node#43014).

This fix ensures compatibility with npm packages that rely on the string
format, which
   has been the stable API since Node.js v18.4.0.

   ## Changes

- Modified `ext/node/polyfills/http.ts` to add `family` property to
`address()` return
- Modified `ext/node/polyfills/internal_binding/tcp_wrap.ts` to return
string `family`
instead of number in `getsockname()`, `getpeername()`, and `#connect()`
- Modified `ext/node/polyfills/net.ts` to fix `socket.remoteFamily`
getter (no longer
   needs conversion since `family` is now a string)
   - Modified `ext/node/polyfills/dns.ts` and
`ext/node/polyfills/internal/dns/promises.ts` to accept string family
values (`"IPv4"`,
`"IPv6"`) in `lookup()`, matching [Node.js
behavior](https://nodejs.org/api/dns.html#dnslookuphostname-options-callback)
- Added tests in `tests/unit_node/http_test.ts`,
`tests/unit_node/http2_test.ts`,
   `tests/unit_node/https_test.ts`, `tests/unit_node/dns_test.ts`, and
   `tests/unit_node/net_test.ts`

   ## Node.js Compatibility Note

For non-IP addresses (when `isIP()` returns 0), the `family` property is
`undefined`.
This matches Node.js C++ behavior in
[`AddressToJS`](https://github.com/nodejs/node/blob/main/src/tcp_wrap.cc)
where family
is only set for `AF_INET` (`"IPv4"`) and `AF_INET6` (`"IPv6"`), and left
undefined
   otherwise.

   ## Refs

   - nodejs/node#43054
   - nodejs/node@70b516e


<!--
Before submitting a PR, please read
https://docs.deno.com/runtime/manual/references/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't
run
   all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench'
label.
-->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Daniel Rahmanto <daniel.rahmanto@gmail.com>
2025-12-06 10:51:55 +07:00
..
_fs fix(ext/node): FileHandle compatibility (#31164) 2025-11-14 12:17:45 +07:00
crypto fix(ext/node): autopadding behavior on crypto.Cipheriv (#31389) 2025-11-24 18:33:57 +07:00
internal fix(ext/node): avoid panic when crypto.randomInt has no arguments (#30314) 2025-08-05 17:09:39 +02:00
testdata fix(ext/node): inspect X509Certificate class (#30882) 2025-10-03 13:49:56 +05:30
_test_utils.ts fix(ext/node): fs.stat and fs.statSync compatibility (#30866) 2025-10-03 11:34:01 -04:00
assert_test.ts fix(node/assert): deepStrictEqual now correctly handles Number objects (#31233) 2025-11-18 09:02:21 +07:00
assertion_error_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
async_hooks_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
buffer_test.ts fix(ext/node): truncate first non-hex value on Buffer.from (#31227) 2025-11-10 18:32:09 +07:00
child_process_test.ts fix(node): support advanced serialization in IPC (#31380) 2025-11-26 23:15:32 +00:00
cluster_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
console_test.ts fix(node:console): ensure that the node:console implementation has an implementation for emitWarning in scope (#31263) 2025-11-13 10:33:50 +01:00
dgram_test.ts fix(ext/node): honor flags with respect to reuseAddress when binding to a UDP socket (#28156) 2025-04-22 17:49:14 +09:00
dns_test.ts fix(node/net): return string family in server.address() (#31465) 2025-12-06 10:51:55 +07:00
domain_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
events_test.ts fix(node): use primordials more consistently in _events.mjs (#29930) 2025-06-28 19:03:21 +02:00
fetch_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
fs_test.ts feat(ext/node): implement FileHandle.appendFile(data[, options]) (#31301) 2025-11-17 08:57:04 +01:00
http2_test.ts fix(node/net): return string family in server.address() (#31465) 2025-12-06 10:51:55 +07:00
http_no_cert_flag_test.ts fix(ext/node): Support mTLS connections node compatibility (#28937) 2025-05-06 14:25:18 +05:30
http_test.ts fix(node/net): return string family in server.address() (#31465) 2025-12-06 10:51:55 +07:00
https_test.ts fix(node/net): return string family in server.address() (#31465) 2025-12-06 10:51:55 +07:00
inspector_test.ts fix(ext/node): handle multiple calls in inspector.Session.post() (#31067) 2025-10-27 10:46:55 +01:00
module_test.ts fix(ext/node): Module.wrap cleanup for npm:v8-code-cache (#29725) 2025-06-17 02:32:10 +02:00
net_test.ts fix(node/net): return string family in server.address() (#31465) 2025-12-06 10:51:55 +07:00
os_test.ts fix(ext/node): os.setPriority and os.getPriority compatibility (#30383) 2025-08-18 19:07:28 +02:00
path_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
perf_hooks_test.ts fix(ext/node): add back perf_hooks.markResourceTiming (#29562) 2025-06-02 17:53:38 +05:30
process_test.ts fix(node/process): make process.stdin.isTTY writable (#31464) 2025-12-02 00:37:23 +01:00
punycode_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
querystring_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
readline_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
repl_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
sqlite_test.ts fix(ext/node): implement DatabaseSync.function() and better error details (#31386) 2025-11-25 14:14:27 +00:00
stream_test.ts fix(ext/node): export promises from stream (#30427) 2025-08-17 18:56:29 +05:30
string_decoder_test.ts fix(ext/node): accept base64url encoding on StringDecoder (#30366) 2025-08-10 18:49:14 +05:30
timers_test.ts fix(ext/node): implement performance.timerify() (#31238) 2025-11-12 13:55:02 +01:00
tls_test.ts fix(ext/node): support JS underlying stream in TLS (#30465) 2025-08-28 17:56:17 +05:30
tty_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
url_test.ts fix(ext/node): url.domainToASCII returns empty string for invalid domains (#31219) 2025-12-03 21:57:53 +07:00
util_test.ts fix(ext/node): implement util.getSystemErrorMessage() (#31147) 2025-11-03 11:24:06 +01:00
v8_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
vm_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
wasi_test.ts chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
worker_threads_test.ts fix(ext/node): ensure 'exit' event is fired only once for worker_threads (#31231) 2025-11-12 14:15:44 +01:00
zlib_test.ts fix(ext/node): omit smi from zlib.crc32 op function (#30907) 2025-10-03 13:57:30 -07:00