MCPcopy
hub / github.com/foambubble/foam / TestFoam

Class TestFoam

packages/foam-vscode/src/test/vscode-mock.ts:1565–1693  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1563// ===== Foam Commands Lazy Initialization =====
1564
1565class TestFoam {
1566 private static instance: Foam | null = null;
1567
1568 static async getInstance(): Promise<Foam> {
1569 if (!TestFoam.instance) {
1570 TestFoam.instance = await TestFoam.bootstrap();
1571 }
1572 return TestFoam.instance;
1573 }
1574
1575 static async bootstrap(): Promise<Foam> {
1576 const workspaceFolder = mockState.workspaceFolders[0];
1577 if (!workspaceFolder) {
1578 throw new Error('No workspace folder available for mock Foam');
1579 }
1580
1581 // Create real file system implementations
1582 const listFiles = async (): Promise<URI[]> => {
1583 // Recursively find all markdown files in the workspace
1584 const findMarkdownFiles = async (dir: string): Promise<URI[]> => {
1585 const files: URI[] = [];
1586 try {
1587 const entries = await fs.promises.readdir(dir, {
1588 withFileTypes: true,
1589 });
1590
1591 for (const entry of entries) {
1592 const fullPath = path.join(dir, entry.name);
1593
1594 if (entry.isDirectory()) {
1595 const subFiles = await findMarkdownFiles(fullPath);
1596 files.push(...subFiles);
1597 } else if (entry.isFile() && entry.name.endsWith('.md')) {
1598 files.push(URI.file(fullPath));
1599 }
1600 }
1601 } catch (error) {
1602 // Ignore errors accessing directories
1603 }
1604
1605 return files;
1606 };
1607
1608 return findMarkdownFiles(workspaceFolder.uri.fsPath);
1609 };
1610
1611 const readFile = async (uri: URI): Promise<string> => {
1612 try {
1613 return await fs.promises.readFile(uri.toFsPath(), 'utf8');
1614 } catch (error) {
1615 Logger.debug(`Failed to read file ${uri.toString()}: ${error}`);
1616 return '';
1617 }
1618 };
1619
1620 // Create services
1621 const dataStore = new GenericDataStore(listFiles, readFile);
1622 const parser = createMarkdownParser();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected