Index `files`, counting per file what resolution reads, strips and looks up.
(files: Record<string, string>)
| 34 | |
| 35 | /** Index `files`, counting per file what resolution reads, strips and looks up. */ |
| 36 | async function indexCounting(files: Record<string, string>) { |
| 37 | tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-py-work-')); |
| 38 | for (const [file, content] of Object.entries(files)) { |
| 39 | fs.mkdirSync(path.dirname(path.join(tmpDir, file)), { recursive: true }); |
| 40 | fs.writeFileSync(path.join(tmpDir, file), content); |
| 41 | } |
| 42 | cg = CodeGraph.initSync(tmpDir); |
| 43 | const context = (cg as unknown as { resolver: ReferenceResolver }).resolver.getResolutionContext(); |
| 44 | const reads = vi.spyOn(context, 'readFile'); |
| 45 | const lookups = vi.spyOn(context, 'getNodesInFile'); |
| 46 | await cg.indexAll(); |
| 47 | return { |
| 48 | graph: cg, |
| 49 | reads: (file: string) => reads.mock.calls.filter(([f]) => f === file).length, |
| 50 | lookups: (file: string) => lookups.mock.calls.filter(([f]) => f === file).length, |
| 51 | strips: (file: string) => vi.mocked(stripCommentsForRegex).mock.calls.filter(([text]) => text === files[file]).length, |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | it('reads no file once per module global, and strips no file once per function', async () => { |
| 56 | const SCALE = 16; |
no test coverage detected