From 27e0b099351dadf4e3b59caec3ad222f5371b650 Mon Sep 17 00:00:00 2001 From: James Talmage Date: Wed, 24 Jun 2015 15:48:08 -0400 Subject: [PATCH] fix(preprocessor): use absolute paths 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 --- lib/preprocessor.js | 5 ++--- test/preprocessor.spec.coffee | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/preprocessor.js b/lib/preprocessor.js index 9c6058c..74f1417 100644 --- a/lib/preprocessor.js +++ b/lib/preprocessor.js @@ -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' @@ -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) } @@ -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) diff --git a/test/preprocessor.spec.coffee b/test/preprocessor.spec.coffee index 161442d..076d79c 100644 --- a/test/preprocessor.spec.coffee +++ b/test/preprocessor.spec.coffee @@ -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) -> @@ -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) -> @@ -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) ->