diff options
Diffstat (limited to 'cli/tests/unit_node/net_test.ts')
-rw-r--r-- | cli/tests/unit_node/net_test.ts | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/cli/tests/unit_node/net_test.ts b/cli/tests/unit_node/net_test.ts index 442f7e61e..3b78cbe32 100644 --- a/cli/tests/unit_node/net_test.ts +++ b/cli/tests/unit_node/net_test.ts @@ -1,11 +1,13 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import * as net from "node:net"; -import { assertEquals } from "../../../test_util/std/testing/asserts.ts"; +import { + assert, + assertEquals, +} from "../../../test_util/std/testing/asserts.ts"; import { deferred } from "../../../test_util/std/async/deferred.ts"; import * as path from "../../../test_util/std/path/mod.ts"; import * as http from "node:http"; -import { assert } from "../../../test_util/std/testing/asserts.ts"; Deno.test("[node/net] close event emits after error event", async () => { const socket = net.createConnection(27009, "doesnotexist"); @@ -96,3 +98,35 @@ Deno.test({ } }, }); + +Deno.test("[node/net] connection event has socket value", async () => { + const p = deferred(); + const p2 = deferred(); + + const server = net.createServer(); + server.on("error", p.reject); + server.on("connection", (socket) => { + assert(socket !== undefined); + socket.end(); + server.close(() => { + p.resolve(); + }); + }); + server.listen(async () => { + // deno-lint-ignore no-explicit-any + const { port } = server.address() as any; + + const conn = await Deno.connect({ + port, + transport: "tcp", + }); + + for await (const _ of conn.readable) { + // + } + + p2.resolve(); + }); + + await Promise.all([p, p2]); +}); |