Cypress E2E 使用 GitLab Runner 测试 VueJS returns 404 未找到

Cypress E2E Testing VueJS with GitLab Runner returns 404 not found

我有以下简单的 GitLab CI 文件

stages:
  - e2e_test

e2e_test:
  stage: e2e_test
  tags:
    - test
  script:
    - npm config set strict-ssl false
    - npm install
    - npm run test:e2e:ci

出于非常具体的公司原因,我 运行 在 shell 运行 中编写上述脚本。

此脚本导致 404 错误并显示以下日志

 npm run test:e2e:ci
> todo-app@0.1.0 test:e2e:ci /home/gitlab-runner/builds/UHz6XzwM/0/microservices-and-cognitive-solutions/demos/microservice-concept/todo-app
> vue-cli-service test:e2e --headless
 INFO  Starting e2e tests...
 INFO  Starting development server...
 DONE  Compiled successfully in 8865ms6:51:36 PM
  App running at:
  - Local:   http://localhost:8083/ 
  - Network: http://10.108.201.150:8083/
  App is served in production mode.
  Note this is for preview or E2E testing only.
====================================================================================================
  (Run Starting)
tput: No value for $TERM and no -T specified
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    3.8.3                                                                              │
  │ Browser:    Electron 78 (headless)                                                             │
  │ Specs:      1 found (test.js)                                                                  │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running:  test.js                                                                         (1 of 1)
Browserslist: caniuse-lite is outdated. Please run the following command: `npm update`
  My First Test
    1) Visits the app root url
  0 passing (341ms)
  1 failing
  1) My First Test Visits the app root url:
     CypressError: cy.visit() failed trying to load:
http://localhost:8083/
The response we received from your web server was:
  > 404: Not Found
This was considered a failure because the status code was not '2xx'.
If you do not want status codes to cause failures pass the option: 'failOnStatusCode: false'
      at Object.cypressErr (http://localhost:8083/__cypress/runner/cypress_runner.js:86207:11)
      at Object.throwErr (http://localhost:8083/__cypress/runner/cypress_runner.js:86162:18)
      at Object.throwErrByPath (http://localhost:8083/__cypress/runner/cypress_runner.js:86194:17)
      at http://localhost:8083/__cypress/runner/cypress_runner.js:71493:31
      at visitFailedByErr (http://localhost:8083/__cypress/runner/cypress_runner.js:71006:12)
      at http://localhost:8083/__cypress/runner/cypress_runner.js:71474:22
      at tryCatcher (http://localhost:8083/__cypress/runner/cypress_runner.js:120203:23)
      at Promise._settlePromiseFromHandler (http://localhost:8083/__cypress/runner/cypress_runner.js:118139:31)
      at Promise._settlePromise (http://localhost:8083/__cypress/runner/cypress_runner.js:118196:18)
      at Promise._settlePromise0 (http://localhost:8083/__cypress/runner/cypress_runner.js:118241:10)
      at Promise._settlePromises (http://localhost:8083/__cypress/runner/cypress_runner.js:118316:18)
      at Async../node_modules/bluebird/js/release/async.js.Async._drainQueue (http://localhost:8083/__cypress/runner/cypress_runner.js:114928:16)
      at Async../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:8083/__cypress/runner/cypress_runner.js:114938:10)
      at Async.drainQueues (http://localhost:8083/__cypress/runner/cypress_runner.js:114812:14)

如果我在同一台服务器上克隆相同的存储库并在终端中手动 运行 以下命令它工作正常。

npm install
npm run test:e2e:ci

知道为什么相同的命令在 GitLab 运行ner shell 中会失败但在用户 shell

中工作

我找到了解决我问题的问题。我需要在我的 gitlab-runner config.toml 文件中设置一个 no_proxy 环境条目。这不会影响到每个人,但由于我是公司代理的幕后黑手,所以我需要它。

export no_proxy="localhost"