-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from hammerlab/coverage
Generate code coverage data
- Loading branch information
Showing
8 changed files
with
200 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
# Generate code coverage and post it to Coveralls. | ||
set -o errexit | ||
set -x | ||
|
||
# Generate LCOV data for the bundled tests | ||
grunt coverage | ||
|
||
# Convert code coverage data on the bundled test file back to the originals. | ||
./scripts/transform-coverage.js \ | ||
build/tests.map \ | ||
build/bundled.lcov \ | ||
| ./node_modules/.bin/coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* This script applies a source map to LCOV data. If you have coverage data for | ||
* a concatenated file, plus a source map, this will output LCOV data for your | ||
* original source files. | ||
* | ||
* Usage: | ||
* | ||
* transform-coverage.js path/to/soure.map path/to/coverage.lcov > out.lcov | ||
*/ | ||
|
||
// TODO: make this a command line argument | ||
var SOURCE = 'src/'; // only report files under this directory | ||
|
||
var assert = require('assert'), | ||
fs = require('fs'), | ||
lcovParse = require('lcov-parse'), | ||
parseDataUri = require('parse-data-uri'), | ||
sourcemap = require('source-map'); | ||
|
||
var sourcemapFile = process.argv[2]; | ||
var lcovFile = process.argv[3]; | ||
|
||
var sourcemapData = fs.readFileSync(sourcemapFile).toString(); | ||
var sourcemap = new sourcemap.SourceMapConsumer(sourcemapData); | ||
|
||
lcovParse(lcovFile, function(err, data) { | ||
assert(!err); | ||
// TODO: 0 --> the correct file | ||
var lines = data[0].lines.details; | ||
|
||
var fileToCov = {}; // filename -> { line num -> hits } | ||
|
||
lines.forEach(function(line) { | ||
var pos = sourcemap.originalPositionFor({line: line.line, column: 0}); | ||
if (pos == null) { | ||
return; | ||
} | ||
|
||
var filename = pos.source; | ||
|
||
// Test coverage of node_modules is never interesting. | ||
if (!filename || filename.indexOf('node_modules') >= 0) { | ||
return; | ||
} | ||
|
||
// Strip paths down to the source root. | ||
var base = filename.indexOf(SOURCE); | ||
if (base == -1) return; | ||
filename = filename.slice(base); | ||
|
||
if (!fileToCov[filename]) fileToCov[filename] = []; | ||
fileToCov[filename][pos.line] = line.hit; | ||
}); | ||
|
||
// Convert to LCOV format | ||
for (var filename in fileToCov) { | ||
var cov = fileToCov[filename] | ||
console.log('SF:' + filename); | ||
for (var i = 0; i < cov.length; i++) { | ||
if (cov[i] != null) { | ||
console.log('DA:' + i + ',' + cov[i]); | ||
} | ||
} | ||
console.log('end_of_record'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>pileup.js Tests</title> | ||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" /> | ||
</head> | ||
<body> | ||
<div id="mocha"></div> | ||
|
||
<!-- Polyfills for PhantomJS --> | ||
<script src="../node_modules/es5-shim/es5-shim.min.js"></script> | ||
<script src="../node_modules/es5-shim/es5-sham.min.js"></script> | ||
<script src="../node_modules/text-encoding/lib/encoding.js"></script> | ||
|
||
<!-- Mocha --> | ||
<script src="../node_modules/mocha/mocha.js"></script> | ||
<script>mocha.setup('bdd')</script> | ||
|
||
<!--<script src="../build/cov/tests-debug.js"></script>--> | ||
<!--<script src="../build/tests-debug.js"></script>--> | ||
<script src="../build/cov/tests.js"></script> | ||
|
||
<script> | ||
mocha.checkLeaks(); | ||
if (window.mochaPhantomJS) { | ||
mochaPhantomJS.run(); | ||
} else { | ||
mocha.run(); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// See https://github.com/StevenLooman/mocha-lcov-reporter/pull/7 | ||
|
||
/** | ||
* 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'); | ||
} |