UNPKG

node-mac-recorder

Version:

Native macOS screen recording package for Node.js applications

164 lines (141 loc) โ€ข 6.62 kB
const MacRecorder = require('./index'); const fs = require('fs'); const path = require('path'); function runComprehensiveTests() { console.log('๐Ÿงช Running Comprehensive ScreenCaptureKit Tests\n'); console.log('=' .repeat(60)); const recorder = new MacRecorder(); let testResults = { passed: 0, failed: 0, details: [] }; function addResult(testName, passed, details = '') { testResults.details.push({ name: testName, passed, details }); if (passed) { testResults.passed++; console.log(`โœ… ${testName}`); } else { testResults.failed++; console.log(`โŒ ${testName}: ${details}`); } if (details && passed) { console.log(` ${details}`); } } // Test 1: Module Loading try { addResult('Module Loading', true, 'MacRecorder class instantiated successfully'); } catch (error) { addResult('Module Loading', false, error.message); } // Test 2: Method Availability const expectedMethods = [ 'getDisplays', 'getWindows', 'getAudioDevices', 'startRecording', 'stopRecording', 'checkPermissions', 'getCursorPosition', 'getWindowThumbnail', 'getDisplayThumbnail' ]; let missingMethods = []; expectedMethods.forEach(method => { if (typeof recorder[method] !== 'function') { missingMethods.push(method); } }); if (missingMethods.length === 0) { addResult('API Method Availability', true, `All ${expectedMethods.length} expected methods available`); } else { addResult('API Method Availability', false, `Missing methods: ${missingMethods.join(', ')}`); } // Test 3: Synchronous Operations try { const cursor = recorder.getCurrentCursorPosition(); if (cursor && typeof cursor.x === 'number' && typeof cursor.y === 'number') { addResult('Cursor Position (Sync)', true, `Position: (${cursor.x}, ${cursor.y}), Type: ${cursor.cursorType}`); } else { addResult('Cursor Position (Sync)', false, 'Invalid cursor data returned'); } } catch (error) { addResult('Cursor Position (Sync)', false, error.message); } // Test 4: Cursor Capture Status try { const status = recorder.getCursorCaptureStatus(); addResult('Cursor Capture Status', true, `Tracking: ${status.isTracking || false}`); } catch (error) { addResult('Cursor Capture Status', false, error.message); } console.log('\n' + 'โ”€'.repeat(60)); console.log('๐Ÿ“Š Test Results Summary:'); console.log('โ”€'.repeat(60)); console.log(`โœ… Passed: ${testResults.passed}`); console.log(`โŒ Failed: ${testResults.failed}`); console.log(`๐Ÿ“ˆ Success Rate: ${Math.round((testResults.passed / (testResults.passed + testResults.failed)) * 100)}%`); console.log('\n๐Ÿ” Detailed Analysis:'); console.log('โ”€'.repeat(60)); // Test async operations with timeout console.log('\n๐Ÿ”„ Testing Async Operations (with 8s timeout each):'); let asyncTests = 0; let asyncPassed = 0; function testAsync(testName, asyncFunction, timeout = 8000) { return new Promise((resolve) => { asyncTests++; const timeoutId = setTimeout(() => { console.log(`โš ๏ธ ${testName}: Timed out after ${timeout/1000}s (likely permission dialog)`); resolve(false); }, timeout); try { asyncFunction((error, result) => { clearTimeout(timeoutId); if (error) { console.log(`โŒ ${testName}: ${error.message || error}`); resolve(false); } else { const resultInfo = Array.isArray(result) ? `${result.length} items` : 'Success'; console.log(`โœ… ${testName}: ${resultInfo}`); asyncPassed++; resolve(true); } }); } catch (error) { clearTimeout(timeoutId); console.log(`โŒ ${testName}: ${error.message}`); resolve(false); } }); } // Run async tests sequentially (async () => { await testAsync('Permissions Check', (cb) => recorder.checkPermissions(cb)); await testAsync('Display Enumeration', (cb) => recorder.getDisplays(cb)); await testAsync('Window Enumeration', (cb) => recorder.getWindows(cb)); await testAsync('Audio Device Enumeration', (cb) => recorder.getAudioDevices(cb)); console.log('\n' + 'โ•'.repeat(60)); console.log('๐Ÿ Final Test Summary:'); console.log('โ•'.repeat(60)); console.log(`๐Ÿ”ง Synchronous Tests: ${testResults.passed}/${testResults.passed + testResults.failed} passed`); console.log(`๐Ÿ”„ Asynchronous Tests: ${asyncPassed}/${asyncTests} passed`); console.log(`๐Ÿ“Š Overall: ${testResults.passed + asyncPassed}/${testResults.passed + testResults.failed + asyncTests} tests passed`); const overallSuccess = Math.round(((testResults.passed + asyncPassed) / (testResults.passed + testResults.failed + asyncTests)) * 100); if (overallSuccess >= 80) { console.log(`\n๐ŸŽ‰ ScreenCaptureKit Migration: ${overallSuccess}% SUCCESS!`); console.log('โœจ The migration is working correctly'); } else if (overallSuccess >= 60) { console.log(`\nโš ๏ธ ScreenCaptureKit Migration: ${overallSuccess}% PARTIAL SUCCESS`); console.log('๐Ÿ”ง Some functionality working, permissions may need attention'); } else { console.log(`\nโŒ ScreenCaptureKit Migration: ${overallSuccess}% - NEEDS WORK`); console.log('๐Ÿšจ Multiple issues detected'); } console.log('\n๐Ÿ’ก Notes:'); console.log('โ€ข Timeouts usually indicate missing screen recording permissions'); console.log('โ€ข Enable permissions in: System Preferences > Privacy & Security > Screen Recording'); console.log('โ€ข ScreenCaptureKit requires macOS 12.3+ and arm64 architecture'); console.log('โ€ข All synchronous operations (cursor tracking) should work without permissions'); process.exit(0); })(); } runComprehensiveTests();