1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-04 08:54:20 -05:00
denoland-deno/cli/tests/unit/broadcast_channel_test.ts
David Sherret 10e4b2e140
chore: update copyright year to 2023 (#17247)
Yearly tradition of creating extra noise in git.
2023-01-02 21:00:42 +00:00

29 lines
840 B
TypeScript

// Copyright 2018-2023 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 = import.meta.resolve(
"../testdata/workers/broadcast_channel.ts",
);
const worker = new Worker(url, { 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;
});