Skip to content

Commit

Permalink
fix: nyc processing files not covered by include when all is enable…
Browse files Browse the repository at this point in the history
…d. (#914)

Fixes #913.
Fixes #782.
  • Loading branch information
AGrzes authored and JaKXz committed Jan 5, 2019
1 parent ba22a26 commit 40afc5f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
16 changes: 8 additions & 8 deletions index.js
Expand Up @@ -178,14 +178,14 @@ NYC.prototype.addAllFiles = function () {
this.fakeRequire = true
this.walkAllFiles(this.cwd, function (filename) {
filename = path.resolve(_this.cwd, filename)
_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
if (_this.exclude.shouldInstrument(filename)) {
_this.addFile(filename)
var coverage = coverageFinder()
var lastCoverage = _this.instrumenter().lastFileCoverage()
if (lastCoverage) {
filename = lastCoverage.path
coverage[filename] = lastCoverage
}
}
})
this.fakeRequire = false
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/transpile-hook.js
Expand Up @@ -9,3 +9,7 @@ require.extensions['.whatever'] = function (module, filename) {
var content = fs.readFileSync(filename, 'utf8');
module._compile(content.replace('--> pork chop sandwiches <--', ''), filename);
}

require.extensions['.do-not-transpile'] = function (module, filename) {
throw new Error(`Should not transpile ${filename}`)
}
20 changes: 20 additions & 0 deletions test/src/nyc-tap.js
Expand Up @@ -440,6 +440,26 @@ describe('nyc', function () {
return done()
})

it('Do not transpiles files when not included', function (done) {
var notNeedTranspilePath = path.join(fixtures, './do-not-need-transpile.do-not-transpile')
fs.writeFileSync(
notNeedTranspilePath,
'--> pork chop sandwiches <--\nvar a = 99',
'utf-8'
)

var nyc = (new NYC(configUtil.buildYargs(fixtures).parse([
'--require=./test/fixtures/transpile-hook',
'--extension=.do-not-transpile',
'--include=needs-transpile.do-not-transpile'
])))

nyc.reset()
nyc.addAllFiles()
fs.unlinkSync(notNeedTranspilePath)
return done()
})

describe('cache', function () {
it('handles collisions', function (done) {
var nyc = new NYC(configUtil.buildYargs(fixtures).parse())
Expand Down

0 comments on commit 40afc5f

Please sign in to comment.