Skip to main content
Glama
pathUtils.test.ts2.25 kB
import path from 'node:path'; import { describe, expect, it } from 'vitest'; import { ErrorCode, PdfError } from '../src/utils/errors.js'; import { PROJECT_ROOT, resolvePath } from '../src/utils/pathUtils.js'; describe('resolvePath Utility', () => { it('should resolve a valid relative path correctly', () => { const userPath = 'some/file.txt'; const expectedPath = path.resolve(PROJECT_ROOT, userPath); expect(resolvePath(userPath)).toBe(expectedPath); }); it('should resolve paths with "." correctly', () => { const userPath = './some/./other/file.txt'; const expectedPath = path.resolve(PROJECT_ROOT, 'some/other/file.txt'); expect(resolvePath(userPath)).toBe(expectedPath); }); it('should resolve paths with ".." correctly', () => { const userPath = 'some/folder/../other/file.txt'; const expectedPath = path.resolve(PROJECT_ROOT, 'some/other/file.txt'); expect(resolvePath(userPath)).toBe(expectedPath); }); it('should resolve relative paths that go outside PROJECT_ROOT', () => { const userPath = '../outside/file.txt'; const result = resolvePath(userPath); expect(result).toBe(path.resolve(PROJECT_ROOT, userPath)); }); it('should accept absolute paths and return them normalized', () => { const userPath = path.resolve(PROJECT_ROOT, 'absolute/file.txt'); expect(resolvePath(userPath)).toBe(path.normalize(userPath)); }); it('should accept any absolute path', () => { const absolutePath = path.sep === '/' ? '/etc/passwd' : 'C:\\Windows\\System32\\config.txt'; expect(resolvePath(absolutePath)).toBe(path.normalize(absolutePath)); }); it('should throw PdfError for non-string input', () => { const userPath = 123 as unknown as string; expect(() => resolvePath(userPath)).toThrow(PdfError); expect(() => resolvePath(userPath)).toThrow('Path must be a string.'); try { resolvePath(userPath); } catch (e) { expect(e).toBeInstanceOf(PdfError); expect((e as PdfError).code).toBe(ErrorCode.InvalidParams); } }); it('should handle empty string input', () => { const userPath = ''; const expectedPath = path.resolve(PROJECT_ROOT, ''); expect(resolvePath(userPath)).toBe(expectedPath); }); });

Latest Blog Posts

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/SylphxAI/pdf-reader-mcp'

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