Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows usage of ignoreClassMethods from istanbul #785

Merged
merged 8 commits into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theres a missing closing " on ignore-class-method.

"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: 24 additions & 0 deletions test/nyc-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ describe('the nyc cli', function () {
})
})

describe('--ignore-class-method', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, thank you for the test 👍

if (parseInt(process.versions.node.split('.')[0]) < 4) return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this check should be needed; we dropped Node <4 support in CI a few months ago.

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