diff --git a/src/index.js b/src/index.js index 031d637..1a0dba9 100644 --- a/src/index.js +++ b/src/index.js @@ -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) diff --git a/test/babel-plugin-istanbul.js b/test/babel-plugin-istanbul.js index bb80efd..7e6d37f 100644 --- a/test/babel-plugin-istanbul.js +++ b/test/babel-plugin-istanbul.js @@ -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 () {