Skip to content

Commit

Permalink
feat: allow 0-line files to be ignored in coverage output (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Apr 16, 2018
1 parent 9cbcc81 commit 24e5979
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Expand Up @@ -451,8 +451,10 @@ NYC.prototype.report = function () {

tree = libReport.summarizers.pkg(map)

this.reporter.forEach(function (_reporter) {
tree.visit(reports.create(_reporter), context)
this.reporter.forEach((_reporter) => {
tree.visit(reports.create(_reporter, {
skipEmpty: this.config.skipEmpty
}), context)
})

if (this._showProcessTree) {
Expand Down
6 changes: 6 additions & 0 deletions lib/commands/report.js
Expand Up @@ -29,6 +29,12 @@ exports.builder = function (yargs) {
default: false,
type: 'boolean'
})
.option('skip-empty', {
describe: 'don\'t show empty files (no lines of code) in report',
default: false,
type: 'boolean',
global: false
})
.example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage')
}

Expand Down
6 changes: 6 additions & 0 deletions lib/config-util.js
Expand Up @@ -215,6 +215,12 @@ Config.buildYargs = function (cwd) {
default: './.nyc_output',
global: false
})
.option('skip-empty', {
describe: 'don\'t show empty files (no lines of code) in report',
default: false,
type: 'boolean',
global: false
})
.pkgConf('nyc', cwd)
.example('$0 npm test', 'instrument your tests with coverage')
.example('$0 --require babel-core/register npm test', 'instrument your tests with coverage and transpile with Babel')
Expand Down
Empty file added test/fixtures/cli/empty.js
Empty file.
35 changes: 35 additions & 0 deletions test/nyc-bin.js
Expand Up @@ -937,6 +937,41 @@ describe('the nyc cli', function () {
})
})
})

describe('skip-empty', () => {
it('does not display 0-line files in coverage output', (done) => {
const args = [
bin,
'--cache', 'false',
'--skip-empty', 'true',
process.execPath, './empty.js'
]

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env: env
})

var stdout = ''
proc.stdout.on('data', function (chunk) {
stdout += chunk
})

proc.stdout.on('error', function (chunk) {
stdout += chunk
})

proc.on('close', function (code) {
code.should.equal(0)
stdoutShouldEqual(stdout, `
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
----------|----------|----------|----------|----------|-------------------|`)
done()
})
})
})
})

function stdoutShouldEqual (stdout, expected) {
Expand Down

0 comments on commit 24e5979

Please sign in to comment.