[Pkg-javascript-commits] [node-mocha-lcov-reporter] 01/02: Imported Upstream version 0.0.2
Julien Puydt
julien.puydt at laposte.net
Fri Jun 26 06:02:56 UTC 2015
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to branch master
in repository node-mocha-lcov-reporter.
commit cd5618755a70fbf1e2fc7640d432ffa48eb5a961
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Fri Jun 26 07:52:37 2015 +0200
Imported Upstream version 0.0.2
---
.gitignore | 15 +++++++++
.npmignore | 0
LICENSE | 25 +++++++++++++++
README.md | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
index.js | 6 ++++
lib/index.js | 1 +
lib/lcov.js | 43 +++++++++++++++++++++++++
package.json | 29 +++++++++++++++++
8 files changed, 221 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f12e0d2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,15 @@
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+node_modules
+npm-debug.log
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..e69de29
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..2ca911c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,25 @@
+Copyright 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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..2da0b68
--- /dev/null
+++ b/README.md
@@ -0,0 +1,102 @@
+mocha-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.
+
+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.
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..3e686a0
--- /dev/null
+++ b/index.js
@@ -0,0 +1,6 @@
+/**
+ * Export lib/
+ *
+ */
+
+module.exports = require('./lib');
diff --git a/lib/index.js b/lib/index.js
new file mode 100644
index 0000000..0ce7ec9
--- /dev/null
+++ b/lib/index.js
@@ -0,0 +1 @@
+module.exports = require('./lcov');
diff --git a/lib/lcov.js b/lib/lcov.js
new file mode 100644
index 0000000..34970cd
--- /dev/null
+++ b/lib/lcov.js
@@ -0,0 +1,43 @@
+
+/**
+ * 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) {
+ runner.on('end', function(){
+ // In a browser context, coverage will be in window.$jscoverage.
+ var g = typeof(global) != 'undefined' ? global : window;
+ var cov = g._$jscoverage || {};
+
+ for (var filename in cov) {
+ var data = cov[filename];
+ reportFile(filename, data);
+ }
+ });
+}
+
+function reportFile(filename, data) {
+ process.stdout.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) {
+ process.stdout.write('DA:' + num + ',' + data[num] + '\n');
+ }
+ });
+
+ process.stdout.write('end_of_record\n');
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..a3af6e2
--- /dev/null
+++ b/package.json
@@ -0,0 +1,29 @@
+{
+ "name": "mocha-lcov-reporter",
+ "description": "LCOV reporter for Mocha",
+ "version": "0.0.2",
+ "author": "Steven Looman <steven.looman at gmail.com>",
+ "keywords": [ "mocha", "reporter", "lcov", "coverage" ],
+ "licenses" : [
+ {
+ "type": "2-clause BSD",
+ "url": "https://raw.github.com/StevenLooman/mocha-lcov-reporter/master/LICENSE"
+ }
+ ],
+
+ "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"
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mocha-lcov-reporter.git
More information about the Pkg-javascript-commits
mailing list