2020-03-06 11:25:55 -06:00
|
|
|
const execa = require('execa');
|
|
|
|
const program = require('commander');
|
|
|
|
const { resolve, sep } = require('path');
|
2020-03-03 17:12:52 -06:00
|
|
|
|
2020-03-06 11:25:55 -06:00
|
|
|
const cypress = commandName => {
|
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
|
|
|
|
|
|
|
const cypressOptions = [commandName, '--env', `CWD=${process.cwd()}`, `--project=${projectPath}`];
|
|
|
|
|
2020-03-06 11:25:55 -06:00
|
|
|
const execaOptions = {
|
2020-03-03 17:12:52 -06:00
|
|
|
cwd: __dirname,
|
|
|
|
stdio: 'inherit',
|
|
|
|
};
|
|
|
|
|
|
|
|
return execa(`${projectPath}/node_modules/.bin/cypress`, cypressOptions, execaOptions)
|
|
|
|
.then(() => {}) // no return value
|
|
|
|
.catch(error => console.error(error.message));
|
|
|
|
};
|
|
|
|
|
2020-03-06 11:25:55 -06:00
|
|
|
module.exports = () => {
|
2020-03-03 17:12:52 -06:00
|
|
|
const configOption = '-c, --config <path>';
|
|
|
|
const configDescription = 'path to JSON file where configuration values are set; defaults to "cypress.json"';
|
|
|
|
|
|
|
|
program
|
|
|
|
.command('open')
|
|
|
|
.description('runs tests within the interactive GUI')
|
|
|
|
.option(configOption, configDescription)
|
|
|
|
.action(() => cypress('open'));
|
|
|
|
|
|
|
|
program
|
|
|
|
.command('run')
|
|
|
|
.description('runs tests from the CLI without the GUI')
|
|
|
|
.option(configOption, configDescription)
|
|
|
|
.action(() => cypress('run'));
|
|
|
|
|
|
|
|
program.parse(process.argv);
|
|
|
|
};
|