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