1// @effect-diagnostics nodeBuiltinImport:off - memory assertions run in an isolated Node process with explicit GC.
2import * as NodeChildProcess from "node:child_process";
3import * as NodeURL from "node:url";
4import * as NodeUtil from "node:util";
5import { expect, it } from "vite-plus/test";
6
7const execFile = NodeUtil.promisify(NodeChildProcess.execFile);
8
9it.each(["prefix", "snapshot", "replay"])(
10 "releases delivered %s history while RPC subscriptions remain open",
11 async (mode) => {
12 const root = NodeURL.fileURLToPath(new URL("../../../", import.meta.url));
13 const fixture = NodeURL.fileURLToPath(
14 new URL("./testkit/RpcInitialMemory.fixture.mjs", import.meta.url),
15 );
16 const { stdout } = await execFile(process.execPath, ["--expose-gc", fixture, root, mode]);
17 const result = JSON.parse(stdout) as {
18 checkpoints: ReadonlyArray<{ subscriptions: number; retained: number }>;
19 };
20 expect(
21 result.checkpoints.map(({ subscriptions, retained }) => ({ subscriptions, retained })),
22 ).toEqual([
23 { subscriptions: 2, retained: 0 },
24 { subscriptions: 4, retained: 0 },
25 ]);
26 },
27);