【问题标题】:baseUrl not being found when running cypress tests through Travis CI通过 Travis CI 运行 cypress 测试时找不到 baseUrl
【发布时间】:2019-11-25 05:02:17
【问题描述】:

在通过 Travis CI 构建项目时,我正在尝试运行我的 cypress 测试。我正在安装 cypress,但是,我收到以下错误:

我查看了网上和 cypress 官方文档以及他们建议通过将以下内容添加到我的 package.json 来解决此问题的方法:

"test:ci": "start-server-and-test http://localhost:3000 cy:run"

cy:run 在这种情况下为cypress run。但是,当我运行它时,它确实构建了服务器,但是之后它似乎并没有运行测试。它只是在构建时冻结。

然后我在我的travis.yml 文件中调用此脚本,如下所示:

  - npm run test:ci

我还有以下作为我的 before_install 和 install 对象:

before_install:
  - npm i -g npm@5
  - npm i -g firebase-tools
  - npm i -g @angular/cli
  - npm cache verify

install:
  - npm i
  - npm ci

澄清一下 - 期望的结果是,当通过 Travis 运行 Cypress 时,会运行本地服务器(我的 baseUrl),然后执行测试。

【问题讨论】:

  • 在 gitlab ci 上有同样的问题。
  • @ElectRocnic 我设法通过运行 http-server 而不是像这样的本地主机来解决这个问题:"http-server dist -p 3000 -c-1 --cors"
  • 谢谢,但我的设置似乎与你的完全不同,因为我已经使用 nginx 作为我的 http-server,但仍然遇到同样的问题。我的问题通过 stackoverflow.com/a/48288560/3433137 解决了。我的设置是使用 dind 的 gitlab-ci。我无法连接到我服务的应用程序,因为暴露的端口 8000 没有暴露给我的跑步者,而是暴露给 gitlab-ci.yml 中定义的服务。因此我可以连接 docker:8000 而不是 localhost:8000

标签: javascript angular travis-ci package.json cypress


【解决方案1】:

在你的 cypress.json 中使用 "baseUrl":"http://host.docker.internal:3000"

【讨论】:

    猜你喜欢
    • 2018-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 2016-05-09
    • 2020-07-27
    相关资源
    最近更新 更多