Skip to content

Commit c6b30ba

Browse files
katerbergbcoe
authored andcommittedMar 13, 2018
feat: allow usage of ignoreClassMethods from istanbul (#785)
1 parent 2d51562 commit c6b30ba

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed
 

‎README.md

+14
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ Any configuration options that can be set via the command line can also be speci
272272
"exclude": [
273273
"src/**/*.spec.js"
274274
],
275+
"ignore-class-method": "methodToIgnore",
275276
"reporter": [
276277
"lcov",
277278
"text-summary"
@@ -344,6 +345,19 @@ hints:
344345
* `/* istanbul ignore file */`: ignore an entire source-file (this should be
345346
placed at the top of the file).
346347

348+
## Ignoring Methods
349+
350+
There may be some methods that you want to universally ignore out of your classes
351+
rather than having to ignore every instance of that method:
352+
353+
```json
354+
{
355+
"nyc": {
356+
"ignore-class-method": "render"
357+
}
358+
}
359+
```
360+
347361
## Integrating with coveralls
348362

349363
[coveralls.io](https://coveralls.io) is a great tool for adding

‎index.js

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ NYC.prototype.instrumenter = function () {
136136

137137
NYC.prototype._createInstrumenter = function () {
138138
return this._instrumenterLib(this.cwd, {
139+
ignoreClassMethods: [].concat(this.config.ignoreClassMethod).filter(a => a),
139140
produceSourceMap: this.config.produceSourceMap,
140141
compact: this.config.compact,
141142
preserveComments: this.config.preserveComments

‎lib/instrumenters/istanbul.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function InstrumenterIstanbul (cwd, options) {
1212
compact: options.compact,
1313
preserveComments: options.preserveComments,
1414
produceSourceMap: options.produceSourceMap,
15+
ignoreClassMethods: options.ignoreClassMethods,
1516
esModules: true
1617
})
1718

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"glob": "^7.0.6",
8686
"istanbul-lib-coverage": "^1.1.2",
8787
"istanbul-lib-hook": "^1.1.0",
88-
"istanbul-lib-instrument": "^1.9.2",
88+
"istanbul-lib-instrument": "^1.10.0",
8989
"istanbul-lib-report": "^1.1.3",
9090
"istanbul-lib-source-maps": "^1.2.3",
9191
"istanbul-reports": "^1.1.4",

‎test/fixtures/cli/classes.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
class Funclass {
4+
hit() {
5+
const miss = () => {
6+
console.log('This is intentionally uncovered');
7+
}
8+
}
9+
10+
skip() {
11+
console.log('this will be skipped');
12+
}
13+
}
14+
15+
new Funclass().hit();

‎test/nyc-bin.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,29 @@ describe('the nyc cli', function () {
7171
})
7272
})
7373

74+
describe('--ignore-class-method', function () {
75+
it('skips methods that match ignored name but still catches those that are not', function (done) {
76+
var args = [bin, '--all', '--ignore-class-method', 'skip', process.execPath, './classes.js']
77+
78+
var proc = spawn(process.execPath, args, {
79+
cwd: fixturesCLI,
80+
env: env
81+
})
82+
83+
var stdout = ''
84+
proc.stdout.on('data', function (chunk) {
85+
stdout += chunk
86+
})
87+
88+
proc.on('close', function (code) {
89+
code.should.equal(0)
90+
var classesOutput = (stdout.match(/^(.*classes\.js).*$/m) || ['no result found'])[0]
91+
classesOutput.should.match(/6 \|/)
92+
done()
93+
})
94+
})
95+
})
96+
7497
describe('--check-coverage', function () {
7598
it('fails when the expected coverage is below a threshold', function (done) {
7699
var args = [bin, '--check-coverage', '--lines', '51', process.execPath, './half-covered.js']
@@ -379,7 +402,6 @@ describe('the nyc cli', function () {
379402
})
380403

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

0 commit comments

Comments
 (0)
Please sign in to comment.