mirror of
https://github.com/denoland/deno.git
synced 2024-11-23 15:16:54 -05:00
af1546391c
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.
27 lines
832 B
TypeScript
27 lines
832 B
TypeScript
// 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;
|
|
});
|