This directory contains test scripts and fixtures for xhs-mcp.
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
npm test
# Test image downloader
node tests/integration/image-downloader.test.js
# Test title validation
node tests/integration/title-validation.test.js
XHS_ENABLE_LOGGING=true node tests/integration/image-downloader.test.js
image-downloader.test.js
)Tests the image URL download and caching functionality:
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!
title-validation.test.js
)Tests the title width validation according to Xiaohongshu’s display rules:
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
...
Sample image file used for testing mixed path processing (URL + local file).
When adding new tests:
tests/integration/
tests/fixtures/
*.test.js
#!/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);
Tests rely on:
dist/
directorypackage.json
Make sure to build the project before running tests:
npm run build
npm test
Make sure to build the project first:
npm run build
Check your internet connection and ensure the test URLs are accessible:
curl -I https://picsum.photos/800/600
Ensure string-width
package is installed:
npm install