Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Code Coverage -- Javascript Frontend + Backend

Code Coverage -- Javascript Frontend + Backend

當開始寫測試後,要怎麼確認專案的那些部份已經測試,哪些又還沒呢?這次將會跟大家介紹與講解要如何設定 node.js 與 front-end 的 code coverage,並且透過整合不同工具與服務讓開發者可以更容易地掌握專案 code coverage 的狀況。

keywords: javascript, node.js, front-end, travis-ci, intern, mocha, istanbul, coveralls, sauce labs

License: https://creativecommons.org/licenses/by/3.0/tw/

Yuren Ju

June 25, 2015
Tweet

More Decks by Yuren Ju

Other Decks in Technology

Transcript

  1. Intern Well-documented AMD loader Istanbul inside! Support Selenium Support Sauce

    Labs, BrowserStack, TestingBot Unit test/Functional Test
  2. Running test on browser remove reporters in intern.js $ http-server

    $ open http://localhost:8080/node_modules/intern/client.html?config=tests/intern
  3. Pull request build & invoke test runner Run tests on

    multiple browsers Track code coverage
  4. Send a pull request & wait result :-) git push

    upstream more-login-test hub pull-request
  5. But on Travis-CI for open source project! Don’t put your

    API token to .travis.yml use travis encrypt SAUCE_USERNAME=<USERNAME> --add travis encrypt SAUCE_ACCESS_KEY=<TOKEN> --add
  6. Limitation Encrypted environment variables are not available to pull requests

    from forks due to the security risk of exposing such information to unknown code. http://docs.travis-ci.com/user/environment-variables/
  7. Coveralls setup npm install coveralls Added ‘lcov’ reporter to tests/intern.js

    add variables into .travis.yml COVERALLS_REPO_TOKEN (don’t forget encrypting) COVERALLS_SERVICE_NAME=travis-ci execute coveralls command in after_script section cat lcov.info | ./node_modules/coveralls/bin/ coveralls.js
  8. Transpiled code Istanbul: #212 babel-istanbul ibrik - CoffeeScript meets Istanbul

    transform-coverage.js - generate lcov report with source code by source map https://github.com/hammerlab/pileup.js/blob/master/scripts/transform- coverage.js