cheatsheets/jscoverage.md

53 lines
1.0 KiB
Markdown
Raw Permalink Normal View History

2014-03-26 04:09:02 +00:00
---
2014-04-01 07:59:39 +00:00
title: jscoverage
2015-11-24 05:09:17 +00:00
category: JavaScript libraries
2017-10-29 12:03:37 +00:00
intro: |
A small guide into installing [jscoverage](https://npmjs.com/package./jscoverage). Also see [mocha-blanket](./mocha-blanket).
2014-03-26 04:09:02 +00:00
---
### Install
2017-10-29 12:03:37 +00:00
#### Install via npm
```bash
npm install --save-dev jscoverage
```
2014-03-26 04:09:02 +00:00
2017-10-29 12:03:37 +00:00
#### Ignore output
2014-03-26 04:09:02 +00:00
2017-10-29 12:03:37 +00:00
```bash
echo coverage.html >> .gitignore
```
2014-03-26 04:09:02 +00:00
2014-04-01 07:59:39 +00:00
### package.json
2014-03-26 04:09:02 +00:00
2014-04-01 07:59:39 +00:00
The `coverage` task injects your source files (`lib`) with jscoverage hooks, runs `mocha -R html-cov`, then restores later.
2017-10-29 12:03:37 +00:00
{: .-setup}
2014-03-26 04:09:02 +00:00
2017-10-29 12:03:37 +00:00
```bash
/* directory */
"coverage": "mv lib lib~; (jscoverage lib~ lib; mocha -R html-cov > coverage.html); rm -rf lib; mv lib~ lib"
```
{: .-hard-wrap}
2014-04-28 10:57:58 +00:00
2017-10-29 12:03:37 +00:00
```bash
/* 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}
2014-03-26 04:09:02 +00:00
### Run
2017-10-29 12:03:37 +00:00
```bash
npm run coverage
```
```bash
open coverage.html
```
2014-04-01 07:59:39 +00:00
### Caveats
2014-11-05 06:14:00 +00:00
If you're using jsdom, be sure to expose the `window._$jscoverage` variable into
the `global` scope.