mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-23 07:34:00 -05:00
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>
This commit is contained in:
+221
-209
@@ -1,136 +1,6 @@
|
||||
exports['cli --version no binary version 1'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: not installed
|
||||
`
|
||||
exports['shows help for open --foo 1'] = `
|
||||
|
||||
exports['cli -v no binary version 1'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: not installed
|
||||
`
|
||||
|
||||
exports['cli cypress run warns with space-separated --specs 1'] = `
|
||||
[33m⚠[39m Warning: It looks like you're passing --spec a space-separated list of files:
|
||||
|
||||
"a b c d e f g"
|
||||
|
||||
This will work, but it's not recommended.
|
||||
|
||||
The most common cause of this warning is using an unescaped glob pattern. If you are
|
||||
trying to pass a glob pattern, escape it using quotes:
|
||||
cypress run --spec "**/*.spec.js"
|
||||
|
||||
If you are trying to pass multiple spec filenames, separate them by commas instead:
|
||||
cypress run --spec spec1,spec2,spec3
|
||||
`
|
||||
|
||||
exports['cli help command shows help 1'] = `
|
||||
|
||||
command: bin/cypress help
|
||||
code: 0
|
||||
failed: false
|
||||
killed: false
|
||||
signal: null
|
||||
timedOut: false
|
||||
|
||||
stdout:
|
||||
-------
|
||||
Usage: cypress <command> [options]
|
||||
|
||||
Options:
|
||||
|
||||
-v, --version prints Cypress version
|
||||
-h, --help output usage information
|
||||
|
||||
Commands:
|
||||
|
||||
help Shows CLI help and exits
|
||||
version prints Cypress version
|
||||
run [options] Runs Cypress tests from the CLI without the GUI
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify [options] Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
|
||||
-------
|
||||
|
||||
`
|
||||
|
||||
exports['cli help command shows help for --help 1'] = `
|
||||
|
||||
command: bin/cypress --help
|
||||
code: 0
|
||||
failed: false
|
||||
killed: false
|
||||
signal: null
|
||||
timedOut: false
|
||||
|
||||
stdout:
|
||||
-------
|
||||
Usage: cypress <command> [options]
|
||||
|
||||
Options:
|
||||
|
||||
-v, --version prints Cypress version
|
||||
-h, --help output usage information
|
||||
|
||||
Commands:
|
||||
|
||||
help Shows CLI help and exits
|
||||
version prints Cypress version
|
||||
run [options] Runs Cypress tests from the CLI without the GUI
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify [options] Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
|
||||
-------
|
||||
|
||||
`
|
||||
|
||||
exports['cli help command shows help for -h 1'] = `
|
||||
|
||||
command: bin/cypress -h
|
||||
code: 0
|
||||
failed: false
|
||||
killed: false
|
||||
signal: null
|
||||
timedOut: false
|
||||
|
||||
stdout:
|
||||
-------
|
||||
Usage: cypress <command> [options]
|
||||
|
||||
Options:
|
||||
|
||||
-v, --version prints Cypress version
|
||||
-h, --help output usage information
|
||||
|
||||
Commands:
|
||||
|
||||
help Shows CLI help and exits
|
||||
version prints Cypress version
|
||||
run [options] Runs Cypress tests from the CLI without the GUI
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify [options] Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
|
||||
-------
|
||||
|
||||
`
|
||||
|
||||
exports['cli unknown command shows usage and exits 1'] = `
|
||||
|
||||
command: bin/cypress foo
|
||||
command: bin/cypress open --foo
|
||||
code: 1
|
||||
failed: true
|
||||
killed: false
|
||||
@@ -139,24 +9,25 @@ exports['cli unknown command shows usage and exits 1'] = `
|
||||
|
||||
stdout:
|
||||
-------
|
||||
Unknown command "foo"
|
||||
error: unknown option: --foo
|
||||
|
||||
Usage: cypress <command> [options]
|
||||
|
||||
Options:
|
||||
Usage: open [options]
|
||||
|
||||
-v, --version prints Cypress version
|
||||
-h, --help output usage information
|
||||
Opens Cypress in the interactive GUI.
|
||||
|
||||
Commands:
|
||||
Options:
|
||||
|
||||
help Shows CLI help and exits
|
||||
version prints Cypress version
|
||||
run [options] Runs Cypress tests from the CLI without the GUI
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify [options] Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-b, --browser <browser-path> path to a custom browser to be added to the list of available browsers in Cypress
|
||||
-c, --config <config> sets configuration values. separate multiple values with a comma. overrides any value in cypress.json.
|
||||
-C, --config-file <config-file> path to JSON file where configuration values are set. defaults to "cypress.json". pass "false" to disable.
|
||||
-d, --detached [bool] runs Cypress application in detached mode
|
||||
-e, --env <env> sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json
|
||||
--global force Cypress into global mode as if its globally installed
|
||||
-p, --port <port> runs Cypress on a specific port. overrides any value in cypress.json.
|
||||
-P, --project <project-path> path to the project
|
||||
--dev runs cypress in development and bypasses binary check
|
||||
-h, --help output usage information
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
@@ -165,9 +36,9 @@ exports['cli unknown command shows usage and exits 1'] = `
|
||||
|
||||
`
|
||||
|
||||
exports['cli unknown option shows help for cache command - no sub-command 1'] = `
|
||||
exports['shows help for run --foo 1'] = `
|
||||
|
||||
command: bin/cypress cache
|
||||
command: bin/cypress run --foo
|
||||
code: 1
|
||||
failed: true
|
||||
killed: false
|
||||
@@ -176,16 +47,34 @@ exports['cli unknown option shows help for cache command - no sub-command 1'] =
|
||||
|
||||
stdout:
|
||||
-------
|
||||
Usage: cache [command]
|
||||
error: unknown option: --foo
|
||||
|
||||
Manages the Cypress binary cache
|
||||
|
||||
Usage: run [options]
|
||||
|
||||
Runs Cypress tests from the CLI without the GUI
|
||||
|
||||
Options:
|
||||
|
||||
list list cached binary versions
|
||||
path print the path to the binary cache
|
||||
clear delete all cached binaries
|
||||
-h, --help output usage information
|
||||
-b, --browser <browser-name-or-path> runs Cypress in the browser with the given name. if a filesystem path is supplied, Cypress will attempt to use the browser at that path.
|
||||
--ci-build-id <id> the unique identifier for a run on your CI provider. typically a "BUILD_ID" env var. this value is automatically detected for most CI providers
|
||||
-c, --config <config> sets configuration values. separate multiple values with a comma. overrides any value in cypress.json.
|
||||
-C, --config-file <config-file> path to JSON file where configuration values are set. defaults to "cypress.json". pass "false" to disable.
|
||||
-e, --env <env> sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json
|
||||
--group <name> a named group for recorded runs in the Cypress Dashboard
|
||||
-k, --key <record-key> your secret Record Key. you can omit this if you set a CYPRESS_RECORD_KEY environment variable.
|
||||
--headed displays the Electron browser instead of running headlessly
|
||||
--no-exit keep the browser open after tests finish
|
||||
--parallel enables concurrent runs and automatic load balancing of specs across multiple machines or processes
|
||||
-p, --port <port> runs Cypress on a specific port. overrides any value in cypress.json.
|
||||
-P, --project <project-path> path to the project
|
||||
--record [bool] records the run. sends test results, screenshots and videos to your Cypress Dashboard.
|
||||
-r, --reporter <reporter> runs a specific mocha reporter. pass a path to use a custom reporter. defaults to "spec"
|
||||
-o, --reporter-options <reporter-options> options for the mocha reporter. defaults to "null"
|
||||
-s, --spec <spec> runs specific spec file(s). defaults to "all"
|
||||
-t, --tag <tag> named tag(s) for recorded runs in the Cypress Dashboard
|
||||
--dev runs cypress in development and bypasses binary check
|
||||
-h, --help output usage information
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
@@ -258,24 +147,9 @@ exports['cli unknown option shows help for cache command - unknown sub-command f
|
||||
|
||||
`
|
||||
|
||||
exports['cli version and binary version 1'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: X.Y.Z
|
||||
`
|
||||
exports['cli unknown option shows help for cache command - no sub-command 1'] = `
|
||||
|
||||
exports['cli version and binary version 2'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: X.Y.Z
|
||||
`
|
||||
|
||||
exports['cli version no binary version 1'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: not installed
|
||||
`
|
||||
|
||||
exports['shows help for open --foo 1'] = `
|
||||
|
||||
command: bin/cypress open --foo
|
||||
command: bin/cypress cache
|
||||
code: 1
|
||||
failed: true
|
||||
killed: false
|
||||
@@ -284,25 +158,16 @@ exports['shows help for open --foo 1'] = `
|
||||
|
||||
stdout:
|
||||
-------
|
||||
error: unknown option: --foo
|
||||
Usage: cache [command]
|
||||
|
||||
|
||||
Usage: open [options]
|
||||
|
||||
Opens Cypress in the interactive GUI.
|
||||
Manages the Cypress binary cache
|
||||
|
||||
Options:
|
||||
|
||||
-p, --port <port> runs Cypress on a specific port. overrides any value in the configuration file.
|
||||
-e, --env <env> sets environment variables. separate multiple values with a comma. overrides any value in the configuration file or cypress.env.json
|
||||
-c, --config <config> sets configuration values. separate multiple values with a comma. overrides any value in the configuration file.
|
||||
-C, --config-file <config-file> path to JSON file where configuration values are set. defaults to "cypress.json". pass "false" to disable.
|
||||
-d, --detached [bool] runs Cypress application in detached mode
|
||||
-b, --browser <browser-path> path to a custom browser to be added to the list of available browsers in Cypress
|
||||
-P, --project <project-path> path to the project
|
||||
--global force Cypress into global mode as if its globally installed
|
||||
--dev runs cypress in development and bypasses binary check
|
||||
-h, --help output usage information
|
||||
list list cached binary versions
|
||||
path print the path to the binary cache
|
||||
clear delete all cached binaries
|
||||
-h, --help output usage information
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
@@ -311,9 +176,114 @@ exports['shows help for open --foo 1'] = `
|
||||
|
||||
`
|
||||
|
||||
exports['shows help for run --foo 1'] = `
|
||||
exports['cli help command shows help 1'] = `
|
||||
|
||||
command: bin/cypress run --foo
|
||||
command: bin/cypress help
|
||||
code: 0
|
||||
failed: false
|
||||
killed: false
|
||||
signal: null
|
||||
timedOut: false
|
||||
|
||||
stdout:
|
||||
-------
|
||||
Usage: cypress <command> [options]
|
||||
|
||||
Options:
|
||||
|
||||
-v, --version prints Cypress version
|
||||
-h, --help output usage information
|
||||
|
||||
Commands:
|
||||
|
||||
help Shows CLI help and exits
|
||||
version prints Cypress version
|
||||
run [options] Runs Cypress tests from the CLI without the GUI
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify [options] Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
|
||||
-------
|
||||
|
||||
`
|
||||
|
||||
exports['cli help command shows help for -h 1'] = `
|
||||
|
||||
command: bin/cypress -h
|
||||
code: 0
|
||||
failed: false
|
||||
killed: false
|
||||
signal: null
|
||||
timedOut: false
|
||||
|
||||
stdout:
|
||||
-------
|
||||
Usage: cypress <command> [options]
|
||||
|
||||
Options:
|
||||
|
||||
-v, --version prints Cypress version
|
||||
-h, --help output usage information
|
||||
|
||||
Commands:
|
||||
|
||||
help Shows CLI help and exits
|
||||
version prints Cypress version
|
||||
run [options] Runs Cypress tests from the CLI without the GUI
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify [options] Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
|
||||
-------
|
||||
|
||||
`
|
||||
|
||||
exports['cli help command shows help for --help 1'] = `
|
||||
|
||||
command: bin/cypress --help
|
||||
code: 0
|
||||
failed: false
|
||||
killed: false
|
||||
signal: null
|
||||
timedOut: false
|
||||
|
||||
stdout:
|
||||
-------
|
||||
Usage: cypress <command> [options]
|
||||
|
||||
Options:
|
||||
|
||||
-v, --version prints Cypress version
|
||||
-h, --help output usage information
|
||||
|
||||
Commands:
|
||||
|
||||
help Shows CLI help and exits
|
||||
version prints Cypress version
|
||||
run [options] Runs Cypress tests from the CLI without the GUI
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify [options] Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
|
||||
-------
|
||||
|
||||
`
|
||||
|
||||
exports['cli unknown command shows usage and exits 1'] = `
|
||||
|
||||
command: bin/cypress foo
|
||||
code: 1
|
||||
failed: true
|
||||
killed: false
|
||||
@@ -322,33 +292,24 @@ exports['shows help for run --foo 1'] = `
|
||||
|
||||
stdout:
|
||||
-------
|
||||
error: unknown option: --foo
|
||||
Unknown command "foo"
|
||||
|
||||
Usage: cypress <command> [options]
|
||||
|
||||
Usage: run [options]
|
||||
Options:
|
||||
|
||||
Runs Cypress tests from the CLI without the GUI
|
||||
-v, --version prints Cypress version
|
||||
-h, --help output usage information
|
||||
|
||||
Options:
|
||||
Commands:
|
||||
|
||||
--record [bool] records the run. sends test results, screenshots and videos to your Cypress Dashboard.
|
||||
--headed displays the Electron browser instead of running headlessly
|
||||
-k, --key <record-key> your secret Record Key. you can omit this if you set a CYPRESS_RECORD_KEY environment variable.
|
||||
-s, --spec <spec> runs a specific spec file. defaults to "all"
|
||||
-r, --reporter <reporter> runs a specific mocha reporter. pass a path to use a custom reporter. defaults to "spec"
|
||||
-o, --reporter-options <reporter-options> options for the mocha reporter. defaults to "null"
|
||||
-p, --port <port> runs Cypress on a specific port. overrides any value in the configuration file.
|
||||
-e, --env <env> sets environment variables. separate multiple values with a comma. overrides any value in the configuration file or cypress.env.json
|
||||
-c, --config <config> sets configuration values. separate multiple values with a comma. overrides any value in the configuration file.
|
||||
-C, --config-file <config-file> path to JSON file where configuration values are set. defaults to "cypress.json". pass "false" to disable.
|
||||
-b, --browser <browser-name-or-path> runs Cypress in the browser with the given name. if a filesystem path is supplied, Cypress will attempt to use the browser at that path.
|
||||
-P, --project <project-path> path to the project
|
||||
--parallel enables concurrent runs and automatic load balancing of specs across multiple machines or processes
|
||||
--group <name> a named group for recorded runs in the Cypress dashboard
|
||||
--ci-build-id <id> the unique identifier for a run on your CI provider. typically a "BUILD_ID" env var. this value is automatically detected for most CI providers
|
||||
--no-exit keep the browser open after tests finish
|
||||
--dev runs cypress in development and bypasses binary check
|
||||
-h, --help output usage information
|
||||
help Shows CLI help and exits
|
||||
version prints Cypress version
|
||||
run [options] Runs Cypress tests from the CLI without the GUI
|
||||
open [options] Opens Cypress in the interactive GUI.
|
||||
install [options] Installs the Cypress executable matching this package's version
|
||||
verify [options] Verifies that Cypress is installed correctly and executable
|
||||
cache [options] Manages the Cypress binary cache
|
||||
-------
|
||||
stderr:
|
||||
-------
|
||||
@@ -385,3 +346,54 @@ exports['cli CYPRESS_ENV catches environment "foo" 1'] = `
|
||||
-------
|
||||
|
||||
`
|
||||
|
||||
exports['cli version and binary version 1'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: X.Y.Z
|
||||
`
|
||||
|
||||
exports['cli version and binary version 2'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: X.Y.Z
|
||||
`
|
||||
|
||||
exports['cli version no binary version 1'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: not installed
|
||||
`
|
||||
|
||||
exports['cli --version no binary version 1'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: not installed
|
||||
`
|
||||
|
||||
exports['cli -v no binary version 1'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: not installed
|
||||
`
|
||||
|
||||
exports['cli cypress run warns with space-separated --spec 1'] = `
|
||||
[33m⚠[39m Warning: It looks like you're passing --spec a space-separated list of arguments:
|
||||
|
||||
"a b c d e f g"
|
||||
|
||||
This will work, but it's not recommended.
|
||||
|
||||
If you are trying to pass multiple arguments, separate them with commas instead:
|
||||
cypress run --spec arg1,arg2,arg3
|
||||
|
||||
The most common cause of this warning is using an unescaped glob pattern. If you are
|
||||
trying to pass a glob pattern, escape it using quotes:
|
||||
cypress run --spec "**/*.spec.js"
|
||||
`
|
||||
|
||||
exports['cli cypress run warns with space-separated --tag 1'] = `
|
||||
[33m⚠[39m Warning: It looks like you're passing --tag a space-separated list of arguments:
|
||||
|
||||
"a b c d e f g"
|
||||
|
||||
This will work, but it's not recommended.
|
||||
|
||||
If you are trying to pass multiple arguments, separate them with commas instead:
|
||||
cypress run --tag arg1,arg2,arg3
|
||||
`
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
exports['exec run .processRunOptions does not remove --record option when using --browser 1'] = [
|
||||
"--run-project",
|
||||
null,
|
||||
"--record",
|
||||
"foo",
|
||||
"--browser",
|
||||
"test browser"
|
||||
"test browser",
|
||||
"--record",
|
||||
"foo"
|
||||
]
|
||||
|
||||
exports['exec run .processRunOptions passes --browser option 1'] = [
|
||||
|
||||
+89
-83
@@ -25,99 +25,107 @@ const coerceFalse = (arg) => {
|
||||
return arg !== 'false'
|
||||
}
|
||||
|
||||
const spaceDelimitedSpecsMsg = (files) => {
|
||||
logger.log()
|
||||
logger.warn(stripIndent`
|
||||
${
|
||||
logSymbols.warning
|
||||
} Warning: It looks like you're passing --spec a space-separated list of files:
|
||||
const spaceDelimitedArgsMsg = (flag, args) => {
|
||||
let msg = `
|
||||
${logSymbols.warning} Warning: It looks like you're passing --${flag} a space-separated list of arguments:
|
||||
|
||||
"${files.join(' ')}"
|
||||
"${args.join(' ')}"
|
||||
|
||||
This will work, but it's not recommended.
|
||||
|
||||
If you are trying to pass multiple arguments, separate them with commas instead:
|
||||
cypress run --${flag} arg1,arg2,arg3
|
||||
`
|
||||
|
||||
if (flag === 'spec') {
|
||||
msg += `
|
||||
The most common cause of this warning is using an unescaped glob pattern. If you are
|
||||
trying to pass a glob pattern, escape it using quotes:
|
||||
cypress run --spec "**/*.spec.js"
|
||||
`
|
||||
}
|
||||
|
||||
If you are trying to pass multiple spec filenames, separate them by commas instead:
|
||||
cypress run --spec spec1,spec2,spec3
|
||||
`)
|
||||
|
||||
logger.log()
|
||||
logger.warn(stripIndent(msg))
|
||||
logger.log()
|
||||
}
|
||||
|
||||
const parseVariableOpts = (fnArgs, args) => {
|
||||
const opts = fnArgs.pop()
|
||||
|
||||
if (fnArgs.length && opts.spec) {
|
||||
// this will capture space-delimited specs after --spec spec1 but before the next option
|
||||
if (fnArgs.length && (opts.spec || opts.tag)) {
|
||||
// this will capture space-delimited args after
|
||||
// flags that could have possible multiple args
|
||||
// but before the next option
|
||||
// --spec spec1 spec2 or --tag foo bar
|
||||
|
||||
const argIndex = _.indexOf(args, '--spec') + 2
|
||||
const nextOptOffset = _.findIndex(_.slice(args, argIndex), (arg) => {
|
||||
return _.startsWith(arg, '--')
|
||||
const multiArgFlags = _.compact([
|
||||
opts.spec ? 'spec' : opts.spec,
|
||||
opts.tag ? 'tag' : opts.tag,
|
||||
])
|
||||
|
||||
_.forEach(multiArgFlags, (flag) => {
|
||||
const argIndex = _.indexOf(args, `--${flag}`) + 2
|
||||
const nextOptOffset = _.findIndex(_.slice(args, argIndex), (arg) => {
|
||||
return _.startsWith(arg, '--')
|
||||
})
|
||||
const endIndex = nextOptOffset !== -1 ? argIndex + nextOptOffset : args.length
|
||||
|
||||
const maybeArgs = _.slice(args, argIndex, endIndex)
|
||||
const extraArgs = _.intersection(maybeArgs, fnArgs)
|
||||
|
||||
if (extraArgs.length) {
|
||||
opts[flag] = [opts[flag]].concat(extraArgs)
|
||||
spaceDelimitedArgsMsg(flag, opts[flag])
|
||||
opts[flag] = opts[flag].join(',')
|
||||
}
|
||||
})
|
||||
const endIndex =
|
||||
nextOptOffset !== -1 ? argIndex + nextOptOffset : args.length
|
||||
|
||||
const maybeSpecs = _.slice(args, argIndex, endIndex)
|
||||
const extraSpecs = _.intersection(maybeSpecs, fnArgs)
|
||||
|
||||
if (extraSpecs.length) {
|
||||
opts.spec = [opts.spec].concat(extraSpecs)
|
||||
spaceDelimitedSpecsMsg(opts.spec)
|
||||
opts.spec = opts.spec.join(',')
|
||||
}
|
||||
}
|
||||
|
||||
return util.parseOpts(opts)
|
||||
}
|
||||
|
||||
const 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 the configuration file.',
|
||||
env: 'sets environment variables. separate multiple values with a comma. overrides any value in the configuration file or cypress.env.json',
|
||||
config: 'sets configuration values. separate multiple values with a comma. overrides any value in the configuration file.',
|
||||
browserRunMode: 'runs Cypress in the browser with the given name. if a filesystem path is supplied, Cypress will attempt to use the browser at that path.',
|
||||
browserOpenMode: 'path to a custom browser to be added to the list of available browsers in Cypress',
|
||||
detached: 'runs Cypress application in detached mode',
|
||||
project: 'path to the project',
|
||||
global: 'force Cypress into global mode as if its globally installed',
|
||||
configFile: 'path to JSON file where configuration values are set. defaults to "cypress.json". pass "false" to disable.',
|
||||
version: 'prints Cypress version',
|
||||
headed: 'displays the Electron browser instead of running headlessly',
|
||||
dev: 'runs cypress in development and bypasses binary check',
|
||||
forceInstall: 'force install the Cypress binary',
|
||||
exit: 'keep the browser open after tests finish',
|
||||
cachePath: 'print the path to the binary cache',
|
||||
cacheList: 'list cached binary versions',
|
||||
browserRunMode: 'runs Cypress in the browser with the given name. if a filesystem path is supplied, Cypress will attempt to use the browser at that path.',
|
||||
cacheClear: 'delete all cached binaries',
|
||||
group: 'a named group for recorded runs in the Cypress dashboard',
|
||||
parallel:
|
||||
'enables concurrent runs and automatic load balancing of specs across multiple machines or processes',
|
||||
ciBuildId:
|
||||
'the unique identifier for a run on your CI provider. typically a "BUILD_ID" env var. this value is automatically detected for most CI providers',
|
||||
cacheList: 'list cached binary versions',
|
||||
cachePath: 'print the path to the binary cache',
|
||||
ciBuildId: 'the unique identifier for a run on your CI provider. typically a "BUILD_ID" env var. this value is automatically detected for most CI providers',
|
||||
config: 'sets configuration values. separate multiple values with a comma. overrides any value in cypress.json.',
|
||||
configFile: 'path to JSON file where configuration values are set. defaults to "cypress.json". pass "false" to disable.',
|
||||
detached: 'runs Cypress application in detached mode',
|
||||
dev: 'runs cypress in development and bypasses binary check',
|
||||
env: 'sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json',
|
||||
exit: 'keep the browser open after tests finish',
|
||||
forceInstall: 'force install the Cypress binary',
|
||||
global: 'force Cypress into global mode as if its globally installed',
|
||||
group: 'a named group for recorded runs in the Cypress Dashboard',
|
||||
headed: 'displays the Electron browser instead of running headlessly',
|
||||
key: 'your secret Record Key. you can omit this if you set a CYPRESS_RECORD_KEY environment variable.',
|
||||
parallel: 'enables concurrent runs and automatic load balancing of specs across multiple machines or processes',
|
||||
port: 'runs Cypress on a specific port. overrides any value in cypress.json.',
|
||||
project: 'path to the project',
|
||||
record: 'records the run. sends test results, screenshots and videos to your Cypress Dashboard.',
|
||||
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"',
|
||||
spec: 'runs specific spec file(s). defaults to "all"',
|
||||
tag: 'named tag(s) for recorded runs in the Cypress Dashboard',
|
||||
version: 'prints Cypress version',
|
||||
}
|
||||
|
||||
const knownCommands = [
|
||||
'version',
|
||||
'run',
|
||||
'open',
|
||||
'install',
|
||||
'verify',
|
||||
'-v',
|
||||
'--version',
|
||||
'cache',
|
||||
'help',
|
||||
'-h',
|
||||
'--help',
|
||||
'cache',
|
||||
'install',
|
||||
'open',
|
||||
'run',
|
||||
'verify',
|
||||
'-v',
|
||||
'--version',
|
||||
'version',
|
||||
]
|
||||
|
||||
const text = (description) => {
|
||||
@@ -165,7 +173,7 @@ module.exports = {
|
||||
|
||||
const program = new commander.Command()
|
||||
|
||||
// bug in commaner not printing name
|
||||
// bug in commander not printing name
|
||||
// in usage help docs
|
||||
program._name = 'cypress'
|
||||
|
||||
@@ -188,25 +196,23 @@ module.exports = {
|
||||
.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('-b, --browser <browser-name-or-path>', text('browserRunMode'))
|
||||
.option('--ci-build-id <id>', text('ciBuildId'))
|
||||
.option('-c, --config <config>', text('config'))
|
||||
.option('-C, --config-file <config-file>', text('configFile'))
|
||||
.option('-b, --browser <browser-name-or-path>', text('browserRunMode'))
|
||||
.option('-P, --project <project-path>', text('project'))
|
||||
.option('--parallel', text('parallel'))
|
||||
.option('-e, --env <env>', text('env'))
|
||||
.option('--group <name>', text('group'))
|
||||
.option('--ci-build-id <id>', text('ciBuildId'))
|
||||
.option('-k, --key <record-key>', text('key'))
|
||||
.option('--headed', text('headed'))
|
||||
.option('--no-exit', text('exit'))
|
||||
.option('--parallel', text('parallel'))
|
||||
.option('-p, --port <port>', text('port'))
|
||||
.option('-P, --project <project-path>', text('project'))
|
||||
.option('--record [bool]', text('record'), coerceFalse)
|
||||
.option('-r, --reporter <reporter>', text('reporter'))
|
||||
.option('-o, --reporter-options <reporter-options>', text('reporterOptions'))
|
||||
.option('-s, --spec <spec>', text('spec'))
|
||||
.option('-t, --tag <tag>', text('tag'))
|
||||
.option('--dev', text('dev'), coerceFalse)
|
||||
.action((...fnArgs) => {
|
||||
debug('running Cypress')
|
||||
@@ -220,14 +226,14 @@ module.exports = {
|
||||
.command('open')
|
||||
.usage('[options]')
|
||||
.description('Opens Cypress in the interactive GUI.')
|
||||
.option('-p, --port <port>', text('port'))
|
||||
.option('-e, --env <env>', text('env'))
|
||||
.option('-b, --browser <browser-path>', text('browserOpenMode'))
|
||||
.option('-c, --config <config>', text('config'))
|
||||
.option('-C, --config-file <config-file>', text('configFile'))
|
||||
.option('-d, --detached [bool]', text('detached'), coerceFalse)
|
||||
.option('-b, --browser <browser-path>', text('browserOpenMode'))
|
||||
.option('-P, --project <project-path>', text('project'))
|
||||
.option('-e, --env <env>', text('env'))
|
||||
.option('--global', text('global'))
|
||||
.option('-p, --port <port>', text('port'))
|
||||
.option('-P, --project <project-path>', text('project'))
|
||||
.option('--dev', text('dev'), coerceFalse)
|
||||
.action((opts) => {
|
||||
debug('opening Cypress')
|
||||
|
||||
@@ -11,10 +11,6 @@ module.exports = {
|
||||
|
||||
const args = []
|
||||
|
||||
if (options.env) {
|
||||
args.push('--env', options.env)
|
||||
}
|
||||
|
||||
if (options.config) {
|
||||
args.push('--config', options.config)
|
||||
}
|
||||
@@ -27,6 +23,10 @@ module.exports = {
|
||||
args.push('--browser', options.browser)
|
||||
}
|
||||
|
||||
if (options.env) {
|
||||
args.push('--env', options.env)
|
||||
}
|
||||
|
||||
if (options.port) {
|
||||
args.push('--port', options.port)
|
||||
}
|
||||
|
||||
+65
-61
@@ -12,14 +12,20 @@ const processRunOptions = (options = {}) => {
|
||||
|
||||
const args = ['--run-project', options.project]
|
||||
|
||||
//// 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 (options.browser) {
|
||||
args.push('--browser', options.browser)
|
||||
}
|
||||
|
||||
if (options.env) {
|
||||
args.push('--env', options.env)
|
||||
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) {
|
||||
@@ -30,70 +36,68 @@ const processRunOptions = (options = {}) => {
|
||||
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 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 (options.ci) {
|
||||
//// push to display the deprecation message
|
||||
args.push('--ci')
|
||||
|
||||
//// also automatically record
|
||||
args.push('--record', true)
|
||||
}
|
||||
|
||||
//// if we have a key assume we're in record mode
|
||||
if (options.key) {
|
||||
args.push('--key', options.key)
|
||||
}
|
||||
|
||||
//// 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 (options.parallel) {
|
||||
args.push('--parallel')
|
||||
}
|
||||
|
||||
if (options.group) {
|
||||
args.push('--group', options.group)
|
||||
}
|
||||
|
||||
if (options.ciBuildId) {
|
||||
args.push('--ci-build-id', options.ciBuildId)
|
||||
}
|
||||
|
||||
if (options.outputPath) {
|
||||
args.push('--output-path', options.outputPath)
|
||||
}
|
||||
|
||||
if (options.browser) {
|
||||
args.push('--browser', options.browser)
|
||||
}
|
||||
|
||||
if (options.headed) {
|
||||
args.push('--headed', options.headed)
|
||||
}
|
||||
|
||||
if (options.exit === false) {
|
||||
args.push('--no-exit')
|
||||
if (options.tag) {
|
||||
args.push('--tag', options.tag)
|
||||
}
|
||||
|
||||
return args
|
||||
|
||||
+23
-24
@@ -178,35 +178,34 @@ const dequote = (str) => {
|
||||
}
|
||||
|
||||
const parseOpts = (opts) => {
|
||||
opts = _.pick(
|
||||
opts,
|
||||
'project',
|
||||
'spec',
|
||||
'reporter',
|
||||
'reporterOptions',
|
||||
'path',
|
||||
'destination',
|
||||
'port',
|
||||
'env',
|
||||
'cypressVersion',
|
||||
'config',
|
||||
'record',
|
||||
'key',
|
||||
'configFile',
|
||||
opts = _.pick(opts,
|
||||
'browser',
|
||||
'detached',
|
||||
'headed',
|
||||
'global',
|
||||
'dev',
|
||||
'force',
|
||||
'exit',
|
||||
'cachePath',
|
||||
'cacheList',
|
||||
'cacheClear',
|
||||
'parallel',
|
||||
'ciBuildId',
|
||||
'config',
|
||||
'configFile',
|
||||
'cypressVersion',
|
||||
'destination',
|
||||
'detached',
|
||||
'dev',
|
||||
'exit',
|
||||
'env',
|
||||
'force',
|
||||
'global',
|
||||
'group',
|
||||
'ciBuildId'
|
||||
)
|
||||
'headed',
|
||||
'key',
|
||||
'path',
|
||||
'parallel',
|
||||
'port',
|
||||
'project',
|
||||
'reporter',
|
||||
'reporterOptions',
|
||||
'record',
|
||||
'spec',
|
||||
'tag')
|
||||
|
||||
if (opts.exit) {
|
||||
opts = _.omit(opts, 'exit')
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@
|
||||
"pretest-watch": "npm run check-deps-pre",
|
||||
"test-watch": "npm run unit -- --watch",
|
||||
"types": "npm run dtslint",
|
||||
"unit": "BLUEBIRD_DEBUG=1 NODE_ENV=test bin-up mocha --reporter mocha-multi-reporters --reporter-options configFile=../mocha-reporter-config.json"
|
||||
"unit": "BLUEBIRD_DEBUG=1 NODE_ENV=test ../node_modules/.bin/mocha --reporter mocha-multi-reporters --reporter-options configFile=../mocha-reporter-config.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cypress/listr-verbose-renderer": "0.4.1",
|
||||
|
||||
+53
-10
@@ -224,13 +224,6 @@ describe('cli', () => {
|
||||
expect(run.start).to.be.calledWith({ port: '7878' })
|
||||
})
|
||||
|
||||
it('calls run with spec', () => {
|
||||
this.exec('run --spec cypress/integration/foo_spec.js')
|
||||
expect(run.start).to.be.calledWith({
|
||||
spec: 'cypress/integration/foo_spec.js',
|
||||
})
|
||||
})
|
||||
|
||||
it('calls run with port with -p arg', () => {
|
||||
this.exec('run -p 8989')
|
||||
expect(run.start).to.be.calledWith({ port: '8989' })
|
||||
@@ -300,21 +293,71 @@ describe('cli', () => {
|
||||
expect(run.start).to.be.calledWith({ group: 'staging' })
|
||||
})
|
||||
|
||||
it('calls run with space-separated --specs', () => {
|
||||
it('calls run with spec', () => {
|
||||
this.exec('run --spec cypress/integration/foo_spec.js')
|
||||
expect(run.start).to.be.calledWith({
|
||||
spec: 'cypress/integration/foo_spec.js',
|
||||
})
|
||||
})
|
||||
|
||||
it('calls run with space-separated --spec', () => {
|
||||
this.exec('run --spec a b c d e f g')
|
||||
expect(run.start).to.be.calledWith({ spec: 'a,b,c,d,e,f,g' })
|
||||
this.exec('run --dev bang --spec foo bar baz -P ./')
|
||||
expect(run.start).to.be.calledWithMatch({ spec: 'foo,bar,baz' })
|
||||
})
|
||||
|
||||
it('warns with space-separated --specs', (done) => {
|
||||
it('warns with space-separated --spec', (done) => {
|
||||
sinon.spy(logger, 'warn')
|
||||
this.exec('run --spec a b c d e f g --dev')
|
||||
snapshot(logger.warn.getCall(0).args[0])
|
||||
done()
|
||||
})
|
||||
|
||||
it('removes stray double quotes', () => {
|
||||
it('calls run with --tag', () => {
|
||||
this.exec('run --tag nightly')
|
||||
expect(run.start).to.be.calledWith({ tag: 'nightly' })
|
||||
})
|
||||
|
||||
it('calls run comma-separated --tag', () => {
|
||||
this.exec('run --tag nightly,staging')
|
||||
expect(run.start).to.be.calledWith({ tag: 'nightly,staging' })
|
||||
})
|
||||
|
||||
it('does not remove double quotes from --tag', () => {
|
||||
// I think it is a good idea to lock down this behavior
|
||||
// to make sure we either preserve it or change it in the future
|
||||
this.exec('run --tag "nightly"')
|
||||
expect(run.start).to.be.calledWith({ tag: '"nightly"' })
|
||||
})
|
||||
|
||||
it('calls run comma-separated --spec', () => {
|
||||
this.exec('run --spec main_spec.js,view_spec.js')
|
||||
expect(run.start).to.be.calledWith({ spec: 'main_spec.js,view_spec.js' })
|
||||
})
|
||||
|
||||
it('calls run with space-separated --tag', () => {
|
||||
this.exec('run --tag a b c d e f g')
|
||||
expect(run.start).to.be.calledWith({ tag: 'a,b,c,d,e,f,g' })
|
||||
this.exec('run --dev bang --tag foo bar baz -P ./')
|
||||
expect(run.start).to.be.calledWithMatch({ tag: 'foo,bar,baz' })
|
||||
})
|
||||
|
||||
it('warns with space-separated --tag', (done) => {
|
||||
sinon.spy(logger, 'warn')
|
||||
this.exec('run --tag a b c d e f g --dev')
|
||||
snapshot(logger.warn.getCall(0).args[0])
|
||||
done()
|
||||
})
|
||||
|
||||
it('calls run with space-separated --tag and --spec', () => {
|
||||
this.exec('run --tag a b c d e f g --spec h i j k l')
|
||||
expect(run.start).to.be.calledWith({ tag: 'a,b,c,d,e,f,g', spec: 'h,i,j,k,l' })
|
||||
this.exec('run --dev bang --tag foo bar baz -P ./ --spec fizz buzz --headed false')
|
||||
expect(run.start).to.be.calledWithMatch({ tag: 'foo,bar,baz', spec: 'fizz,buzz' })
|
||||
})
|
||||
|
||||
it('removes stray double quotes from --ci-build-id and --group', () => {
|
||||
this.exec('run --ci-build-id "123" --group "staging"')
|
||||
expect(run.start).to.be.calledWith({ ciBuildId: '123', group: 'staging' })
|
||||
})
|
||||
|
||||
@@ -131,5 +131,23 @@ describe('exec run', function () {
|
||||
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--output-path', '/path/to/output'])
|
||||
})
|
||||
})
|
||||
|
||||
it('spawns with --tag value', function () {
|
||||
return run.start({ tag: 'nightly' })
|
||||
.then(() => {
|
||||
expect(spawn.start).to.be.calledWith([
|
||||
'--run-project', process.cwd(), '--tag', 'nightly',
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
it('spawns with several --tag words unchanged', function () {
|
||||
return run.start({ tag: 'nightly, sanity' })
|
||||
.then(() => {
|
||||
expect(spawn.start).to.be.calledWith([
|
||||
'--run-project', process.cwd(), '--tag', 'nightly, sanity',
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user