mirror of https://github.com/lukechilds/docs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
6.5 KiB
143 lines
6.5 KiB
'use strict';
|
|
|
|
var _templateObject = _taggedTemplateLiteral(['\n runs Cypress in the browser with the given name.\n note: using an external browser will not record a video.\n '], ['\n runs Cypress in the browser with the given name.\n note: using an external browser will not record a video.\n ']);
|
|
|
|
function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
|
|
var _ = require('lodash');
|
|
var commander = require('commander');
|
|
|
|
var _require = require('common-tags'),
|
|
oneLine = _require.oneLine;
|
|
|
|
var debug = require('debug')('cypress:cli');
|
|
var util = require('./util');
|
|
var logger = require('./logger');
|
|
|
|
var coerceFalse = function coerceFalse(arg) {
|
|
return arg !== 'false';
|
|
};
|
|
|
|
var parseOpts = function parseOpts(opts) {
|
|
opts = _.pick(opts, 'project', 'spec', 'reporter', 'reporterOptions', 'path', 'destination', 'port', 'env', 'cypressVersion', 'config', 'record', 'key', 'browser', 'detached', 'headed', 'group', 'groupId', 'global', 'dev');
|
|
|
|
debug('parsed cli options', opts);
|
|
|
|
return opts;
|
|
};
|
|
|
|
var descriptions = {
|
|
record: 'records the run. sends test results, screenshots and videos to your Cypress Dashboard.',
|
|
key: 'your secret Record Key. you can omit this if you set a CYPRESS_RECORD_KEY environment variable.',
|
|
spec: 'runs a specific spec file. defaults to "all"',
|
|
reporter: 'runs a specific mocha reporter. pass a path to use a custom reporter. defaults to "spec"',
|
|
reporterOptions: 'options for the mocha reporter. defaults to "null"',
|
|
port: 'runs Cypress on a specific port. overrides any value in cypress.json.',
|
|
env: 'sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json',
|
|
config: 'sets configuration values. separate multiple values with a comma. overrides any value in cypress.json.',
|
|
browser: oneLine(_templateObject),
|
|
detached: 'runs Cypress application in detached mode',
|
|
project: 'path to the project',
|
|
global: 'force Cypress into global mode as if its globally installed',
|
|
version: 'Prints Cypress version',
|
|
headed: 'displays the Electron browser instead of running headlessly',
|
|
group: 'flag to group individual runs by using common --group-id',
|
|
groupId: 'optional common id to group runs by, extracted from CI environment variables by default',
|
|
dev: 'runs cypress in development and bypasses binary check'
|
|
};
|
|
|
|
var knownCommands = ['version', 'run', 'open', 'install', 'verify', '-v', '--version', 'help', '-h', '--help'];
|
|
|
|
var text = function text(description) {
|
|
if (!descriptions[description]) {
|
|
throw new Error('Could not find description for: ' + description);
|
|
}
|
|
|
|
return descriptions[description];
|
|
};
|
|
|
|
function includesVersion(args) {
|
|
return _.includes(args, 'version') || _.includes(args, '--version') || _.includes(args, '-v');
|
|
}
|
|
|
|
function showVersions() {
|
|
debug('printing Cypress version');
|
|
return require('./exec/versions').getVersions().then(function () {
|
|
var versions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
|
|
logger.log('Cypress package version:', versions.package);
|
|
logger.log('Cypress binary version:', versions.binary);
|
|
process.exit(0);
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
init: function init(args) {
|
|
if (!args) {
|
|
args = process.argv;
|
|
}
|
|
|
|
var program = new commander.Command();
|
|
|
|
// bug in commaner not printing name
|
|
// in usage help docs
|
|
program._name = 'cypress';
|
|
|
|
program.command('help').description('Shows CLI help and exits').action(function () {
|
|
program.help();
|
|
});
|
|
|
|
program.option('-v, --version', text('version')).command('version').description(text('version')).action(showVersions);
|
|
|
|
program.command('run').usage('[options]').description('Runs Cypress tests from the CLI without the GUI').option('--record [bool]', text('record'), coerceFalse).option('--headed', text('headed')).option('-k, --key <record-key>', text('key')).option('-s, --spec <spec>', text('spec')).option('-r, --reporter <reporter>', text('reporter')).option('-o, --reporter-options <reporter-options>', text('reporterOptions')).option('-p, --port <port>', text('port')).option('-e, --env <env>', text('env')).option('-c, --config <config>', text('config')).option('-b, --browser <browser-name>', text('browser')).option('-P, --project <project-path>', text('project')).option('--group', text('group'), coerceFalse).option('--group-id <group-id>', text('groupId')).option('--dev', text('dev'), coerceFalse).action(function (opts) {
|
|
debug('running Cypress');
|
|
require('./exec/run').start(parseOpts(opts)).then(util.exit).catch(util.logErrorExit1);
|
|
});
|
|
|
|
program.command('open').usage('[options]').description('Opens Cypress in the interactive GUI.').option('-p, --port <port>', text('port')).option('-e, --env <env>', text('env')).option('-c, --config <config>', text('config')).option('-d, --detached [bool]', text('detached'), coerceFalse).option('-P, --project <project path>', text('project')).option('--global', text('global')).option('--dev', text('dev'), coerceFalse).action(function (opts) {
|
|
debug('opening Cypress');
|
|
require('./exec/open').start(parseOpts(opts)).catch(util.logErrorExit1);
|
|
});
|
|
|
|
program.command('install').description('Installs the Cypress executable matching this package\'s version').action(function () {
|
|
require('./tasks/install').start({ force: true }).catch(util.logErrorExit1);
|
|
});
|
|
|
|
program.command('verify').description('Verifies that Cypress is installed correctly and executable').action(function () {
|
|
require('./tasks/verify').start({ force: true, welcomeMessage: false }).catch(util.logErrorExit1);
|
|
});
|
|
|
|
debug('cli starts with arguments %j', args);
|
|
|
|
// if there are no arguments
|
|
if (args.length <= 2) {
|
|
debug('printing help');
|
|
program.help();
|
|
// exits
|
|
}
|
|
|
|
var firstCommand = args[2];
|
|
if (!_.includes(knownCommands, firstCommand)) {
|
|
debug('unknwon command %s', firstCommand);
|
|
logger.error('Unknown command', '"' + firstCommand + '"');
|
|
program.outputHelp();
|
|
return util.exit(1);
|
|
}
|
|
|
|
if (includesVersion(args)) {
|
|
// commander 2.11.0 changes behavior
|
|
// and now does not understand top level options
|
|
// .option('-v, --version').command('version')
|
|
// so we have to manually catch '-v, --version'
|
|
return showVersions();
|
|
}
|
|
debug('program parsing arguments');
|
|
return program.parse(args);
|
|
}
|
|
};
|
|
|
|
if (!module.parent) {
|
|
logger.error('This CLI module should be required from another Node module');
|
|
logger.error('and not executed directly');
|
|
process.exit(-1);
|
|
}
|