Skip to content

Commit 24e5979

Browse files
authoredApr 16, 2018
feat: allow 0-line files to be ignored in coverage output (#808)
1 parent 9cbcc81 commit 24e5979

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed
 

‎index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,10 @@ NYC.prototype.report = function () {
451451

452452
tree = libReport.summarizers.pkg(map)
453453

454-
this.reporter.forEach(function (_reporter) {
455-
tree.visit(reports.create(_reporter), context)
454+
this.reporter.forEach((_reporter) => {
455+
tree.visit(reports.create(_reporter, {
456+
skipEmpty: this.config.skipEmpty
457+
}), context)
456458
})
457459

458460
if (this._showProcessTree) {

‎lib/commands/report.js

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ exports.builder = function (yargs) {
2929
default: false,
3030
type: 'boolean'
3131
})
32+
.option('skip-empty', {
33+
describe: 'don\'t show empty files (no lines of code) in report',
34+
default: false,
35+
type: 'boolean',
36+
global: false
37+
})
3238
.example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage')
3339
}
3440

‎lib/config-util.js

+6
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ Config.buildYargs = function (cwd) {
215215
default: './.nyc_output',
216216
global: false
217217
})
218+
.option('skip-empty', {
219+
describe: 'don\'t show empty files (no lines of code) in report',
220+
default: false,
221+
type: 'boolean',
222+
global: false
223+
})
218224
.pkgConf('nyc', cwd)
219225
.example('$0 npm test', 'instrument your tests with coverage')
220226
.example('$0 --require babel-core/register npm test', 'instrument your tests with coverage and transpile with Babel')

‎test/fixtures/cli/empty.js

Whitespace-only changes.

‎test/nyc-bin.js

+35
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,41 @@ describe('the nyc cli', function () {
937937
})
938938
})
939939
})
940+
941+
describe('skip-empty', () => {
942+
it('does not display 0-line files in coverage output', (done) => {
943+
const args = [
944+
bin,
945+
'--cache', 'false',
946+
'--skip-empty', 'true',
947+
process.execPath, './empty.js'
948+
]
949+
950+
const proc = spawn(process.execPath, args, {
951+
cwd: fixturesCLI,
952+
env: env
953+
})
954+
955+
var stdout = ''
956+
proc.stdout.on('data', function (chunk) {
957+
stdout += chunk
958+
})
959+
960+
proc.stdout.on('error', function (chunk) {
961+
stdout += chunk
962+
})
963+
964+
proc.on('close', function (code) {
965+
code.should.equal(0)
966+
stdoutShouldEqual(stdout, `
967+
----------|----------|----------|----------|----------|-------------------|
968+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
969+
----------|----------|----------|----------|----------|-------------------|
970+
----------|----------|----------|----------|----------|-------------------|`)
971+
done()
972+
})
973+
})
974+
})
940975
})
941976

942977
function stdoutShouldEqual (stdout, expected) {

0 commit comments

Comments
 (0)
Please sign in to comment.