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

Inconsistent behaviour about envvars #2726

Closed
kud opened this issue Nov 6, 2018 · 3 comments
Closed

Inconsistent behaviour about envvars #2726

kud opened this issue Nov 6, 2018 · 3 comments

Comments

@kud
Copy link

kud commented Nov 6, 2018

I'm reading https://docs.cypress.io/guides/guides/environment-variables.html and I've got some troubles.

I'm setting our cypress configuration on cypress.json. Which is great. However, I can't set there the baseUrl as we have different url for each dev machine like:

  • app.colleague-a.com:8000
  • app.colleague-b.com:8000

So by reading https://docs.cypress.io/guides/guides/environment-variables.html, I can see two things

1/ I am able to use a cypress.env.json to set some envvars, which is great, because we've got multiple projects with cypress so CYPRESS_baseUrl in shell is impossible + we don't want to pollute our shell.

2/ I read there https://docs.cypress.io/guides/guides/environment-variables.html#Overriding-Configuration I can override standard configuration keys by using the same word like baseUrl like CYPRESS_baseUrl. However, said in the 1/, I don't want to use shell envvars. So I thought, writing in cypress.env.json could be the trick like:

  • cypress.json
{
  "fixturesFolder": "__tests__/cypress/fixtures",
  "integrationFolder": "__tests__/cypress/integration",
  "pluginsFile": "__tests__/cypress/plugins/index.js",
  "screenshotsFolder": "__tests__/cypress/screenshots",
  "supportFile": "__tests__/cypress/support/index.js",
  "videosFolder": "__tests__/cypress/videos",
  "video": false
}
  • cypress.env.json
{
  "baseUrl": "app.colleague-a.com:8000"
}

but in fact, it doesn't work at all as it does this (when debugging config):

{
  baseUrl: null,
  env: { baseUrl: 'http://journal.erwann.contexte:8000/' },
}

which is quite logical but does not do the magic said there: https://docs.cypress.io/guides/guides/environment-variables.html#Overriding-Configuration (yes, the example was for the shell but we could imagine it worked with any way to write envvars).

So I'd like to ask you to make a choice:

Note that it's just my opinion, and I'll use a workaround for the moment which is there: https://gist.github.com/ryanhaney/c586a080fa2a90c12328b762ba8266c5

I want to be able to override configuration in cypress.env.json. :)

Thank you for your time.

@kud
Copy link
Author

kud commented Nov 6, 2018

My current workaround:

plugins/index.js:

module.exports = (on, config) => {
  config.baseUrl = config.env.baseUrl

  return config
}

@jennifer-shehane
Copy link
Member

There is a long thread involving env vars and baseUrl here: #909

@kud
Copy link
Author

kud commented Nov 6, 2018

Thank you @jennifer-shehane :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants