1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-06-16 07:07:37 +02:00
cheatsheets/jscoverage.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.0 KiB

title category intro
jscoverage JavaScript libraries A small guide into installing [jscoverage](https://npmjs.com/package./jscoverage). Also see [mocha-blanket](./mocha-blanket).

Install

Install via npm

npm install --save-dev jscoverage

Ignore output

echo coverage.html >> .gitignore

package.json

The coverage task injects your source files (lib) with jscoverage hooks, runs mocha -R html-cov, then restores later. {: .-setup}

/* directory */
"coverage": "mv lib lib~; (jscoverage lib~ lib; mocha -R html-cov > coverage.html); rm -rf lib; mv lib~ lib"

{: .-hard-wrap}

/* single file */
"coverage": "(cp index.js index.js~; jscoverage index.js; mv index-cov.js index.js; mocha -R html-cov > coverage.html); mv index.js~ index.js"

{: .-hard-wrap}

Run

npm run coverage
open coverage.html

Caveats

If you're using jsdom, be sure to expose the window._$jscoverage variable into the global scope.