简体   繁体   English

赛普拉斯 CI:错误:连接 ECONNREFUSED 127.0.0.1:3000

[英]Cypress CI: Error: connect ECONNREFUSED 127.0.0.1:3000

for a small project i'm trying to run Cypress tests against a Nodejs app that i took from an example in GitHub.对于一个小项目,我正在尝试针对我从 GitHub 中的示例中获取的 Nodejs 应用程序运行赛普拉斯测试。 Additionally, i want to execute the tests in GitLab CI/CD.此外,我想在 GitLab CI/CD 中执行测试。 My yml file looks something like this:我的 yml 文件如下所示:

stages:
 - build
 - publish # (consumer only)
 - can-i-deploy
 - deploy
 - tag

pact-test:
  image: $CI_REGISTRY_IMAGE
  stage: build
  script:
    - npm ci
    - npm run start &
    - npm run cypress
  artifacts:
    paths:
      - pacts

Here is the reference to the application i took as example, and here are the Cypress tests .这是我作为示例的应用程序的参考,这里是赛普拉斯测试

The error i get is this:我得到的错误是这样的:

 "before each" hook for "displays product item":
     CypressError: `cy.visit()` failed trying to load:
http://localhost:3000/products/09
We attempted to make an http request to this URL but the request failed without a response.
We received this error at the network level:
  > Error: connect ECONNREFUSED 127.0.0.1:3000
Common situations why this would fail:
  - you don't have internet access
  - you forgot to run / boot your web server
  - your web server isn't accessible
  - you have weird network configuration settings on your computer
Because this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `product page`

UPDATE After running a sleep and a curl command this is the result:更新运行睡眠和 curl 命令后,结果如下:

$ npm run start &
$ sleep 5
> poc-consumer@0.1.0 start /builds/poc-consumer
> react-scripts --openssl-legacy-provider start
node: bad option: --openssl-legacy-provider
npm ERR! code ELIFECYCLE
npm ERR! errno 9
npm ERR! poc-consumer@0.1.0 start: `react-scripts --openssl-legacy-provider start`
npm ERR! Exit status 9
npm ERR! 
npm ERR! Failed at the poc-consumer@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-08-18T13_20_15_778Z-debug.log
$ curl http://localhost:3000/products/09
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to localhost port 3000: Connection refused

The error itself already provides the most likely reasons:错误本身已经提供了最可能的原因:

  • you don't have internet access你没有互联网访问权限
  • you forgot to run / boot your web server您忘记运行/启动您的 web 服务器
  • your web server isn't accessible您的 web 服务器无法访问
  • you have weird network configuration settings on your computer您的计算机上有奇怪的网络配置设置

In your case, it appears that you did not start the server.在您的情况下,您似乎没有启动服务器。

Looking at your CI script, you are starting the server and then immediately attempt to run tests.查看您的 CI 脚本,您正在启动服务器,然后立即尝试运行测试。 Chances are that server did not start this quick.服务器可能没有这么快启动。 Try this instead:试试这个:

- npm run start &
- sleep 5
- npm run cypress

This will force npm run cypress to wait 5 seconds before starting.这将强制npm run cypress在启动前等待 5 秒。

can you provide the port like你能提供像这样的端口吗

 - name: 🌳 Cypress run
   uses: cypress-io/github-action@v4
   with:
     start: npm run xx
     wait-on: "http://localhost:8811"

hope it can be help希望能有所帮助

Problem found!发现问题!

The issue was an option for react, that is not supported from npm: --openssl-legacy-provider removed that, i was able to curl the node server and run the cypress test问题是反应的一个选项,npm 不支持: --openssl-legacy-provider删除了它,我能够 curl 节点服务器并运行 cypress 测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM