pax_global_header00006660000000000000000000000064130530757500014517gustar00rootroot0000000000000052 comment=a6d38a2db85fc40f8a1b534aedee62d34858cbaa mocha-lcov-reporter-1.3.0/000077500000000000000000000000001305307575000154105ustar00rootroot00000000000000mocha-lcov-reporter-1.3.0/.gitignore000066400000000000000000000001411305307575000173740ustar00rootroot00000000000000lib-cov *.seed *.log *.csv *.dat *.out *.pid *.gz pids logs results node_modules npm-debug.log mocha-lcov-reporter-1.3.0/.npmignore000066400000000000000000000000001305307575000173750ustar00rootroot00000000000000mocha-lcov-reporter-1.3.0/CHANGELOG.md000066400000000000000000000007671305307575000172330ustar00rootroot00000000000000## 1.3.0 (Feb 21 2017) Changes: - Make writing to output monkey-patchable. (#16) ## 1.2.0 (Feb 21 2016) Changes: - Report when no coverage data was found. (#12) ## 1.1.0 (Feb 17 2016) Changes: - Add support for Blanket.js. (#13) ## 1.0.0 (Sep 22 2015) Changes: - Releasing 1.0.0 (#11) - Update license attribute in package.json. (#9) ## 0.0.2 (Feb 26 2015) Changes: - Check for window._$jscoverage (Dan Vanderkam) - Add more instructions to README ## 0.0.1 (Jul 03 2012) Initial release mocha-lcov-reporter-1.3.0/LICENSE000066400000000000000000000027221305307575000164200ustar00rootroot00000000000000Copyright 2011 Steven Looman. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY STEVEN LOOMAN ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STEVEN LOOMAN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Steven Looman. mocha-lcov-reporter-1.3.0/README.md000066400000000000000000000072631305307575000166770ustar00rootroot00000000000000mocha-lcov-reporter =================== LCOV reporter for Mocha. LCOV format can be found in this [geninfo manpage](http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php). This LCOV reporter was built after [Sonar Javascript Plugin LCOVParser class](https://github.com/SonarCommunity/sonar-javascript/blob/master/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/lcov/LCOVParser.java). Usage ===== The mocha-lcov-reporter is a reporter for mocha. In order to get coverage data, the same instructions are to be followed as for the `JSONCov` and `HTMLCov` reporters: - Install [jscover](https://github.com/node-modules/jscover) or [node-jscoverage](https://github.com/visionmedia/node-jscoverage) - Instrument your library with `jscover` (or `node-jscoverage`) - Run your tests against your instrumented library and save the output For example, the following script can be part of your build process (add `jscover`, `mocha`, and `mocha-lcov-reporter` as `devDependencies` to your `package.json` file and run `npm install`): ``` #!/usr/bin/env bash rm -rf coverage rm -rf lib-cov mkdir coverage node_modules/.bin/jscover lib lib-cov mv lib lib-orig mv lib-cov lib node_modules/.bin/mocha -R mocha-lcov-reporter > coverage/coverage.lcov rm -rf lib mv lib-orig lib ``` This script instruments your sources (source 'lib', target 'lib-cov'), temporarily replaces your library by the instrumented version, run the tests against the instrumented version of your sources, and undoes the replacing of the original library by the instrumented library. A safer and better approach is to instrument your library (target 'lib-cov'), and include that directory from your tests directly. Instead of doing a 'require("../lib")' do a 'require("../lib-cov")'. This saves the hassle of replacing directory 'lib' with directory 'lib-cov' and undoing it afterwards. You can use an environment variable to check if the instrumented library should be included or the normal version: ``` var lib = process.env.JSCOV ? require('../lib-cov') : require('../lib'); ``` And to get the test-coverage, run mocha as follows: ``` JSCOV=1 mocha -R mocha-lcov-reporter > coverage/coverage.lcov ``` See the [SaXPath project](https://github.com/StevenLooman/saxpath) for an example on how to do this. Incomplete paths in LCOV output =============================== Unfortunately, when the code is instrumented using `jscover` or `node-jscoverage`, the output of the reporter will have incomplete paths for the covered files. A quick fix is to update the paths after running the tests with the mocha-lcov-reporter, like so: ``` # run the tests JS_COV=1 ./node_modules/.bin/mocha -R mocha-lcov-reporter > coverage/coverage_temp.lcov # fix the paths sed 's,SF:,SF:lib/,' coverage/coverage_temp.lcov > coverage/coverage.lcov ``` The reason this is that `jscover` runs on the directory you specify (e.g., `lib/`) and regards that as the root for the project. Blanket support =============== [Blanket.js](http://blanketjs.org/) can be used as well. After the lcov file, be sure to fix the paths for the covered files. The path will be an URL, having `file:` as its protocol. Using the same manner as above, the path can be fixed using `sed`. Example output ============== What does LCOV output look like? LCOV is meant to be interpreted by other programs and not meant to be readable by humans. This is an example: ``` SF:base_unit.js DA:1,1 DA:4,1 DA:5,155 DA:7,155 DA:8,140 DA:9,140 DA:12,155 DA:13,155 DA:16,1 DA:17,1 DA:20,1 DA:21,9 DA:24,1 DA:25,40 DA:28,1 DA:29,26 DA:32,1 DA:33,7 DA:36,1 DA:37,6 DA:40,1 DA:41,45 DA:44,1 DA:45,52 DA:51,1 DA:52,3 DA:55,1 end_of_record ``` If you are looking for something human readable, the `HTMLCov` reporter can be used. mocha-lcov-reporter-1.3.0/index.js000066400000000000000000000000761305307575000170600ustar00rootroot00000000000000/** * Export lib/ * */ module.exports = require('./lib'); mocha-lcov-reporter-1.3.0/lib/000077500000000000000000000000001305307575000161565ustar00rootroot00000000000000mocha-lcov-reporter-1.3.0/lib/index.js000066400000000000000000000000441305307575000176210ustar00rootroot00000000000000module.exports = require('./lcov'); mocha-lcov-reporter-1.3.0/lib/lcov.js000066400000000000000000000027001305307575000174560ustar00rootroot00000000000000 /** * Expose `LCov`. */ exports = module.exports = LCov; /** * Initialize a new LCOV reporter. * File format of LCOV can be found here: http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php * The reporter is built after this parser: https://raw.github.com/SonarCommunity/sonar-javascript/master/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/coverage/LCOVParser.java * * @param {Runner} runner * @api public */ function LCov(runner) { var self = this; runner.on('end', function() { self.onEnd(); }); } LCov.prototype.onEnd = function() { // In a browser context, coverage will be in window.$jscoverage or window._$blanket. var g = typeof(global) != 'undefined' ? global : window; var cov = g._$jscoverage || g._$blanket; if (!cov) { console.error('mocha-lcov-reporter: No coverage data found, make sure your code is properly instrumented'); return; } for (var filename in cov) { var data = cov[filename]; this.reportFile(filename, data); } } LCov.prototype.reportFile = function(filename, data) { var self = this; self.write('SF:' + filename + '\n'); data.source.forEach(function(line, num) { // increase the line number, as JS arrays are zero-based num++; if (data[num] !== undefined) { self.write('DA:' + num + ',' + data[num] + '\n'); } }); self.write('end_of_record\n'); } LCov.prototype.write = function(string) { process.stdout.write(string); } mocha-lcov-reporter-1.3.0/package.json000066400000000000000000000011011305307575000176670ustar00rootroot00000000000000{ "name": "mocha-lcov-reporter", "description": "LCOV reporter for Mocha", "version": "1.3.0", "author": "Steven Looman ", "keywords": [ "mocha", "reporter", "lcov", "coverage" ], "license": "BSD-2-Clause", "dependencies": { }, "devDependencies": { }, "directories": { "lib": "./lib" }, "main": "index.js", "engines": { "node": ">= 0.6.0" }, "scripts": { }, "repository": { "type": "git", "url": "git://github.com/StevenLooman/mocha-lcov-reporter.git" } }