Skip to content

Commit 63a8758

Browse files
motiz88bcoe
authored andcommitted
feat: read coverage header when using "noop" instrumenter (#420)
1 parent 92dedda commit 63a8758

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ function NYC (config) {
8484

8585
this.processInfo = new ProcessInfo(config && config._processInfo)
8686
this.rootId = this.processInfo.root || this.generateUniqueID()
87+
this.instrument = config.instrument
88+
this.all = config.all
8789
}
8890

8991
NYC.prototype._createTransform = function (ext) {
@@ -166,6 +168,9 @@ NYC.prototype.addAllFiles = function () {
166168
_this.addFile(filename)
167169
var coverage = coverageFinder()
168170
var lastCoverage = _this.instrumenter().lastFileCoverage()
171+
if (lastCoverage) {
172+
filename = lastCoverage.path
173+
}
169174
if (lastCoverage && _this.exclude.shouldInstrument(filename)) {
170175
coverage[filename] = lastCoverage
171176
}
@@ -233,7 +238,7 @@ NYC.prototype.walkAllFiles = function (dir, visitor) {
233238
}
234239

235240
NYC.prototype._maybeInstrumentSource = function (code, filename, relFile) {
236-
var instrument = this.exclude.shouldInstrument(filename, relFile)
241+
var instrument = (!this.instrument && this.all) || this.exclude.shouldInstrument(filename, relFile)
237242
if (!instrument) {
238243
return null
239244
}

lib/instrumenters/noop.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
var FileCoverage = require('istanbul-lib-coverage').classes.FileCoverage
2+
var readInitialCoverage = require('istanbul-lib-instrument').readInitialCoverage
3+
14
function NOOP () {
25
return {
36
instrumentSync: function (code) {
7+
var extracted = readInitialCoverage(code)
8+
if (extracted) {
9+
this.fileCoverage = new FileCoverage(extracted.coverageData)
10+
} else {
11+
this.fileCoverage = null
12+
}
413
return code
514
},
615
lastFileCoverage: function () {
7-
return null
16+
return this.fileCoverage
817
}
918
}
1019
}

0 commit comments

Comments
 (0)