1
0
forked from icd/rentgen

Compare commits

..

No commits in common. "ccd35baf2c2f5c13be6d343a6b46a6c3df93cd92" and "7513594b0058d6382ebf1a49be953e131fdaae26" have entirely different histories.

4 changed files with 359 additions and 152 deletions

View File

@ -112,4 +112,3 @@ Każdy problem zostanie sprawdzony i przeniesiony na wewnętrzną listę problem
--- ---
# Test pre-commit hook - without Docker check

View File

@ -1,7 +1,5 @@
import esbuild from 'esbuild'; import esbuild from 'esbuild';
import scss from 'esbuild-plugin-sass'; import scss from 'esbuild-plugin-sass';
import fs from 'fs';
import path from 'path';
const watch = process.argv.includes('--watch') && { const watch = process.argv.includes('--watch') && {
onRebuild(error) { onRebuild(error) {
@ -75,34 +73,5 @@ esbuild
external: ['react', 'react-dom', 'survey-react'], external: ['react', 'react-dom', 'survey-react'],
watch, watch,
}) })
.then(() => { .then(() => console.log('Add-on was built'))
console.log('Add-on was built');
// Modify manifest.json to include test content script when ENABLE_TESTS=true
if (ENABLE_TESTS) {
const manifestPath = path.join(process.cwd(), 'manifest.json');
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
// Add content_scripts for testing
if (!manifest.content_scripts) {
manifest.content_scripts = [];
}
// Check if test script is already added
const hasTestScript = manifest.content_scripts.some(
cs => cs.js && cs.js.includes('lib/tests/test-content-script.js')
);
if (!hasTestScript) {
manifest.content_scripts.push({
matches: ['<all_urls>'],
js: ['lib/tests/test-content-script.js'],
run_at: 'document_start'
});
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 4));
console.log('Added test content script to manifest.json');
}
}
})
.catch(() => process.exit(1)); .catch(() => process.exit(1));

440
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,21 +2,24 @@
// This JavaScript code runs in the browser context via Marionette // This JavaScript code runs in the browser context via Marionette
/** /**
* Check if test content script is loaded * Inject test content script into the page
* The content script is automatically injected by manifest.json when ENABLE_TESTS=true * @returns {Promise<boolean>} - True if injection successful
* @returns {Promise<boolean>} - True if content script is loaded
*/ */
async function waitForTestContentScript() { async function injectTestContentScript() {
// Wait for content script to set the marker // Read the content script file
let attempts = 0; const response = await fetch(browser.runtime.getURL('lib/tests/test-content-script.js'));
while (attempts < 50) { const scriptCode = await response.text();
if (document.body && document.body.getAttribute('data-rentgen-injected') === 'true') {
return true; // Inject it into the page
} const script = document.createElement('script');
await new Promise(resolve => setTimeout(resolve, 100)); script.textContent = scriptCode;
attempts++; document.documentElement.appendChild(script);
} script.remove();
return false;
// Wait a bit for script to initialize
await new Promise(resolve => setTimeout(resolve, 100));
return document.body.getAttribute('data-rentgen-injected') === 'true';
} }
/** /**
@ -25,9 +28,9 @@ async function waitForTestContentScript() {
* @returns {Promise<number|null>} - Badge count (number of third-party domains) or null on failure * @returns {Promise<number|null>} - Badge count (number of third-party domains) or null on failure
*/ */
async function testBadgeCount() { async function testBadgeCount() {
// Wait for content script to be loaded // Inject content script first
const loaded = await waitForTestContentScript(); const injected = await injectTestContentScript();
if (!loaded) { if (!injected) {
return -1; // Content script not loaded return -1; // Content script not loaded
} }