2020-03-06 11:25:55 -06:00
|
|
|
const execa = require('execa');
|
|
|
|
const program = require('commander');
|
2020-05-20 19:49:36 -05:00
|
|
|
const resolveBin = require('resolve-as-bin');
|
2020-03-06 11:25:55 -06:00
|
|
|
const { resolve, sep } = require('path');
|
2020-03-03 17:12:52 -06:00
|
|
|
|
2020-06-01 07:48:23 -05:00
|
|
|
const cypress = (commandName, { updateScreenshots }) => {
|
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
|
|
|
|
2020-03-06 11:25:55 -06:00
|
|
|
const execaOptions = {
|
2020-03-03 17:12:52 -06:00
|
|
|
cwd: __dirname,
|
|
|
|
stdio: 'inherit',
|
|
|
|
};
|
|
|
|
|
2020-05-20 19:49:36 -05:00
|
|
|
return execa(resolveBin('cypress'), cypressOptions, execaOptions)
|
2020-03-03 17:12:52 -06:00
|
|
|
.then(() => {}) // no return value
|
2020-03-27 07:59:43 -05:00
|
|
|
.catch(error => {
|
|
|
|
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';
|
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)
|
|
|
|
.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)
|
|
|
|
.action(options => cypress('run', options));
|
2020-03-03 17:12:52 -06:00
|
|
|
|
|
|
|
program.parse(process.argv);
|
|
|
|
};
|