1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-10-16 15:38:44 +02:00
cheatsheets/mocha-blanket.md
Rico Sta. Cruz 511de900ba
Formatting updates (#2133)
- Update some sheets which have very long sections
- Remove `layout: 2017/sheet` (everything has the same layout now)
- Remove outdated sheets
2024-04-03 18:30:24 +11:00

1.2 KiB

title, category, intro
title category intro
Mocha blanket JavaScript libraries Use [blanket](https://npmjs.com/package/blanket) for easy coverage reporting for Mocha JavaScript tests.

Quickstart guide

Install blanket: {: .-setup}

npm i --save-dev blanket

In your test helpers, use Blanket before requireing:

if (process.env.COVERAGE) {
  require('blanket')({
    pattern: require('path').resolve('./index.js')
  });
}
thing = require('../index');

Add to package.json:

"scripts": {
  "coverage": "env COVERAGE=1 mocha -R html-cov > coverage.html && open coverage.html"
}

Be sure to ignore it:

echo "coverage.html" >> .gitignore

Then run:

npm run coverage

Travis + coveralls.io support

Visit coveralls.io then activate your repo. Then install the appropriate packages: {: .-setup}

npm i --save-dev mocha-lcov-reporter coveralls

Add this to .travis.yml:

after_success:
  - ./node_modules/.bin/mocha -R mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js

Commit, push, wait for Travis to finish.