1test("a path stays deduplicated after an older copy is collected", async () => {
2 const raw = "/clover/path.test/deduplicated";
3 (() => void new Path(raw))();
4 // a WeakRef keeps its target alive until the task that created it ends
5 await delay(0);
6 collectGarbage();
7
8 // the first copy is collected, but its finalizer has not yet run
9 const second = new Path(raw);
10 await delay(10);
11 assert.equal(new Path(raw), second);
12});
13
14v8.setFlagsFromString("--expose-gc");
15const collectGarbage: () => void = vm.runInNewContext("gc");
16
17import { delay } from "@clo/lib/async";
18import { strict as assert } from "node:assert";
19import * as v8 from "node:v8";
20import * as vm from "node:vm";
21import { test } from "vitest";
22import { Path } from "./path.ts";