Skip to content

Commit

Permalink
fix: Exit when both --e2e and --component flags are passed in (#18855)
Browse files Browse the repository at this point in the history
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
  • Loading branch information
Blue F and jennifer-shehane committed Nov 12, 2021
1 parent d65a6df commit f967908
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 24 deletions.
48 changes: 25 additions & 23 deletions cli/__snapshots__/errors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,6 @@ Platform: test platform (Foo-OsVersion)
Cypress Version: 1.2.3
`

exports['errors individual has the following errors 1'] = [
"CYPRESS_RUN_BINARY",
"binaryNotExecutable",
"childProcessKilled",
"failedDownload",
"failedUnzip",
"incompatibleHeadlessFlags",
"invalidCacheDirectory",
"invalidCypressEnv",
"invalidRunProjectPath",
"invalidSmokeTestDisplayError",
"invalidTestingType",
"missingApp",
"missingDependency",
"missingXvfb",
"nonZeroExitCodeXvfb",
"notInstalledCI",
"smokeTestFailure",
"unexpected",
"unknownError",
"versionMismatch"
]

exports['invalid display error'] = `
Cypress verification failed.
Expand Down Expand Up @@ -95,3 +72,28 @@ Consider opening a new issue.
Platform: test platform (Foo-OsVersion)
Cypress Version: 1.2.3
`

exports['errors individual has the following errors 1'] = [
"CYPRESS_RUN_BINARY",
"binaryNotExecutable",
"childProcessKilled",
"failedDownload",
"failedUnzip",
"incompatibleHeadlessFlags",
"incompatibleTestTypeFlags",
"incompatibleTestingTypeAndFlag",
"invalidCacheDirectory",
"invalidCypressEnv",
"invalidRunProjectPath",
"invalidSmokeTestDisplayError",
"invalidTestingType",
"missingApp",
"missingDependency",
"missingXvfb",
"nonZeroExitCodeXvfb",
"notInstalledCI",
"smokeTestFailure",
"unexpected",
"unknownError",
"versionMismatch"
]
14 changes: 13 additions & 1 deletion cli/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const binaryNotExecutable = (executable) => {
Please check that you have the appropriate user permissions.
You can also try clearing the cache with 'cypress cache clear' and reinstalling.
You can also try clearing the cache with 'cypress cache clear' and reinstalling.
`,
}
}
Expand Down Expand Up @@ -213,6 +213,16 @@ const invalidTestingType = {
solution: `Please provide a valid testingType. Valid test types are ${chalk.cyan('\'e2e\'')} and ${chalk.cyan('\'component\'')}.`,
}

const incompatibleTestTypeFlags = {
description: '`--e2e` and `--component` cannot both be passed.',
solution: 'Either pass `--e2e` or `--component`, but not both.',
}

const incompatibleTestingTypeAndFlag = {
description: 'Set a `testingType` and also passed `--e2e` or `--component` flags.',
solution: 'Either set `testingType` or pass a testing type flag, but not both.',
}

/**
* This error happens when CLI detects that the child Test Runner process
* was killed with a signal, like SIGBUS
Expand Down Expand Up @@ -404,5 +414,7 @@ module.exports = {
incompatibleHeadlessFlags,
invalidRunProjectPath,
invalidTestingType,
incompatibleTestTypeFlags,
incompatibleTestingTypeAndFlag,
},
}
8 changes: 8 additions & 0 deletions cli/lib/exec/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ const throwInvalidOptionError = (details) => {
* @returns {string[]} The array of new exec arguments
*/
const processTestingType = (options) => {
if (options.e2e && options.component) {
return throwInvalidOptionError(errors.incompatibleTestTypeFlags)
}

if (options.testingType && (options.component || options.e2e)) {
return throwInvalidOptionError(errors.incompatibleTestTypeFlags)
}

if (options.testingType === 'component' || options.component || options.ct) {
return ['--testing-type', 'component']
}
Expand Down
8 changes: 8 additions & 0 deletions cli/test/lib/exec/run_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ describe('exec run', function () {
it('throws if testingType is invalid', () => {
expect(() => run.processRunOptions({ testingType: 'randomTestingType' })).to.throw()
})

it('throws if both e2e and component are set', () => {
expect(() => run.processRunOptions({ e2e: true, component: true })).to.throw()
})

it('throws if both testingType and component are set', () => {
expect(() => run.processRunOptions({ testingType: 'component', component: true })).to.throw()
})
})

context('.start', function () {
Expand Down

0 comments on commit f967908

Please sign in to comment.