README.md•3.42 kB
# Test Suite
This directory contains automated tests for the Ember Docs MCP server.
## Running Tests
```bash
# Run all tests once
npm test
# Run tests in watch mode (re-runs on file changes)
npm run test:watch
# Run tests with coverage report
npm run test:coverage
```
## Test Files
### `documentation-service.test.js`
Unit tests for the `DocumentationService` class, covering:
- **Section Parsing**: Tests for parsing markdown documentation into sections
- **API Indexing**: Tests for extracting and indexing JSON API documentation
- Handles complex JSON structures (ArrayProxy format)
- Handles JSON with preceding text
- Indexes by module name and class name
- Handles dotted names (e.g., `Ember.Component`)
- **Search Functionality**: Tests for the improved search algorithm
- Multi-term search with relevance scoring
- Title match prioritization
- Proximity scoring (terms near each other rank higher)
- Quality filtering (minimum score requirements)
- Category filtering (API, guides, community)
- **Excerpt Extraction**: Tests for context-aware excerpt generation
- Finds clusters of matched terms
- Cleans up JSON/code blocks
- Handles edge cases
- **API Reference Lookup**: Tests for getting detailed API docs
- Case-insensitive lookup
- Module name lookup
- Proper error handling for missing APIs
### `integration.test.js`
End-to-end integration tests covering real-world use cases:
- **Complex Search Queries**: Multi-term searches like "proxy deprecation modern replacement tracked"
- **API Reference Lookups**: Finding ArrayProxy, Component, Router, etc.
- **Migration Guides**: Searching community content for migration information
- **Performance**: Verifying relevant excerpts are returned
- **Edge Cases**:
- Empty documentation
- Malformed JSON (graceful handling)
- Special characters in search queries
## Test Coverage
The test suite covers:
- ✅ JSON parsing with edge cases (preceding text, malformed data)
- ✅ Search relevance algorithm (scoring, proximity, filtering)
- ✅ Excerpt extraction (term clustering, context)
- ✅ API indexing (multiple index keys, case insensitivity)
- ✅ Error handling (malformed JSON, missing data)
- ✅ Real-world use cases (complex queries, migrations)
## Testing Framework
We use [Vitest](https://vitest.dev/) as our testing framework because:
- Fast and modern
- Native ESM support (works with our `"type": "module"` setup)
- Compatible API with Jest
- Built-in coverage reporting
## Writing New Tests
When adding new features, please add corresponding tests:
1. **Unit tests** in `documentation-service.test.js` for new methods
2. **Integration tests** in `integration.test.js` for new workflows
3. Follow the existing patterns:
- Use `describe()` blocks to group related tests
- Use `beforeEach()` for common setup
- Use clear, descriptive test names
- Test both success and failure cases
Example:
```javascript
describe('NewFeature', () => {
beforeEach(() => {
// Setup code
});
it('should handle normal case', () => {
// Test code
expect(result).toBeDefined();
});
it('should handle edge case', () => {
// Test code
expect(result).toBe(expected);
});
});
```
## Continuous Integration
These tests should be run:
- Before committing changes
- In CI/CD pipelines
- Before releasing new versions
All tests must pass before merging pull requests.