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

Commit 0141825

Browse files
committed
Make sure uncovered lines appear in the HTML report. fixes #40
1 parent ff89a86 commit 0141825

File tree

7 files changed

+90
-9
lines changed

7 files changed

+90
-9
lines changed

contrib/cover.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ CoverageSession.prototype.allStats = function () {
809809
lines = fstats.lineDetails;
810810
sourceArray = [];
811811
code.forEach(function(codeLine, index){
812-
var count = null, statements = null, numStatements = 0, segs, lineNo, allSame = true, lineStruct;
812+
var count = -1, statements = null, numStatements = 0, segs, lineNo, allSame = true, lineStruct;
813813
line = lines[index];
814814
if (line && line.statementDetails[0]) {
815815
count = line.count;
@@ -832,17 +832,15 @@ CoverageSession.prototype.allStats = function () {
832832
count: count
833833
}];
834834
}
835-
} else if (dataLines.indexOf(index+1) === -1) {
835+
} else {
836836
segs = [{
837837
code: codeLine,
838838
count: 0
839839
}];
840-
} else {
841-
return;
842840
}
843841
lineStruct = {
844842
coverage: count,
845-
statements: statements === null ? null : (statements / numStatements) * 100,
843+
statements: statements === null ? 100 : (statements / numStatements) * 100,
846844
segments: segs
847845
};
848846
sourceArray.push(lineStruct);

contrib/reporters/templates/coverage.jade

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ html
5050
for line, number in file.source
5151
tr(class=coverageCategory(line))
5252
td.line #{number + 1}
53-
td.hits #{line.coverage ? line.coverage : (line.coverage === 0 ? 0 : '')}
54-
td.statements #{line.coverage ? line.statements.toFixed(0) + '%' : ''}
53+
td.hits #{line.coverage > 0 ? line.coverage : (line.coverage === 0 ? 0 : '')}
54+
td.statements #{line.coverage > 0 ? line.statements.toFixed(0) + '%' : ''}
5555
td.source
5656
for segment in line.segments
5757
span(class="statement #{segment.count ? '' : 'notok'}")

gulpfile.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var lintDeps = [],
1919
jasmineDeps = [],
2020
testchainDeps = [],
2121
rewireDeps = [],
22+
classPatternDeps = [],
2223
coverallsDeps = [];
2324

2425
/*
@@ -68,6 +69,24 @@ function mocha () {
6869
.pipe(gulp.dest('./testoutput'));
6970
}
7071

72+
function classPattern () {
73+
return gulp.src(['testsupport/src4.js'], { read: false })
74+
.pipe(cover.instrument({
75+
pattern: ['**/test3.js'],
76+
debugDirectory: 'debug/info'
77+
}))
78+
.pipe(mochaTask({
79+
reporter: 'spec'
80+
}))
81+
.pipe(cover.gather())
82+
.pipe(cover.format({
83+
outFile: 'classPattern.html'
84+
}))
85+
.pipe(gulp.dest('./testoutput'));
86+
}
87+
88+
89+
7190
function coveralls () {
7291
return gulp.src(['testsupport/src.js', 'testsupport/src3.js'], { read: false })
7392
.pipe(cover.instrument({
@@ -183,6 +202,7 @@ function testc2 () {
183202
function setup () {
184203
gulp.task('coveralls', coverallsDeps, coveralls);
185204
gulp.task('rewire', rewireDeps, rewire);
205+
gulp.task('classPattern', classPatternDeps, classPattern);
186206
gulp.task('test', testDeps, test);
187207
gulp.task('lint', lintDeps, lint);
188208
gulp.task('mocha', mochaDeps, mocha);
@@ -197,6 +217,7 @@ function setup () {
197217

198218
gulp.task('default', function() {
199219
// Setup the chain of dependencies
220+
coverallsDeps = ['classPattern'];
200221
rewireDeps = ['coveralls'];
201222
testchainDeps = ['rewire'];
202223
jasmineDeps = ['testchain'];

test/cover.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ describe('cover.js', function () {
185185
'testsupport/src.js',
186186
'testsupport/src2.js',
187187
'testsupport/src3.js',
188+
'testsupport/src4.js',
188189
'testsupport/srcchain.js',
189190
'testsupport/srcjasmine.js',
190-
'testsupport/test.js' ]);
191+
'testsupport/test.js',
192+
'testsupport/test3.js' ]);
191193
});
192194
it('will return the correct number of code lines', function () {
193195
assert.equal(stats.sloc, 9);

test/gulp-coverage.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,28 @@ describe('gulp-coverage', function () {
219219
});
220220
writer.end();
221221
});
222+
it('Does correctly support module pattern', function (done) {
223+
reader = through2.obj(function (data, enc, cb) {
224+
assert.ok(data.coverage);
225+
// this next test makes sure that comments and other lines that do not
226+
// contain statements will get output to the HTML report
227+
assert.equal(data.coverage.files[0].source[18].coverage, -1);
228+
cb();
229+
},
230+
function (cb) {
231+
cb();
232+
done();
233+
});
234+
writer.pipe(cover.instrument({
235+
pattern: ['./testsupport/test*'],
236+
debugDirectory: path.join(process.cwd(), 'debug')
237+
})).pipe(mocha({
238+
})).pipe(cover.gather()).pipe(reader);
239+
writer.write({
240+
path: require.resolve('../testsupport/src4.js')
241+
});
242+
writer.end();
243+
});
222244
});
223245
describe('enforce', function () {
224246
it('should throw if not passed the correct data', function(done) {
@@ -446,7 +468,7 @@ describe('gulp-coverage', function () {
446468
statements: 80,
447469
lines: 83,
448470
blocks: 60,
449-
uncovered: 1
471+
uncovered: 2
450472
})).pipe(reader);
451473
writer.write({
452474
path: require.resolve('../testsupport/src.js')

testsupport/src4.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var assert = require('assert'),
2+
Controller = require('./test3');
3+
4+
describe('Test AlertController', function () {
5+
it('Should work', function () {
6+
var c = new Controller();
7+
assert.equal(c.show(), 1);
8+
assert.equal(c.hide(), 0);
9+
});
10+
});

testsupport/test3.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
3+
var AlertController = function () {
4+
this.count = 0;
5+
};
6+
7+
AlertController.prototype = {
8+
/**
9+
* Comment
10+
*/
11+
show: function () {
12+
this.count++;
13+
return this.count;
14+
},
15+
16+
/**
17+
* comment
18+
*/
19+
hide: function () {
20+
this.count--;
21+
return this.count;
22+
}
23+
};
24+
25+
// to pull into node namespace if included
26+
if (typeof module !== "undefined" && module.exports !== undefined) {
27+
module.exports = AlertController;
28+
}

0 commit comments

Comments
 (0)