Skip to main content
Glama

Simple Files Vector Store Server

ignorePatternMatcher.test.ts3.43 kB
import { expect, test, describe, beforeEach, afterEach, vi } from 'vitest'; import { IgnorePatternMatcher } from '../ignorePatternMatcher.js'; import * as fs from 'fs/promises'; import * as path from 'path'; // Mock fs.readFile vi.mock('fs/promises', () => ({ readFile: vi.fn(), })); describe('IgnorePatternMatcher', () => { beforeEach(() => { vi.resetAllMocks(); }); test('should ignore .vscode directory', async () => { // Mock the readFile to return a pattern that should ignore .vscode (fs.readFile as any).mockResolvedValue('.vscode'); const matcher = new IgnorePatternMatcher('/path/to/ignore/file'); await matcher.loadPatterns(); // This should be ignored expect(matcher.shouldIgnore('/some/path/.vscode', true)).toBe(true); expect(matcher.shouldIgnore('/some/path/.vscode/settings.json', false)).toBe(true); // These should not be ignored expect(matcher.shouldIgnore('/some/path/not-vscode', false)).toBe(false); expect(matcher.shouldIgnore('/some/path/folder/file.txt', false)).toBe(false); }); test('should handle multiple patterns', async () => { // Mock the readFile to return multiple patterns (fs.readFile as any).mockResolvedValue('.vscode\nnode_modules\n*.log'); const matcher = new IgnorePatternMatcher('/path/to/ignore/file'); await matcher.loadPatterns(); // These should be ignored expect(matcher.shouldIgnore('/some/path/.vscode', true)).toBe(true); expect(matcher.shouldIgnore('/some/path/node_modules', true)).toBe(true); expect(matcher.shouldIgnore('/some/path/file.log', false)).toBe(true); // These should not be ignored expect(matcher.shouldIgnore('/some/path/src/index.ts', false)).toBe(false); expect(matcher.shouldIgnore('/some/path/file.txt', false)).toBe(false); }); test('should handle nested .vscode directories', async () => { // Mock the readFile to return a pattern that should ignore .vscode (fs.readFile as any).mockResolvedValue('.vscode'); const matcher = new IgnorePatternMatcher('/path/to/ignore/file'); await matcher.loadPatterns(); // These should be ignored expect(matcher.shouldIgnore('/root/.vscode', true)).toBe(true); expect(matcher.shouldIgnore('/root/project/.vscode', true)).toBe(true); expect(matcher.shouldIgnore('/root/project/subproject/.vscode', true)).toBe(true); expect(matcher.shouldIgnore('/root/project/.vscode/launch.json', false)).toBe(true); }); test('should not ignore anything when no patterns are loaded', async () => { // Mock the readFile to return an empty string (fs.readFile as any).mockResolvedValue(''); const matcher = new IgnorePatternMatcher('/path/to/ignore/file'); await matcher.loadPatterns(); expect(matcher.shouldIgnore('/some/path/.vscode', true)).toBe(false); expect(matcher.shouldIgnore('/some/path/file.txt', false)).toBe(false); }); test('should handle errors when loading patterns', async () => { // Mock the readFile to throw an error (fs.readFile as any).mockRejectedValue(new Error('File not found')); const matcher = new IgnorePatternMatcher('/path/to/ignore/file'); await matcher.loadPatterns(); // Should not ignore anything when patterns couldn't be loaded expect(matcher.shouldIgnore('/some/path/.vscode', true)).toBe(false); expect(matcher.shouldIgnore('/some/path/file.txt', false)).toBe(false); }); });

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lishenxydlgzs/simple-files-vectorstore'

If you have feedback or need assistance with the MCP directory API, please join our Discord server