Skip to main content
Glama

LCBro

by lcbro
README.md•6.05 kB
# Testing Suite This directory contains comprehensive tests for the Low Cost Browsing MCP Server. ## Test Structure ``` tests/ ā”œā”€ā”€ unit/ # Unit tests for individual components │ ā”œā”€ā”€ browser-manager.test.ts # BrowserManager tests │ ā”œā”€ā”€ llm-provider.test.ts # LLM provider tests │ ā”œā”€ā”€ navigation.test.ts # Navigation tools tests │ ā”œā”€ā”€ extraction.test.ts # Extraction tools tests │ ā”œā”€ā”€ llm-tools.test.ts # LLM transformation tests │ ā”œā”€ā”€ error-scenarios.test.ts # Error handling tests │ └── llm-errors.test.ts # LLM-specific error tests ā”œā”€ā”€ e2e/ # End-to-end tests │ ā”œā”€ā”€ basic-navigation.spec.ts # Basic navigation flows │ └── interaction-flow.spec.ts # Complex interaction scenarios ā”œā”€ā”€ integration/ # Integration tests │ ā”œā”€ā”€ llm-integration.test.ts # LLM integration tests │ └── real-website.test.ts # Real website tests ā”œā”€ā”€ mocks/ # Mock implementations │ └── llm-providers.ts # Mock LLM providers and browser ā”œā”€ā”€ fixtures/ # Test data and configurations │ └── test-config.yaml # Test configuration └── setup.ts # Global test setup ``` ## Test Types ### Unit Tests - Test individual components in isolation - Use mocks for external dependencies - Fast execution, no network calls - Coverage: BrowserManager, LLM providers, all tools ### E2E Tests - Test complete user scenarios - Use real browser automation - Test actual tool interactions - Scenarios: navigation, form filling, data extraction ### Integration Tests - Test with real external services - Require actual LLM providers - May require API keys or local models - Test real website interactions ### Error Tests - Test all error scenarios - Verify proper error codes and messages - Cover timeouts, network issues, invalid inputs - Test graceful degradation ## Running Tests ### All Tests ```bash npm test # Run unit tests only npm run test:e2e # Run E2E tests only npm run test:all # Run all tests npm run test:coverage # Run with coverage report ``` ### Specific Test Categories ```bash # Unit tests npx jest tests/unit/ # E2E tests npx playwright test # Integration tests (requires setup) npx jest tests/integration/ # Error scenarios npx jest tests/unit/error-scenarios.test.ts ``` ### Watch Mode ```bash npm run test:watch # Watch unit tests npm run test:e2e:ui # Playwright UI mode ``` ## Test Configuration ### Jest (Unit Tests) - Configuration: `jest.config.js` - TypeScript support with `ts-jest` - ESM module support - Coverage threshold: 80% - Timeout: 30 seconds ### Playwright (E2E Tests) - Configuration: `playwright.config.ts` - Browsers: Chromium, Firefox, WebKit - Parallel execution - Trace collection on failures ## Environment Setup ### Required Environment Variables For integration tests that use real LLM providers: ```bash # Optional - enables LLM integration tests OPENAI_API_KEY=sk-your-key-here ANTHROPIC_API_KEY=sk-ant-your-key-here OLLAMA_AVAILABLE=true # Set to true if Ollama is running ``` ### Local Model Setup For Ollama tests: ```bash # Install and start Ollama ollama serve # Pull test model ollama pull llama3.1 ``` ## Coverage Reports Coverage reports are generated in the `coverage/` directory: - `coverage/lcov-report/index.html` - HTML report - `coverage/lcov.info` - LCOV format - `coverage/coverage-final.json` - JSON format ### Coverage Targets - Statements: >80% - Branches: >80% - Functions: >80% - Lines: >80% ## Mock Strategy ### External Dependencies - **OpenAI API**: Mocked to return predictable responses - **Anthropic API**: Mocked for consistent testing - **Ollama/JAN APIs**: Mocked HTTP requests - **Playwright Browser**: Mocked for unit tests, real for E2E ### Mock Data - Predefined responses for various scenarios - Error conditions for testing edge cases - Large content for testing limits - CAPTCHA detection scenarios ## Test Scenarios ### Navigation Tests - āœ… Basic URL opening - āœ… Page navigation - āœ… Session persistence - āœ… Timeout handling - āœ… Invalid URLs ### Interaction Tests - āœ… Form filling - āœ… Button clicking - āœ… Text input - āœ… Wait conditions - āœ… Dynamic content ### Extraction Tests - āœ… HTML content extraction - āœ… Text content extraction - āœ… Table extraction - āœ… Attribute extraction - āœ… Screenshot capture - āœ… Size limits ### LLM Tests - āœ… Text transformation - āœ… JSON schema validation - āœ… Preprocessing - āœ… Multiple providers - āœ… Error handling ### Error Scenarios - āœ… Navigation timeouts - āœ… Element not found - āœ… CAPTCHA detection - āœ… Content too large - āœ… LLM failures - āœ… API errors ## Continuous Integration Tests are designed to run in CI environments: - Headless browser mode - No external dependencies for unit tests - Optional integration tests with proper env vars - Coverage reporting - Parallel execution support ## Debugging Tests ### Failed Tests ```bash # Run specific test npx jest navigation.test.ts # Run with debug output npx jest --verbose navigation.test.ts # Playwright debug mode npx playwright test --debug ``` ### Coverage Analysis ```bash # Generate detailed coverage npm run test:coverage # Open HTML report open coverage/lcov-report/index.html ``` ### Logs and Traces - E2E test traces in `test-results/` - Playwright screenshots on failures - Jest verbose output for debugging - Browser console logs captured ## Contributing When adding new features: 1. Add unit tests for new components 2. Add E2E tests for new user scenarios 3. Test error conditions 4. Maintain >80% coverage 5. Update this README if needed ### Test Naming Convention - Unit tests: `component-name.test.ts` - E2E tests: `scenario-name.spec.ts` - Integration tests: `integration-name.test.ts` - Error tests: `error-type.test.ts`

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/lcbro/lcbro-mcp'

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