Skip to content

Commit

Permalink
Istanbul is finally here! \o/
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit b07ba1e
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Tue Jun 4 10:48:48 2013 -0700

    removing debugging hardwire to lib-cov

commit aa24561
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Mon Jun 3 17:00:29 2013 -0700

    Missing fs module in coverage.js

commit 3333dda
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Mon Jun 3 15:49:35 2013 -0700

    Debugging -- why u no work all of a sudden?!?!

commit 9578824
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Mon Jun 3 14:21:41 2013 -0700

    Removing unnecessary code

commit 722db9c
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Mon Jun 3 13:52:39 2013 -0700

    Finishing touches and code clean-up before final review

    * Reverted hard-wired library dependencies on lib-cov.  Correct behavior
      has been observationally confirmed, so it's time to wrap things up and
      put things back in order.

      As a feature-request, rch requested that we integrate Rewire into
      Whiskey to better support this kind of testing, where we want to use
      the examples with code-coverage.

    * Fixed many missing "global variable" leaks.

    * Fixed style issues, such as " vs ' for strings.

    * Removed unused references to fs module and fs.appendFileSync().

    * I believe I did the right thing to list Istanbul as a proper npm
      dependency for Whiskey.

commit 70c9209
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Mon Jun 3 13:26:51 2013 -0700

    Fixed abnormally low hit-vs-missing bug in coverage reports

commit 281b650
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Fri May 31 15:57:04 2013 -0700

    HTML reporter once again has proper source listing.

commit 9d607c2
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Fri May 31 14:40:40 2013 -0700

    Coverage reports for CLI reporter working again

commit 035f1ae
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Thu May 30 18:09:16 2013 -0700

    typo

commit 9452542
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Thu May 30 18:03:31 2013 -0700

    Work done to convert Istanbul coverage objects into jsCoverage objects.

    The conversion seems to work, at least from a type-safety point of view.
    However, both HTML and CLI reporters indicate 0 lines of code covered.
    Using the json reporter, however, clearly indicates otherwise.

    To run:
    NODE_PATH=$(pwd)/lib-cov bin/whiskey --coverage --coverage-reporter cli --coverage-file /tmp/hooey --coverage-dir /tmp -t example/test-bdd.js

commit c05b7f1
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Thu May 30 14:09:20 2013 -0700

    Code cleanup prepping for todays editing.

commit 5cbfed7
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Wed May 29 15:09:24 2013 -0700

    blah

commit dbbaaf4
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Mon Apr 29 15:41:45 2013 -0700

    Fixed missing istanbul instrumentation command

commit 9ec686a
Author: Samuel A. Falvo II <sam.falvo@rackspace.com>
Date:   Wed Apr 24 16:37:20 2013 -0700

    Attempt to move instrumentation over to Istanbul.
  • Loading branch information
Samuel A. Falvo II committed Jun 4, 2013
1 parent f1e6f87 commit 422d95f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 23 deletions.
43 changes: 39 additions & 4 deletions lib/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,44 @@ var path = require('path');
var fs = require('fs');

/*
* Convert a _$jscoverage object so it's JSON serializable
* Convert an Istanbul __coverage__ object so it's JSON serializable
*/

function jscoverageFromIstanbulCoverage(coverage) {
var jscov = {};

for (var file in coverage) {
filename = path.basename(file);
jscov[filename] = {};

jscov[filename]['source'] = fs.readFileSync(file).toString().split('\n');

for (var line = 0; line < jscov[filename]['source'].length; ++line) {
jscov[filename][line] = 0;
}

for (var sid in coverage[file].s) {
if (coverage[file].s.hasOwnProperty(sid)) {
hitCount = coverage[file].s[sid];
if (typeof(coverage[file].statementMap[sid]) !== 'undefined') {
line = coverage[file].statementMap[sid].start.line;
jscov[filename][line] = hitCount;
} else {
// somehow log an error here. Recommendations welcome.
// Can this error ever happen in the first place?
}
}
}
}
return jscov;
}

