question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Overriding baseUrl from cypress.env.json

See original GitHub issue

Current behavior:

Setting baseUrl in cypress.env.json leads to the key baseUrl being created inside env (the environment variables), not in the existing baseUrl being overridden at the configuration variable level.

Desired behavior:

baseUrl should be overridden, the behavior matching that stated in the section “Overriding Configuration” in the environment variables documentation. (Note: Overriding via the command line works as expected.)

How to reproduce/Test Code:

cypress.json:

{
  "baseUrl": "http://example.com/setFromCypress.json",
  "env": {
    "someVariable": "originalValue"
  }
}

cypress.env.json:

{
  "baseUrl": "http://example.com/setFromCypress.env.json",
  "someVariable": "newValue"
}

Screenshot of the resulting configuration: screen shot 2017-11-13 at 11 28 44

Additional Info (images, stack traces, etc)

This issue was initially posted and phrased as a question on StackOverflow: https://stackoverflow.com/q/47262338/1858138

  • Operating System: Mac OS 10.13.1 (17B48)
  • Cypress Version: Cypress package version: 1.0.3
  • Browser Version: Chrome 60

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:38 (14 by maintainers)

github_iconTop GitHub Comments

14reactions
dwellecommented, Nov 14, 2017

From docs, I got the same idea as OP. This part in particular:

If your environment variables match a standard configuration key, then instead of setting an environment variable they will instead override the configuration value.

Plus, the cypress runner configuartion “settings” tab doesn’t do a good job in explaining that even though env has higher precedence than e.g. cypress.json or default, it doesn’t override it at all…

7reactions
DanielSwaincommented, Nov 16, 2017

@brian-mann I think that the concept of cypress.env.json was a good one but that perhaps expanding it would be more than adequate at this point (as opposed to creating a new plugin event right now). Changing the names/function of the files as follows might be a good approach.

  • Change cypress.json to cypress.conf.json

  • Have a cypress.conf.local.json file whose key structure can match and override cypress.conf.json as @Vages suggests and which would not be checked into source control

This structure would allow you to keep the cypress.env.json for backward compatibility at this point, but it could be deprecated and then eventually eliminated (same for cypress.json).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment Variables | Cypress Documentation
You can create your own cypress.env.json file that Cypress will automatically check. Values in here will overwrite conflicting environment variables in your ...
Read more >
Override Cypress.config().baseUrl with environment variable ...
env file. I can't set it directly in the cypress.json file. And when I try to use cy.visit(process.
Read more >
Switch between environments in Cypress - Filip Hric
The easiest way to switch environments is to simply rewrite your cypress.json file and set baseUrl to a different value each time you...
Read more >
cypress-io/cypress - Gitter
baseUrl return config }. _. in plugins/index.js. I know, baseUrl isn't really an envvar, it's right, so it shouldn't be in cypress.env.json in...
Read more >
Configure Cypress Tests to Run on Multiple Environments
Method 1. Configuring Cypress To Run On Different Environments Using baseUrl in cypress.json · Step 1: Navigate to The cypress.json File Located ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found