Skip to content
This repository was archived by the owner on Mar 26, 2021. It is now read-only.

Commit

Permalink
Make sure uncovered lines appear in the HTML report. fixes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanb committed May 30, 2015
1 parent ff89a86 commit 0141825
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 9 deletions.
8 changes: 3 additions & 5 deletions contrib/cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ CoverageSession.prototype.allStats = function () {
lines = fstats.lineDetails;
sourceArray = [];
code.forEach(function(codeLine, index){
var count = null, statements = null, numStatements = 0, segs, lineNo, allSame = true, lineStruct;
var count = -1, statements = null, numStatements = 0, segs, lineNo, allSame = true, lineStruct;
line = lines[index];
if (line && line.statementDetails[0]) {
count = line.count;
Expand All @@ -832,17 +832,15 @@ CoverageSession.prototype.allStats = function () {
count: count
}];
}
} else if (dataLines.indexOf(index+1) === -1) {
} else {
segs = [{
code: codeLine,
count: 0
}];
} else {
return;
}
lineStruct = {
coverage: count,
statements: statements === null ? null : (statements / numStatements) * 100,
statements: statements === null ? 100 : (statements / numStatements) * 100,
segments: segs
};
sourceArray.push(lineStruct);
Expand Down
4 changes: 2 additions & 2 deletions contrib/reporters/templates/coverage.jade
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ html
for line, number in file.source
tr(class=coverageCategory(line))
td.line #{number + 1}
td.hits #{line.coverage ? line.coverage : (line.coverage === 0 ? 0 : '')}
td.statements #{line.coverage ? line.statements.toFixed(0) + '%' : ''}
td.hits #{line.coverage > 0 ? line.coverage : (line.coverage === 0 ? 0 : '')}
td.statements #{line.coverage > 0 ? line.statements.toFixed(0) + '%' : ''}
td.source
for segment in line.segments
span(class="statement #{segment.count ? '' : 'notok'}")
Expand Down
21 changes: 21 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var lintDeps = [],
jasmineDeps = [],
testchainDeps = [],
rewireDeps = [],
classPatternDeps = [],
coverallsDeps = [];

/*
Expand Down Expand Up @@ -68,6 +69,24 @@ function mocha () {
.pipe(gulp.dest('./testoutput'));
}

function classPattern () {
return gulp.src(['testsupport/src4.js'], { read: false })
.pipe(cover.instrument({
pattern: ['**/test3.js'],
debugDirectory: 'debug/info'
}))
.pipe(mochaTask({
reporter: 'spec'
}))
.pipe(cover.gather())
.pipe(cover.format({
outFile: 'classPattern.html'
}))
.pipe(gulp.dest('./testoutput'));
}



function coveralls () {
return gulp.src(['testsupport/src.js', 'testsupport/src3.js'], { read: false })
.pipe(cover.instrument({
Expand Down Expand Up @@ -183,6 +202,7 @@ function testc2 () {
function setup () {
gulp.task('coveralls', coverallsDeps, coveralls);
gulp.task('rewire', rewireDeps, rewire);
gulp.task('classPattern', classPatternDeps, classPattern);
gulp.task('test', testDeps, test);
gulp.task('lint', lintDeps, lint);
gulp.task('mocha', mochaDeps, mocha);
Expand All @@ -197,6 +217,7 @@ function setup () {

gulp.task('default', function() {
// Setup the chain of dependencies
coverallsDeps = ['classPattern'];
rewireDeps = ['coveralls'];
testchainDeps = ['rewire'];
jasmineDeps = ['testchain'];
Expand Down
4 changes: 3 additions & 1 deletion test/cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ describe('cover.js', function () {
'testsupport/src.js',
'testsupport/src2.js',
'testsupport/src3.js',
'testsupport/src4.js',
'testsupport/srcchain.js',
'testsupport/srcjasmine.js',
'testsupport/test.js' ]);
'testsupport/test.js',
'testsupport/test3.js' ]);
});
it('will return the correct number of code lines', function () {
assert.equal(stats.sloc, 9);
Expand Down
24 changes: 23 additions & 1 deletion test/gulp-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ describe('gulp-coverage', function () {
});
writer.end();
});
it('Does correctly support module pattern', function (done) {
reader = through2.obj(function (data, enc, cb) {
assert.ok(data.coverage);
// this next test makes sure that comments and other lines that do not
// contain statements will get output to the HTML report
assert.equal(data.coverage.files[0].source[18].coverage, -1);
cb();
},
function (cb) {
cb();
done();
});
writer.pipe(cover.instrument({
pattern: ['./testsupport/test*'],
debugDirectory: path.join(process.cwd(), 'debug')
})).pipe(mocha({
})).pipe(cover.gather()).pipe(reader);
writer.write({
path: require.resolve('../testsupport/src4.js')
});
writer.end();
});
});
describe('enforce', function () {
it('should throw if not passed the correct data', function(done) {
Expand Down Expand Up @@ -446,7 +468,7 @@ describe('gulp-coverage', function () {
statements: 80,
lines: 83,
blocks: 60,
uncovered: 1
uncovered: 2
})).pipe(reader);
writer.write({
path: require.resolve('../testsupport/src.js')
Expand Down
10 changes: 10 additions & 0 deletions testsupport/src4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var assert = require('assert'),
Controller = require('./test3');

describe('Test AlertController', function () {
it('Should work', function () {
var c = new Controller();
assert.equal(c.show(), 1);
assert.equal(c.hide(), 0);
});
});
28 changes: 28 additions & 0 deletions testsupport/test3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";

var AlertController = function () {
this.count = 0;
};

AlertController.prototype = {
/**
* Comment
*/
show: function () {
this.count++;
return this.count;
},

/**
* comment
*/
hide: function () {
this.count--;
return this.count;
}
};

// to pull into node namespace if included
if (typeof module !== "undefined" && module.exports !== undefined) {
module.exports = AlertController;
}

0 comments on commit 0141825

Please sign in to comment.