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

Need to validate config object returned from the plugins file #5712

Closed
bahmutov opened this issue Nov 15, 2019 · 2 comments · Fixed by #5068
Closed

Need to validate config object returned from the plugins file #5712

bahmutov opened this issue Nov 15, 2019 · 2 comments · Fixed by #5068
Assignees

Comments

@bahmutov
Copy link
Contributor

Cypress v3.6.1
Example in https://github.com/cypress-io/cypress-test-tiny/tree/return-invalid-value-from-plugins

When cypress.json has an invalid value we show a good error message during cypress open. For example, an invalid viewportWidth

{
  "viewportWidth": "foo"
}

leads to
Screen Shot 2019-11-15 at 11 56 11 AM

and during cypress run shows the error

We found an invalid value in the file: `cypress.json`

Expected `viewportWidth` to be a number. Instead the value was: `"foo"`

But if we return invalid viewportWidth from file cypress/integration/plugins.js like this

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
  return {
    viewportWidth: 'foo'
  }
}

The cypress open is happy, yet the browser shows NaN

Screen Shot 2019-11-15 at 11 58 10 AM

and in this simple test cypress run finishes.

Using invalid baseUrl returned from plugins file breaks cypress run

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
  return {
    viewportWidth: 'foo',
    baseUrl: 123
  }
}
$ npm run dev -- --run-project ~/git/cypress-test-tiny/

> [email protected] dev /Users/gleb/git/cypress
> node ./scripts/start.js "--run-project" "/Users/gleb/git/cypress-test-tiny/"

TypeError [ERR_INVALID_ARG_TYPE] [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type number
    at validateString (internal/validators.js:105:11)
    at Url.parse (url.js:154:3)
    at Object.urlParse [as parse] (url.js:149:13)
    at Object.exports.isListening (/Users/gleb/git/cypress/packages/server/lib/util/ensure-url.ts:50:18)
    at run (/Users/gleb/git/cypress/packages/server/lib/util/ensure-url.ts:29:24)
    at Object.exports.retryIsListening (/Users/gleb/git/cypress/packages/server/lib/util/ensure-url.ts:46:12)
    at Server._retryBaseUrlCheck (/Users/gleb/git/cypress/packages/server/lib/server.coffee:615:15)
    at /Users/gleb/git/cypress/packages/server/lib/server.coffee:246:23

Goal

Validate the configuration object returned from the plugins file the same way as we validate object loaded from cypress.json

@bahmutov bahmutov self-assigned this Nov 15, 2019
@cypress-bot cypress-bot bot added the stage: needs review The PR code is done & tested, needs review label Nov 18, 2019
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Nov 19, 2019
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 19, 2019

The code for this is done in cypress-io/cypress#5068, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 27, 2019

Released in 3.7.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant