1
0
forked from icd/rentgen
rentgen/tests/test-lib.js
Jacek Wielemborek 8bf58a2cb1 refactor(test): extract JavaScript test code to test-lib.js
- Created tests/test-lib.js with testBackgroundComputation() function
- Updated test_verify.py to load and execute test library via Marionette
- Modified Dockerfile to copy both test-lib.js and test_verify.py to /app/tests/
- Improved code organization and reusability

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-26 17:46:26 +01:00

37 lines
1.2 KiB
JavaScript

// Test library for Marionette-based extension verification
// This JavaScript code runs in the browser context via Marionette
/**
* Test that background script performs computation correctly
* @param {number} testValue - Input value for computation
* @returns {Promise<number|null>} - Computed result or null on failure
*/
function testBackgroundComputation(testValue) {
// Check if content script loaded
if (!document.body.getAttribute('data-rentgen-injected')) {
return -1; // Content script not loaded
}
// Dispatch test request to content script
document.dispatchEvent(new CustomEvent('rentgen_test_request', {
detail: { value: testValue, timestamp: Date.now() }
}));
// Wait for background response
return new Promise((resolve) => {
let attempts = 0;
const checkInterval = setInterval(() => {
attempts++;
const computed = document.body.getAttribute('data-rentgen-computed');
if (computed) {
clearInterval(checkInterval);
resolve(parseInt(computed));
} else if (attempts > 50) {
clearInterval(checkInterval);
resolve(null);
}
}, 100);
});
}