Skip to content

Commit

Permalink
runtime.dispose tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Oct 12, 2024
1 parent d7afbb0 commit baadd7a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/runtime/dispose-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {Runtime} from "@observablehq/runtime";
import assert from "assert";
import {sleep} from "../variable/valueof.js";

describe("runtime.dispose", () => {
it("invalidates all variables", async () => {
const runtime = new Runtime();
const main = runtime.module();
const log = [];
main.variable(true).define(["invalidation"], async (invalidation) => {
await invalidation;
log.push("invalidation");
});
await sleep();
runtime.dispose();
await sleep();
assert.deepStrictEqual(log, ["invalidation"]);
});
it("terminates generators", async () => {
const runtime = new Runtime();
const main = runtime.module();
const log = [];
main.variable(true).define([], function* () {
try {
while (true) yield;
} finally {
log.push("return");
}
});
await sleep();
runtime.dispose();
await sleep();
assert.deepStrictEqual(log, ["return"]);
});
});

0 comments on commit baadd7a

Please sign in to comment.