Cypress: Easier use of Cypress module API

Created on 12 Mar 2018  路  12Comments  路  Source: cypress-io/cypress

  • Operating System: Ubuntu 17.10
  • Cypress Version: 2.1.0
  • Browser Version: Chrome 65

Is this a Feature or Bug?

Feature

Current behavior:

  • I am currently working on a internal node_module/lib for usage within our company whose sole purpose is to ensure common settings/structure for all our projects.
  • The Cypress module API is a bit verbose to work with when you are trying to achieve this.

Desired behavior:

  • The options object that cypress.open or cypress.run takes, expects the values to be strings as how it would be passed from command line. I should be able to pass a normal object.
  • Also it keeps creating an empty cypress.json, is it absolutely mandatory for this file to be present.

PS: Also I am a complete beginner in using Cypress, I apologize in advance if some parts/all of this issue is misinformed. I got sold by watching the intro video!! I feel this is THE TOOL for e2e-tests!

Note: I am willing to contribute if needed.

cli

All 12 comments

I know there was some work to normalize some of the module API options, so there could probably be some more work done there.

Code: https://github.com/cypress-io/cypress/blob/develop/cli/lib/cypress.js#L17

I have a small function which I'm currently running my config object through to get the string equivs. Shall I give a PR with that?

Edit: This is the function

function strigifyObj(obj) {
    return Object.keys(obj)
        .map(item => `${item}=${obj[item]}`)
        .join(',');
}

I have been digging though the cypress codebase. What about the open API? There is no normalisation there?

I don't see an normalize step in the code here. https://github.com/cypress-io/cypress/blob/develop/cli/lib/exec/open.js

It happens before its passed to open or run.

BTW what you are asking for is essentially / related to these other two issues. It is different but very close:

It happens before its passed to open or run.

In module API usage, I don't think it is normalising. https://github.com/cypress-io/cypress/blob/develop/cli/lib/cypress.js.

Yeah you're right, it's not. I dunno how we missed this. I'd be happy to merge in a PR!

About generating empty cypress.json, is it avoidable?

The reason I ask this is, it fails when call the .run() api when there is no cypress.json in the project. And I feel that is unwarranted, since it is an empty object to begin with.

Since I just started using Cypress, I don't about it's importance. But I'd prefer if the API didn't error out because of this.

Ah, I just came here to report the same thing! Awesome that there's already a PR up for it.

馃憤 on avoiding an empty cypress.json as well

@Aftabnack @SimenB The cypress.json file is a separate issue if you'd like to +1 it over here: https://github.com/cypress-io/cypress/issues/1369

Released in 3.0.0.

Was this page helpful?
0 / 5 - 0 ratings