Skip to content

Commit

Permalink
fix: don't prepend the webpack context to absolute source roots
Browse files Browse the repository at this point in the history
Fixes #33
  • Loading branch information
Matt Lewis committed Dec 26, 2017
1 parent facac56 commit 138e8f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ function fixWebpackSourcePaths(sourceMap, webpackConfig) {
let sourceRoot = sourceMap.sourceRoot;
// Fix for https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/32
// The sourceRoot is relative to the project directory and not an absolute path, so add the webpack context to it if set
if (webpackConfig && webpackConfig.context && sourceMap.sourceRoot && !sourceMap.sourceRoot.startsWith(webpackConfig.context)) {
if (
webpackConfig &&
webpackConfig.context &&
sourceMap.sourceRoot &&
!sourceMap.sourceRoot.startsWith(webpackConfig.context) &&
!path.isAbsolute(sourceMap.sourceRoot)
) {
sourceRoot = path.join(webpackConfig.context, sourceRoot);
}

Expand Down
17 changes: 17 additions & 0 deletions test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,22 @@ describe('util', () => {
context: '/Users/mattlewis/Code/open-source/karma-coverage-istanbul-reporter/test/fixtures/typescript'
})).to.deep.equal(output);
});

it('should not the webpack context to the source root if the source root is absolute', () => {
const input = {
file: 'example.ts',
sourceRoot: '/Users/mattlewis/Code/open-source/karma-coverage-istanbul-reporter/test/fixtures/typescript',
sources: ['example.ts']
};

const output = {
file: 'example.ts',
sourceRoot: '/Users/mattlewis/Code/open-source/karma-coverage-istanbul-reporter/test/fixtures/typescript',
sources: ['example.ts']
};
expect(fixWebpackSourcePaths(input, {
context: '/Users/mattlewis/Code/open-source/karma-coverage-istanbul-reporter/test/fixtures/typescript/src'
})).to.deep.equal(output);
});
});
});

0 comments on commit 138e8f8

Please sign in to comment.