mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
616354e76c
Closes #21041 --------- Signed-off-by: Asher Gomez <ashersaupingomez@gmail.com>
25 lines
812 B
TypeScript
25 lines
812 B
TypeScript
import { assertEquals } from "../../../../test_util/std/testing/asserts.ts";
|
|
|
|
const errorDeferred = Promise.withResolvers<void>();
|
|
const closeDeferred = Promise.withResolvers<void>();
|
|
|
|
const listener = Deno.listen({ port: 4509 });
|
|
console.log("READY");
|
|
const httpConn = Deno.serveHttp(await listener.accept());
|
|
const { request, respondWith } = (await httpConn.nextRequest())!;
|
|
const { response, socket } = Deno.upgradeWebSocket(request, {
|
|
idleTimeout: 1,
|
|
});
|
|
socket.onerror = (e) => {
|
|
assertEquals((e as ErrorEvent).message, "No response from ping frame.");
|
|
errorDeferred.resolve();
|
|
};
|
|
socket.onclose = (e) => {
|
|
assertEquals(e.reason, "No response from ping frame.");
|
|
closeDeferred.resolve();
|
|
};
|
|
await respondWith(response);
|
|
|
|
await errorDeferred.promise;
|
|
await closeDeferred.promise;
|
|
listener.close();
|