mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
fix: add io ops to worker to fix fetch (#4054)
This commit is contained in:
parent
6dd9643845
commit
d9efb8c02a
5 changed files with 37 additions and 4 deletions
|
@ -38,9 +38,7 @@ impl CompilerWorker {
|
||||||
// TODO(bartlomieju): CompilerWorker should not
|
// TODO(bartlomieju): CompilerWorker should not
|
||||||
// depend on those ops
|
// depend on those ops
|
||||||
ops::os::init(isolate, &state);
|
ops::os::init(isolate, &state);
|
||||||
ops::files::init(isolate, &state);
|
|
||||||
ops::fs::init(isolate, &state);
|
ops::fs::init(isolate, &state);
|
||||||
ops::io::init(isolate, &state);
|
|
||||||
}
|
}
|
||||||
Self(worker)
|
Self(worker)
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,10 +57,14 @@ import "./url_search_params_test.ts";
|
||||||
import "./utime_test.ts";
|
import "./utime_test.ts";
|
||||||
import "./write_file_test.ts";
|
import "./write_file_test.ts";
|
||||||
import "./performance_test.ts";
|
import "./performance_test.ts";
|
||||||
import "./permissions_test.ts";
|
|
||||||
import "./version_test.ts";
|
import "./version_test.ts";
|
||||||
import "./workers_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) {
|
if (import.meta.main) {
|
||||||
await Deno.runTests();
|
await Deno.runTests();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// 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> {
|
export interface ResolvableMethods<T> {
|
||||||
resolve: (value?: T | PromiseLike<T>) => void;
|
resolve: (value?: T | PromiseLike<T>) => void;
|
||||||
|
@ -82,3 +82,24 @@ test(async function workerThrowsWhenExecuting(): Promise<void> {
|
||||||
|
|
||||||
await promise;
|
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;
|
||||||
|
});
|
||||||
|
|
6
cli/tests/subdir/fetching_worker.js
Normal file
6
cli/tests/subdir/fetching_worker.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
const r = await fetch(
|
||||||
|
"http://localhost:4545/cli/tests/subdir/fetching_worker.js"
|
||||||
|
);
|
||||||
|
await r.text();
|
||||||
|
postMessage("Done!");
|
||||||
|
close();
|
|
@ -36,9 +36,13 @@ impl WebWorker {
|
||||||
ops::runtime::init(isolate, &state);
|
ops::runtime::init(isolate, &state);
|
||||||
ops::web_worker::init(isolate, &state, &worker.internal_channels.sender);
|
ops::web_worker::init(isolate, &state, &worker.internal_channels.sender);
|
||||||
ops::worker_host::init(isolate, &state);
|
ops::worker_host::init(isolate, &state);
|
||||||
|
ops::io::init(isolate, &state);
|
||||||
ops::errors::init(isolate, &state);
|
ops::errors::init(isolate, &state);
|
||||||
ops::timers::init(isolate, &state);
|
ops::timers::init(isolate, &state);
|
||||||
ops::fetch::init(isolate, &state);
|
ops::fetch::init(isolate, &state);
|
||||||
|
// FIXME(bartlomieju): this is added only to provide "close"
|
||||||
|
// op - it should be moved to `ops::io`
|
||||||
|
ops::files::init(isolate, &state);
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
|
Loading…
Add table
Reference in a new issue