64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
// 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 sourceScreenshotsDir = path.join(__dirname, 'data', 'screenShots');
|
|
const screenshotFiles = [
|
|
'snapshot_video0_1778819665744.jpg',
|
|
'snapshot_video1_1778819665744.jpg',
|
|
];
|
|
|
|
beforeEach(() => {
|
|
screenshotFiles.forEach((file) => {
|
|
const src = path.join(sourceScreenshotsDir, file);
|
|
if (!fs.existsSync(src)) {
|
|
throw new Error(`Missing test fixture screenshot: ${src}`);
|
|
}
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
// Keep generated detection JSON files in the screenshot directory.
|
|
});
|
|
|
|
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(sourceScreenshotsDir)).toBe(true);
|
|
});
|
|
|
|
test('should process screenshots successfully', () => {
|
|
const screenshots = fs.readdirSync(sourceScreenshotsDir)
|
|
.filter(file => file.endsWith('.jpg') || file.endsWith('.png'))
|
|
.filter(file => screenshotFiles.includes(file));
|
|
|
|
expect(screenshots.length).toBeGreaterThan(0);
|
|
|
|
screenshots.forEach(screenshot => {
|
|
const screenshotPath = path.join(sourceScreenshotsDir, screenshot);
|
|
const jsonPath = screenshotPath.replace(/\.(jpg|png)$/i, '_aruco_detection.json');
|
|
const cmd = `python ${scriptPath} -i "${screenshotPath}" -npz "${calibrationFile}" -cameraId 0`;
|
|
|
|
try {
|
|
execSync(cmd, { stdio: 'inherit' });
|
|
expect(fs.existsSync(jsonPath)).toBe(true);
|
|
|
|
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}`);
|
|
}
|
|
});
|
|
});
|
|
}); |