Bitbucket pipeline 您的系统缺少依赖项:Xvfb

Sir*_*axi 16 testing bitbucket npm cypress

我正在尝试将 cypress 添加到 bitbucket 管道,但它告诉我需要安装 Xvfb,但我不知道如何继续。这是我的 bitbucket.pipelines.yml

#  Template NodeJS build

#  This template allows you to validate your NodeJS code.
#  The workflow allows running tests and code linting on the default branch.

image: node:14.15.4

pipelines:
  default:
    - step:
        name: Build
        script:
          - npm install
          - npm run lint
          - npm run cypress:run
Run Code Online (Sandbox Code Playgroud)

这是我的 package.json 脚本

"scripts": {
    "cypress:open": "cypress open",
    "cypress:run": "npx cypress run --record --key xxxxxxxxxxxx"
}
Run Code Online (Sandbox Code Playgroud)

并且测试在本地运行良好 在此输入图像描述

但在管道中我收到此错误:

+ npm run cypress:run
> wallet-frontend@0.1.0 cypress:run /opt/atlassian/pipelines/agent/build
> npx cypress run --record --key 70004462-62d4-42ce-b359-5bff73d8b001
It looks like this is your first time using Cypress: 6.5.0
[16:30:09]  Verifying Cypress can run /root/.cache/Cypress/6.5.0/Cypress [started]
[16:30:09]  Verifying Cypress can run /root/.cache/Cypress/6.5.0/Cypress [failed]
Your system is missing the dependency: Xvfb
Install Xvfb and run Cypress again.
Read our documentation on dependencies for more information:
https://on.cypress.io/required-dependencies
If you are using Docker, we provide containers with all required dependencies installed.
----------
Error: spawn Xvfb ENOENT
----------
Platform: linux (Debian - 9.13)
Cypress Version: 6.5.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wallet-frontend@0.1.0 cypress:run: `npx cypress run --record --key xxxxxxxxx`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the wallet-frontend@0.1.0 cypress:run script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Run Code Online (Sandbox Code Playgroud)

Sag*_*iga 16

Xvfb 是一个用于类 UNIX 操作系统的内存显示服务器,在您的例子中是 Linux (Debian - 9.13)。这是 cypress 假定已预先安装的系统级依赖项。对于 bitbucket env,未安装,因此出现此错误。这主要用于运行 cypress 时有头浏览器的显示 (UI)。

这里有一些简单的解决方法:

  1. 手动安装依赖项:我不会建议这样做,因为除非您彻底研究所有依赖项,否则您可能会错过更多依赖项。

  2. 运行无头浏览器::无头浏览器不使用 Xvfb,因此不会遇到这个确切的错误,但正如我在第 1 点中所说,可能还有其他问题。命令将变成cypress run --headless

  3. 使用 Cypress 提供的 Docker 镜像(建议):我可以看到您正在使用该node:14.15.4镜像进行此构建。相反,请使用 cypress 为您想要运行的任何节点版本提供的官方基础映像(在标签中查找不同的节点版本)。如果你查看 Dockerfile 你会发现他们已经尽力安装在 docker 内运行 Cypress 所需的依赖项(你可以在那里看到 Xvfb)。

另外,当您遇到与 cypress 相关的问题时,请查找已经开放的问题,它们有一个非常活跃且有用的问题部分。我在那里发现了同样的问题:https ://github.com/cypress-io/cypress/issues/14457