char-slop/berry

multipurpose self-modifiable agentic harness

git clone https://git.t4t.associates/char-slop/berry

Charlotte Somcut a bunch of code volumecb11725

main
933 B31 linesraw
1// The app's client signed in to a fake berry, in a happy-dom page.
2
3import { type FakeBerry, fakeBerry, withDom } from "@berry/util/dom.ts";
4import type { Window } from "happy-dom";
5import { Scope } from "./ui.ts";
6
7export type Page = {
8  window: Window;
9  server: FakeBerry;
10  /** Disposed once the test ends. */
11  scope: Scope;
12  settle(): Promise<void>;
13};
14
15export function withBerry(
16  test: (page: Page) => Promise<void>,
17  { url, globals }: { url?: string; globals?: Record<string, unknown> } = {},
18): Promise<void> {
19  const server = fakeBerry();
20  return withDom(async (window) => {
21    const { setToken } = await import("./client.ts");
22    const scope = new Scope();
23    setToken("test");
24    try {
25      await test({ window, server, scope, settle: () => window.happyDOM.waitUntilComplete() });
26    } finally {
27      scope.dispose();
28      setToken(null);
29    }
30  }, { url, globals: { ...server.globals, ...globals } });
31}