[Deploy] coveralls 筆記
- Coveralls @ official website ✨
- Coveralls @ Travis CI > Integrations and Notifications
- node-coveralls @ Github
Steps
-
進到 coveralls 的官網
-
連結 Github
-
在 coveralls 中 add repository(轉到
ON
) -
點選
details
可以看到對應的repo_token
-
到 Travis CI 上對應 repository 的 環境變數:
COVERALLS_REPO_TOKEN=<repo-token> # 從 coveralls 上取得
COVERALLS_SERVICE_NAME=travis-pro # 可不填
COVERALLS_GIT_BRANCH (the branch name) # 可不填 -
在專案中安裝
coveralls
npm install coveralls --save-dev
- 在專案的
package.json
中加入指令:
// package.json
{
"scripts": {
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls"
}
}
- 在專案的
.travis.yml
中加入下述設定(可參考此設定檔):
# .travis.yml
language: node_js
node_js:
- 12
jobs:
include:
- stage: Produce Coverage
node_js: node
script: npm run coveralls
-
push 專案到 github 上觸發 Travis CI 執行
-
正確的話回到 coveralls 即可看到結果,並可把測試覆蓋率嵌入
README
中
[![Coverage Status](https://coveralls.io/repos/github/<user-name>/<repo-name>/badge.svg?branch=master)](https://coveralls.io/github/<user-name>/<repo-name>?branch=master)
錯誤處理
Coveralls returns 422 error: Couldn't find a repository matching this job @ Github Issues