2021-10-27 08:54:10 -05:00
|
|
|
const { program } = require('commander');
|
2022-04-22 08:33:13 -05:00
|
|
|
const execa = require('execa');
|
2020-03-06 11:25:55 -06:00
|
|
|
const { resolve, sep } = require('path');
|
2023-03-08 03:17:26 -06:00
|
|
|
const resolveBin = require('resolve-bin');
|
2020-03-03 17:12:52 -06:00
|
|
|
|
2022-11-24 03:15:21 -06:00
|
|
|
const cypress = (commandName, { updateScreenshots, browser }) => {
|
2020-03-03 17:12:52 -06:00
|
|
|
// Support running an unpublished dev build
|
2020-03-06 11:25:55 -06:00
|
|
|
const dirname = __dirname.split(sep).pop();
|
|
|
|
const projectPath = resolve(`${__dirname}${dirname === 'dist' ? '/..' : ''}`);
|
2020-03-03 17:12:52 -06:00
|
|
|
|
2020-06-01 07:48:23 -05:00
|
|
|
// For plugins/extendConfig
|
|
|
|
const CWD = `CWD=${process.cwd()}`;
|
|
|
|
|
|
|
|
// For plugins/compareSnapshots
|
|
|
|
const UPDATE_SCREENSHOTS = `UPDATE_SCREENSHOTS=${updateScreenshots ? 1 : 0}`;
|
|
|
|
|
|
|
|
const cypressOptions = [commandName, '--env', `${CWD},${UPDATE_SCREENSHOTS}`, `--project=${projectPath}`];
|
2020-03-03 17:12:52 -06:00
|
|
|
|
2022-11-24 03:15:21 -06:00
|
|
|
if (browser) {
|
|
|
|
cypressOptions.push('--browser', browser);
|
|
|
|
}
|
|
|
|
|
2020-03-06 11:25:55 -06:00
|
|
|
const execaOptions = {
|
2020-03-03 17:12:52 -06:00
|
|
|
cwd: __dirname,
|
|
|
|
stdio: 'inherit',
|
|
|
|
};
|
|
|
|
|
2023-03-08 03:17:26 -06:00
|
|
|
return execa(resolveBin.sync('cypress'), cypressOptions, execaOptions)
|
2020-03-03 17:12:52 -06:00
|
|
|
.then(() => {}) // no return value
|
2021-01-20 00:59:48 -06:00
|
|
|
.catch((error) => {
|
2020-03-27 07:59:43 -05:00
|
|
|
console.error(error.message);
|
|
|
|
process.exitCode = 1;
|
|
|
|
});
|
2020-03-03 17:12:52 -06:00
|
|
|
};
|
|
|
|
|
2020-03-06 11:25:55 -06:00
|
|
|
module.exports = () => {
|
2020-06-01 07:48:23 -05:00
|
|
|
const updateOption = '-u, --update-screenshots';
|
|
|
|
const updateDescription = 'update expected screenshots';
|
2022-11-24 03:15:21 -06:00
|
|
|
const browserOption = '-b, --browser <browser>';
|
|
|
|
const browserDescription = 'specify which browser to use';
|
2020-03-03 17:12:52 -06:00
|
|
|
|
|
|
|
program
|
|
|
|
.command('open')
|
|
|
|
.description('runs tests within the interactive GUI')
|
2020-06-01 07:48:23 -05:00
|
|
|
.option(updateOption, updateDescription)
|
2022-11-24 03:15:21 -06:00
|
|
|
.option(browserOption, browserDescription)
|
2021-01-20 00:59:48 -06:00
|
|
|
.action((options) => cypress('open', options));
|
2020-03-03 17:12:52 -06:00
|
|
|
|
|
|
|
program
|
|
|
|
.command('run')
|
|
|
|
.description('runs tests from the CLI without the GUI')
|
2020-06-01 07:48:23 -05:00
|
|
|
.option(updateOption, updateDescription)
|
2022-11-24 03:15:21 -06:00
|
|
|
.option(browserOption, browserDescription)
|
2021-01-20 00:59:48 -06:00
|
|
|
.action((options) => cypress('run', options));
|
2020-03-03 17:12:52 -06:00
|
|
|
|
|
|
|
program.parse(process.argv);
|
|
|
|
};
|