Skip to content

Commit

Permalink
fix: respect changes of cwd in options (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
jure authored and coreyfarrell committed Oct 16, 2018
1 parent 61d3c44 commit adec723
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions fixtures/should-respect-cwd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let foo = function () {
console.log('foo')
}
foo()
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function getRealpath (n) {
function makeShouldSkip () {
let exclude
return function shouldSkip (file, opts) {
if (!exclude) {
if (!exclude || exclude.cwd !== opts.cwd) {
const cwd = getRealpath(process.env.NYC_CWD || process.cwd())
const nycConfig = process.env.NYC_CONFIG ? JSON.parse(process.env.NYC_CONFIG) : {}

Expand Down Expand Up @@ -44,7 +44,6 @@ function makeShouldSkip () {
config
))
}

return !exclude.shouldInstrument(file)
}
}
Expand Down
22 changes: 22 additions & 0 deletions test/babel-plugin-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,27 @@ describe('babel-plugin-istanbul', function () {
})
result.code.match(/statementMap/)
})

it('should respect a changed cwd in options', function () {
const opts = {
cwd: path.resolve(__dirname, '..', 'lib')
}
const plugins = [
[makeVisitor, opts]
]

var resultBefore = babel.transformFileSync('./fixtures/should-respect-cwd.js', {
plugins
})

resultBefore.code.should.not.match(/statementMap/)

opts.cwd = path.resolve(__dirname, '..', 'fixtures')

var resultAfter = babel.transformFileSync('./fixtures/should-respect-cwd.js', {
plugins
})
resultAfter.code.should.match(/statementMap/)
})
})
})

0 comments on commit adec723

Please sign in to comment.