Blanket.js
A seamless JavaScript code coverage library.
Project home page
Philosophy
Blanket.js is a code coverage tool for javascript that aims to be:
- Easy to install
- Easy to use
- Easy to understand
Blanket.js can be run seamlessly or can be customized for your needs.
Mechanism
JavaScript code coverage compliments your existing JavaScript tests by adding code coverage statistics (which lines of your source code are covered by your tests).
Blanket works in a 3 step process:
- Loading your source files using a modified RequireJS/Require script
- Parsing the code using Esprima and node-falafel, and instrumenting the file by adding code tracking lines.
- Connecting to hooks in the test runner to output the coverage details after the tests have completed.
Install
Download the appropriate version of blanket.js for your test runner:
QUnit: blanket.js for QUnit
Mocha: npm install blanket
Or build it yourself.
Reference the script in your test runner.
QUnit: <script src="blanket.js"></script>
Mocha: require("blanket")(<pattern-for-source-files>);
The argument passed is a string (or regex) that refers to the folder where the source scripts are stored.
Note: This require statement must be placed before the require statement of any scripts that you want covered.
Configure
QUnit: Add the data attribute data-cover
to any script file you want covered.
(Ex: <script src="mylibrary.js data-cover></script>
)
Mocha: No additional configuration required.
Use
QUnit: Run the tests (with the 'Enable Coverage' box checked) and you'll see the coverage statistics appended below the test results.
Mocha: Use the built-in reporters to output coverage details, i.e. mocha -R html-cov > coverage.html
Continuous Integration
To integrate Blanket.js with an instance of Travis CI:
npm install travis-cov
- Add to your package.json,
"test": "mocha ./node_modules/.bin/mocha -R travis-cov"
},
"travis-cov-threshold": <number>```
- When you commit your code to Travis the coverage results will be compared against the threshold and will fail if any files fall below the threshold.
Roll your own
git clone git@github.com:Migrii/blanket.git
cd /blanket/lib
node builder.js <runner>
where runner is qunit for browser based, and mocha for node based (for the moment).- Your newly rolled file can be found at
/dist/mocha/blanket.js
or /dist/qunit/blanket.js
Minification is built into the build script but is disabled for the time being.
We plan on adding a variety of different command line options to allow you to create a version of blanket customized for your needs.
Let us know what you'd like to see!
FAQ
See the FAQ in the Blanket Wiki.
Disclaimer
This product is currently in beta release and is NOT stable or production ready. It is subject to changes. We appreciate any feedback or assistance.
Documentation
(Coming soon)
Revision History
Nov-8-12 - 0.9.2
Bug fixes to instrumentation and node require loader.
Nov-4-12 - 0.9.1
Works seamlessly with mocha (in node) and uses built in mocha reporters for coverage.
Oct-29-12 - 0.9.0
Initial release of blanket.js. Works with qunit, but coverage output is not complete.
License
Copyright (c) 2012 Alex-Seville
Licensed under the MIT license.