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

Include input source map in file coverage #23

Merged

Conversation

MichaReiser
Copy link
Contributor

Add an option to include an input source map. The input source map
is the source map that maps the code before its instumentation back it's
original form. This is needed to support more complex setups, e.g. when
bundlers are involved. If a bundler like webpack, browserify - or you
name it - is used, then there are several, intermediate, source maps
involved. The main issue is, that the instrumented code is bundled
into a single file, and therefore a new source map is created. But the
source map of the bundled file cannot be used to remap the istanbul coverage.
Therefore, these intermediate source maps need to be stored to be available
when creating the report or remaping.

This solution is kind of hacky and should start a discussion how to solve
it best. Anyway, it fixes variouis issues that, up to now, required hacky
solutions.

refs SitePen/remap-istanbul#2

@yahoocla
Copy link

yahoocla commented Sep 5, 2016

Thank you for submitting this pull request, however I do not see a valid CLA on file for you. Before we can merge this request please visit https://yahoocla.herokuapp.com/ and agree to the terms. Thanks! 😄

@yahoocla
Copy link

yahoocla commented Sep 5, 2016

CLA is valid!

MichaReiser pushed a commit to MichaReiser/istanbul-lib-source-maps that referenced this pull request Sep 5, 2016
Part of istanbuljs-archived-repos/istanbul-lib-instrument#23

Alternative could be
to move it to remap-istanbul instead and implement there a custom source
map resolution strategy
MichaReiser pushed a commit to MichaReiser/istanbul-instrumenter-loader that referenced this pull request Sep 6, 2016
Pass the intermediate source map to the instrumenter that can be used
to remap the coverage report to the original source.
Requires istanbuljs-archived-repos/istanbul-lib-instrument#23.

Fixes webpack-contrib#22, webpack-contrib#7, karma-runner/karma-coverage#109,
MichaReiser pushed a commit to MichaReiser/remap-istanbul that referenced this pull request Sep 6, 2016
When locating the source map, use the source map included in the
file coverage whenever possible. Closes SitePen#2 but requires
istanbuljs-archived-repos/istanbul-lib-instrument#23
Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

Add some tests and let's work on landing this 👍

If I'm reading this correctly, this doesn't change any of the existing API, just allows us to attach an additional piece of information to the coverage object?

this.varName = genVar(sourceFilePath);
this.attrs = {};
this.nextIgnore = null;
this.cov = new SourceCoverage(sourceFilePath);
this.cov.inputSourceMap(inputSourceMap);
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps let's only assign this.data.inputSourceMap if inputSourceMap is undefined? that way, for anyone not using the new API feature, the shape of the coverage object stays identical 👍

@MichaReiser
Copy link
Contributor Author

Added a simple unit test that verifies if the inputSourceMap is included

If I'm reading this correctly, this doesn't change any of the existing API, just allows us to attach an additional piece of information to the coverage object?

Thats right. If the option is not provided (and with your suggested change), the coverage object should be exactly equal to the one before.

One question is left. Should inputSourceMap be exposed (no need for .data.inputSourceMap)? Would be more consistent, however, if the coverage object is converted to json that the new property is always included....

MichaReiser pushed a commit to MichaReiser/istanbul-lib-source-maps that referenced this pull request Nov 7, 2016
Part of istanbuljs-archived-repos/istanbul-lib-instrument#23

Alternative could be
to move it to remap-istanbul instead and implement there a custom source
map resolution strategy
Add an option to include an input source map. The input source map
is the source map that maps the code before its instumentation back it's
original form. This is needed to support more complex setups, e.g. when
bundlers are involved. If a bundler like webpack, browserify - or you
name it - is used, then there are several, intermediate, source maps
involved. The main issue is, that the instrumented code is bundled
into a single file, and therefore a new source map is created. But the
source map of the bundled file cannot be used to remap the istanbul coverage.
Therefore, these intermediate source maps need to be stored to be available
when creating the report or remaping.

This solution is kind of hacky and should start a discussion how to solve
it best. Anyway, it fixes variouis issues that, up to now, required hacky
solutions.

refs SitePen/remap-istanbul#2
MichaReiser pushed a commit to MichaReiser/istanbul-lib-source-maps that referenced this pull request Nov 7, 2016
Part of istanbuljs-archived-repos/istanbul-lib-instrument#23

Alternative could be
to move it to remap-istanbul instead and implement there a custom source
map resolution strategy
MichaReiser pushed a commit to MichaReiser/remap-istanbul that referenced this pull request Nov 7, 2016
When locating the source map, use the source map included in the
file coverage whenever possible. Closes SitePen#2 but requires
istanbuljs-archived-repos/istanbul-lib-instrument#23
this.varName = genVar(sourceFilePath);
this.attrs = {};
this.nextIgnore = null;
this.cov = new SourceCoverage(sourceFilePath);

if (typeof (inputSourceMap) !== "undefined") {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, thanks!

@bcoe bcoe merged commit b08e4f5 into istanbuljs-archived-repos:master Nov 10, 2016
deepsweet pushed a commit to webpack-contrib/istanbul-instrumenter-loader that referenced this pull request Nov 27, 2016
* Upgrade to istanbul-lib-instrument

* Pass intermediate source map to instrumenter

Pass the intermediate source map to the instrumenter that can be used
to remap the coverage report to the original source.
Requires istanbuljs-archived-repos/istanbul-lib-instrument#23.

Fixes #22, #7, karma-runner/karma-coverage#109,
@JSONRice
Copy link

Solid work @bcoe @MichaReiser Integrating this now.

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.

None yet

4 participants