Skip to main content
Glama
README.mdβ€’4.47 kB
# Tests This directory contains test scripts and fixtures for xhs-mcp. ## πŸ“ Directory Structure ``` tests/ β”œβ”€β”€ integration/ # Integration test scripts β”‚ β”œβ”€β”€ image-downloader.test.js # Image URL download tests β”‚ └── title-validation.test.js # Title validation tests β”œβ”€β”€ fixtures/ # Test data and fixtures β”‚ └── Bert.jpg # Sample image for testing └── README.md # This file ``` ## πŸ§ͺ Running Tests ### Run All Tests ```bash npm test ``` ### Run Individual Tests ```bash # Test image downloader node tests/integration/image-downloader.test.js # Test title validation node tests/integration/title-validation.test.js ``` ### Enable Debug Logging ```bash XHS_ENABLE_LOGGING=true node tests/integration/image-downloader.test.js ``` ## πŸ“‹ Test Coverage ### Integration Tests #### 1. Image Downloader Tests (`image-downloader.test.js`) Tests the image URL download and caching functionality: - βœ… Download single image from URL - βœ… Download multiple images concurrently - βœ… Process mixed paths (URLs + local files) - βœ… Cache mechanism (avoid duplicate downloads) - βœ… URL detection and validation **Expected Output:** ``` πŸš€ Testing image URL download feature... βœ… ImageDownloader created πŸ“₯ Test 1: Downloading single image... βœ… Downloaded: ./temp_images/img_abc123_1234567890.jpg File size: 45.67 KB Cached: false ... πŸŽ‰ All tests passed! ``` #### 2. Title Validation Tests (`title-validation.test.js`) Tests the title width validation according to Xiaohongshu's display rules: - βœ… English-only titles - βœ… Chinese-only titles - βœ… Mixed language titles - βœ… Emoji handling - βœ… Width calculation (CJK: 2 units, ASCII: 1 unit) - βœ… Title truncation - βœ… Detailed character breakdown - βœ… Edge cases **Expected Output:** ``` πŸ§ͺ Testing Title Width Validation XHS Title Constraints: Max 40 units πŸ“Š Test Results: Test 1: English only ──────────────────────────────────────────────────────────── Title: "Hello World" Length: 11 characters Width: 11 units (max: 40) Remaining: 29 units Status: βœ… Valid ... ``` ## πŸ”§ Test Fixtures ### fixtures/Bert.jpg Sample image file used for testing mixed path processing (URL + local file). - **Format**: JPEG - **Usage**: Integration tests for image downloader - **Purpose**: Verify local file handling alongside URL downloads ## πŸ“ Writing Tests When adding new tests: 1. Place integration tests in `tests/integration/` 2. Add test data to `tests/fixtures/` 3. Follow the naming convention: `*.test.js` 4. Include clear test descriptions and expected outputs 5. Update this README with test coverage information ### Test Template ```javascript #!/usr/bin/env node /** * Test script for [feature name] * * Usage: * node tests/integration/[test-name].test.js * npm test */ async function testFeature() { console.log('πŸš€ Testing [feature]...\n'); try { // Test setup // Test 1 console.log('πŸ“₯ Test 1: [description]...'); // ... test code ... console.log('βœ… Passed\n'); // Test 2 console.log('πŸ“₯ Test 2: [description]...'); // ... test code ... console.log('βœ… Passed\n'); console.log('πŸŽ‰ All tests passed!'); } catch (error) { console.error('❌ Test failed:', error.message); process.exit(1); } } testFeature().catch(console.error); ``` ## βš™οΈ Test Configuration Tests rely on: - **Built artifacts**: Tests run against `dist/` directory - **Dependencies**: All dependencies from `package.json` - **Environment**: Node.js runtime Make sure to build the project before running tests: ```bash npm run build npm test ``` ## πŸ› Troubleshooting ### Test Fails with Module Not Found Make sure to build the project first: ```bash npm run build ``` ### Image Download Test Fails Check your internet connection and ensure the test URLs are accessible: ```bash curl -I https://picsum.photos/800/600 ``` ### Title Validation Test Fails Ensure `string-width` package is installed: ```bash npm install ``` ## πŸ”— Related Documentation - [Usage Guide](../docs/USAGE_GUIDE.md) - How to use xhs-mcp - [Project Structure](../docs/PROJECT_STRUCTURE.md) - Code organization - [README](../README.md) - Main project documentation

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/Algovate/xhs-mcp'

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