Feat: Adding an optional browser config option to e2e test runner (#59076)

Adding an optional browser config option to e2e test runner
This commit is contained in:
Timur Olzhabayev 2022-11-24 10:15:21 +01:00 committed by GitHub
parent 6f00bc5674
commit 24ce1a8a0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@ const execa = require('execa');
const { resolve, sep } = require('path');
const resolveBin = require('resolve-as-bin');
const cypress = (commandName, { updateScreenshots }) => {
const cypress = (commandName, { updateScreenshots, browser }) => {
// Support running an unpublished dev build
const dirname = __dirname.split(sep).pop();
const projectPath = resolve(`${__dirname}${dirname === 'dist' ? '/..' : ''}`);
@ -16,6 +16,10 @@ const cypress = (commandName, { updateScreenshots }) => {
const cypressOptions = [commandName, '--env', `${CWD},${UPDATE_SCREENSHOTS}`, `--project=${projectPath}`];
if (browser) {
cypressOptions.push('--browser', browser);
}
const execaOptions = {
cwd: __dirname,
stdio: 'inherit',
@ -32,17 +36,21 @@ const cypress = (commandName, { updateScreenshots }) => {
module.exports = () => {
const updateOption = '-u, --update-screenshots';
const updateDescription = 'update expected screenshots';
const browserOption = '-b, --browser <browser>';
const browserDescription = 'specify which browser to use';
program
.command('open')
.description('runs tests within the interactive GUI')
.option(updateOption, updateDescription)
.option(browserOption, browserDescription)
.action((options) => cypress('open', options));
program
.command('run')
.description('runs tests from the CLI without the GUI')
.option(updateOption, updateDescription)
.option(browserOption, browserDescription)
.action((options) => cypress('run', options));
program.parse(process.argv);