From e01d3acfe862a4655e10d9fd7eb911cf5ae1ec13 Mon Sep 17 00:00:00 2001 From: BlueWinds Date: Tue, 5 Oct 2021 10:02:54 -0700 Subject: [PATCH] Add --e2e and --component CLI options --- cli/__snapshots__/cli_spec.js | 4 ++++ cli/lib/cli.js | 6 ++++++ cli/lib/exec/open.js | 2 +- cli/lib/exec/run.js | 2 +- cli/lib/exec/shared.js | 16 ++++++++-------- cli/lib/util.js | 2 ++ cli/test/lib/exec/run_spec.js | 14 ++++++++++++++ 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/cli/__snapshots__/cli_spec.js b/cli/__snapshots__/cli_spec.js index 2bf70683b4..2f49a5c409 100644 --- a/cli/__snapshots__/cli_spec.js +++ b/cli/__snapshots__/cli_spec.js @@ -21,10 +21,12 @@ exports['shows help for open --foo 1'] = ` -c, --config sets configuration values. separate multiple values with a comma. overrides any value in cypress.json. + --component runs component tests -C, --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 + --e2e runs end to end tests -e, --env sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json @@ -64,8 +66,10 @@ exports['shows help for run --foo 1'] = ` Options: -b, --browser 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 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 + --component runs component tests -c, --config sets configuration values. separate multiple values with a comma. overrides any value in cypress.json. -C, --config-file path to JSON file where configuration values are set. defaults to "cypress.json". pass "false" to disable. + --e2e runs end to end tests -e, --env sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json --group a named group for recorded runs in the Cypress Dashboard -k, --key your secret Record Key. you can omit this if you set a CYPRESS_RECORD_KEY environment variable. diff --git a/cli/lib/cli.js b/cli/lib/cli.js index 11b2ccc91c..563bbefdec 100644 --- a/cli/lib/cli.js +++ b/cli/lib/cli.js @@ -106,10 +106,12 @@ const descriptions = { cachePath: 'print the path to the binary cache', cacheSize: 'Used with the list command to show the sizes of the cached folders', 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', + component: 'runs component tests', 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', + e2e: 'runs end to end tests', 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', @@ -248,8 +250,10 @@ const addCypressRunCommand = (program) => { .description('Runs Cypress tests from the CLI without the GUI') .option('-b, --browser ', text('browserRunMode')) .option('--ci-build-id ', text('ciBuildId')) + .option('--component', text('component')) .option('-c, --config ', text('config')) .option('-C, --config-file ', text('configFile')) + .option('--e2e', text('e2e')) .option('-e, --env ', text('env')) .option('--group ', text('group')) .option('-k, --key ', text('key')) @@ -386,8 +390,10 @@ module.exports = { .description('Opens Cypress in the interactive GUI.') .option('-b, --browser ', text('browserOpenMode')) .option('-c, --config ', text('config')) + .option('--component', text('component')) .option('-C, --config-file ', text('configFile')) .option('-d, --detached [bool]', text('detached'), coerceFalse) + .option('--e2e', text('e2e')) .option('-e, --env ', text('env')) .option('--global', text('global')) .option('-p, --port ', text('port')) diff --git a/cli/lib/exec/open.js b/cli/lib/exec/open.js index ca2f50a5ed..1389d2d247 100644 --- a/cli/lib/exec/open.js +++ b/cli/lib/exec/open.js @@ -36,7 +36,7 @@ module.exports = { args.push('--project', options.project) } - args.push(...processTestingType(options.testingType)) + args.push(...processTestingType(options)) debug('opening from options %j', options) debug('command line arguments %j', args) diff --git a/cli/lib/exec/run.js b/cli/lib/exec/run.js index b5fac314e8..6912728af4 100644 --- a/cli/lib/exec/run.js +++ b/cli/lib/exec/run.js @@ -137,7 +137,7 @@ const processRunOptions = (options = {}) => { args.push('--tag', options.tag) } - args.push(...processTestingType(options.testingType)) + args.push(...processTestingType(options)) return args } diff --git a/cli/lib/exec/shared.js b/cli/lib/exec/shared.js index d861a1fe1e..20b6844d4a 100644 --- a/cli/lib/exec/shared.js +++ b/cli/lib/exec/shared.js @@ -23,16 +23,16 @@ const throwInvalidOptionError = (details) => { * @param {string} testingType The type of tests being executed * @returns {string[]} The array of new exec arguments */ -const processTestingType = (testingType) => { - if (testingType) { - if (testingType === 'e2e') { - return ['--testing-type', 'e2e'] - } +const processTestingType = (options) => { + if (options.testingType === 'component' || options.component) { + return ['--testing-type', 'component'] + } - if (testingType === 'component') { - return ['--testing-type', 'component'] - } + if (options.testingType === 'e2e' || options.e2e) { + return ['--testing-type', 'e2e'] + } + if (options.testingType) { return throwInvalidOptionError(errors.invalidTestingType) } diff --git a/cli/lib/util.js b/cli/lib/util.js index da4729caab..a37a66b76e 100644 --- a/cli/lib/util.js +++ b/cli/lib/util.js @@ -197,12 +197,14 @@ const parseOpts = (opts) => { 'cacheClear', 'cachePrune', 'ciBuildId', + 'component', 'config', 'configFile', 'cypressVersion', 'destination', 'detached', 'dev', + 'e2e', 'exit', 'env', 'force', diff --git a/cli/test/lib/exec/run_spec.js b/cli/test/lib/exec/run_spec.js index ef54d86cc7..82428d09de 100644 --- a/cli/test/lib/exec/run_spec.js +++ b/cli/test/lib/exec/run_spec.js @@ -190,6 +190,20 @@ describe('exec run', function () { }) }) + it('spawns with --testing-type e2e when given --e2e', function () { + return run.start({ e2e: true }) + .then(() => { + expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--testing-type', 'e2e']) + }) + }) + + it('spawns with --testing-type component when given --component', function () { + return run.start({ component: true }) + .then(() => { + expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--testing-type', 'component']) + }) + }) + it('spawns with --tag value', function () { return run.start({ tag: 'nightly' }) .then(() => {