The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { expect, it } from "vite-plus/test"; |
| 2 | import { loadFileAncestors } from "./loadFileAncestors"; |
| 3 | |
| 4 | function queuedLoader() { |
| 5 | const paths: string[] = []; |
| 6 | const resolve: Array<() => void> = []; |
| 7 | const load = (path: string) => { |
| 8 | paths.push(path); |
| 9 | return new Promise<void>((done) => resolve.push(done)); |
| 10 | }; |
| 11 | return { paths, resolve, load }; |
| 12 | } |
| 13 | |
| 14 | it("stops aborted reveals while a new selection loads independently", async () => { |
| 15 | const old = queuedLoader(); |
| 16 | const controller = new AbortController(); |
| 17 | const oldReveal = loadFileAncestors("old/a/b/c/d/file.ts", old.load, controller); |
| 18 | controller.abort(); |
| 19 | const fresh = queuedLoader(); |
| 20 | const newReveal = loadFileAncestors("new/file.ts", fresh.load, new AbortController()); |
| 21 | for (const resolve of [...old.resolve, ...fresh.resolve]) resolve(); |
| 22 | await Promise.all([oldReveal, newReveal]); |
| 23 | await loadFileAncestors("aborted/path/file.ts", old.load, controller); |
| 24 | expect(old.paths).toEqual(["", "old", "old/a", "old/a/b"]); |
| 25 | expect(fresh.paths).toEqual(["", "new"]); |
| 26 | }); |