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.

Verification of baseUrl is failing when using `hosts` in cypress.json

See original GitHub issue

Current behavior

Having a cypress.json like following

{
  "baseUrl": "http://wordpress.local",
  "hosts": {
    "wordpress.local": "121.0.0.1"
  }
}

When running cypress we get an unexpected behavior, Cypress fails to verify the URL.

DEBUG=cypress:network:connect,cypress:server:server-e2e,cypress:server:server-base cypress run -P /tmp/wordpress/cypress
[30:0316/162352.034421:ERROR:bus.cc(392)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[30:0316/162352.036782:ERROR:bus.cc(392)] Failed to connect to the bus: Address does not contain a colon
[30:0316/162352.036984:ERROR:bus.cc(392)] Failed to connect to the bus: Address does not contain a colon
[202:0316/162352.061512:ERROR:gpu_init.cc(453)] Passthrough is not supported, GL is swiftshader, ANGLE is
  cypress:server:server-base server open +0ms
  cypress:server:server-e2e createServer connecting to server +0ms
  cypress:server:server-base Server listening on  { address: '127.0.0.1', family: 'IPv4', port: 36635 } +22ms
  cypress:network:connect beginning getAddress { hostname: 'wordpress.local', port: 80 } +0ms
  cypress:network:connect got addresses { hostname: 'wordpress.local', port: 80, addresses: '192.168.1.107' } +2ms
Cypress could not verify that this server is running:

  > http://wordpress.local/

We are verifying this server because it has been configured as your baseUrl.

Cypress automatically waits until your server is accessible before running tests.

We will try connecting to it 3 more times...
  cypress:network:connect beginning getAddress { hostname: 'wordpress.local', port: 80 } +3s
  cypress:network:connect got addresses { hostname: 'wordpress.local', port: 80, addresses: '192.168.1.107' } +1ms
We will try connecting to it 2 more times...
  cypress:network:connect beginning getAddress { hostname: 'wordpress.local', port: 80 } +3s
  cypress:network:connect got addresses { hostname: 'wordpress.local', port: 80, addresses: '192.168.1.107' } +1ms
We will try connecting to it 1 more time...

  cypress:network:connect beginning getAddress { hostname: 'wordpress.local', port: 80 } +4s
  cypress:network:connect got addresses { hostname: 'wordpress.local', port: 80, addresses: '192.168.1.107' } +2ms
  cypress:server:server-e2e
  cypress:server:server-e2e AggregateError of:
  cypress:server:server-e2e     Error: connect ECONNREFUSED 127.0.0.1:80
  cypress:server:server-e2e
  cypress:server:server-e2e     at SomePromiseArray._checkOutcome (/root/.cache/Cypress/9.5.2/Cypress/resources/app/node_modules/bluebird/js/release/some.js:82:17)
  cypress:server:server-e2e     at SomePromiseArray._promiseRejected (/root/.cache/Cypress/9.5.2/Cypress/resources/app/node_modules/bluebird/js/release/some.js:69:17)
  cypress:server:server-e2e     at Promise._settlePromise (/root/.cache/Cypress/9.5.2/Cypress/resources/app/node_modules/bluebird/js/release/promise.js:576:26)
  cypress:server:server-e2e     at Promise._settlePromise0 (/root/.cache/Cypress/9.5.2/Cypress/resources/app/node_modules/bluebird/js/release/promise.js:614:10)
  cypress:server:server-e2e     at Promise._settlePromises (/root/.cache/Cypress/9.5.2/Cypress/resources/app/node_modules/bluebird/js/release/promise.js:690:18)
  cypress:server:server-e2e     at _drainQueueStep (/root/.cache/Cypress/9.5.2/Cypress/resources/app/node_modules/bluebird/js/release/async.js:138:12)
  cypress:server:server-e2e     at _drainQueue (/root/.cache/Cypress/9.5.2/Cypress/resources/app/node_modules/bluebird/js/release/async.js:131:9)
  cypress:server:server-e2e     at Async._drainQueues (/root/.cache/Cypress/9.5.2/Cypress/resources/app/node_modules/bluebird/js/release/async.js:147:5)
  cypress:server:server-e2e     at Immediate.Async.drainQueues [as _onImmediate] (/root/.cache/Cypress/9.5.2/Cypress/resources/app/node_modules/bluebird/js/release/async.js:17:14)
  cypress:server:server-e2e     at processImmediate (node:internal/timers:464:21)
  cypress:server:server-e2e  +10s
  cypress:server:server-base Setting remoteAuth undefined +10s
  cypress:server:server-base Setting remoteOrigin http://wordpress.local +2ms
  cypress:server:server-base Setting remoteHostAndPort { port: '80', tld: 'local', domain: 'wordpress' } +0ms
  cypress:server:server-base Setting remoteDocDomain wordpress.local +0ms
  cypress:server:server-base Getting remote state: { auth: undefined, props: { port: '80', tld: 'local', domain: 'wordpress' }, origin: 'http://wordpress.local', strategy: 'http', visiting: undefined, domainName: 'wordpress.local', fileServer: null } +1ms
Cypress failed to verify that your server is running.

However if we remove baseUrl from the cypress.json and we use cy.visit('http://wordpress.local/'); instead of cy.visit('/'); it work perfect.

{
  "hosts": {
    "wordpress.local": "121.0.0.1"
  }
}
  cypress:server:server-base server open +0ms
  cypress:server:server-e2e createServer connecting to server +0ms
  cypress:server:server-base Server listening on  { address: '127.0.0.1', family: 'IPv4', port: 32997 } +19ms
  cypress:server:server-base Setting remoteAuth undefined +36ms
  cypress:server:server-base Setting remoteOrigin http://localhost:32997 +1ms
  cypress:server:server-base Setting remoteStrategy file +0ms
  cypress:server:server-base Setting remoteHostAndPort null +0ms
  cypress:server:server-base Setting remoteDocDomain localhost +0ms
  cypress:server:server-base Setting remoteFileServer http://localhost:32783 +0ms
  cypress:server:server-base Getting remote state: { auth: undefined, props: null, origin: 'http://localhost:32997', strategy: 'file', visiting: undefined, domainName: 'localhost', fileServer: 'http://localhost:32783' } +1ms
====================================================================================================

  (Run Starting)

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ Cypress:        9.4.1                                                                          β”‚
  β”‚ Browser:        Electron 94 (headless)                                                         β”‚
  β”‚ Node Version:   v14.19.0 (/usr/bin/node)                                                       β”‚
  β”‚ Specs:          1 found (wordpress_spec.js)                                                    β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
...
  cypress:server:server-base Getting remote state: { auth: null, props: { port: '80', tld: 'local', domain: 'wordpress' }, origin: 'http://wordpress.local', strategy: 'http', visiting: false, domainName: 'wordpress.local', fileServer: null } +1ms
  cypress:network:connect beginning getAddress { hostname: 'wordpress.local', port: 80 } +464ms
  cypress:network:connect got addresses { hostname: 'wordpress.local', port: 80, addresses: '192.168.1.107' } +1ms

Desired behavior

We are using a Linux base container like cypress/included:9.4.1 in our CI system so the error happens. However, it doesn’t happen locally using MacOS. You can see the following logs

$ DEBUG=cypress:network:connect,cypress:server:server-e2e,cypress:server:server-base cypress run -P /examples/wordpress/cypress
  cypress:server:server-base server open +0ms
  cypress:server:server-e2e createServer connecting to server +0ms
  cypress:server:server-base Server listening on  { address: '127.0.0.1', family: 'IPv4', port: 49206 } +11ms
  cypress:network:connect beginning getAddress { hostname: 'wordpress.local', port: 80 } +0ms
  cypress:network:connect got addresses { hostname: 'wordpress.local', port: 80, addresses: '127.0.0.1' } +1ms
  cypress:server:server-base Setting remoteAuth undefined +23ms
  cypress:server:server-base Setting remoteOrigin http://wordpress.local +0ms
  cypress:server:server-base Setting remoteHostAndPort { port: '80', tld: 'local', domain: 'wordpress' } +0ms
  cypress:server:server-base Setting remoteDocDomain wordpress.local +1ms
  cypress:server:server-base Getting remote state: { auth: undefined, props: { port: '80', tld: 'local', domain: 'wordpress' }, origin: 'http://wordpress.local', strategy: 'http', visiting: undefined, domainName: 'wordpress.local', fileServer: null } +0ms
...
  (Run Starting)

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ Cypress:        9.4.1                                                                          β”‚
  β”‚ Browser:        Electron 94 (headless)                                                         β”‚
  β”‚ Node Version:   v14.19.0 (/Users/darteaga/.nvm/versions/node/v14.19.0/bin/node)                β”‚
  β”‚ Specs:          1 found (wordpress_spec.js)                                                    β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜


───────────────────

The desired behavior is this working on a Linux system. The problem seems to be related to the verification of the baseUrl that is performed when it is found in the cypress.jso.

Test code to reproduce

Cypress.json

{
  "baseUrl": "https://google.local"
  "hosts": {
    "google.local": "216.58.214.142"
  }
}

spec.js

/// <reference types="cypress" />

it('Google is shown', () => {
    cy.visit('/');
    cy.get('img.lnXdpd').should('have.attr', 'src').should('include','googlelogo_color_272x92dp.png');
});

Cypress Version

9.4.1

Other

$ cypress --version
Cypress package version: 9.4.1
Cypress binary version: 9.4.1
Electron version: 15.3.4
Bundled Node version: 16.5.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:10
  • Comments:8

github_iconTop GitHub Comments

3reactions
ManuelLRcommented, Jun 14, 2022

Hi! We have encountered the same problem but in our case, we cannot use the workaround proposed by @dani8art.

We need hosts and baseUrl configs working at the same time because we need to map the domain to an IP and, additionally, we need to avoid the β€œreloading error” in the middle of a test whose solution is to define the baseUrl ( tickets: https://github.com/cypress-io/cypress/issues/2636, https://github.com/cypress-io/cypress/issues/3454, https://github.com/cypress-io/cypress/issues/2777 … ).

So this is also critical for us and we can not use the workaround.

0reactions
dani8artcommented, Dec 1, 2022

Wow, @funktionalsystems this is really great research, Since I saw that it was working depending on the OS I thought it might be related to β€œbe some kind of runtime scope/timing issue”.

However, I can see this line

cypress:server:server-base Server listening on  { address: '127.0.0.1', family: 'IPv4', port: 46389 }

Which is always pointing to 127.0.0.1 instead of being pointing to $MY_REDACTED_IP as you have mentioned it may be related to β€œPerhaps this is somehow a bug in isListening (ensure-url.ts)”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress could not verify that the server set as your 'baseUrl' is ...
I got the "Cypress failed to verify that your server is running" problem despite being able to access the site through a browser....
Read more >
Configuration - Cypress Documentation
This guide is for Cypress 10 and the new JavaScript configuration file format. If you are on an older version of Cypress that...
Read more >
A Practical Guide to Intercepting Network Requests in Cypress
Cypress has become one of the most favorite testing tools for frontend ... It's a very simple Vue.js app built with json-server -...
Read more >
Configurations in Cypress and How to Disable Default ...
json. Additionally, we can override the configurations via the command line as well while using the "cypress open" and "cypress run" commands.
Read more >
Cypress Hosts Option - Gleb Bahmutov
How to test an HTTPS site locally using Cypress and a custom domain name. ... my local testing for cypress-hosts-option ... cypress.json ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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