Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: istanbuljs/nyc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: dd372f59831f1ce0b90d7633123bc8331dc59484
Choose a base ref
...
head repository: istanbuljs/nyc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5e40c7cfe8fbf7c1bd0093ebbb19212a14b5bf65
Choose a head ref
  • 7 commits
  • 9 files changed
  • 5 contributors

Commits on Apr 7, 2018

  1. feat: load coverage files individually instead of all at once, addres…

    …sing memory issues (#806)
    RyanV authored and bcoe committed Apr 7, 2018
    Copy the full SHA
    05fea60 View commit details
  2. docs: reference minimatch usage (#774)

    Carlos García authored and bcoe committed Apr 7, 2018
    Copy the full SHA
    1f4f6ae View commit details
  3. Copy the full SHA
    9cbcc81 View commit details

Commits on Apr 16, 2018

  1. Copy the full SHA
    24e5979 View commit details
  2. chore(release): 11.7.0

    Benjamin Coe committed Apr 16, 2018
    Copy the full SHA
    62a4e83 View commit details

Commits on Apr 17, 2018

  1. Copy the full SHA
    5c0adb5 View commit details
  2. chore(release): 11.7.1

    Benjamin Coe committed Apr 17, 2018
    Copy the full SHA
    5e40c7c View commit details
Showing with 101 additions and 11 deletions.
  1. +16 −0 CHANGELOG.md
  2. +9 −0 README.md
  3. +26 −8 index.js
  4. +6 −0 lib/commands/report.js
  5. +6 −0 lib/config-util.js
  6. +1 −1 lib/process.js
  7. +2 −2 package.json
  8. 0 test/fixtures/cli/empty.js
  9. +35 −0 test/nyc-bin.js
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,22 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="11.7.1"></a>
## [11.7.1](https://github.com/istanbuljs/nyc/compare/v11.7.0...v11.7.1) (2018-04-17)



<a name="11.7.0"></a>
# [11.7.0](https://github.com/istanbuljs/nyc/compare/v11.6.0...v11.7.0) (2018-04-16)


### Features

* allow 0-line files to be ignored in coverage output ([#808](https://github.com/istanbuljs/nyc/issues/808)) ([24e5979](https://github.com/istanbuljs/nyc/commit/24e5979))
* load coverage files individually instead of all at once, addressing memory issues ([#806](https://github.com/istanbuljs/nyc/issues/806)) ([05fea60](https://github.com/istanbuljs/nyc/commit/05fea60))



<a name="11.6.0"></a>
# [11.6.0](https://github.com/istanbuljs/nyc/compare/v11.5.0...v11.6.0) (2018-03-13)

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -192,6 +192,13 @@ nyc report --reporter=lcov

You can find examples of the output for various reporters [here](https://istanbul.js.org/docs/advanced/alternative-reporters).

You also have the choice of using a [custom reporter](https://github.com/pedrocarrico/istanbul-reporter-aws-cloudwatch-metrics).
Install custom reporters as a development dependency and you can use the `--reporter` flag to load and view them:

```bash
nyc report --reporter=<custom-reporter-name>
```

## Excluding files

You can tell nyc to exclude specific files and directories by adding
@@ -233,6 +240,8 @@ an `include` key with a list of globs to specify specific files that should be c
}
```

> `nyc` uses micromatch for glob expansions, you can read its documentation [here](https://www.npmjs.com/package/micromatch).
> Note: include defaults to `['**']`
> ### Use the `--all` flag to include files that have not been required in your tests.
34 changes: 26 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -425,7 +425,7 @@ NYC.prototype._getCoverageMapFromAllCoverageFiles = function () {
var _this = this
var map = libCoverage.createCoverageMap({})

this.loadReports().forEach(function (report) {
this.eachReport(function (report) {
map.merge(report)
})
// depending on whether source-code is pre-instrumented
@@ -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) {
@@ -514,26 +516,42 @@ NYC.prototype._loadProcessInfos = function () {
})
}

NYC.prototype.loadReports = function (filenames) {
NYC.prototype.eachReport = function (filenames, iterator) {
if (typeof filenames === 'function') {
iterator = filenames
filenames = undefined
}

var _this = this
var files = filenames || fs.readdirSync(this.tempDirectory())

return files.map(function (f) {
files.forEach(function (f) {
var report
try {
report = JSON.parse(fs.readFileSync(
path.resolve(_this.tempDirectory(), f),
'utf-8'
))

_this.sourceMaps.reloadCachedSourceMaps(report)
} catch (e) { // handle corrupt JSON output.
return {}
report = {}
}

_this.sourceMaps.reloadCachedSourceMaps(report)
return report
iterator(report)
})
}

NYC.prototype.loadReports = function (filenames) {
var reports = []

this.eachReport(filenames, function (report) {
reports.push(report)
})

return reports
}

NYC.prototype.tempDirectory = function () {
return path.resolve(this.cwd, this._tempDirectory)
}
6 changes: 6 additions & 0 deletions lib/commands/report.js
Original file line number Diff line number Diff line change
@@ -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')
}

6 changes: 6 additions & 0 deletions lib/config-util.js
Original file line number Diff line number Diff line change
@@ -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')
2 changes: 1 addition & 1 deletion lib/process.js
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ ProcessInfo.prototype.render = function (nyc) {
this.getCoverageMap(function (filenames, maps) {
var map = libCoverage.createCoverageMap({})

nyc.loadReports(filenames).forEach(function (report) {
nyc.eachReport(filenames, function (report) {
map.merge(report)
})

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nyc",
"version": "11.6.0",
"version": "11.7.1",
"description": "the Istanbul command line interface",
"main": "index.js",
"scripts": {
@@ -88,7 +88,7 @@
"istanbul-lib-instrument": "^1.10.0",
"istanbul-lib-report": "^1.1.3",
"istanbul-lib-source-maps": "^1.2.3",
"istanbul-reports": "^1.1.4",
"istanbul-reports": "^1.4.0",
"md5-hex": "^1.2.0",
"merge-source-map": "^1.0.2",
"micromatch": "^2.3.11",
Empty file added test/fixtures/cli/empty.js
Empty file.
35 changes: 35 additions & 0 deletions test/nyc-bin.js
Original file line number Diff line number Diff line change
@@ -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) {