From 15ffdd2624108f99960fc2da86e4f751e32bfd16 Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Tue, 20 Apr 2021 19:56:31 +0530 Subject: fix(runtime): include HTTP op in WebWorker (#10207) --- cli/tests/workers/http_worker.js | 10 ++++++++++ cli/tests/workers/test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 cli/tests/workers/http_worker.js (limited to 'cli') diff --git a/cli/tests/workers/http_worker.js b/cli/tests/workers/http_worker.js new file mode 100644 index 000000000..ee2e5397e --- /dev/null +++ b/cli/tests/workers/http_worker.js @@ -0,0 +1,10 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +const listener = Deno.listen({ hostname: "127.0.0.1", port: 4500 }); +for await (const conn of listener) { + (async () => { + const requests = Deno.serveHttp(conn); + for await (const { respondWith } of requests) { + respondWith(new Response("Hello world")); + } + })(); +} diff --git a/cli/tests/workers/test.ts b/cli/tests/workers/test.ts index e5e9e44f7..72b87e398 100644 --- a/cli/tests/workers/test.ts +++ b/cli/tests/workers/test.ts @@ -697,3 +697,27 @@ Deno.test({ worker.terminate(); }, }); + +Deno.test({ + name: "Worker with native HTTP", + fn: async function () { + const worker = new Worker( + new URL( + "./http_worker.js", + import.meta.url, + ).href, + { + type: "module", + deno: { + namespace: true, + permissions: "inherit", + }, + }, + ); + + assert(worker); + const response = await fetch("http://localhost:4500"); + assert(await response.arrayBuffer()); + worker.terminate(); + }, +}); -- cgit v1.2.3