Files
cypress/cli/lib/exec/run.js
Jennifer Shehane 692a3c07d9 Support --tag argument (#5164)
* Alphabetize cli options for my own sanity

* begin added tag flag

* Fix some minor grammar in cli help output + be more specific for specs description

* update snapshot based on alphabetization change

* update snapshot to include --tag in help output

* update logic for pulling out space delimited args to look through --tag and --spec flags dynamically

* Support and pass along tag flag to run and record

- show err if passed without record flag
- sanitize args into comma separated string
- display tag in record errors

* fix some tests/snapshots where 'tag' was missing

* Actually try passing in tag through tests to ensure it prints.

* Merge branch 'develop' into issue-2561-tags

# Conflicts:
#	cli/__snapshots__/cli_spec.js
#	cli/lib/cli.js
#	cli/lib/exec/run.js
#	packages/server/lib/modes/run.js
#	packages/server/lib/util/args.js

* Send 'tags' as an array to backend API

* Update json-schemas to query against 2.2.0 of postRun

- this will require a bump to json-schemas repo

* update test to reflect tags array

* update snapshot to display nightly tag

* rearrange args to alphabetical order in specs

* Add tags to runResponses / remove tag from incorrect instance post

* Fix failing specs / snapshots

* Update error messages + snapshots

* Fix snapshot that no longer displays tag arg

* fix args unit test

* remove extra slash

* add a few more cli tests

* another test just in case

* a quick unit test for displayFlags utility


Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
2019-12-05 23:02:14 +06:30

136 lines
2.9 KiB
JavaScript

const _ = require('lodash')
const debug = require('debug')('cypress:cli')
const util = require('../util')
const spawn = require('./spawn')
const verify = require('../tasks/verify')
// maps options collected by the CLI
// and forms list of CLI arguments to the server
const processRunOptions = (options = {}) => {
debug('processing run options')
const args = ['--run-project', options.project]
if (options.browser) {
args.push('--browser', options.browser)
}
if (options.ci) {
// push to display the deprecation message
args.push('--ci')
// also automatically record
args.push('--record', true)
}
if (options.ciBuildId) {
args.push('--ci-build-id', options.ciBuildId)
}
if (options.config) {
args.push('--config', options.config)
}
if (options.configFile !== undefined) {
args.push('--config-file', options.configFile)
}
if (options.env) {
args.push('--env', options.env)
}
if (options.exit === false) {
args.push('--no-exit')
}
if (options.group) {
args.push('--group', options.group)
}
if (options.headed) {
args.push('--headed', options.headed)
}
// if key is set use that - else attempt to find it by environment variable
if (options.key == null) {
debug('--key is not set, looking up environment variable CYPRESS_RECORD_KEY')
options.key = util.getEnv('CYPRESS_RECORD_KEY') || util.getEnv('CYPRESS_CI_KEY')
}
// if we have a key assume we're in record mode
if (options.key) {
args.push('--key', options.key)
}
if (options.outputPath) {
args.push('--output-path', options.outputPath)
}
if (options.parallel) {
args.push('--parallel')
}
if (options.port) {
args.push('--port', options.port)
}
// if record is defined and we're not
// already in ci mode, then send it up
if (options.record != null && !options.ci) {
args.push('--record', options.record)
}
// if we have a specific reporter push that into the args
if (options.reporter) {
args.push('--reporter', options.reporter)
}
// if we have a specific reporter push that into the args
if (options.reporterOptions) {
args.push('--reporter-options', options.reporterOptions)
}
// if we have specific spec(s) push that into the args
if (options.spec) {
args.push('--spec', options.spec)
}
if (options.tag) {
args.push('--tag', options.tag)
}
return args
}
module.exports = {
processRunOptions,
// resolves with the number of failed tests
start (options = {}) {
_.defaults(options, {
key: null,
spec: null,
reporter: null,
reporterOptions: null,
project: process.cwd(),
})
function run () {
const args = processRunOptions(options)
debug('run to spawn.start args %j', args)
return spawn.start(args, {
dev: options.dev,
})
}
if (options.dev) {
return run()
}
return verify.start()
.then(run)
},
}