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

feat(preprocessor): Add sourcemap support #146

Merged
merged 1 commit into from
Jun 9, 2015

Conversation

nmalaguti
Copy link
Contributor

Pending gotwarlost/istanbul#349, which is needed to fix istanbul sourcemap outputs to have the correct offset.

Adds sourcemap support to the preprocessor. If the file being
processed has a sourcemap property, it is merged with the output
from the coverage instrumentation. This enables better debugging
on instrumented code.

Closes #109

@nmalaguti
Copy link
Contributor Author

To give more context on this change, when you want to debug transpiled code (e.g. TypeScript) that has been preprocessed to add coverage, it is very difficult to debug it in the browser.

As a workaround, one can disable coverage when debugging.

The behavior added by this PR checks to see if the file has a sourceMap property specified (source maps can be loaded by https://github.com/demerzel3/karma-sourcemap-loader). If it is there, source map generation is enabled in Istanbul and afterwards, the lines from the original source map are mapped onto the transformed code.

This allows you to set break points in the browser using source maps and you can then step through the code.

@dignifiedquire
Copy link
Member

I would like to get this in, could you add some documentation and rebase onto the latest master please

@nmalaguti
Copy link
Contributor Author

The PR on istanbul gotwarlost/istanbul#349 hasn't been released yet, so this is still blocked.

@dignifiedquire
Copy link
Member

Ah okay thanks for the info, I thought it was released as the PR seemed to be merged

@dignifiedquire
Copy link
Member

Cleaned up the code base a bit, can you please rebase onto those changes?

@dignifiedquire
Copy link
Member

@nmalaguti new version was just published including the linked fix

instrumenter.instrument(content, jsPath, function(err, instrumentedCode) {

if (err) {
log.error('%s\n at %s', err.message, file.originalPath);
}

if (file.sourceMap) {
var consumer = new SourceMapConsumer(file.sourceMap);
Copy link
Member

Choose a reason for hiding this comment

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

Why is the consumer never used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

Adds sourcemap support to the preprocessor. If the file being
processed has a sourcemap property, it is merged with the output
from the coverage instrumentation. This enables better debugging
on instrumented code.

Closes karma-runner#109
@nmalaguti
Copy link
Contributor Author

Rebased and updated with the latest version of istanbul.

dignifiedquire added a commit that referenced this pull request Jun 9, 2015
feat(preprocessor): Add sourcemap support
@dignifiedquire dignifiedquire merged commit 1607f1a into karma-runner:master Jun 9, 2015
@nmalaguti nmalaguti deleted the feature/source-maps branch June 14, 2015 23:02
@chadxz
Copy link

chadxz commented Nov 4, 2015

did docs ever get added for this feature? I'm trying to use it and having trouble at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sourcemaps support
3 participants