Skip to content

Commit

Permalink
feat: add support to exclude files on coverage report generation (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemotaesteves authored and JaKXz committed Feb 20, 2019
1 parent 12b8986 commit 509c6aa
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 53 deletions.
49 changes: 33 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ const glob = require('glob')
const Hash = require('./lib/hash')
const libCoverage = require('istanbul-lib-coverage')
const libHook = require('istanbul-lib-hook')
const libReport = require('istanbul-lib-report')
const mkdirp = require('make-dir')
const Module = require('module')
const onExit = require('signal-exit')
const path = require('path')
const reports = require('istanbul-reports')
const resolveFrom = require('resolve-from')
const rimraf = require('rimraf')
const SourceMaps = require('./lib/source-maps')
const testExclude = require('test-exclude')
const uuid = require('uuid/v4')
const api = require('istanbul-api')

const debugLog = util.debuglog('nyc')

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

this.hashCache = {}

this.config.reporting = config.reporting || {}
this.config.reporting['dir'] = this.reportDirectory()
this.config.reporting['report-config'] = this._reportConfig()
this.config.reporting['summarizer'] = this._reportSummarizer()
this.config.reporting['watermarks'] = this._reportWatermarks()
}

NYC.prototype._createTransform = function (ext) {
Expand Down Expand Up @@ -441,21 +446,12 @@ NYC.prototype.getCoverageMapFromAllCoverageFiles = function (baseDirectory) {
}

NYC.prototype.report = function () {
var tree
var map = this.getCoverageMapFromAllCoverageFiles()
var context = libReport.createContext({
dir: this.reportDirectory(),
watermarks: this.config.watermarks
})
const config = api.config.loadObject(this.config)
const reporter = api.createReporter(config)
const map = this.getCoverageMapFromAllCoverageFiles()

tree = libReport.summarizers.pkg(map)

this.reporter.forEach((_reporter) => {
tree.visit(reports.create(_reporter, {
skipEmpty: this.config.skipEmpty,
skipFull: this.config.skipFull
}), context)
})
reporter.addAll(this.reporter)
reporter.write(map)

if (this._showProcessTree) {
this.showProcessTree()
Expand Down Expand Up @@ -566,4 +562,25 @@ NYC.prototype.processInfoDirectory = function () {
return path.resolve(this.tempDirectory(), 'processinfo')
}

NYC.prototype._reportConfig = function () {
const config = {}

this.reporter.forEach(_reporter => {
config[_reporter] = {
skipEmpty: this.config.skipEmpty,
skipFull: this.config.skipFull
}
})

return config
}

NYC.prototype._reportSummarizer = function () {
return 'pkg'
}

NYC.prototype._reportWatermarks = function () {
return this.config.watermarks
}

module.exports = NYC
Loading

0 comments on commit 509c6aa

Please sign in to comment.