From d6ad653aeb2f55faed95dc48a4531af4b8f8ca80 Mon Sep 17 00:00:00 2001 From: cirospaciari Date: Mon, 4 Mar 2024 11:13:04 -0300 Subject: [PATCH] fix dns tests to match behavior on windows (same as nodejs) --- test/js/bun/dns/resolve-dns.test.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/js/bun/dns/resolve-dns.test.ts b/test/js/bun/dns/resolve-dns.test.ts index 8073938657..4835227827 100644 --- a/test/js/bun/dns/resolve-dns.test.ts +++ b/test/js/bun/dns/resolve-dns.test.ts @@ -1,4 +1,4 @@ -import { dns } from "bun"; +import { SystemError, dns } from "bun"; import { describe, expect, it, test } from "bun:test"; import { withoutAggressiveGC } from "harness"; import { isIP, isIPv4, isIPv6 } from "node:net"; @@ -7,7 +7,7 @@ const backends = ["system", "libc", "c-ares"]; const validHostnames = ["localhost", "example.com"]; const invalidHostnames = ["adsfa.asdfasdf.asdf.com"]; // known invalid const malformedHostnames = ["", " ", ".", " .", "localhost:80", "this is not a hostname"]; - +const isWindows = process.platform === "win32"; describe("dns", () => { describe.each(backends)("lookup() [backend: %s]", backend => { describe.each(validHostnames)("%s", hostname => { @@ -45,6 +45,23 @@ describe("dns", () => { address: isIP, }, ])("%j", async ({ options, address: expectedAddress, family: expectedFamily }) => { + // this behavior matchs nodejs + const expect_to_fail = + isWindows && + backend !== "c-ares" && + (options.family === "IPv6" || options.family === 6) && + hostname !== "localhost"; + if (expect_to_fail) { + try { + // @ts-expect-error + await dns.lookup(hostname, options); + expect.unreachable(); + } catch (err: unknown) { + expect(err).toBeDefined(); + expect((err as SystemError).code).toBe("DNS_ENOTFOUND"); + } + return; + } // @ts-expect-error const result = await dns.lookup(hostname, options); expect(result).toBeArray();