1
0
forked from icd/rentgen
rentgen/background.ts
Jacek Wielemborek 7d57d3cc07 refactor: make test code conditional via ENABLE_TESTS env var
Test code in background.ts and test-content-script.js now only builds
when ENABLE_TESTS=true is set. Production builds (default) exclude test
code completely via esbuild's define feature.

Changes:
- esbuild.config.js: conditionally add test entrypoints and define ENABLE_TESTS
- background.ts: wrap test message listener in if (ENABLE_TESTS) block
- Dockerfile: add test_builder stage that builds with ENABLE_TESTS=true
- package-lock.json: updated from npm install

Verified with typecheck and lint.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-27 15:21:03 +00:00

34 lines
1.2 KiB
TypeScript

import { init } from "./memory";
// Use global browser object directly (available in extension context)
declare const browser: any;
declare const ENABLE_TESTS: boolean;
init();
// Test verification handler for Marionette tests
// This proves the background script is executing and can communicate with content scripts
if (ENABLE_TESTS) {
browser.runtime.onMessage.addListener((message: any, sender: any, sendResponse: any) => {
if (message.type === 'RENTGEN_TEST_VERIFICATION') {
// Perform a computation to prove the background script is running
// This is not just an echo - we're doing actual processing
const inputValue = message.inputValue || 0;
const computed = (inputValue * 2) + 3;
// Send back a response with computed value and metadata
const response = {
success: true,
computed: computed,
formula: `(${inputValue} * 2) + 3 = ${computed}`,
backgroundTimestamp: Date.now(),
receivedFrom: message.url || 'unknown',
originalInput: inputValue
};
sendResponse(response);
return true; // Keep channel open for async response
}
});
}