在Docker环境下跳过cypress下载

使用vue-cli脚手架建立的项目,一般都带有cypress功能, cypress是用于端到端的测试框架,在项目开发过程中(本地或者云主机),我们有可能会对端到端测试做一些编码处理,但在项目构建过程中,一般不依赖此功能。

因此,我们实际上可能并不需要在vue项目中添加cypress功能。然而,如果已有的项目已经接入了cypress功能,我们应该如何在docker构建环境中避免呢。我从cypress的官方文档中找到了答案

在安装cypress时,有这样的文档:https://docs.cypress.io/guides/getting-started/installing-cypress#Advanced

简单来说,如下:


Environment variables

NameDescription
CYPRESS_INSTALL_BINARYDestination of Cypress binary that’s downloaded and installed
CYPRESS_DOWNLOAD_MIRRORDownloads the Cypress binary though a mirror server
CYPRESS_CACHE_FOLDERChanges the Cypress binary cache location
CYPRESS_RUN_BINARYLocation of Cypress binary at run-time

CYPRESS_INSTALL_BINARY

因为流水线环境的网络安全策略(企业防火墙),我们正常下载cypress会提示证书失败,这里的做法是忽略安装cypress,

You can also force Cypress to skip the installation of the binary application by setting CYPRESS_INSTALL_BINARY=0. This could be useful if you want to prevent Cypress from downloading the Cypress binary at the time of npm install.

CYPRESS_INSTALL_BINARY=0 npm install

CYPRESS_DOWNLOAD_MIRROR

也可以设置从镜像网站下载cypress运行时,比如:https://npm.taobao.org/mirrors/cypress/,指令如下:

CYPRESS_DOWNLOAD_MIRROR=https://npm.taobao.org/mirrors/cypress/9.0.0/linux64/cypress.zip npm install

CYPRESS_CACHE_FOLDER,CYPRESS_RUN_BINARY

这两个环境变量一般用在真实的机器环境中,而非虚拟机。这里不做赘述。


综合地说,还是强制忽略掉cypress的安装最方便快捷,当然,你必须要确认你的项目在构建时不需要走端到端测试流程的
posted @ 2021-11-12 10:28  西河  阅读(111)  评论(0编辑  收藏  举报