Skip to content

Commit adec723

Browse files
jurecoreyfarrell
authored andcommitted
fix: respect changes of cwd in options (#171)
1 parent 61d3c44 commit adec723

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

fixtures/should-respect-cwd.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let foo = function () {
2+
console.log('foo')
3+
}
4+
foo()

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function getRealpath (n) {
1616
function makeShouldSkip () {
1717
let exclude
1818
return function shouldSkip (file, opts) {
19-
if (!exclude) {
19+
if (!exclude || exclude.cwd !== opts.cwd) {
2020
const cwd = getRealpath(process.env.NYC_CWD || process.cwd())
2121
const nycConfig = process.env.NYC_CONFIG ? JSON.parse(process.env.NYC_CONFIG) : {}
2222

@@ -44,7 +44,6 @@ function makeShouldSkip () {
4444
config
4545
))
4646
}
47-
4847
return !exclude.shouldInstrument(file)
4948
}
5049
}

test/babel-plugin-istanbul.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,27 @@ describe('babel-plugin-istanbul', function () {
148148
})
149149
result.code.match(/statementMap/)
150150
})
151+
152+
it('should respect a changed cwd in options', function () {
153+
const opts = {
154+
cwd: path.resolve(__dirname, '..', 'lib')
155+
}
156+
const plugins = [
157+
[makeVisitor, opts]
158+
]
159+
160+
var resultBefore = babel.transformFileSync('./fixtures/should-respect-cwd.js', {
161+
plugins
162+
})
163+
164+
resultBefore.code.should.not.match(/statementMap/)
165+
166+
opts.cwd = path.resolve(__dirname, '..', 'fixtures')
167+
168+
var resultAfter = babel.transformFileSync('./fixtures/should-respect-cwd.js', {
169+
plugins
170+
})
171+
resultAfter.code.should.match(/statementMap/)
172+
})
151173
})
152174
})

0 commit comments

Comments
 (0)