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

Fix broken mapped coverage map #6

Merged
merged 3 commits into from
Oct 3, 2016

Conversation

mourner
Copy link
Contributor

@mourner mourner commented Oct 3, 2016

Closes istanbuljs/nyc#400, closes istanbuljs-archived-repos/istanbul-lib-instrument#25.

@bcoe sorry this slipped past me! The bug was only visible when you run coverage on both source-mapped and non-source-mapped files and then it tried to merge the two.

  • update tests

@yahoocla
Copy link

yahoocla commented Oct 3, 2016

CLA is valid!

@@ -51,7 +51,7 @@ describe('mapped coverage', function () {
assert.equal(mc.fnMap[index].name,'(unknown_' + index + ')');

index = mc.addBranch('if', loc(1, 15, 1, 20), [loc(1, 15, 1, 20), loc(1, 21, 1, 40)], [1,0]);
assert.ok(index);
assert.ok(index === 0);
Copy link
Contributor

@JaKXz JaKXz Oct 3, 2016

Choose a reason for hiding this comment

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

nit: why not just use assert.equal here? The assertion message if it fails would be more helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point, replaced with strictEqual.

index = meta.last.s;
meta.last.s += 1;
Copy link

Choose a reason for hiding this comment

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

Let me see if I'm following here:

  1. there was logic in place that handled populating a statement the first time that it was observed; this logic used ! so was triggering on 0, which currently counts as a valid mapping.
  2. as a result, we accidentally fall outside of bounds in istanbul-lib-coverage? could you better explain to me the cause of this?

This fix addresses the issue by looking for undefined rather than 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bcoe no, the main issue was that this code started from 1 when filling out statement, function, and branch stats, rather than 0 we switched to in istanbuljs-archived-repos/istanbul-lib-instrument#22. Then, when trying to merge stats generated by this code (1-based) with ones instrumented by instanbul-lib-instrument (0-based), it throwed because 0 element was undefined on the first.

@bcoe bcoe merged commit d9dd738 into istanbuljs-archived-repos:master Oct 3, 2016
@bcoe
Copy link

bcoe commented Oct 3, 2016

@mourner published in + istanbul-lib-source-maps@1.0.2 mind submitting the corresponding pull to nyc; I think that's the only other place we need to update?

@mourner mourner deleted the fix-source-maps branch October 4, 2016 08:43
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.

Strange bug TypeError: Cannot read property 'length' of undefined
4 participants