Skip to content

Commit 40afc5f

Browse files
AGrzesJaKXz
authored andcommittedJan 5, 2019
fix: nyc processing files not covered by include when all is enabled. (#914)
Fixes #913. Fixes #782.
1 parent ba22a26 commit 40afc5f

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed
 

‎index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ NYC.prototype.addAllFiles = function () {
178178
this.fakeRequire = true
179179
this.walkAllFiles(this.cwd, function (filename) {
180180
filename = path.resolve(_this.cwd, filename)
181-
_this.addFile(filename)
182-
var coverage = coverageFinder()
183-
var lastCoverage = _this.instrumenter().lastFileCoverage()
184-
if (lastCoverage) {
185-
filename = lastCoverage.path
186-
}
187-
if (lastCoverage && _this.exclude.shouldInstrument(filename)) {
188-
coverage[filename] = lastCoverage
181+
if (_this.exclude.shouldInstrument(filename)) {
182+
_this.addFile(filename)
183+
var coverage = coverageFinder()
184+
var lastCoverage = _this.instrumenter().lastFileCoverage()
185+
if (lastCoverage) {
186+
filename = lastCoverage.path
187+
coverage[filename] = lastCoverage
188+
}
189189
}
190190
})
191191
this.fakeRequire = false

‎test/fixtures/transpile-hook.js

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ require.extensions['.whatever'] = function (module, filename) {
99
var content = fs.readFileSync(filename, 'utf8');
1010
module._compile(content.replace('--> pork chop sandwiches <--', ''), filename);
1111
}
12+
13+
require.extensions['.do-not-transpile'] = function (module, filename) {
14+
throw new Error(`Should not transpile ${filename}`)
15+
}

‎test/src/nyc-tap.js

+20
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,26 @@ describe('nyc', function () {
440440
return done()
441441
})
442442

443+
it('Do not transpiles files when not included', function (done) {
444+
var notNeedTranspilePath = path.join(fixtures, './do-not-need-transpile.do-not-transpile')
445+
fs.writeFileSync(
446+
notNeedTranspilePath,
447+
'--> pork chop sandwiches <--\nvar a = 99',
448+
'utf-8'
449+
)
450+
451+
var nyc = (new NYC(configUtil.buildYargs(fixtures).parse([
452+
'--require=./test/fixtures/transpile-hook',
453+
'--extension=.do-not-transpile',
454+
'--include=needs-transpile.do-not-transpile'
455+
])))
456+
457+
nyc.reset()
458+
nyc.addAllFiles()
459+
fs.unlinkSync(notNeedTranspilePath)
460+
return done()
461+
})
462+
443463
describe('cache', function () {
444464
it('handles collisions', function (done) {
445465
var nyc = new NYC(configUtil.buildYargs(fixtures).parse())

0 commit comments

Comments
 (0)
Please sign in to comment.