diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 1c04d7eb71..4b3663de55 100755 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -209,10 +209,10 @@ type CaptureOptions = { fullPage: boolean; }; -async function launchContext(options: Options, headless: boolean): Promise<{ browser: Browser, browserName: string, launchOptions: LaunchOptions, contextOptions: BrowserContextOptions, context: BrowserContext }> { +async function launchContext(options: Options, headless: boolean, executablePath?: string): Promise<{ browser: Browser, browserName: string, launchOptions: LaunchOptions, contextOptions: BrowserContextOptions, context: BrowserContext }> { validateOptions(options); const browserType = lookupBrowserType(options); - const launchOptions: LaunchOptions = { headless }; + const launchOptions: LaunchOptions = { headless, executablePath }; if (options.channel) launchOptions.channel = options.channel as any; @@ -347,7 +347,7 @@ async function openPage(context: BrowserContext, url: string | undefined): Promi } async function open(options: Options, url: string | undefined, language: string) { - const { context, launchOptions, contextOptions } = await launchContext(options, !!process.env.PWTEST_CLI_HEADLESS); + const { context, launchOptions, contextOptions } = await launchContext(options, !!process.env.PWTEST_CLI_HEADLESS, process.env.PWTEST_CLI_EXECUTABLE_PATH); await context._enableRecorder({ language, launchOptions, @@ -361,7 +361,7 @@ async function open(options: Options, url: string | undefined, language: string) } async function codegen(options: Options, url: string | undefined, language: string, outputFile?: string) { - const { context, launchOptions, contextOptions } = await launchContext(options, !!process.env.PWTEST_CLI_HEADLESS); + const { context, launchOptions, contextOptions } = await launchContext(options, !!process.env.PWTEST_CLI_HEADLESS, process.env.PWTEST_CLI_EXECUTABLE_PATH); await context._enableRecorder({ language, launchOptions, diff --git a/src/server/supplements/recorder/codeGenerator.ts b/src/server/supplements/recorder/codeGenerator.ts index 1f55b09bb6..9b9e404df4 100644 --- a/src/server/supplements/recorder/codeGenerator.ts +++ b/src/server/supplements/recorder/codeGenerator.ts @@ -41,6 +41,7 @@ export class CodeGenerator extends EventEmitter { super(); launchOptions = { headless: false, ...launchOptions }; + delete launchOptions.executablePath; this._enabled = generateHeaders; this._options = { browserName, generateHeaders, launchOptions, contextOptions, deviceName, saveStorage }; this.restart(); diff --git a/tests/inspector/inspectorTest.ts b/tests/inspector/inspectorTest.ts index 33b9284226..0f48c726fa 100644 --- a/tests/inspector/inspectorTest.ts +++ b/tests/inspector/inspectorTest.ts @@ -27,6 +27,7 @@ type CLITestArgs = { recorderPageGetter: () => Promise; openRecorder: () => Promise; runCLI: (args: string[]) => CLIMock; + executablePath: string | undefined; }; export const test = contextTest.extend({ @@ -34,7 +35,7 @@ export const test = contextTest.extend({ process.env.PWTEST_RECORDER_PORT = String(10907 + workerInfo.workerIndex); }, - async beforeEach({ page, context, toImpl, browserName, browserChannel, headful, mode }, testInfo: folio.TestInfo): Promise { + async beforeEach({ page, context, toImpl, browserName, browserChannel, headful, mode, launchOptions: { executablePath } }, testInfo: folio.TestInfo): Promise { testInfo.skip(mode === 'service'); const recorderPageGetter = async () => { while (!toImpl(context).recorderAppForTest) @@ -46,7 +47,7 @@ export const test = contextTest.extend({ }; return { runCLI: (cliArgs: string[]) => { - this._cli = new CLIMock(browserName, browserChannel, !headful, cliArgs); + this._cli = new CLIMock(browserName, browserChannel, !headful, cliArgs, executablePath); return this._cli; }, openRecorder: async () => { @@ -54,6 +55,7 @@ export const test = contextTest.extend({ return new Recorder(page, await recorderPageGetter()); }, recorderPageGetter, + executablePath }; }, @@ -161,7 +163,7 @@ class CLIMock { private waitForCallback: () => void; exited: Promise; - constructor(browserName: string, browserChannel: string, headless: boolean, args: string[]) { + constructor(browserName: string, browserChannel: string, headless: boolean, args: string[], executablePath?: string) { this.data = ''; const nodeArgs = [ path.join(__dirname, '..', '..', 'lib', 'cli', 'cli.js'), @@ -176,6 +178,7 @@ class CLIMock { ...process.env, PWTEST_CLI_EXIT: '1', PWTEST_CLI_HEADLESS: headless ? '1' : undefined, + PWTEST_CLI_EXECUTABLE_PATH: executablePath, }, stdio: 'pipe' }); @@ -186,9 +189,15 @@ class CLIMock { }); this.exited = new Promise((f, r) => { this.process.stderr.on('data', data => { - r(new Error(data)); + console.error(data.toString()); + }); + this.process.on('exit', (exitCode, signal) => { + if (exitCode) + r(new Error(`Process failed with exit code ${exitCode}`)); + if (signal) + r(new Error(`Process recieved signal: ${signal}`)); + f(); }); - this.process.on('exit', f); }); }