1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-20 20:42:19 -05:00

move test case to tests/specs as NPM_CONFIG_REGISTRY is not set in js unit test

This commit is contained in:
Yoshiya Hinosawa 2025-01-20 18:10:38 +09:00
parent 69bab0352e
commit 7d3c4ac956
No known key found for this signature in database
GPG key ID: 9017DB4559488785
4 changed files with 51 additions and 33 deletions

View file

@ -0,0 +1,9 @@
{
"tests": {
"resolve_dns": {
"args": "test --allow-net=127.0.0.1 test.ts",
"output": "test.out",
"exitCode": 0
}
}
}

View file

@ -0,0 +1,6 @@
[WILDCARD]
running 1 test from ./test.ts
EDNS0 enabled ... ok ([WILDCARD]s)
ok | 1 passed | 0 failed ([WILDCARD]s)

View file

@ -0,0 +1,36 @@
// Copyright 2018-2025 the Deno authors. MIT license.
import dns2 from "npm:dns2@2.1.0";
Deno.test("EDNS0 enabled", async () => {
// With EDNS0 enabled, Deno.resolveDns can handle 44 A records.
const NUM_RECORD = 44;
const { Packet } = dns2;
const server = dns2.createServer({
udp: true,
// deno-lint-ignore no-explicit-any
handle(request: any, send: any) {
const response = Packet.createResponseFromRequest(request);
const { name } = request.questions[0];
for (const i of [...Array(NUM_RECORD).keys()]) {
response.answers.push({
name,
type: Packet.TYPE.A,
class: Packet.CLASS.IN,
ttl: 300,
address: "1.2.3." + i,
});
}
send(response);
},
});
const { udp: { port } } = await server.listen({
udp: { port: 0, address: "127.0.0.1", type: "udp4" },
});
const addr = await Deno.resolveDns("example.com", "A", {
nameServer: { ipAddr: "127.0.0.1", port },
});
if (addr.length !== NUM_RECORD) {
throw new Error(`Expected ${NUM_RECORD} records, got ${addr.length}`);
}
await server.close();
});

View file

@ -9,7 +9,6 @@ import {
execCode2,
tmpUnixSocketPath,
} from "./test_util.ts";
import dns2 from "npm:dns2@2.1.0";
// Since these tests may run in parallel, ensure this port is unique to this file
const listenPort = 4503;
@ -1328,35 +1327,3 @@ Deno.test(
// calling [Symbol.dispose] after manual close is a no-op
},
);
Deno.test({ permissions: { net: true } }, async function resolveDnsEdns0() {
// With EDNS0 enabled, Deno.resolveDns can handle 44 A records.
const NUM_RECORD = 44;
const { Packet } = dns2;
const server = dns2.createServer({
udp: true,
// deno-lint-ignore no-explicit-any
handle(request: any, send: any) {
const response = Packet.createResponseFromRequest(request);
const { name } = request.questions[0];
for (const i of [...Array(NUM_RECORD).keys()]) {
response.answers.push({
name,
type: Packet.TYPE.A,
class: Packet.CLASS.IN,
ttl: 300,
address: "1.2.3." + i,
});
}
send(response);
},
});
const { udp: { port } } = await server.listen({
udp: { port: 0, address: "127.0.0.1", type: "udp4" },
});
const addr = await Deno.resolveDns("example.com", "A", {
nameServer: { ipAddr: "127.0.0.1", port },
});
assertEquals(addr.length, NUM_RECORD);
await server.close();
});