LoginSignup
6
3

More than 5 years have passed since last update.

npm ライブラリを travis-ci でテストして Coveralls でカバレッジを計測する

Posted at

travis-ciCoveralls を使って自動テストとカバレッジの計測を行えるようにしてみた。
starhoshi/rescue-fire このレポジトリで実際に動かしている。

Test

今回は yarn と jest を使う。

yarn run jest --coverage

このコマンドだけでテストとカバレッジの出力が同時にできて便利。

travis-ci

目的のレポジトリを ON にして

スクリーンショット 2018-02-11 0.11.05.png

Build only if .travis.yml is preset を ON。

スクリーンショット 2018-02-10 21.35.30.png

これで下準備は完了なので、レポジトリに .travis.yml を作る。

package.json と yarn.lock があると勝手に yarn install をしてくれる。dist: trusty にするとデフォルトで yarn が install 済みの Ubuntu を使えるっぽい。

language: node_js
node_js:
  - node
dist: trusty
sudo: false
cache: yarn
script: yarn run jest --coverage

まずこれで travis-ci でテストが動かせるようになった。

Coveralls

travis と同様に、目的のレポジトリを ON にする。

スクリーンショット 2018-02-11 0.24.18.png

travis でテストしたカバレッジ結果を Coveralls に投げる必要があるので、ライブラリを追加する。

yarn add --dev coveralls

最後にカバレッジ結果を投げるように .travis.yml を修正する。Token などは設定する必要がなく、勝手にやってくれるっぽい。

script: yarn run test --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js

これで travis, Coveralls の設定は終わり。

おわり

上記の手順をした後に git push するとテストが回り、カバレッジが集計される。

travis, Coveralls それぞれのバッジも設定できるので、 README に貼っておくと見栄えが良い。

スクリーンショット 2018-02-11 0.32.43.png
https://github.com/starhoshi/rescue-fire

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3