| 1 | test("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 | |
| 14 | v8.setFlagsFromString("--expose-gc"); |
| 15 | const collectGarbage: () => void = vm.runInNewContext("gc"); |
| 16 | |
| 17 | import { delay } from "@clo/lib/async"; |
| 18 | import { strict as assert } from "node:assert"; |
| 19 | import * as v8 from "node:v8"; |
| 20 | import * as vm from "node:vm"; |
| 21 | import { test } from "vitest"; |
| 22 | import { Path } from "./path.ts"; |