Comprehensive testing setup for beat parser development and validation.
tests/
├── demos/
│ └── audio-decode-demo.js # Audio decoding demonstration
├── integration/
│ ├── beat-parser-integration.js # Full integration tests
│ └── music-analysis.js # Real music file analysis
├── utils/
│ ├── test-runner.js # Test execution utility
│ └── quick-test.js # Fast validation tests
└── archived/ # Legacy test files
npm run test:quick # Fast validation tests
npm run test:demo # Audio decoding demo
npm run test:music # Music file analysis
npm run test:integration # Full integration tests
npm run test:all # Complete test suite{
"scripts": {
"test:quick": "node tests/utils/quick-test.js",
"test:demo": "node tests/demos/audio-decode-demo.js",
"test:music": "node tests/integration/music-analysis.js",
"test:integration": "node tests/integration/beat-parser-integration.js",
"test:all": "node tests/utils/test-runner.js"
}
}Fast validation of core functionality:
- Library loading and initialization
- Basic configuration validation
- Audio buffer processing
- Error handling
- Resource cleanup
Expected output:
✅ Library loads successfully
✅ Parser initializes correctly
✅ Audio processing works
✅ All quick tests passed
Demonstrates audio decoding capabilities:
- MP3/WAV/FLAC format support
- Sample rate conversion
- Channel mixing
- Audio normalization
Tests with real music files from ./music/ directory:
- Beat detection accuracy
- Tempo estimation
- Processing performance
- Output validation
Expected results:
Processing: summer-vibes-158665.mp3
Found 16 beats in 5.2 seconds
Tempo: ~158 BPM
Processing time: 2.1 seconds
✅ Analysis complete
Comprehensive system testing:
- End-to-end processing pipeline
- Multiple algorithm coordination
- Error handling and recovery
- Performance benchmarking
- Memory usage validation
Place audio files in ./music/ directory:
music/
├── summer-vibes-158665.mp3 # Primary test file
├── test-track.wav # WAV format test
└── sample.flac # FLAC format test
- Duration: 3-10 seconds for quick tests
- Format: MP3, WAV, or FLAC
- Quality: 44.1kHz sample rate preferred
- Content: Clear rhythmic patterns
// Performance test example
const startTime = Date.now();
const result = await parser.parseFile('./music/test-track.mp3');
const processingTime = Date.now() - startTime;
console.log(`Processing time: ${processingTime}ms`);
console.log(`Beats found: ${result.beats.length}`);
console.log(`Efficiency: ${result.metadata.samplesProcessed / processingTime} samples/ms`);| File Duration | Processing Time | Memory Usage |
|---|---|---|
| 5 seconds | <3 seconds | <10MB |
| 30 seconds | <15 seconds | <25MB |
| 2 minutes | <60 seconds | <50MB |
# Install dependencies
npm install
# Build the project
npm run build
# Run quick validation
npm run test:quick
# Test with music files
npm run test:music// Enable debug logging
process.env.DEBUG = 'beat-parser:*';
// Run specific test
node tests/integration/beat-parser-integration.js ./music/test-file.mp3// Validate beat detection results
function validateBeatResults(result) {
// Check basic structure
assert(Array.isArray(result.beats), 'Beats should be array');
assert(result.beats.length > 0, 'Should detect some beats');
// Validate beat properties
result.beats.forEach(beat => {
assert(typeof beat.timestamp === 'number', 'Beat timestamp should be number');
assert(beat.confidence >= 0 && beat.confidence <= 1, 'Confidence should be 0-1');
assert(beat.strength >= 0, 'Strength should be positive');
});
// Check temporal ordering
for (let i = 1; i < result.beats.length; i++) {
assert(result.beats[i].timestamp > result.beats[i-1].timestamp,
'Beats should be temporally ordered');
}
}// Validate tempo detection
function validateTempo(tempo) {
if (tempo) {
assert(tempo.bpm > 0, 'BPM should be positive');
assert(tempo.bpm >= 60 && tempo.bpm <= 300, 'BPM should be reasonable range');
assert(tempo.confidence >= 0 && tempo.confidence <= 1, 'Tempo confidence 0-1');
}
}name: Test Beat Parser
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm install
- run: npm run build
- run: npm run test:quick
- run: npm run test:integration# Add to .husky/pre-commit
#!/bin/sh
npm run test:quick// Test error handling
describe('Error Handling', () => {
it('should handle invalid audio data', async () => {
const parser = new BeatParser();
try {
await parser.parseBuffer(null);
assert.fail('Should throw error for null input');
} catch (error) {
assert(error.message.includes('Invalid audio data'));
}
});
it('should handle file not found', async () => {
const parser = new BeatParser();
try {
await parser.parseFile('./nonexistent.mp3');
assert.fail('Should throw error for missing file');
} catch (error) {
assert(error.message.includes('not found'));
}
});
});// Test for memory leaks
async function testMemoryLeaks() {
const parser = new BeatParser();
const initialMemory = process.memoryUsage().heapUsed;
// Process multiple files
for (let i = 0; i < 10; i++) {
const result = await parser.parseFile('./music/test-track.mp3');
// Force garbage collection if available
if (global.gc) global.gc();
}
await parser.cleanup();
if (global.gc) global.gc();
const finalMemory = process.memoryUsage().heapUsed;
const memoryIncrease = finalMemory - initialMemory;
console.log(`Memory increase: ${memoryIncrease / 1024 / 1024} MB`);
assert(memoryIncrease < 50 * 1024 * 1024, 'Memory increase should be <50MB');
}- Unit Tests: >90% code coverage
- Integration Tests: All major workflows
- Error Handling: All error paths
- Performance: Benchmarks for all operations
# Install coverage tools
npm install --save-dev nyc
# Run with coverage
nyc npm run test:all
# Generate coverage report
nyc report --reporter=html-
Tests fail with "audio-decode not found"
- Run
npm installto install dependencies - Check that audio-decode is in package.json
- Run
-
Music files not found
- Create
./music/directory - Add test audio files (MP3, WAV, FLAC)
- Verify file paths in test scripts
- Create
-
Memory errors during testing
- Reduce test file sizes
- Enable garbage collection
- Always call parser.cleanup()
-
Performance tests fail
- Check system resources
- Use smaller test files
- Verify no other heavy processes running
# Enable debug logging
export DEBUG=beat-parser:*
npm run test:music
# Or for specific test
DEBUG=beat-parser:* node tests/integration/music-analysis.jsFor complete API documentation, see API.md.