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

Bad mappings when applying coverage #75

Closed
j03m opened this issue Nov 17, 2019 · 3 comments
Closed

Bad mappings when applying coverage #75

j03m opened this issue Nov 17, 2019 · 3 comments
Labels

Comments

@j03m
Copy link
Contributor

j03m commented Nov 17, 2019

I noticed this behavior when implementing this PR for c8: bcoe/c8#158

When we supply coverage there is often a default range coverage that covers the whole file. For some files, I seem to get a sort of undefined behavior when remapping columns.

For example for this compiled typescript fixture: https://github.com/bcoe/c8/blob/2a21d8d9e3d89478da866e8f8663e3cbd1fd8321/test/fixtures/all/ts-source-maps/loaded.js

We get an initial coverage block that looks like this:

{
	"functionName": "",
	"ranges": [
		{
			"startOffset": 0,
			"endOffset": 460,
			"count": 1
		}
	],
	"isBlockCoverage": true
}

When the first range 0-460 is fed down through into source-map's SourceMapConsumer for the mappings come back as null. That code lives here: https://github.com/mozilla/source-map/blob/master/lib/source-map-consumer.js#L494

The result here in v8-to-istanbul's code is that an empty object is returned here: https://github.com/istanbuljs/v8-to-istanbul/blob/master/lib/v8-to-istanbul.js#L153 and our destructured variables are all undefined. This causes relativeToOffset to return eof because line is now NaN.

Now, in a normal covered file this seems to mostly not matter because the subsequent coverage ranges will get processed and the coverage report recovers.

However, in our --all case where we fake a single coverage block with the full range, we end up having a situation where lines in the file get filtered out and we can never assign count 0 to them. This causes the fake entries in our report to have 100 line coverage.

On my end the simplest fix was to wrap these lines: https://github.com/istanbuljs/v8-to-istanbul/blob/master/lib/v8-to-istanbul.js#L161 in an if check for undefineds which defaults to the originally supplied values.

I would issue that as a PR but I have to wait until monday to get legal clearance (womp womp).

Anyway - I wanted to give you a heads up.

@bcoe
Copy link
Member

bcoe commented Nov 18, 2019

@j03m since this mostly comes up in the case of --all, I have a hack that I wrote on the weekend for this edge-case:

#74

I ended up getting an approach to --all working similar to yours, but not fully tested with your work yet, that populates the v8 object with the fake function (empty-report).

@bcoe
Copy link
Member

bcoe commented Nov 30, 2019

@j03m do we think this is still an issue?

@bcoe bcoe added the bug label Nov 30, 2019
@j03m
Copy link
Contributor Author

j03m commented Dec 13, 2019

Nope, closing. We're good with your latest changes.

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

No branches or pull requests

2 participants