Skip to content

Cannot pass config-file option to parseRunArguments  #8632

Closed
@bjowes

Description

@bjowes
Contributor

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.

Activity

self-assigned this
on Sep 21, 2020
bahmutov

bahmutov commented on Sep 21, 2020

@bahmutov
Contributor

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

bjowes

bjowes commented on Sep 21, 2020

@bjowes
ContributorAuthor

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

bahmutov

bahmutov commented on Sep 21, 2020

@bahmutov
Contributor
cypress-bot

cypress-bot commented on Sep 22, 2020

@cypress-bot
Contributor

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

cypress-bot commented on Sep 29, 2020

@cypress-bot
Contributor

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.

locked as resolved and limited conversation to collaborators on Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

clitopic: npm module apiIssues related to using Cypress via its NPM module API

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @bahmutov@bjowes

    Issue actions

      Cannot pass config-file option to parseRunArguments · Issue #8632 · cypress-io/cypress