1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

chore: use import.meta.resolve() in tests (#15256)

This commit is contained in:
Bartek Iwańczuk 2022-07-20 16:56:53 +02:00 committed by GitHub
parent 73504d76b2
commit d17b3906bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 71 additions and 74 deletions

View file

@ -1,4 +1,4 @@
new Worker(
new URL("084_worker_custom_inspect_worker.ts", import.meta.url).href,
import.meta.resolve("./084_worker_custom_inspect_worker.ts"),
{ type: "module" },
);

View file

@ -1,2 +1,2 @@
const url = new URL("./imported.js", import.meta.url);
await import(url.href);
const url = import.meta.resolve("./imported.js");
await import(url);

View file

@ -1,8 +1,8 @@
import { deferred } from "../../../../../test_util/std/async/deferred.ts";
const promise = deferred();
const url = new URL("./worker.mjs", import.meta.url);
const worker = new Worker(url.href, { type: "module" });
const url = import.meta.resolve("./worker.mjs");
const worker = new Worker(url, { type: "module" });
worker.onmessage = (e) => {
const pid = e.data.pid;

View file

@ -1,4 +1,4 @@
new Worker(
new URL("./subdeb/worker_types.ts", import.meta.url).toString(),
import.meta.resolve("./subdeb/worker_types.ts"),
{ type: "module" },
);

View file

@ -1,4 +1,4 @@
new Worker(
new URL("event_listener_error_immediate_exit.ts", import.meta.url).href,
import.meta.resolve("./event_listener_error_immediate_exit.ts"),
{ type: "module" },
);

View file

@ -6,7 +6,7 @@
Deno.core.opSync("op_set_exit_code", 21);
const worker = new Worker(
new URL("op_exit_op_set_exit_code_worker.js", import.meta.url).href,
import.meta.resolve("./op_exit_op_set_exit_code_worker.js"),
{ type: "module" },
);

View file

@ -4,14 +4,14 @@ await import("./single_compile_with_reload_dyn.ts");
console.log("2");
await new Promise((r) =>
new Worker(
new URL("single_compile_with_reload_worker.ts", import.meta.url).href,
import.meta.resolve("single_compile_with_reload_worker.ts"),
{ type: "module" },
).onmessage = r
);
console.log("3");
await new Promise((r) =>
new Worker(
new URL("single_compile_with_reload_worker.ts", import.meta.url).href,
import.meta.resolve("single_compile_with_reload_worker.ts"),
{ type: "module" },
).onmessage = r
);

View file

@ -21,7 +21,7 @@ Deno.test("output", async () => {
});
await c.status;
const worker = new Worker(
new URL("./captured_output.worker.js", import.meta.url).href,
import.meta.resolve("./captured_output.worker.js"),
{ type: "module" },
);

View file

@ -1,5 +1,5 @@
const w = new Worker(
new URL("workers/worker_unstable.ts", import.meta.url).href,
import.meta.resolve("./workers/worker_unstable.ts"),
{ type: "module", name: "Unstable Worker" },
);

View file

@ -5,6 +5,6 @@
// WASM async operation.
new Worker(
new URL("./workers/close_in_wasm_reactions.js", import.meta.url),
import.meta.resolve("./workers/close_in_wasm_reactions.js"),
{ type: "module" },
);

View file

@ -6,7 +6,7 @@
console.log("Starting the main thread");
const worker = new Worker(
new URL("./workers/close_nested_parent.js", import.meta.url),
import.meta.resolve("./workers/close_nested_parent.js"),
{ type: "module" },
);

View file

@ -5,7 +5,7 @@
// `Worker.prototype.terminate()`.
const worker = new Worker(
new URL("./workers/close_race_worker.js", import.meta.url),
import.meta.resolve("./workers/close_race_worker.js"),
{ type: "module" },
);

View file

@ -7,6 +7,6 @@
// The exception thrown in the worker will not terminate the worker, but it will
// propagate to the main thread and cause it to exit.
new Worker(
new URL("./workers/drop_handle_race.js", import.meta.url).href,
import.meta.resolve("./workers/drop_handle_race.js"),
{ type: "module" },
);

View file

@ -1,5 +1,5 @@
const w = new Worker(
new URL("./workers/worker_event_handlers.js", import.meta.url).href,
import.meta.resolve("./workers/worker_event_handlers.js"),
{ type: "module" },
);
w.postMessage({});

View file

@ -2,7 +2,7 @@ const messagesReceived = new Set();
for (let i = 0; i < 4; i++) {
const worker = new Worker(
new URL("./workers/message_before_close.js", import.meta.url).href,
import.meta.resolve("./workers/message_before_close.js"),
{ type: "module", name: String(i) },
);

View file

@ -4,7 +4,7 @@ function oneWorker(i: number) {
return new Promise<void>((resolve) => {
let countDown = 10;
const worker = new Worker(
new URL("worker_large_message.js", import.meta.url).href,
import.meta.resolve("./worker_large_message.js"),
{ type: "module" },
);
worker.onmessage = (_e) => {

View file

@ -25,7 +25,7 @@ async function main() {
const workers: Array<[Map<number, Deferred<string>>, Worker]> = [];
for (let i = 1; i <= workerCount; ++i) {
const worker = new Worker(
new URL("bench_worker.ts", import.meta.url).href,
import.meta.resolve("./bench_worker.ts"),
{ type: "module" },
);
const promise = deferred();

View file

@ -5,7 +5,7 @@ async function bench() {
const workers: Worker[] = [];
for (let i = 1; i <= workerCount; ++i) {
const worker = new Worker(
new URL("bench_worker.ts", import.meta.url).href,
import.meta.resolve("./bench_worker.ts"),
{ type: "module" },
);
const promise = new Promise<void>((resolve) => {

View file

@ -3,7 +3,7 @@
console.log("Starting the parent worker");
new Worker(
new URL("./close_nested_child.js", import.meta.url),
import.meta.resolve("./close_nested_child.js"),
{ type: "module" },
);

View file

@ -1,4 +1,4 @@
const worker = new Worker(new URL("error.ts", import.meta.url).href, {
const worker = new Worker(import.meta.resolve("./error.ts"), {
type: "module",
});
worker.addEventListener("error", (e) => {

View file

@ -1,6 +1,6 @@
// Specifier should be resolved relative to current file
const jsWorker = new Worker(
new URL("sibling_worker.js", import.meta.url).href,
import.meta.resolve("./sibling_worker.js"),
{ type: "module", name: "sibling" },
);

View file

@ -1,4 +1,4 @@
const w = new Worker(new URL("doesnt_exist.js", import.meta.url).href, {
const w = new Worker(import.meta.resolve("./doesnt_exist.js"), {
type: "module",
});

View file

@ -1,5 +1,5 @@
const worker = new Worker(
new URL("./read_check_granular_worker.js", import.meta.url).href,
import.meta.resolve("./read_check_granular_worker.js"),
{ type: "module", deno: { permissions: "none" } },
);

View file

@ -14,11 +14,11 @@ Deno.test({
name: "worker terminate",
fn: async function () {
const jsWorker = new Worker(
new URL("test_worker.js", import.meta.url).href,
import.meta.resolve("./test_worker.js"),
{ type: "module" },
);
const tsWorker = new Worker(
new URL("test_worker.ts", import.meta.url).href,
import.meta.resolve("./test_worker.ts"),
{ type: "module", name: "tsWorker" },
);
@ -64,7 +64,7 @@ Deno.test({
name: "worker nested",
fn: async function () {
const nestedWorker = new Worker(
new URL("nested_worker.js", import.meta.url).href,
import.meta.resolve("./nested_worker.js"),
{ type: "module", name: "nested" },
);
@ -83,7 +83,7 @@ Deno.test({
name: "worker throws when executing",
fn: async function () {
const throwingWorker = new Worker(
new URL("throwing_worker.js", import.meta.url).href,
import.meta.resolve("./throwing_worker.js"),
{ type: "module" },
);
@ -104,7 +104,7 @@ Deno.test({
fn: async function () {
const workerOptions: WorkerOptions = { type: "module" };
const w = new Worker(
new URL("worker_globals.ts", import.meta.url).href,
import.meta.resolve("./worker_globals.ts"),
workerOptions,
);
@ -123,7 +123,7 @@ Deno.test({
name: "worker fetch API",
fn: async function () {
const fetchingWorker = new Worker(
new URL("fetching_worker.js", import.meta.url).href,
import.meta.resolve("./fetching_worker.js"),
{ type: "module" },
);
@ -149,7 +149,7 @@ Deno.test({
const promise = deferred();
const busyWorker = new Worker(
new URL("busy_worker.js", import.meta.url),
import.meta.resolve("./busy_worker.js"),
{ type: "module" },
);
@ -181,7 +181,7 @@ Deno.test({
const promise = deferred();
const racyWorker = new Worker(
new URL("racy_worker.js", import.meta.url),
import.meta.resolve("./racy_worker.js"),
{ type: "module" },
);
@ -206,7 +206,7 @@ Deno.test({
const promise2 = deferred();
const worker = new Worker(
new URL("event_worker.js", import.meta.url),
import.meta.resolve("./event_worker.js"),
{ type: "module" },
);
@ -248,7 +248,7 @@ Deno.test({
name: "worker scope is event listener",
fn: async function () {
const worker = new Worker(
new URL("event_worker_scope.js", import.meta.url),
import.meta.resolve("./event_worker_scope.js"),
{ type: "module" },
);
@ -274,7 +274,7 @@ Deno.test({
name: "worker with Deno namespace",
fn: async function () {
const denoWorker = new Worker(
new URL("deno_worker.ts", import.meta.url),
import.meta.resolve("./deno_worker.ts"),
{ type: "module", deno: { permissions: "inherit" } },
);
@ -293,7 +293,7 @@ Deno.test({
name: "worker with crypto in scope",
fn: async function () {
const w = new Worker(
new URL("worker_crypto.js", import.meta.url).href,
import.meta.resolve("./worker_crypto.js"),
{ type: "module" },
);
@ -313,7 +313,7 @@ Deno.test({
fn: async function () {
const promise = deferred();
const w = new Worker(
new URL("test_worker.ts", import.meta.url).href,
import.meta.resolve("./test_worker.ts"),
{ type: "module", name: "tsWorker" },
);
const arr: number[] = [];
@ -337,7 +337,7 @@ Deno.test({
fn: async function () {
const promise = deferred();
const w = new Worker(
new URL("./immediately_close_worker.js", import.meta.url).href,
import.meta.resolve("./immediately_close_worker.js"),
{ type: "module" },
);
setTimeout(() => {
@ -353,7 +353,7 @@ Deno.test({
fn: async function () {
const promise = deferred();
const worker = new Worker(
new URL("./post_undefined.ts", import.meta.url).href,
import.meta.resolve("./post_undefined.ts"),
{ type: "module" },
);
@ -375,7 +375,7 @@ Deno.test({
Deno.test("Worker inherits permissions", async function () {
const worker = new Worker(
new URL("./read_check_worker.js", import.meta.url).href,
import.meta.resolve("./read_check_worker.js"),
{ type: "module", deno: { permissions: "inherit" } },
);
@ -391,7 +391,7 @@ Deno.test("Worker inherits permissions", async function () {
Deno.test("Worker limit children permissions", async function () {
const worker = new Worker(
new URL("./read_check_worker.js", import.meta.url).href,
import.meta.resolve("./read_check_worker.js"),
{ type: "module", deno: { permissions: { read: false } } },
);
@ -407,7 +407,7 @@ Deno.test("Worker limit children permissions", async function () {
Deno.test("Worker limit children permissions granularly", async function () {
const worker = new Worker(
new URL("./read_check_granular_worker.js", import.meta.url).href,
import.meta.resolve("./read_check_granular_worker.js"),
{
type: "module",
deno: {
@ -459,7 +459,7 @@ Deno.test("Worker limit children permissions granularly", async function () {
Deno.test("Nested worker limit children permissions", async function () {
/** This worker has permissions but doesn't grant them to its children */
const worker = new Worker(
new URL("./parent_read_check_worker.js", import.meta.url).href,
import.meta.resolve("./parent_read_check_worker.js"),
{ type: "module", deno: { permissions: "inherit" } },
);
const promise = deferred();
@ -504,7 +504,7 @@ Deno.test({
assertThrows(
() => {
const worker = new Worker(
new URL("./deno_worker.ts", import.meta.url).href,
import.meta.resolve("./deno_worker.ts"),
{ type: "module", deno: { permissions: { env: true } } },
);
worker.terminate();
@ -517,7 +517,7 @@ Deno.test({
Deno.test("Worker with disabled permissions", async function () {
const worker = new Worker(
new URL("./no_permissions_worker.js", import.meta.url).href,
import.meta.resolve("./no_permissions_worker.js"),
{ type: "module", deno: { permissions: "none" } },
);
@ -533,7 +533,7 @@ Deno.test("Worker with disabled permissions", async function () {
Deno.test("Worker permissions are not inherited with empty permission object", async function () {
const worker = new Worker(
new URL("./permission_echo.js", import.meta.url).href,
import.meta.resolve("./permission_echo.js"),
{ type: "module", deno: { permissions: {} } },
);
@ -557,7 +557,7 @@ Deno.test("Worker permissions are not inherited with empty permission object", a
Deno.test("Worker permissions are not inherited with single specified permission", async function () {
const worker = new Worker(
new URL("./permission_echo.js", import.meta.url).href,
import.meta.resolve("./permission_echo.js"),
{ type: "module", deno: { permissions: { net: true } } },
);
@ -596,8 +596,7 @@ Deno.test({
name: "worker location",
fn: async function () {
const promise = deferred();
const workerModuleHref =
new URL("worker_location.ts", import.meta.url).href;
const workerModuleHref = import.meta.resolve("./worker_location.ts");
const w = new Worker(workerModuleHref, { type: "module" });
w.onmessage = (e) => {
promise.resolve(e.data);
@ -631,7 +630,7 @@ Deno.test({
fn: async function () {
const result = deferred();
const worker = new Worker(
new URL("worker_with_top_level_await.ts", import.meta.url).href,
import.meta.resolve("./worker_with_top_level_await.ts"),
{ type: "module" },
);
worker.onmessage = (e) => {
@ -653,7 +652,7 @@ Deno.test({
fn: async function () {
const result = deferred();
const worker = new Worker(
new URL("./http_worker.js", import.meta.url).href,
import.meta.resolve("./http_worker.js"),
{ type: "module", deno: { permissions: "inherit" } },
);
worker.onmessage = () => {
@ -672,7 +671,7 @@ Deno.test({
name: "structured cloning postMessage",
fn: async function () {
const worker = new Worker(
new URL("worker_structured_cloning.ts", import.meta.url).href,
import.meta.resolve("./worker_structured_cloning.ts"),
{ type: "module" },
);
@ -726,7 +725,7 @@ Deno.test({
const promise = deferred();
const workerOptions: WorkerOptions = { type: "module" };
const w = new Worker(
new URL("shared_array_buffer.ts", import.meta.url).href,
import.meta.resolve("./shared_array_buffer.ts"),
workerOptions,
);
const sab1 = new SharedArrayBuffer(1);
@ -752,7 +751,7 @@ Deno.test({
name: "Send MessagePorts from / to workers",
fn: async function () {
const worker = new Worker(
new URL("message_port.ts", import.meta.url).href,
import.meta.resolve("./message_port.ts"),
{ type: "module" },
);
const channel = new MessageChannel();

View file

@ -1,5 +1,5 @@
const worker = new Worker(
new URL("async_error.ts", import.meta.url).href,
import.meta.resolve("./async_error.ts"),
{ type: "module", name: "foo" },
);
setTimeout(() => worker.terminate(), 30000);

View file

@ -1,5 +1,5 @@
const worker = new Worker(
new URL("error.ts", import.meta.url).href,
import.meta.resolve("./error.ts"),
{ type: "module", name: "bar" },
);
setTimeout(() => worker.terminate(), 30000);

View file

@ -1,5 +1,5 @@
const worker = new Worker(
new URL("message_handler_error.ts", import.meta.url).href,
import.meta.resolve("./message_handler_error.ts"),
{ type: "module", name: "foo" },
);
worker.onmessage = () => {

View file

@ -1,5 +1,5 @@
const worker = new Worker(
new URL("worker_error.ts", import.meta.url).href,
import.meta.resolve("./worker_error.ts"),
{ type: "module", name: "baz" },
);
setTimeout(() => worker.terminate(), 30000);

View file

@ -6,11 +6,10 @@ Deno.test("broadcastchannel worker", async () => {
const intercom = new BroadcastChannel("intercom");
let count = 0;
const url = new URL(
const url = import.meta.resolve(
"../testdata/workers/broadcast_channel.ts",
import.meta.url,
);
const worker = new Worker(url.href, { type: "module", name: "worker" });
const worker = new Worker(url, { type: "module", name: "worker" });
worker.onmessage = () => intercom.postMessage(++count);
const promise = deferred();

View file

@ -1464,7 +1464,7 @@ Deno.test(
Deno.test({ permissions: { read: false } }, async function fetchFilePerm() {
await assertRejects(async () => {
await fetch(new URL("../testdata/subdir/json_1.json", import.meta.url));
await fetch(import.meta.resolve("../testdata/subdir/json_1.json"));
}, Deno.errors.PermissionDenied);
});
@ -1472,7 +1472,7 @@ Deno.test(
{ permissions: { read: false } },
async function fetchFilePermDoesNotExist() {
await assertRejects(async () => {
await fetch(new URL("./bad.json", import.meta.url));
await fetch(import.meta.resolve("./bad.json"));
}, Deno.errors.PermissionDenied);
},
);
@ -1483,7 +1483,7 @@ Deno.test(
await assertRejects(
async () => {
await fetch(
new URL("../testdata/subdir/json_1.json", import.meta.url),
import.meta.resolve("../testdata/subdir/json_1.json"),
{
method: "POST",
},
@ -1500,7 +1500,7 @@ Deno.test(
async function fetchFileDoesNotExist() {
await assertRejects(
async () => {
await fetch(new URL("./bad.json", import.meta.url));
await fetch(import.meta.resolve("./bad.json"));
},
TypeError,
);
@ -1511,7 +1511,7 @@ Deno.test(
{ permissions: { read: true } },
async function fetchFile() {
const res = await fetch(
new URL("../testdata/subdir/json_1.json", import.meta.url),
import.meta.resolve("../testdata/subdir/json_1.json"),
);
assert(res.ok);
const fixture = await Deno.readTextFile(

View file

@ -79,8 +79,8 @@ Deno.test(async function wasmInstantiateStreaming() {
Deno.test(
{ permissions: { read: true } },
async function wasmFileStreaming() {
const url = new URL("../testdata/unreachable.wasm", import.meta.url);
assert(url.href.startsWith("file://"));
const url = import.meta.resolve("../testdata/unreachable.wasm");
assert(url.startsWith("file://"));
const { module } = await WebAssembly.instantiateStreaming(fetch(url));
assertEquals(WebAssembly.Module.exports(module), [{

View file

@ -7,10 +7,9 @@ Deno.test(
const promise = deferred<boolean[]>();
const worker = new Worker(
new URL(
import.meta.resolve(
"../testdata/workers/env_read_check_worker.js",
import.meta.url,
).href,
),
{ type: "module", deno: { permissions: { env: ["test", "OTHER"] } } },
);

View file

@ -5,7 +5,7 @@ Deno.test(
{ permissions: { read: true } },
function utimeSyncFileSuccess() {
const w = new Worker(
new URL("../testdata/workers/worker_types.ts", import.meta.url).href,
import.meta.resolve("../testdata/workers/worker_types.ts"),
{ type: "module" },
);
assert(w);