如何使用 Cloud Build 运行 angular 进行测试?
How to run angular test using Cloud Build?
我使用开箱即用的 Angular 测试框架:用于单元测试的 Jasmine 和 karma 以及 GCP Cloud Build 来部署应用程序。但是在测试中出现问题,因为节点Docker镜像没有安装Chrome。
最好的处理方法是什么?创建自定义 docker 图像?或者是否有任何众所周知的 docker 图像我可以用来在 Cloud Build 中构建和测试 Angular 应用程序?
cloudbuild.yaml
steps:
# Install
- name: node:14
entrypoint: npm
args: ["install"]
#Build
- name: node:14
entrypoint: npm
args: ["run", "build", "--", "--aot"]
# Test <- This step fails. See the error message below
- name: node:14
entrypoint: npm
args: ["run", "test", "--", "--watch=false"]
# Deploy to Firebase
- name: gcr.io/$PROJECT_ID/firebase
args: ["deploy", "--project=$PROJECT_ID", "--only=hosting"]
错误
Already have image: node:14
> carealth@0.0.0 test /workspace
> ng test "--watch=false"
- Generating browser application bundles (phase: setup)...
18 01 2022 19:22:45.740:INFO [karma-server]: Karma v6.3.11 server started at http://localhost:9876/
18 01 2022 19:22:45.744:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
18 01 2022 19:22:45.749:INFO [launcher]: Starting browser Chrome
18 01 2022 19:22:45.756:ERROR [launcher]: No binary for Chrome browser on your platform.
Please, set "CHROME_BIN" env variable.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! carealth@0.0.0 test: `ng test "--watch=false"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the carealth@0.0.0 test 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! /builder/home/.npm/_logs/2022-01-18T19_22_45_880Z-debug.log
如果您的容器中需要无头 chrome,请选择安装了 node14 和无头 chrome 的容器。我发现 this one 和 Chrome 89 并于 10 个月前发布。我想你可以找到更好的来源
否则,您可以使用 node:14
容器,如果可能的话,在其上安装 headless Google Chrome(类似的东西,安装工作,但我还没有节点文件对其进行测试以完全验证该示例)
- name: node:14
entrypoint: bash
args:
- -c
- |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt update && apt install -y libappindicator1 fonts-liberation ./google-chrome-stable_current_amd64.deb
npm run test -- --watch=false
我使用开箱即用的 Angular 测试框架:用于单元测试的 Jasmine 和 karma 以及 GCP Cloud Build 来部署应用程序。但是在测试中出现问题,因为节点Docker镜像没有安装Chrome。
最好的处理方法是什么?创建自定义 docker 图像?或者是否有任何众所周知的 docker 图像我可以用来在 Cloud Build 中构建和测试 Angular 应用程序?
cloudbuild.yaml
steps:
# Install
- name: node:14
entrypoint: npm
args: ["install"]
#Build
- name: node:14
entrypoint: npm
args: ["run", "build", "--", "--aot"]
# Test <- This step fails. See the error message below
- name: node:14
entrypoint: npm
args: ["run", "test", "--", "--watch=false"]
# Deploy to Firebase
- name: gcr.io/$PROJECT_ID/firebase
args: ["deploy", "--project=$PROJECT_ID", "--only=hosting"]
错误
Already have image: node:14
> carealth@0.0.0 test /workspace
> ng test "--watch=false"
- Generating browser application bundles (phase: setup)...
18 01 2022 19:22:45.740:INFO [karma-server]: Karma v6.3.11 server started at http://localhost:9876/
18 01 2022 19:22:45.744:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
18 01 2022 19:22:45.749:INFO [launcher]: Starting browser Chrome
18 01 2022 19:22:45.756:ERROR [launcher]: No binary for Chrome browser on your platform.
Please, set "CHROME_BIN" env variable.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! carealth@0.0.0 test: `ng test "--watch=false"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the carealth@0.0.0 test 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! /builder/home/.npm/_logs/2022-01-18T19_22_45_880Z-debug.log
如果您的容器中需要无头 chrome,请选择安装了 node14 和无头 chrome 的容器。我发现 this one 和 Chrome 89 并于 10 个月前发布。我想你可以找到更好的来源
否则,您可以使用 node:14
容器,如果可能的话,在其上安装 headless Google Chrome(类似的东西,安装工作,但我还没有节点文件对其进行测试以完全验证该示例)
- name: node:14
entrypoint: bash
args:
- -c
- |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt update && apt install -y libappindicator1 fonts-liberation ./google-chrome-stable_current_amd64.deb
npm run test -- --watch=false