Skip to content

Commit 509c6aa

Browse files
henriquemotaestevesJaKXz
authored andcommitted
feat: add support to exclude files on coverage report generation (#982)
1 parent 12b8986 commit 509c6aa

File tree

3 files changed

+109
-53
lines changed

3 files changed

+109
-53
lines changed

index.js

+33-16
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ const glob = require('glob')
1111
const Hash = require('./lib/hash')
1212
const libCoverage = require('istanbul-lib-coverage')
1313
const libHook = require('istanbul-lib-hook')
14-
const libReport = require('istanbul-lib-report')
1514
const mkdirp = require('make-dir')
1615
const Module = require('module')
1716
const onExit = require('signal-exit')
1817
const path = require('path')
19-
const reports = require('istanbul-reports')
2018
const resolveFrom = require('resolve-from')
2119
const rimraf = require('rimraf')
2220
const SourceMaps = require('./lib/source-maps')
2321
const testExclude = require('test-exclude')
2422
const uuid = require('uuid/v4')
23+
const api = require('istanbul-api')
2524

2625
const debugLog = util.debuglog('nyc')
2726

@@ -90,6 +89,12 @@ function NYC (config) {
9089
this.rootId = this.processInfo.root || this.generateUniqueID()
9190

9291
this.hashCache = {}
92+
93+
this.config.reporting = config.reporting || {}
94+
this.config.reporting['dir'] = this.reportDirectory()
95+
this.config.reporting['report-config'] = this._reportConfig()
96+
this.config.reporting['summarizer'] = this._reportSummarizer()
97+
this.config.reporting['watermarks'] = this._reportWatermarks()
9398
}
9499

95100
NYC.prototype._createTransform = function (ext) {
@@ -441,21 +446,12 @@ NYC.prototype.getCoverageMapFromAllCoverageFiles = function (baseDirectory) {
441446
}
442447

443448
NYC.prototype.report = function () {
444-
var tree
445-
var map = this.getCoverageMapFromAllCoverageFiles()
446-
var context = libReport.createContext({
447-
dir: this.reportDirectory(),
448-
watermarks: this.config.watermarks
449-
})
449+
const config = api.config.loadObject(this.config)
450+
const reporter = api.createReporter(config)
451+
const map = this.getCoverageMapFromAllCoverageFiles()
450452

451-
tree = libReport.summarizers.pkg(map)
452-
453-
this.reporter.forEach((_reporter) => {
454-
tree.visit(reports.create(_reporter, {
455-
skipEmpty: this.config.skipEmpty,
456-
skipFull: this.config.skipFull
457-
}), context)
458-
})
453+
reporter.addAll(this.reporter)
454+
reporter.write(map)
459455

460456
if (this._showProcessTree) {
461457
this.showProcessTree()
@@ -566,4 +562,25 @@ NYC.prototype.processInfoDirectory = function () {
566562
return path.resolve(this.tempDirectory(), 'processinfo')
567563
}
568564

565+
NYC.prototype._reportConfig = function () {
566+
const config = {}
567+
568+
this.reporter.forEach(_reporter => {
569+
config[_reporter] = {
570+
skipEmpty: this.config.skipEmpty,
571+
skipFull: this.config.skipFull
572+
}
573+
})
574+
575+
return config
576+
}
577+
578+
NYC.prototype._reportSummarizer = function () {
579+
return 'pkg'
580+
}
581+
582+
NYC.prototype._reportWatermarks = function () {
583+
return this.config.watermarks
584+
}
585+
569586
module.exports = NYC

0 commit comments

Comments
 (0)