Skip to content

Commit fd0bb4e

Browse files
authored
Merge pull request #686 from geek/bug
Fix coverage of zero-comment scripts
2 parents 3760545 + 7bd6262 commit fd0bb4e

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/coverage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ internals.instrument = function (filename) {
352352
}
353353
}
354354
return commented;
355-
}).reduce((a, b) => a + b);
355+
}).reduce((a, b) => a + b, 0);
356356
}
357357

358358
return chunks.join('');

test/coverage.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ describe('Coverage', () => {
3636
done();
3737
});
3838

39+
it('computes sloc on script that has no comments', (done) => {
40+
41+
const Test = require('./coverage/nocomment');
42+
Test.method(1);
43+
44+
const cov = Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/nocomment') });
45+
expect(cov.percent).to.equal(100);
46+
done();
47+
});
48+
3949
it('instruments and measures coverage', (done) => {
4050

4151
const Test = require('./coverage/basic');

test/coverage/nocomment.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
const internals = {};
4+
5+
6+
exports.method = function (value) {
7+
8+
return value;
9+
};

0 commit comments

Comments
 (0)