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

Cannot pass config-file option to parseRunArguments #8632

Closed
bjowes opened this issue Sep 21, 2020 · 5 comments · Fixed by #8636
Closed

Cannot pass config-file option to parseRunArguments #8632

bjowes opened this issue Sep 21, 2020 · 5 comments · Fixed by #8636
Assignees
Labels
cli topic: npm module api Issues related to using Cypress via its NPM module API

Comments

@bjowes
Copy link
Contributor

bjowes commented Sep 21, 2020

Current behavior:

When passing --config-file cypress.json as part of the command line arguments to parseRunArguments, cypress fails with the following error:

The "path" argument must be of type string. Received type boolean
TypeError [ERR_INVALID_ARG_TYPE] [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type boolean

Desired behavior:

The --config-file argument should be properly parsed also when using the node module API.

Test code to reproduce

const cypress = require('cypress');
async function reproduceError() {
  const runOptions = await cypress.cli.parseRunArguments(['cypress', 'run', '--config-file', 'cypress.json']);
  const results = await cypress.run(runOptions);
}
reproduceError();

Versions

Cypress 5.2.0
Windows 10

Analysis

With debugging it is clear where the issue appears:

  cypress:cli:cli parsing args: [ null, null, 'run', '--config-file=myConfigFile.json' ] +3ms
  ...
  cypress:cli parsed cli options { configFile: 'myConfigFile.json' } +0ms
  cypress:cli:cli parsed options { configFile: 'myConfigFile.json' } +46ms
  cypress:cli:cli casted options { configFile: true } +1ms

`
Looking through the code, there is a coercion function applied to the configFile property when parsing arguments, since this argument may be a string or false. However, the coercion function always returns a boolean

cypress/cli/lib/cli.js

Lines 25 to 27 in ef2363e

const coerceFalse = (arg) => {
return arg !== 'false'
}

Suggested fix

If the coercion function is replaced with

const coerceFalse = (arg) => { 
   return arg !== 'false' ? arg : false;
} 

it should work as expected.

@bahmutov bahmutov self-assigned this Sep 21, 2020
@bahmutov bahmutov added cli topic: npm module api Issues related to using Cypress via its NPM module API labels Sep 21, 2020
@bahmutov
Copy link
Contributor

Good catch @bjowes - do you mind opening a pull request with this fix and a corresponding unit test?

@bjowes
Copy link
Contributor Author

bjowes commented Sep 21, 2020

Sure, why not. Would be nice to be able to claim that I have contributed to the cypress code base :)

@bahmutov
Copy link
Contributor

bahmutov commented Sep 21, 2020 via email

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 22, 2020

The code for this is done in cypress-io/cypress#8636, 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 Sep 29, 2020

Released in 5.3.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.3.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cli topic: npm module api Issues related to using Cypress via its NPM module API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants