Skip to main content
Glama
test.js4.44 kB
import { AudioInspector } from '../lib/inspector.js'; import { promises as fs } from 'fs'; import path from 'path'; async function runTests() { console.log('Running MCP Audio Inspector Tests...\n'); const inspector = new AudioInspector(); let passedTests = 0; let totalTests = 0; // Test 1: Check supported formats totalTests++; try { const formats = inspector.getSupportedFormats(); console.log('✓ Test 1: Get supported formats'); console.log(' Supported formats:', formats.primary.length, 'primary formats'); passedTests++; } catch (error) { console.log('✗ Test 1: Get supported formats -', error.message); } // Test 2: Test with non-existent file (should handle gracefully) totalTests++; try { const result = await inspector.analyzeFile('non-existent-file.mp3'); if (result.error) { console.log('✓ Test 2: Non-existent file error handling'); passedTests++; } else { console.log('✗ Test 2: Should have returned error for non-existent file'); } } catch (error) { console.log('✗ Test 2: Non-existent file error handling -', error.message); } // Test 3: Test batch analysis with empty directory totalTests++; try { // Create a temporary empty directory const tempDir = './temp-test-dir'; await fs.mkdir(tempDir, { recursive: true }); const batchResult = await inspector.analyzeBatch(tempDir); if (batchResult.summary.totalFiles === 0) { console.log('✓ Test 3: Empty directory batch analysis'); passedTests++; } else { console.log('✗ Test 3: Empty directory should return 0 files'); } // Clean up await fs.rmdir(tempDir); } catch (error) { console.log('✗ Test 3: Empty directory batch analysis -', error.message); } // Test 4: Test format extraction with mock data totalTests++; try { const mockMetadata = { format: { container: 'MP3', codec: 'mp3', duration: 180.5, bitrate: 128000, sampleRate: 44100, numberOfChannels: 2 } }; const formatInfo = inspector.extractFormatInfo(mockMetadata); if (formatInfo.container === 'MP3' && formatInfo.duration === 180.5) { console.log('✓ Test 4: Format extraction'); passedTests++; } else { console.log('✗ Test 4: Format extraction failed'); } } catch (error) { console.log('✗ Test 4: Format extraction -', error.message); } // Test 5: Test tags extraction with mock data totalTests++; try { const mockMetadata = { common: { title: 'Test Song', artist: 'Test Artist', album: 'Test Album', year: 2024, genre: ['Electronic'] } }; const tags = inspector.extractTags(mockMetadata); if (tags.title === 'Test Song' && tags.artist === 'Test Artist') { console.log('✓ Test 5: Tags extraction'); passedTests++; } else { console.log('✗ Test 5: Tags extraction failed'); } } catch (error) { console.log('✗ Test 5: Tags extraction -', error.message); } // Test 6: Test game audio analysis totalTests++; try { const mockBasicInfo = { format: { duration: 15.5, sampleRate: 44100, channels: 2, bitsPerSample: 16 }, file: { size: 1024000 } }; const gameAnalysis = await inspector.analyzeForGameAudio(mockBasicInfo, 'test.mp3'); if (gameAnalysis.hasOwnProperty('suitableForLoop') && gameAnalysis.hasOwnProperty('recommendedCompressionFormat')) { console.log('✓ Test 6: Game audio analysis'); passedTests++; } else { console.log('✗ Test 6: Game audio analysis missing properties'); } } catch (error) { console.log('✗ Test 6: Game audio analysis -', error.message); } // Summary console.log(`\nTest Results: ${passedTests}/${totalTests} tests passed`); if (passedTests === totalTests) { console.log('🎉 All tests passed!'); return true; } else { console.log('❌ Some tests failed'); return false; } } // Run tests if this file is executed directly if (import.meta.url === `file://${process.argv[1]}`) { runTests() .then(success => { process.exit(success ? 0 : 1); }) .catch(error => { console.error('Test execution failed:', error); process.exit(1); }); } export { runTests };

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/DeveloperZo/mcp-audio-inspector'

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