Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to specify custom coverage variable #167

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.js
Expand Up @@ -60,14 +60,14 @@ function makeVisitor ({types: t}) {
if (shouldSkip(realPath, this.opts)) {
return
}
let { inputSourceMap } = this.opts
let { inputSourceMap, coverageVariable = '__coverage__' } = this.opts
if (this.opts.useInlineSourceMaps !== false) {
if (!inputSourceMap && this.file.inputMap) {
inputSourceMap = this.file.inputMap.sourcemap
}
}
this.__dv__ = programVisitor(t, realPath, {
coverageVariable: '__coverage__',
coverageVariable,
inputSourceMap
})
this.__dv__.enter(path)
Expand Down
24 changes: 24 additions & 0 deletions test/babel-plugin-istanbul.js
Expand Up @@ -45,6 +45,30 @@ describe('babel-plugin-istanbul', function () {
args[0].should.equal(path.resolve('./fixtures/plugin-should-cover.js'))
args[1].statementMap.should.exist // eslint-disable-line
})

it('should set a default coverageVariable', function () {
var result = babel.transformFileSync('./fixtures/has-inline-source-map.js', {
plugins: [
[makeVisitor({types: babel.types}), {
include: ['fixtures/has-inline-source-map.js']
}]
]
})
result.code.should.match(/__coverage__/)
})

it('should set a custom coverageVariable', function () {
var result = babel.transformFileSync('./fixtures/has-inline-source-map.js', {
plugins: [
[makeVisitor({types: babel.types}), {
include: ['fixtures/has-inline-source-map.js'],
coverageVariable: '__fooBar__'
}]
]
})
result.code.should.not.match(/__coverage__/)
result.code.should.match(/__fooBar__/)
})
})

context('source maps', function () {
Expand Down