Skip to content

Commit

Permalink
feat: allow usage of ignoreClassMethods from istanbul (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
katerberg authored and bcoe committed Mar 13, 2018
1 parent 2d51562 commit c6b30ba
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ Any configuration options that can be set via the command line can also be speci
"exclude": [
"src/**/*.spec.js"
],
"ignore-class-method": "methodToIgnore",
"reporter": [
"lcov",
"text-summary"
Expand Down Expand Up @@ -344,6 +345,19 @@ hints:
* `/* istanbul ignore file */`: ignore an entire source-file (this should be
placed at the top of the file).

## Ignoring Methods

There may be some methods that you want to universally ignore out of your classes
rather than having to ignore every instance of that method:

```json
{
"nyc": {
"ignore-class-method": "render"
}
}
```

## Integrating with coveralls

[coveralls.io](https://coveralls.io) is a great tool for adding
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ NYC.prototype.instrumenter = function () {

NYC.prototype._createInstrumenter = function () {
return this._instrumenterLib(this.cwd, {
ignoreClassMethods: [].concat(this.config.ignoreClassMethod).filter(a => a),
produceSourceMap: this.config.produceSourceMap,
compact: this.config.compact,
preserveComments: this.config.preserveComments
Expand Down
1 change: 1 addition & 0 deletions lib/instrumenters/istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function InstrumenterIstanbul (cwd, options) {
compact: options.compact,
preserveComments: options.preserveComments,
produceSourceMap: options.produceSourceMap,
ignoreClassMethods: options.ignoreClassMethods,
esModules: true
})

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"glob": "^7.0.6",
"istanbul-lib-coverage": "^1.1.2",
"istanbul-lib-hook": "^1.1.0",
"istanbul-lib-instrument": "^1.9.2",
"istanbul-lib-instrument": "^1.10.0",
"istanbul-lib-report": "^1.1.3",
"istanbul-lib-source-maps": "^1.2.3",
"istanbul-reports": "^1.1.4",
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/cli/classes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

class Funclass {
hit() {
const miss = () => {
console.log('This is intentionally uncovered');
}
}

skip() {
console.log('this will be skipped');
}
}

new Funclass().hit();
24 changes: 23 additions & 1 deletion test/nyc-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ describe('the nyc cli', function () {
})
})

describe('--ignore-class-method', function () {
it('skips methods that match ignored name but still catches those that are not', function (done) {
var args = [bin, '--all', '--ignore-class-method', 'skip', process.execPath, './classes.js']

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

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

proc.on('close', function (code) {
code.should.equal(0)
var classesOutput = (stdout.match(/^(.*classes\.js).*$/m) || ['no result found'])[0]
classesOutput.should.match(/6 \|/)
done()
})
})
})

describe('--check-coverage', function () {
it('fails when the expected coverage is below a threshold', function (done) {
var args = [bin, '--check-coverage', '--lines', '51', process.execPath, './half-covered.js']
Expand Down Expand Up @@ -379,7 +402,6 @@ describe('the nyc cli', function () {
})

describe('coverage', function () {
if (parseInt(process.versions.node.split('.')[0]) < 4) return
it('reports appropriate coverage information for es6 source files', function (done) {
var args = [bin, '--reporter=lcov', '--reporter=text', process.execPath, './es6.js']

Expand Down

0 comments on commit c6b30ba

Please sign in to comment.