Skip to content

Commit

Permalink
fix(preprocessor): use absolute paths
Browse files Browse the repository at this point in the history
According to the spec, the absolute file path should be used in the
coverage report. Currently karma-coverage substitutes this with a
path relative to `baseDir`. This causes problems when trying to
combine coverage with other reports not generated by karma-coverage.
Fixing this would help with #1.

coverag.json spec for reference:
 - https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md
  • Loading branch information
jamestalmage committed Jun 24, 2015
1 parent c6c0f74 commit 27e0b09
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions lib/preprocessor.js
Expand Up @@ -76,7 +76,6 @@ function createCoveragePreprocessor (logger, helper, basePath, reporters, covera
return function (content, file, done) {
log.debug('Processing "%s".', file.originalPath)

var jsPath = file.originalPath.replace(basePath + '/', './')
// default instrumenters
var instrumenterLiteral = 'istanbul'

Expand Down Expand Up @@ -106,7 +105,7 @@ function createCoveragePreprocessor (logger, helper, basePath, reporters, covera
options = extend(options, {codeGenerationOptions: codeGenerationOptions})

var instrumenter = new InstrumenterConstructor(options)
instrumenter.instrument(content, jsPath, function (err, instrumentedCode) {
instrumenter.instrument(content, file.originalPath, function (err, instrumentedCode) {
if (err) {
log.error('%s\n at %s', err.message, file.originalPath)
}
Expand All @@ -121,7 +120,7 @@ function createCoveragePreprocessor (logger, helper, basePath, reporters, covera
}

// remember the actual immediate instrumented JS for given original path
sourceCache[jsPath] = content
sourceCache[file.originalPath] = content

if (includeAllSources) {
var coverageObjMatch = coverageObjRegex.exec(instrumentedCode)
Expand Down
6 changes: 3 additions & 3 deletions test/preprocessor.spec.coffee
Expand Up @@ -58,7 +58,7 @@ describe 'preprocessor', ->
something: ->

vm.runInNewContext preprocessedCode, sandbox
expect(sandbox.__coverage__).to.have.ownProperty './file.js'
expect(sandbox.__coverage__).to.have.ownProperty '/base/path/file.js'
done()

it 'should preprocess the fake code', (done) ->
Expand Down Expand Up @@ -118,7 +118,7 @@ describe 'preprocessor', ->

vm.runInNewContext preprocessedCode, sandbox
expect(file.path).to.equal '/base/path/file.coffee'
expect(sandbox.__coverage__).to.have.ownProperty './file.coffee'
expect(sandbox.__coverage__).to.have.ownProperty '/base/path/file.coffee'
done()

it 'should fail if invalid instrumenter provided', (done) ->
Expand All @@ -136,7 +136,7 @@ describe 'preprocessor', ->
coverageMap.reset()

process ORIGINAL_CODE, file, (preprocessedCode) ->
expect(coverageMap.get()['./file.js']).to.exist
expect(coverageMap.get()['/base/path/file.js']).to.exist
done()

it 'should not add coverageMap when not including all sources', (done) ->
Expand Down

0 comments on commit 27e0b09

Please sign in to comment.