MCPcopy Index your code
hub / github.com/nodejs/node / mergeCoverageRanges

Function mergeCoverageRanges

lib/internal/test_runner/coverage.js:717–767  ·  view source on GitHub ↗
(oldFn, newFn)

Source from the content-addressed store, hash-verified

715}
716
717function mergeCoverageRanges(oldFn, newFn) {
718 const mergedRanges = new SafeSet();
719
720 // Keep all of the existing covered ranges.
721 for (let i = 0; i < oldFn.ranges.length; ++i) {
722 const oldRange = oldFn.ranges[i];
723
724 if (oldRange.count > 0) {
725 mergedRanges.add(oldRange);
726 }
727 }
728
729 // Merge in the new ranges where appropriate.
730 for (let i = 0; i < newFn.ranges.length; ++i) {
731 const newRange = newFn.ranges[i];
732 let exactMatch = false;
733
734 for (let j = 0; j < oldFn.ranges.length; ++j) {
735 const oldRange = oldFn.ranges[j];
736
737 if (doesRangeEqualOtherRange(newRange, oldRange)) {
738 // These are the same ranges, so keep the existing one.
739 oldRange.count += newRange.count;
740 mergedRanges.add(oldRange);
741 exactMatch = true;
742 break;
743 }
744
745 // Look at ranges representing missing coverage and add ranges that
746 // represent the intersection.
747 if (oldRange.count === 0 && newRange.count === 0) {
748 if (doesRangeContainOtherRange(oldRange, newRange)) {
749 // The new range is completely within the old range. Discard the
750 // larger (old) range, and keep the smaller (new) range.
751 mergedRanges.add(newRange);
752 } else if (doesRangeContainOtherRange(newRange, oldRange)) {
753 // The old range is completely within the new range. Discard the
754 // larger (new) range, and keep the smaller (old) range.
755 mergedRanges.add(oldRange);
756 }
757 }
758 }
759
760 // Add new ranges that do not represent missing coverage.
761 if (newRange.count > 0 && !exactMatch) {
762 mergedRanges.add(newRange);
763 }
764 }
765
766 oldFn.ranges = ArrayFrom(mergedRanges);
767}
768
769function doesRangeEqualOtherRange(range, otherRange) {
770 return range.startOffset === otherRange.startOffset &&

Callers 1

mergeCoverageScriptsFunction · 0.85

Calls 3

doesRangeEqualOtherRangeFunction · 0.85
addMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…