我使用開箱即用的 Angular 測驗框架:Jasmine 和 karma for Unit Test 和 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
> [email protected] 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! [email protected] test: `ng test "--watch=false"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
uj5u.com熱心網友回復:
如果您的容器中需要 headless chrome,請選擇安裝了 node14 和 headless chrome 的容器。我在 Chrome 89 中找到了這個,并在 10 個月前發布。我猜你可以找到更好的來源
否則,您可以使用您的node:14容器,如果可能的話,在其上安裝無頭 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/421467.html
標籤:
上一篇:開玩笑的異步測驗讓我很困惑
