summaryrefslogtreecommitdiff
path: root/tests/unit/event_source_test.ts
diff options
context:
space:
mode:
authorud2 <sjx233@qq.com>2024-03-25 22:31:13 +0800
committerGitHub <noreply@github.com>2024-03-25 07:31:13 -0700
commit5c1fa0cf9cbe4301082b6cad343d42ef4c414c0d (patch)
treefb0b360146bf9bc59c7987e965dec3c7ee177f6a /tests/unit/event_source_test.ts
parentbf9c57aeac7c9d03a382cc7bfb54cc41ddaf1f27 (diff)
fix(ext/fetch): do not truncate field value in `EventSource` (#22368)
Depends on #22493. Closes #22367.
Diffstat (limited to 'tests/unit/event_source_test.ts')
-rw-r--r--tests/unit/event_source_test.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/unit/event_source_test.ts b/tests/unit/event_source_test.ts
new file mode 100644
index 000000000..242c12d6e
--- /dev/null
+++ b/tests/unit/event_source_test.ts
@@ -0,0 +1,27 @@
+// 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"}');
+ },
+);