cypress: 'Cypress could not verify that this server is running' error with baseUrl in component test after updating to v13

Current behavior

In the UI it displays the warning “cannot connect base url” image But here it is possible to ignore and execute the tests.

With the CLI it fails: image

Desired behavior

Before I updated it to version 13 it was working and it was not required to define the baseUrl for component tests. And the command npx nx component-test core-tables works without problems

Test code to reproduce

import { defineConfig } from 'cypress';
import { nxComponentTestingPreset } from '@nrwl/angular/plugins/component-testing';

export default defineConfig({
  component: {
    ...nxComponentTestingPreset(__filename),
    video: false,
    reporter: '../../../node_modules/cypress-multi-reporters',
    reporterOptions: {
      configFile: 'reporter.json'
    },
    screenshotsFolder: '../../../dist/cypress/libs/reports/mochawesome/screenshots/about'
  }
});

Cypress Version

13.2.0

Node version

v18.15.0

Operating System

Windows 10

Debug Logs

> nx run core-tables:component-test

DevTools listening on ws://127.0.0.1:59615/devtools/browser/3a1d1242-0013-46a8-9bd2-6d4ea7994825
Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
- Generating browser application bundles (phase: setup)...
Cypress could not verify that this server is running:

  > http://localhost:8080

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...
We will try connecting to it 2 more times...
We will try connecting to it 1 more time...

Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
Cypress failed to verify that your server is running.

Please start this server and then run Cypress again.

Other

nx version: 15.7.2

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 10
  • Comments: 37 (4 by maintainers)

Most upvoted comments

I found a clue! In /etc/hosts, if I comment out the line for ::1, component tests work:

#::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1	localhost.localdomain	localhost myhostname

Then this issue is now similar to https://github.com/cypress-io/cypress/issues/25397, except here we don’t even use a base URL, and nothing I tried so far helps as a workaround.

I am also getting this after upgrading to v13. If I replace localhost with its IP address in the baseUrl config, then it works as normal, but either ought to work.

I have the same issue after upgrading from Cypress 12.7.2 to 13.6.2. When I run the following command on Linux, I get:

> cypress run --component --browser chromium


DevTools listening on ws://127.0.0.1:43411/devtools/browser/f036190f-b6d2-4bbf-a3b3-512953f97dbc
[356314:0109/140456.248459:ERROR:object_proxy.cc(590)] Failed to call method: org.freedesktop.portal.Settings.Read: object_path= /org/freedesktop/portal/desktop: org.freedesktop.portal.Error.NotFound: Requested setting not found
(node:356503) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:356503) ExperimentalWarning: The Node.js specifier resolution flag is experimental. It could change or be removed at any time.
vite:istanbul> Sourcemaps was automatically enabled for code coverage to be accurate.
 To hide this message set build.sourcemap to true, 'inline' or 'hidden'.
Cypress could not verify that this server is running:

  > http://localhost:5173

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...
We will try connecting to it 2 more times...
We will try connecting to it 1 more time...

Cypress failed to verify that your server is running.

Please start this server and then run Cypress again.

The cypress open --component command would also show me a warning about the base URL, but at least the tests can still be executed. Edit: If i pressed Try again, the warning would not go away until I selected a browser. Once the browser is opened, the warning disappeared when pressing Try again.

Interestingly enough, I can run component tests inside a cypress/browsers Docker image … I don’t know what the difference is yet.

thanks @beckiechoi, it fix my pipeline too !

@scsannalli yes the problem occured while i ran the tests on container. Maybe the etc/host is not configured well in the docker container

I was able to fix this issue by adding hosts in the config option. I was able to find the key while digging through their .d.ts file, but didn’t see it on the website/docs. Using cypress@13.14.2, webpack server on a docker container.

export default defineConfig({
  e2e: {
    baseUrl: "<my-localhost-url>",
    ...
  },
  component: {
     ...
  },
  hosts: {
    "localhost": "127.0.0.1"
  }
});

I think it is proxy related, as I cannot reproduce on my personal PC but can on my work machine

The issue is reproducible as well with Cypress version: 13.9.0

After few days of reading the Cypress source code and testing on our Azure server, I found that if ENV-variable HTTP_PROXY or HTTPS_PROXY is set, the server verification would fail.

Row 59 in server/lib/util/ensure-url. ts function isListening:

export const isListening = (urlStr: string) => {
  // takes a urlStr and verifies the hostname + port is listening
  let { hostname, protocol, port } = url.parse(urlStr)

  if (port == null) {
    port = protocol === 'https:' ? '443' : '80'
  }

  if (process.env.HTTP_PROXY) { <-- HERE
    // cannot make arbitrary connections behind a proxy, attempt HTTP/HTTPS
    // For some reason, TypeScript gets confused by the "agent" parameter
    // and required double ts-ignore to allow it on local machines and on CI
    // @ts-ignore
    return rp({
      url: urlStr,
      // @ts-ignore
      agent,
      proxy: null,
    })
    .catch({ name: 'StatusCodeError' }, () => {}) // we just care if it can connect, not if it's a valid resource
  }

  return connect.getAddress(Number(port), String(hostname))
}

I’m seeing a similar issue, @MetRonnie Thanks, updating the baseUrl to IP worked for e2e tests. But component testing doesn’t have the property exposed in config and cannot be overridden.


interface ComponentConfigOptions<ComponentDevServerOpts = any> extends Omit<CoreConfigOptions, 'baseUrl' | 'experimentalStudio'> {
    devServer: DevServerFn<ComponentDevServerOpts> | DevServerConfigOptions
    devServerConfig?: ComponentDevServerOpts
    /**
     * Runs all component specs in a single tab, trading spec isolation for faster run mode execution.
     * @default false
     */
    experimentalSingleTabRunMode?: boolean
  }