mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 04:51:22 +00:00
5c1fa0cf9c
Depends on #22493. Closes #22367.
28 lines
895 B
TypeScript
28 lines
895 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
import { assertStrictEquals } from "./test_util.ts";
|
|
|
|
Deno.test(
|
|
{ permissions: { net: ["127.0.0.1"] } },
|
|
async function eventSourceColonInMessage() {
|
|
const portDeferred = Promise.withResolvers<number>();
|
|
|
|
await using _server = Deno.serve({
|
|
handler: () =>
|
|
new Response('data: {"key":"value"}\n\n', {
|
|
headers: { "content-type": "text/event-stream" },
|
|
}),
|
|
onListen: ({ port }) => portDeferred.resolve(port),
|
|
hostname: "127.0.0.1",
|
|
port: 0,
|
|
});
|
|
|
|
const port = await portDeferred.promise;
|
|
const eventSource = new EventSource(`http://127.0.0.1:${port}/`);
|
|
const event = await new Promise<MessageEvent>((resolve) =>
|
|
eventSource.onmessage = resolve
|
|
);
|
|
eventSource.close();
|
|
assertStrictEquals(event.data, '{"key":"value"}');
|
|
},
|
|
);
|