Skip to main content
Glama
README.mdβ€’4.13 kB
# πŸ§ͺ Testing Documentation Comprehensive testing guides and troubleshooting for the Lokalise MCP Server. ## Documents ### [Testing Guide](./TESTING-GUIDE.md) Complete guide to writing tests with: - Three-tier mocking architecture - Mock builders and factories - Snapshot testing - Performance testing - Coverage requirements ### [Test Troubleshooting](./TEST-TROUBLESHOOTING.md) Quick fixes for common test issues: - Mock not working - Type errors - Async issues - Coverage problems ## Quick Testing Reference ### Running Tests ```bash # Run all tests npm test # Run with coverage npm run test:coverage # Watch mode for development npm run test:watch # Run specific test file npm test -- keys.service.test.ts # Update snapshots npm test -- --updateSnapshot ``` ### Three-Tier Mocking Architecture Our testing uses three distinct mock types: ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Layer Being Tested β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Tool/Resource/CLI β†’ Module Mocks β”‚ β”‚ Controller β†’ Mock Builders β”‚ β”‚ Service β†’ Mock Factory β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Quick Mock Examples **1. Module Mock** (for Tool tests): ```javascript // __mocks__/keys.controller.js export default { listKeys: vi.fn(), getKey: vi.fn() }; ``` **2. Mock Builder** (for Controller tests): ```typescript const mockData = new KeysMockBuilder() .withKey({ key_id: 123 }) .withPagination(1, 100) .build(); ``` **3. Mock Factory** (for Service tests): ```typescript const mockApi = createMockLokaliseApi({ failOnMethod: 'keys.list' }); ``` ## Testing Standards ### Coverage Requirements - **Target**: >80% overall coverage - **Critical paths**: 100% coverage - **New features**: Must include tests - **Bug fixes**: Must include regression tests ### Test Organization ``` src/domains/{domain}/ β”œβ”€β”€ __fixtures__/ # Test data β”œβ”€β”€ __snapshots__/ # Snapshots β”œβ”€β”€ *.test.ts # Test files └── __mocks__/ # Module mocks ``` ### Writing Good Tests **DO:** - βœ… Test behavior, not implementation - βœ… Use descriptive test names - βœ… Keep tests isolated and independent - βœ… Mock external dependencies - βœ… Test error cases **DON'T:** - ❌ Use `any` type in tests - ❌ Skip error scenarios - ❌ Leave console.log in tests - ❌ Ignore flaky tests - ❌ Test private methods directly ## Common Testing Patterns ### Testing Async Operations ```typescript it('should handle async operations', async () => { const result = await service.fetchData(); expect(result).toBeDefined(); }); ``` ### Testing Error Cases ```typescript it('should handle API errors', async () => { mockApi.keys.list.mockRejectedValue(new Error('API Error')); await expect(service.listKeys()).rejects.toThrow('API Error'); }); ``` ### Testing with Fixtures ```typescript import { keysFixture } from './__fixtures__/keys.fixtures'; it('should format keys correctly', () => { const result = formatter.format(keysFixture); expect(result).toMatchSnapshot(); }); ``` ## Debugging Tests ### Enable Console Output ```typescript import { restoreConsole } from '@/test-utils/setup'; it('debug test', () => { restoreConsole(); // Temporarily enable console console.log('Debug info'); }); ``` ### Run Single Test ```bash npm test -- --testNamePattern="should list keys" ``` ### Debug with VS Code 1. Set breakpoint in test 2. Use "Debug Vitest Tests" launch config 3. Step through test execution ## Test Utilities Located in `src/test-utils/`: - `setup.ts` - Global test configuration - `mock-factory.ts` - API mock factory - `mock-builders/` - Domain-specific builders - `fixture-helpers/` - Data generators --- *For detailed testing patterns and examples, see [TESTING-GUIDE.md](./TESTING-GUIDE.md)*

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/AbdallahAHO/lokalise-mcp'

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