danvk / source-map-explorer

Analyze and debug space usage through source maps
Apache License 2.0
3.82k stars 100 forks source link

Ignore coverage for inlined code #154

Closed jackyef closed 4 years ago

jackyef commented 4 years ago

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 commented 4 years ago

Coverage Status

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

nikolay-borzov commented 4 years ago

Thanks for your contribution!