From 5dc832822c7c6506deb14d251f930317eded2c0a Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Sat, 28 Sep 2024 22:58:37 -0300 Subject: [PATCH] test_runner: ignore unmappes lines for coverage --- lib/internal/test_runner/coverage.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index 1b5ba7912dcb7d..2315ba2d532fa2 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -3,6 +3,7 @@ const { ArrayFrom, ArrayPrototypeMap, ArrayPrototypePush, + ArrayPrototypeForEach, JSONParse, MathFloor, MathMax, @@ -365,6 +366,12 @@ class TestCoverage { } } const sourceMap = new SourceMap(data, { __proto__: null, lineLengths }); + const linesToCover = new Set(); + + for(let mapping of sourceMap[kMappings]) { + const { 3: originalLine } = mapping + linesToCover.add(originalLine + 1); + } for (let j = 0; j < functions.length; ++j) { const { ranges, functionName, isBlockCoverage } = functions[j]; @@ -413,6 +420,13 @@ class TestCoverage { // No mappable ranges. Skip the function. continue; } + + ArrayPrototypeForEach(this.getLines(newUrl), (mappedLine) => { + if (!linesToCover.has(mappedLine.line)) { + mappedLine.ignore = true; + } + }); + const newScript = newResult.get(newUrl) ?? { __proto__: null, url: newUrl, functions: [] }; ArrayPrototypePush(newScript.functions, { __proto__: null, functionName, ranges: newRanges, isBlockCoverage }); newResult.set(newUrl, newScript);