Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Exit when both --e2e and --component flags are passed in #18855

Merged
merged 4 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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