fix(test): properly handle custom executable path (#1723)

This commit is contained in:
Dmitry Gozman 2020-04-08 19:34:33 -07:00 committed by GitHub
parent b385ea8415
commit 1b366b0fc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 19 deletions

View File

@ -99,10 +99,31 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {
delete state.browserType;
});
const browserType = playwright[product.toLowerCase()];
const executablePath = {
'chromium': process.env.CRPATH,
'firefox': process.env.FFPATH,
'webkit': process.env.WKPATH,
}[browserType.name()];
if (executablePath) {
const YELLOW_COLOR = '\x1b[33m';
const RESET_COLOR = '\x1b[0m';
console.warn(`${YELLOW_COLOR}WARN: running ${product} tests with ${executablePath}${RESET_COLOR}`);
browserType._executablePath = executablePath;
} else {
// Make sure the `npm install` was run after the chromium roll.
if (!fs.existsSync(browserType.executablePath()))
throw new Error(`Browser is not downloaded. Run 'npm install' and try to re-run tests`);
}
const launchOptions = {
handleSIGINT: false,
slowMo: valueFromEnv('SLOW_MO', 0),
headless: !!valueFromEnv('HEADLESS', true),
};
const browserEnvironment = new Environment(product);
browserEnvironment.beforeAll(async state => {
const { defaultBrowserOptions } = require('./utils').testOptions(state.browserType);
state.browser = await state.browserType.launch(defaultBrowserOptions);
state.browser = await state.browserType.launch(launchOptions);
state.browserServer = state.browser._ownedServer;
state._stdout = readline.createInterface({ input: state.browserServer.process().stdout });
state._stderr = readline.createInterface({ input: state.browserServer.process().stderr });
@ -156,7 +177,7 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {
describe(product, () => {
// In addition to state, expose these two on global so that describes can access them.
global.playwright = playwright;
global.browserType = playwright[product.toLowerCase()];
global.browserType = browserType;
testRunner.collector().useEnvironment(browserTypeEnvironment);
testRunner.collector().useEnvironment(goldenEnvironment); // Custom environment.

View File

@ -216,26 +216,11 @@ const utils = module.exports = {
testOptions(browserType) {
const headless = !!valueFromEnv('HEADLESS', true);
const executablePath = {
'chromium': process.env.CRPATH,
'firefox': process.env.FFPATH,
'webkit': process.env.WKPATH,
}[browserType.name()];
const defaultBrowserOptions = {
handleSIGINT: false,
executablePath,
slowMo: valueFromEnv('SLOW_MO', 0),
headless,
};
if (defaultBrowserOptions.executablePath) {
const YELLOW_COLOR = '\x1b[33m';
const RESET_COLOR = '\x1b[0m';
console.warn(`${YELLOW_COLOR}WARN: running ${product} tests with ${defaultBrowserOptions.executablePath}${RESET_COLOR}`);
} else {
// Make sure the `npm install` was run after the chromium roll.
if (!fs.existsSync(browserType.executablePath()))
throw new Error(`Browser is not downloaded. Run 'npm install' and try to re-run tests`);
}
const GOLDEN_DIR = path.join(__dirname, 'golden-' + browserType.name());
const OUTPUT_DIR = path.join(__dirname, 'output-' + browserType.name());
return {
@ -248,7 +233,7 @@ const utils = module.exports = {
browserType,
defaultBrowserOptions,
playwrightPath: PROJECT_ROOT,
headless: !!defaultBrowserOptions.headless,
headless,
GOLDEN_DIR,
OUTPUT_DIR,
};