A seamless JavaScript code coverage library.
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.
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.
Download the appropriate version of blanket.js for your test runner:
QUnit: blanket.js for QUnit
Mocha: npm install blanket
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.
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.
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
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!
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.
(Coming soon)
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.
Copyright (c) 2012 Alex-Seville
Licensed under the MIT license.