From af1546391c4a561eb26ccf9cd244b05aed9b5bfc Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 22 May 2021 18:08:24 +0200 Subject: feat(extensions): BroadcastChannel WPT conformance Replaces the file-backed provider by an in-memory one because proper file locking is a hard problem that detracts from the proof of concept. Teach the WPT runner how to extract tests from .html files because all the relevant tests in test_util/wpt/webmessaging/broadcastchannel are inside basics.html and interface.html. --- cli/tests/unit/broadcast_channel_test.ts | 27 +++++++++++++++++++++++++++ cli/tests/workers/broadcast_channel.ts | 5 +++++ 2 files changed, 32 insertions(+) create mode 100644 cli/tests/unit/broadcast_channel_test.ts create mode 100644 cli/tests/workers/broadcast_channel.ts (limited to 'cli/tests') diff --git a/cli/tests/unit/broadcast_channel_test.ts b/cli/tests/unit/broadcast_channel_test.ts new file mode 100644 index 000000000..cfa62c856 --- /dev/null +++ b/cli/tests/unit/broadcast_channel_test.ts @@ -0,0 +1,27 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +import { assertEquals } from "../../../test_util/std/testing/asserts.ts"; +import { deferred } from "../../../test_util/std/async/deferred.ts"; + +Deno.test("broadcastchannel worker", async () => { + const intercom = new BroadcastChannel("intercom"); + let count = 0; + + const url = new URL("../workers/broadcast_channel.ts", import.meta.url); + const worker = new Worker(url.href, { type: "module", name: "worker" }); + worker.onmessage = () => intercom.postMessage(++count); + + const promise = deferred(); + + intercom.onmessage = function (e) { + assertEquals(count, e.data); + if (count < 42) { + intercom.postMessage(++count); + } else { + worker.terminate(); + intercom.close(); + promise.resolve(); + } + }; + + await promise; +}); diff --git a/cli/tests/workers/broadcast_channel.ts b/cli/tests/workers/broadcast_channel.ts new file mode 100644 index 000000000..5076e9eb7 --- /dev/null +++ b/cli/tests/workers/broadcast_channel.ts @@ -0,0 +1,5 @@ +new BroadcastChannel("intercom").onmessage = function (e) { + this.postMessage(e.data); +}; + +self.postMessage("go"); -- cgit v1.2.3