From 161adfc51b750a7c8c62a898ea9948c2ad5b6cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 29 Jan 2020 18:54:23 +0100 Subject: workers: proper TS libs, more spec-compliant APIs (#3812) * split lib.deno_main.d.ts into: - lib.deno.shared_globals.d.ts - lib.deno.window.d.ts - lib.deno.worker.d.ts * remove no longer used libs: - lib.deno_main.d.ts - lib.deno_worker.d.ts * change module loading to use proper TS library for compilation * align to Worker API spec: - Worker.terminate() - self.close() - self.name --- cli/tests/026_workers.ts | 10 ++++++++-- cli/tests/subdir/bench_worker.ts | 2 +- cli/tests/subdir/test_worker.js | 7 ++++++- cli/tests/subdir/test_worker.ts | 6 +++++- cli/tests/types.out | 6 ++++-- 5 files changed, 24 insertions(+), 7 deletions(-) (limited to 'cli/tests') diff --git a/cli/tests/026_workers.ts b/cli/tests/026_workers.ts index 3043cc7b9..7ec6996e1 100644 --- a/cli/tests/026_workers.ts +++ b/cli/tests/026_workers.ts @@ -1,5 +1,11 @@ -const jsWorker = new Worker("./subdir/test_worker.js", { type: "module" }); -const tsWorker = new Worker("./subdir/test_worker.ts", { type: "module" }); +const jsWorker = new Worker("./subdir/test_worker.js", { + type: "module", + name: "jsWorker" +}); +const tsWorker = new Worker("./subdir/test_worker.ts", { + type: "module", + name: "tsWorker" +}); tsWorker.onmessage = (e): void => { console.log("Received ts: " + e.data); diff --git a/cli/tests/subdir/bench_worker.ts b/cli/tests/subdir/bench_worker.ts index 696a84b9f..619a35fa2 100644 --- a/cli/tests/subdir/bench_worker.ts +++ b/cli/tests/subdir/bench_worker.ts @@ -15,7 +15,7 @@ onmessage = function(e): void { break; case 3: // Close postMessage({ cmdId: 3 }); - workerClose(); + close(); break; } }; diff --git a/cli/tests/subdir/test_worker.js b/cli/tests/subdir/test_worker.js index cec5bdf9b..f0d9fbed6 100644 --- a/cli/tests/subdir/test_worker.js +++ b/cli/tests/subdir/test_worker.js @@ -1,5 +1,10 @@ let thrown = false; +// TODO(bartlomieju): add test for throwing in web worker +if (self.name !== "jsWorker") { + throw Error(`Bad worker name: ${self.name}, expected jsWorker`); +} + onmessage = function(e) { console.log(e.data); @@ -10,7 +15,7 @@ onmessage = function(e) { postMessage(e.data); - workerClose(); + close(); }; onerror = function() { diff --git a/cli/tests/subdir/test_worker.ts b/cli/tests/subdir/test_worker.ts index c8109d131..bc3f358f8 100644 --- a/cli/tests/subdir/test_worker.ts +++ b/cli/tests/subdir/test_worker.ts @@ -1,7 +1,11 @@ +if (self.name !== "tsWorker") { + throw Error(`Invalid worker name: ${self.name}, expected tsWorker`); +} + onmessage = function(e): void { console.log(e.data); postMessage(e.data); - workerClose(); + close(); }; diff --git a/cli/tests/types.out b/cli/tests/types.out index df79ff821..a212c01e8 100644 --- a/cli/tests/types.out +++ b/cli/tests/types.out @@ -5,10 +5,12 @@ declare namespace Deno { [WILDCARD] } [WILDCARD] -declare interface Window { +declare interface WindowOrWorkerGlobalScope { +[WILDCARD] +declare interface Window extends WindowOrWorkerGlobalScope { [WILDCARD] Deno: typeof Deno; } -declare const window: Window & typeof globalThis; +declare const window: Window & WindowOrWorkerGlobalScope & typeof globalThis; [WILDCARD] -- cgit v1.2.3