Skip to content

Commit

Permalink
feat: read coverage header when using "noop" instrumenter (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
motiz88 authored and bcoe committed Oct 30, 2016
1 parent 92dedda commit 63a8758
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion index.js
Expand Up @@ -84,6 +84,8 @@ function NYC (config) {

this.processInfo = new ProcessInfo(config && config._processInfo)
this.rootId = this.processInfo.root || this.generateUniqueID()
this.instrument = config.instrument
this.all = config.all
}

NYC.prototype._createTransform = function (ext) {
Expand Down Expand Up @@ -166,6 +168,9 @@ NYC.prototype.addAllFiles = function () {
_this.addFile(filename)
var coverage = coverageFinder()
var lastCoverage = _this.instrumenter().lastFileCoverage()
if (lastCoverage) {
filename = lastCoverage.path
}
if (lastCoverage && _this.exclude.shouldInstrument(filename)) {
coverage[filename] = lastCoverage
}
Expand Down Expand Up @@ -233,7 +238,7 @@ NYC.prototype.walkAllFiles = function (dir, visitor) {
}

NYC.prototype._maybeInstrumentSource = function (code, filename, relFile) {
var instrument = this.exclude.shouldInstrument(filename, relFile)
var instrument = (!this.instrument && this.all) || this.exclude.shouldInstrument(filename, relFile)
if (!instrument) {
return null
}
Expand Down
11 changes: 10 additions & 1 deletion lib/instrumenters/noop.js
@@ -1,10 +1,19 @@
var FileCoverage = require('istanbul-lib-coverage').classes.FileCoverage
var readInitialCoverage = require('istanbul-lib-instrument').readInitialCoverage

function NOOP () {
return {
instrumentSync: function (code) {
var extracted = readInitialCoverage(code)
if (extracted) {
this.fileCoverage = new FileCoverage(extracted.coverageData)
} else {
this.fileCoverage = null
}
return code
},
lastFileCoverage: function () {
return null
return this.fileCoverage
}
}
}
Expand Down

0 comments on commit 63a8758

Please sign in to comment.