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
Assignees

Comments

@bahmutov
Copy link
Collaborator

@bahmutov bahmutov commented Nov 15, 2019

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/

> cypress@3.6.1 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
bahmutov added a commit that referenced this issue Nov 15, 2019
@bahmutov bahmutov mentioned this issue Nov 15, 2019
4 of 5 tasks complete
@cypress-bot

This comment has been minimized.

Copy link

@cypress-bot 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

This comment has been minimized.

Copy link

@cypress-bot cypress-bot bot commented Nov 27, 2019

Released in 3.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.