Skip to content

Commit

Permalink
feat: include warning when running with invalid config (#9088)
Browse files Browse the repository at this point in the history
Co-authored-by: Jennifer Shehane <[email protected]>
  • Loading branch information
mrmodise and jennifer-shehane authored Nov 16, 2020
1 parent d5eadc2 commit 470c69e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/server/__snapshots__/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,10 @@ You passed: nonono
The error was: Cannot read property 'split' of undefined
`

exports['INVALID_CONFIG_OPTION'] = `
\`test\` is not a valid configuration option,\`foo\` is not a valid configuration option
https://on.cypress.io/configuration
`
20 changes: 18 additions & 2 deletions packages/server/lib/cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const Promise = require('bluebird')
const debug = require('debug')('cypress:server:cypress')
const argsUtils = require('./util/args')

const warning = (code) => {
return require('./errors').warning(code)
const warning = (code, args) => {
return require('./errors').warning(code, args)
}

const exit = (code = 0) => {
Expand All @@ -27,6 +27,20 @@ const exit = (code = 0) => {
return process.exit(code)
}

const showWarningForInvalidConfig = (options) => {
const invalidConfigOptions = require('lodash').keys(options.config).reduce((invalid, option) => {
if (!require('./config').getConfigKeys().find((configKey) => configKey === option)) {
invalid.push(option)
}

return invalid
}, [])

if (invalidConfigOptions.length && options.invokedFromCli) {
return warning('INVALID_CONFIG_OPTION', invalidConfigOptions)
}
}

const exit0 = () => {
return exit(0)
}
Expand Down Expand Up @@ -115,6 +129,8 @@ module.exports = {

try {
options = argsUtils.toObject(argv)

showWarningForInvalidConfig(options)
} catch (argumentsError) {
debug('could not parse CLI arguments: %o', argv)

Expand Down
6 changes: 6 additions & 0 deletions packages/server/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,12 @@ const getMsgByType = function (type, arg1 = {}, arg2, arg3) {
https://on.cypress.io/test-retries
`
case 'INVALID_CONFIG_OPTION':
return stripIndent`\
${arg1.map((arg) => `\`${arg}\` is not a valid configuration option`)}
https://on.cypress.io/configuration
`
default:
}
}
Expand Down
42 changes: 42 additions & 0 deletions packages/server/test/integration/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,48 @@ describe('lib/cypress', () => {
})
})

context('invalid config', function () {
beforeEach(function () {
this.win = {
on: sinon.stub(),
webContents: {
on: sinon.stub(),
},
}

sinon.stub(electron.app, 'on').withArgs('ready').yieldsAsync()
sinon.stub(Windows, 'open').resolves(this.win)
})

it('shows warning if config is not valid', function () {
return cypress.start(['--config=test=false', '--cwd=/foo/bar'])
.then(() => {
expect(errors.warning).to.be.calledWith('INVALID_CONFIG_OPTION')
expect(console.log).to.be.calledWithMatch('`test` is not a valid configuration option')
expect(console.log).to.be.calledWithMatch('https://on.cypress.io/configuration')
})
})

it('shows warning when multiple config are not valid', function () {
return cypress.start(['--config=test=false,foo=bar', '--cwd=/foo/bar'])
.then(() => {
expect(errors.warning).to.be.calledWith('INVALID_CONFIG_OPTION')
expect(console.log).to.be.calledWithMatch('`test` is not a valid configuration option')
expect(console.log).to.be.calledWithMatch('`foo` is not a valid configuration option')
expect(console.log).to.be.calledWithMatch('https://on.cypress.io/configuration')

snapshotConsoleLogs('INVALID_CONFIG_OPTION')
})
})

it('does not show warning if config is valid', function () {
return cypress.start(['--config=trashAssetsBeforeRuns=false'])
.then(() => {
expect(errors.warning).to.not.be.calledWith('INVALID_CONFIG_OPTION')
})
})
})

context('--get-key', () => {
it('writes out key and exits on success', function () {
return Promise.all([
Expand Down

4 comments on commit 470c69e

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 470c69e Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.0.0/circle-develop-470c69ec5a72784f014952d62f9298a07d67bd16/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 470c69e Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.0.0/appveyor-develop-470c69ec5a72784f014952d62f9298a07d67bd16/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 470c69e Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.0.0/appveyor-develop-470c69ec5a72784f014952d62f9298a07d67bd16/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 470c69e Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.0.0/circle-develop-470c69ec5a72784f014952d62f9298a07d67bd16/cypress.tgz

Please sign in to comment.