Skip to content

feat: add USE_OWN_LOCAL_BINARY_PROCESS option to control local binary usage #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ for (const key of BROWSERSTACK_LOCAL_OPTION_KEYS) {
}
}

/**
* USE_OWN_LOCAL_BINARY_PROCESS:
* If true, the system will not start a new local binary process, but will use the user's own process.
*/
export class Config {
constructor(
public readonly browserstackUsername: string,
public readonly browserstackAccessKey: string,
public readonly DEV_MODE: boolean,
public readonly browserstackLocalOptions: Record<string, any>,
public readonly USE_OWN_LOCAL_BINARY_PROCESS: boolean,
) {}
}

Expand All @@ -44,6 +49,7 @@ const config = new Config(
process.env.BROWSERSTACK_ACCESS_KEY!,
process.env.DEV_MODE === "true",
browserstackLocalOptions,
process.env.USE_OWN_LOCAL_BINARY_PROCESS === "true",
);

export default config;
18 changes: 18 additions & 0 deletions src/lib/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ export async function ensureLocalBinarySetup(
"Ensuring local binary setup as it is required for private URLs...",
);

if (config.USE_OWN_LOCAL_BINARY_PROCESS) {
logger.info(
"Using user's own BrowserStack Local binary process, checking if it's running...",
);

const isRunning = await isBrowserStackLocalRunning();
if (!isRunning) {
throw new Error(
"USE_OWN_LOCAL_BINARY_PROCESS is enabled but BrowserStack Local process is not running. Please start your BrowserStack Local binary process first.",
);
}

logger.info(
"BrowserStack Local process is running, proceeding with user's own process.",
);
return;
}

const localBinary = new Local();
await killExistingBrowserStackLocalProcesses();

Expand Down
6 changes: 6 additions & 0 deletions src/tools/accessiblity-utils/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export class AccessibilityScanner {
const localHosts = new Set(["127.0.0.1", "localhost", "0.0.0.0"]);
const BS_LOCAL_DOMAIN = "bs-local.com";

if (config.USE_OWN_LOCAL_BINARY_PROCESS && hasLocal) {
throw new Error(
"Cannot start scan with local URLs when using own BrowserStack Local binary process. Please set USE_OWN_LOCAL_BINARY_PROCESS to false.",
);
}

if (hasLocal) {
await ensureLocalBinarySetup(localIdentifier);
} else {
Expand Down