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

fix(preprocessor): use absolute paths #163

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/preprocessor.js
Original file line number Diff line number Diff line change
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure someone had a reason they thought this was a good idea, but mucking about with istanbuls output breaks it for any downstream consumers that expect the output to conform to the spec (including istanbuls own command line tools). This makes karma-coverage brittle as its manipulating internal implementation details in istanbuls output and breaking encapsulation.

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
Original file line number Diff line number Diff line change
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