function stringifyCoverage(cov) {
var i, files, file, fileObj, source;
var tmp = {}, coverageObj = {};

cov = jscoverageFromIstanbulCoverage(cov);

files = Object.keys(cov);

for (i = 0; i < files.length; i++) {
Expand Down Expand Up @@ -76,7 +108,9 @@ function coverage(data, type) {
throw new Error('Invalid type: ' + type);
}

for (var i = 0, len = data.lines.length; i < len; ++i) {
var len = Object.keys(data.lines).length;

for (var i = 0; i < len; ++i) {
if (data.lines[i] !== null && comparisionFunc(data.lines[i])) {
++n;
}
Expand Down Expand Up @@ -194,6 +228,7 @@ function aggregateCoverage(files) {
}



function installCoverageHandler() {
var pid = process.pid;
var coverageDirectory = process.env['COVERAGE_DIRECTORY'];
Expand All @@ -202,8 +237,8 @@ function installCoverageHandler() {
function writeCoverage() {
var coverage = {};

if (typeof _$jscoverage === 'object') {
coverage[pid] = JSON.parse(stringifyCoverage(_$jscoverage));
if (typeof __coverage__ === 'object') {
coverage[pid] = JSON.parse(stringifyCoverage(__coverage__));

try {
fs.writeFileSync(coveragePath, JSON.stringify(coverage), 'utf8');
Expand Down
26 changes: 11 additions & 15 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,32 +571,28 @@ function run(cwd, argv) {
' must contain lib-cov path for the coverage to work.');
}

coverageArgs = ['jscoverage'];
coverageArgs = ['node_modules/.bin/istanbul instrument --no-compact'];

if (options['coverage-encoding']) {
coverageArgs.push(sprintf('--encoding=%s', options['coverage-encoding']));
}
// Istanbul has no concept of an output format for instrumenting.
// if (options['coverage-encoding']) {
// coverageArgs.push(sprintf('--encoding=%s', options['coverage-encoding']));
// }

if (options['coverage-exclude']) {
coverageArgs.push(sprintf('--exclude=%s', options['coverage-exclude']));
coverageArgs.push(sprintf('-x %s', options['coverage-exclude']));
}

if (options['coverage-no-instrument']) {
coverageArgs.push(sprintf('--no-instrument=%s', options['coverage-no-instrument']));
}
// Istanbul instrument has no concept of a no-instrument flag.
// if (options['coverage-no-instrument']) {
// coverageArgs.push(sprintf('--no-instrument=%s', options['coverage-no-instrument']));
// }

coverageArgs.push(sprintf('lib %s', constants.COVERAGE_PATH));
coverageArgs.push(sprintf('--output %s lib', constants.COVERAGE_PATH));
coverageArgs = coverageArgs.join(' ');

if (!path.existsSync(path.join(process.cwd(), constants.COVERAGE_PATH)) || !options['coverage-no-regen']) {
exec(sprintf('rm -fr %s ; %s', constants.COVERAGE_PATH, coverageArgs), function(err) {
if (err) {
if (err.message.match(/jscoverage: not found/i)) {
err = new Error('jscoverage binary not found. To use test coverage ' +
' you need to install node-jscoverag binary - ' +
'https://github.com/visionmedia/node-jscoverage');
}

throw err;
}

Expand Down
5 changes: 2 additions & 3 deletions lib/run_test_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ var options = { 'cwd': cwd, 'socket_path': socketPath,
'pattern': pattern};
var testFile = new common.TestFile(testPath, options);
testFile.runTests(function onTestFileEnd() {
if (libCovDir && typeof _$jscoverage === 'object') {
testFile._reportTestCoverage(_$jscoverage);
if (libCovDir && typeof __coverage__ === 'object') {
testFile._reportTestCoverage(__coverage__);
}

testFile._reportTestFileEnd();
});

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"gex": "= 0.0.1",
"simplesets": "= 1.1.6",
"logmagic": "= 0.1.4",
"underscore": ">= 1.4.2"
"underscore": ">= 1.4.2",
"istanbul": ">= 0.1.36"
},
"engines": {
"node": ">= 0.4.0"
Expand Down

0 comments on commit 422d95f

Please sign in to comment.