diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-02-21 10:35:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-21 10:35:41 -0500 |
commit | d9efb8c02a0036d755c35e8e9c88d58bd45a9e2b (patch) | |
tree | 2ebce022c1c8b286cfb31845f145d8249f7b395e /cli/js | |
parent | 6dd964384509e71598d08ae09c59f5f2c035a135 (diff) |
fix: add io ops to worker to fix fetch (#4054)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/unit_tests.ts | 6 | ||||
-rw-r--r-- | cli/js/workers_test.ts | 23 |
2 files changed, 27 insertions, 2 deletions
diff --git a/cli/js/unit_tests.ts b/cli/js/unit_tests.ts index c43abaa5c..0bdd17964 100644 --- a/cli/js/unit_tests.ts +++ b/cli/js/unit_tests.ts @@ -57,10 +57,14 @@ import "./url_search_params_test.ts"; import "./utime_test.ts"; import "./write_file_test.ts"; import "./performance_test.ts"; -import "./permissions_test.ts"; import "./version_test.ts"; import "./workers_test.ts"; +// FIXME(bartlomieju): +// This test file revokes permissions, it must be run last, +// otherwise it might revoke permission for tests that need them. +import "./permissions_test.ts"; + if (import.meta.main) { await Deno.runTests(); } diff --git a/cli/js/workers_test.ts b/cli/js/workers_test.ts index 9cb4f4a07..eccf83f65 100644 --- a/cli/js/workers_test.ts +++ b/cli/js/workers_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test, assert, assertEquals } from "./test_util.ts"; +import { test, testPerm, assert, assertEquals } from "./test_util.ts"; export interface ResolvableMethods<T> { resolve: (value?: T | PromiseLike<T>) => void; @@ -82,3 +82,24 @@ test(async function workerThrowsWhenExecuting(): Promise<void> { await promise; }); + +testPerm({ net: true }, async function workerCanUseFetch(): Promise<void> { + const promise = createResolvable(); + + const fetchingWorker = new Worker("../tests/subdir/fetching_worker.js", { + type: "module" + }); + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + fetchingWorker.onerror = (e: any): void => { + e.preventDefault(); + promise.reject(e.message); + }; + + fetchingWorker.onmessage = (e): void => { + assert(e.data === "Done!"); + promise.resolve(); + }; + + await promise; +}); |