(files: Record<string, string>, fromFile: string)
| 15 | let cg: CodeGraph | null = null; |
| 16 | |
| 17 | async function importEdges(files: Record<string, string>, fromFile: string): Promise<string[]> { |
| 18 | tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-2584-')); |
| 19 | for (const [rel, source] of Object.entries(files)) { |
| 20 | fs.mkdirSync(path.dirname(path.join(tempDir, rel)), { recursive: true }); |
| 21 | fs.writeFileSync(path.join(tempDir, rel), source); |
| 22 | } |
| 23 | cg = await CodeGraph.init(tempDir, { index: true }); |
| 24 | cg.resolveReferences(); |
| 25 | const file = cg.getNodesByKind('file').find((n) => n.filePath === fromFile)!; |
| 26 | expect(file).toBeDefined(); |
| 27 | return cg |
| 28 | .getOutgoingEdges(file.id) |
| 29 | .filter((e) => e.kind === 'imports') |
| 30 | .map((e) => cg!.getNode(e.target)) |
| 31 | .filter((n): n is NonNullable<typeof n> => !!n) |
| 32 | .map((n) => `${n.kind}:${n.name}@${n.filePath}`) |
| 33 | .sort(); |
| 34 | } |
| 35 | |
| 36 | afterEach(() => { |
| 37 | cg?.close(); |
no test coverage detected