Cypress: Cypress fails to parse environment variables with commas

Created on 24 Jun 2019  路  9Comments  路  Source: cypress-io/cypress

Current behavior:

Cypress fails to run when passing an environment variable containing a comma.

Command run:
cypress open --env ABC="1,2,3"

Stacktrace:

A JavaScript error occurred in the main process
Uncaught Exception:
TypeError: Cannot read property 'split' of undefined
at pipesToCommas (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/lib/util/args.js:95:14)
at JSONOrCoerce (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/lib/util/args.js:115:9)
at /home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:13402:38
at /home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:4911:15
at baseForOwn (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:2996:24)
at Function.mapValues (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:13401:7)
at /home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:4374:28
at arrayReduce (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:683:21)
at baseWrapperValue (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:4373:14)
at LodashWrapper.wrapperValue (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:9052:14)
at sanitizeAndConvertNestedArgs (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/lib/util/args.js:151:4)
at Object.toObject (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/lib/util/args.js:227:21)
at Object.start (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/lib/cypress.js:77:40)
at Object. (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/index.js:27:43)
at Object. (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/packages/server/index.js:29:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
at Object. (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/index.js:2:1)
at Object. (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/app/index.js:3:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Object. (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/electron.asar/browser/init.js:186:8)
at Object. (/home/ehlerts/.cache/Cypress/3.3.1/Cypress/resources/electron.asar/browser/init.js:188:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Function.Module.runMain (module.js:683:10)
at startup (bootstrap_node.js:196:16)
at bootstrap_node.js:622:3

Once the stacktrace has been printed, nothing happens.

Desired behavior:

Cypress should be able to parse environment variables containing commas.

Steps to reproduce: (app code and test code)

Run the following from a terminal:

cypress open --env ABC="1,2,3"

Versions

Tested Cypress versions: 3.3.1, 3.2.0, 3.1.5
Operating system: Ubuntu 18.04.2 LTS

1锔忊儯 first-timers-only pkserver ready for work bug

All 9 comments

Confirmed, this is happening in version 3.4.0 of Cypress.

Screen Shot 2019-07-13 at 9 56 25 AM

This is the culprit line of code: https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/util/args.js#L95

@jennifer-shehane can I pick this up?

@sidag95 Sure! See our CONTRIBUTING.md in our root directory of the repo.

Awesome will do, thanks!

I did something pretty silly but had this error too.

In case someone else does something similar to me I've explained it here https://github.com/cypress-io/cypress/issues/3742#issuecomment-515941416

Hi @jennifer-shehane ,

I am running into this issue on Cypress binary version: 4.6.0.

npx cypress run --env CYPRESS_tags=smoke,regulations --spec "cypress\integration\examples-fen\tagging.spec.ts"

Cypress encountered an error while parsing the argument env

You passed: CYPRESS_tags=smoke,regulations

The error was: Cannot read property 'split' of undefined

Also occurs on CI with Azure.

You passed: app=TestApp,RETRIES=0,tags=smoke,regulations

The error was: Cannot read property 'split' of undefined

Can you advise?

Aidan

@aidanhyland
I think it's because of this: https://docs.cypress.io/guides/guides/environment-variables.html#Option-4-env

Cypress tries to pair your env variables by splitting via , so it gets confused with tags, as it expect regulations to have an assignable value it can call .split() on.
Cypress sees: tags=smoke and regulations=undefined
And you expect it to be a list.

I stumbled into it when I tried to create a filter that is loaded with support/index.js and I ended up doing something, that splitted on whitespace.

I think you can do something that splits on space in plugins/index.js and then modifies the environment variables. See https://docs.cypress.io/api/plugins/configuration-api.html#Usage.

I'm thinking something like:

// cypress/plugins/index.js
module.exports = (on, config) => {
  // modify env var value where tags='smoke regulations'
  let tags = config.env.TAGS.split(' ');
  config.env.TAGS = tags;

  // return config
  return config
}

I'm guessing here, as I haven't worked with the plugins part 馃檪

@thviQit Thank you for the reply & help, I was able to use the " , " within the CI pipeline (yaml azure) but convert it to " : " in the application before been utilzed.

One stumbling block jumped 馃憤

@jennifer-shehane @Stehlert am interested in looking at this issue but I wasn't sure what the correct behaviour should be:

User should be able to pass:

  1. --env ABC={1,2,3} currently in this scenario Cypress ignore 2 and 3 and returns ABC=1. What should be the correct behaviour here; ABC=1,ABC=2,ABC=3 or ABC=[1,2,3]?
  1. --env ABC="1,2,3" currently throws and coerces value to ABC=1,2,3. what should be the correct behaviour?
Was this page helpful?
0 / 5 - 0 ratings