// test/aruco.test.js const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); describe('Aruco Detection Script', () => { const scriptPath = 'programs/01_read_Aruco_jpg_to_json.py'; const calibrationFile = 'data/settings/callibration_cam0.npz'; const screenshotsDir = 'test/data/screenShots'; test('should exist and be executable', () => { expect(fs.existsSync(scriptPath)).toBe(true); }); test('should have calibration file', () => { expect(fs.existsSync(calibrationFile)).toBe(true); }); test('should have screenshot directory', () => { expect(fs.existsSync(screenshotsDir)).toBe(true); }); test('should process screenshots successfully', () => { const screenshots = fs.readdirSync(screenshotsDir) .filter(file => file.endsWith('.jpg') || file.endsWith('.png')); expect(screenshots.length).toBeGreaterThan(0); screenshots.forEach(screenshot => { const screenshotPath = path.join(screenshotsDir, screenshot); const jsonPath = screenshotPath.replace(/\.(jpg|png)$/i, '_aruco_detection.json'); // Lösche alte JSON-Datei, falls vorhanden if (fs.existsSync(jsonPath)) { fs.unlinkSync(jsonPath); } // Führe das Python-Skript aus const cmd = `python ${scriptPath} -i ${screenshotPath} -npz ${calibrationFile} -cameraId 0`; try { execSync(cmd, { stdio: 'inherit' }); // Überprüfe, ob JSON-Datei erstellt wurde expect(fs.existsSync(jsonPath)).toBe(true); // Lese und prüfe JSON-Inhalt const jsonData = JSON.parse(fs.readFileSync(jsonPath, 'utf8')); expect(jsonData).toBeDefined(); expect(typeof jsonData).toBe('object'); } catch (error) { fail(`Failed to process ${screenshot}: ${error.message}`); } }); }); });