From 098182fb635dd443220946698fcc68ec1cf5abbb Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Fri, 28 Aug 2015 22:59:01 +0200 Subject: [PATCH] fix(preprocessor): Resolve all paths properly Closes #65 --- lib/preprocessor.js | 3 ++- test/preprocessor.spec.coffee | 8 ++++---- test/reporter.spec.coffee | 29 +++++++++++++++-------------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/preprocessor.js b/lib/preprocessor.js index aeb4b3d..54f6075 100644 --- a/lib/preprocessor.js +++ b/lib/preprocessor.js @@ -8,6 +8,7 @@ var istanbul = require('istanbul') var minimatch = require('minimatch') +var path = require('path') var SourceMapConsumer = require('source-map').SourceMapConsumer var SourceMapGenerator = require('source-map').SourceMapGenerator var globalSourceCache = require('./source-cache') @@ -76,7 +77,7 @@ function createCoveragePreprocessor (logger, helper, basePath, reporters, covera return function (content, file, done) { log.debug('Processing "%s".', file.originalPath) - var jsPath = require.resolve(file.originalPath) + var jsPath = path.resolve(file.originalPath) // default instrumenters var instrumenterLiteral = 'istanbul' diff --git a/test/preprocessor.spec.coffee b/test/preprocessor.spec.coffee index 076d79c..af21ec0 100644 --- a/test/preprocessor.spec.coffee +++ b/test/preprocessor.spec.coffee @@ -1,8 +1,8 @@ vm = require 'vm' util = require 'util' +path = require 'path' helper = {_: require 'lodash'} - coverageMap = require '../lib/coverage-map' describe 'preprocessor', -> @@ -58,7 +58,7 @@ describe 'preprocessor', -> something: -> vm.runInNewContext preprocessedCode, sandbox - expect(sandbox.__coverage__).to.have.ownProperty '/base/path/file.js' + expect(sandbox.__coverage__).to.have.ownProperty path.resolve('/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 '/base/path/file.coffee' + expect(sandbox.__coverage__).to.have.ownProperty path.resolve('/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()['/base/path/file.js']).to.exist + expect(coverageMap.get()[path.resolve('/base/path/file.js')]).to.exist done() it 'should not add coverageMap when not including all sources', (done) -> diff --git a/test/reporter.spec.coffee b/test/reporter.spec.coffee index ce7d286..bc31945 100644 --- a/test/reporter.spec.coffee +++ b/test/reporter.spec.coffee @@ -13,6 +13,7 @@ describe 'reporter', -> Collection = require '../node_modules/karma/lib/browser_collection' require('../node_modules/karma/lib/logger').setup 'INFO', false, [] + resolve = (v...) -> helper.normalizeWinPath(path.resolve(v...)) nodeMocks = require 'mocks' loadFile = nodeMocks.loadFile m = null @@ -138,8 +139,8 @@ describe 'reporter', -> reporter.onRunComplete browsers expect(mockMkdir).to.have.been.calledTwice dir = rootConfig.coverageReporter.dir - expect(mockMkdir.getCall(0).args[0]).to.deep.equal path.resolve('/base', dir, fakeChrome.name) - expect(mockMkdir.getCall(1).args[0]).to.deep.equal path.resolve('/base', dir, fakeOpera.name) + expect(mockMkdir.getCall(0).args[0]).to.deep.equal resolve('/base', dir, fakeChrome.name) + expect(mockMkdir.getCall(1).args[0]).to.deep.equal resolve('/base', dir, fakeOpera.name) mockMkdir.getCall(0).args[1]() expect(mockReportCreate).to.have.been.called expect(mockWriteReport).to.have.been.called @@ -157,8 +158,8 @@ describe 'reporter', -> expect(mockMkdir).to.have.been.calledTwice dir = customConfig.coverageReporter.dir subdir = customConfig.coverageReporter.subdir - expect(mockMkdir.getCall(0).args[0]).to.deep.equal path.resolve('/base', dir, subdir) - expect(mockMkdir.getCall(1).args[0]).to.deep.equal path.resolve('/base', dir, subdir) + expect(mockMkdir.getCall(0).args[0]).to.deep.equal resolve('/base', dir, subdir) + expect(mockMkdir.getCall(1).args[0]).to.deep.equal resolve('/base', dir, subdir) mockMkdir.getCall(0).args[1]() expect(mockReportCreate).to.have.been.called expect(mockWriteReport).to.have.been.called @@ -175,8 +176,8 @@ describe 'reporter', -> reporter.onRunComplete browsers expect(mockMkdir).to.have.been.calledTwice dir = customConfig.coverageReporter.dir - expect(mockMkdir.getCall(0).args[0]).to.deep.equal path.resolve('/base', dir, 'chrome') - expect(mockMkdir.getCall(1).args[0]).to.deep.equal path.resolve('/base', dir, 'opera') + expect(mockMkdir.getCall(0).args[0]).to.deep.equal resolve('/base', dir, 'chrome') + expect(mockMkdir.getCall(1).args[0]).to.deep.equal resolve('/base', dir, 'opera') mockMkdir.getCall(0).args[1]() expect(mockReportCreate).to.have.been.called expect(mockWriteReport).to.have.been.called @@ -203,10 +204,10 @@ describe 'reporter', -> reporter.onRunComplete browsers expect(mockMkdir.callCount).to.equal 4 - expect(mockMkdir.getCall(0).args[0]).to.deep.equal path.resolve('/base', 'reporter1', 'chrome') - expect(mockMkdir.getCall(1).args[0]).to.deep.equal path.resolve('/base', 'reporter1', 'opera') - expect(mockMkdir.getCall(2).args[0]).to.deep.equal path.resolve('/base', 'reporter2', 'CHROME') - expect(mockMkdir.getCall(3).args[0]).to.deep.equal path.resolve('/base', 'reporter2', 'OPERA') + expect(mockMkdir.getCall(0).args[0]).to.deep.equal resolve('/base', 'reporter1', 'chrome') + expect(mockMkdir.getCall(1).args[0]).to.deep.equal resolve('/base', 'reporter1', 'opera') + expect(mockMkdir.getCall(2).args[0]).to.deep.equal resolve('/base', 'reporter2', 'CHROME') + expect(mockMkdir.getCall(3).args[0]).to.deep.equal resolve('/base', 'reporter2', 'OPERA') mockMkdir.getCall(0).args[1]() expect(mockReportCreate).to.have.been.called expect(mockWriteReport).to.have.been.called @@ -231,10 +232,10 @@ describe 'reporter', -> reporter.onRunComplete browsers expect(mockMkdir.callCount).to.equal 4 - expect(mockMkdir.getCall(0).args[0]).to.deep.equal path.resolve('/base', 'reporter1', 'defaultsubdir') - expect(mockMkdir.getCall(1).args[0]).to.deep.equal path.resolve('/base', 'reporter1', 'defaultsubdir') - expect(mockMkdir.getCall(2).args[0]).to.deep.equal path.resolve('/base', 'defaultdir', 'CHROME') - expect(mockMkdir.getCall(3).args[0]).to.deep.equal path.resolve('/base', 'defaultdir', 'OPERA') + expect(mockMkdir.getCall(0).args[0]).to.deep.equal resolve('/base', 'reporter1', 'defaultsubdir') + expect(mockMkdir.getCall(1).args[0]).to.deep.equal resolve('/base', 'reporter1', 'defaultsubdir') + expect(mockMkdir.getCall(2).args[0]).to.deep.equal resolve('/base', 'defaultdir', 'CHROME') + expect(mockMkdir.getCall(3).args[0]).to.deep.equal resolve('/base', 'defaultdir', 'OPERA') mockMkdir.getCall(0).args[1]() expect(mockReportCreate).to.have.been.called expect(mockWriteReport).to.have.been.called