node-mac-recorder
Version:
Native macOS screen recording package for Node.js applications
164 lines (141 loc) โข 6.62 kB
JavaScript
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();