fix: propagate custom executable path to codegen (#6509)

This commit is contained in:
Yury Semikhatsky 2021-05-12 18:45:57 +00:00 committed by GitHub
parent d540b4478b
commit 460cc31941
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 9 deletions

View File

@ -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,

View File

@ -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();

View File

@ -27,6 +27,7 @@ type CLITestArgs = {
recorderPageGetter: () => Promise<Page>;
openRecorder: () => Promise<Recorder>;
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<CLITestArgs> {
async beforeEach({ page, context, toImpl, browserName, browserChannel, headful, mode, launchOptions: { executablePath } }, testInfo: folio.TestInfo): Promise<CLITestArgs> {
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<void>;
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);
});
}