Skip to content

Ignore coverage for inlined code #154

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

Merged
merged 2 commits into from
Jan 9, 2020
Merged

Ignore coverage for inlined code #154

merged 2 commits into from
Jan 9, 2020

Conversation

jackyef
Copy link
Contributor

@jackyef jackyef commented Jan 8, 2020

In Chrome-generated coverage.json, scripts inlined to HTML doc will have the url of the HTML document.

Example: { url: "https://google.com/", ranges: [...] }

When this happens, we ended up with an empty array inside coveragePaths.

const coveragePaths = coverages.map(({ url }) => getPathParts(new URL(url).pathname || '').reverse())

This will cause the for-loop below to never be run; causing false positive because matchingBundles.length will equal to 1.

coveragePaths.forEach((partsA, coverageIndex) => {
      let matchingBundles = [...bundlesPaths];

      // Start from filename and go up to path root
      for (let i = 0; i < partsA.length; i++) {
        matchingBundles = matchingBundles.filter(
          ([partsB]) => i < partsB.length && partsB[i] === partsA[i]
        );

        // Stop when exact (among bundles) match found or no matches found
        if (matchingBundles.length <= 1) {
          break;
        }
      }

      if (matchingBundles.length === 1) {
        const [[, bundleIndex]] = matchingBundles;

        bundles[bundleIndex].coverageRanges = convertRangesToLinesRanges(coverages[coverageIndex]);
      }
    });

@coveralls
Copy link

coveralls commented Jan 8, 2020

Coverage Status

Coverage increased (+0.2%) to 96.552% when pulling 3bf6233 on jackyef:master into 3d3a007 on danvk:master.

- Add test for case when covergae is for inlined code
@nikolay-borzov nikolay-borzov changed the title fix: handle cases where coveragePaths is an empty array Ignore coverage for inlined code Jan 8, 2020
@nikolay-borzov nikolay-borzov added this to the 2.2.2 milestone Jan 8, 2020
@nikolay-borzov nikolay-borzov self-requested a review January 8, 2020 17:32
@nikolay-borzov nikolay-borzov self-assigned this Jan 8, 2020
@nikolay-borzov nikolay-borzov merged commit d3746c2 into danvk:master Jan 9, 2020
@nikolay-borzov
Copy link
Collaborator

Thanks for your contribution!

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

Successfully merging this pull request may close these issues.

3 participants