forked from icd/rentgen
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>
This commit is contained in:
parent
e6f025335a
commit
7d57d3cc07
26
Dockerfile
26
Dockerfile
@ -20,12 +20,32 @@ RUN npm install
|
||||
# Copy source code (respecting .dockerignore)
|
||||
COPY . .
|
||||
|
||||
# Build the extension for Firefox (default)
|
||||
# Build the extension for Firefox (default) - without tests
|
||||
RUN npm run build
|
||||
|
||||
# Create the package
|
||||
RUN npm run create-package
|
||||
|
||||
# Test builder stage - builds with ENABLE_TESTS=true
|
||||
FROM node:lts AS test_builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files for dependency installation
|
||||
COPY package.json package-lock.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm install
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build with tests enabled
|
||||
RUN ENABLE_TESTS=true npm run build
|
||||
|
||||
# Create the package
|
||||
RUN npm run create-package
|
||||
|
||||
# Code quality stage - for running quality checks
|
||||
FROM builder AS code_quality
|
||||
RUN npm run typecheck && npm run lint
|
||||
@ -47,8 +67,8 @@ FROM node:lts AS runtime
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy built extension from builder
|
||||
COPY --from=builder /app /app
|
||||
# Copy built extension from test_builder (includes test code)
|
||||
COPY --from=test_builder /app /app
|
||||
|
||||
# Install Firefox and Xvfb for headless execution (cached layer)
|
||||
RUN apt-get update && apt-get install -y \
|
||||
|
||||
@ -2,11 +2,13 @@ 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
|
||||
@ -28,3 +30,4 @@ browser.runtime.onMessage.addListener((message: any, sender: any, sendResponse:
|
||||
return true; // Keep channel open for async response
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -8,6 +8,8 @@ const watch = process.argv.includes('--watch') && {
|
||||
},
|
||||
};
|
||||
|
||||
const ENABLE_TESTS = process.env.ENABLE_TESTS === 'true';
|
||||
|
||||
// see https://github.com/evanw/esbuild/issues/806#issuecomment-779138268
|
||||
let skipReactImports = {
|
||||
name: 'skipReactImports',
|
||||
@ -41,18 +43,23 @@ let skipReactImports = {
|
||||
},
|
||||
};
|
||||
|
||||
esbuild
|
||||
.build({
|
||||
entryPoints: [
|
||||
const entryPoints = [
|
||||
'components/toolbar/toolbar.tsx',
|
||||
'components/sidebar/sidebar.tsx',
|
||||
'components/report-window/report-window.tsx',
|
||||
'background.ts',
|
||||
'tests/test-content-script.js',
|
||||
'diag.tsx',
|
||||
'styles/global.scss',
|
||||
'styles/fonts.scss',
|
||||
],
|
||||
];
|
||||
|
||||
if (ENABLE_TESTS) {
|
||||
entryPoints.push('tests/test-content-script.js');
|
||||
}
|
||||
|
||||
esbuild
|
||||
.build({
|
||||
entryPoints,
|
||||
bundle: true,
|
||||
// minify: true,
|
||||
outdir: './lib',
|
||||
@ -61,6 +68,7 @@ esbuild
|
||||
define: {
|
||||
PLUGIN_NAME: '"Rentgen"',
|
||||
PLUGIN_URL: '"https://addons.mozilla.org/pl/firefox/addon/rentgen/"',
|
||||
ENABLE_TESTS: String(ENABLE_TESTS),
|
||||
},
|
||||
external: ['react', 'react-dom', 'survey-react'],
|
||||
watch,
|
||||
|
||||
440
package-lock.json
generated
440
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user