From 4f974701ff45f785f761af3f9c2b13242f980ce4 Mon Sep 17 00:00:00 2001 From: Codebuff Contributor Date: Wed, 20 May 2026 08:28:13 +0600 Subject: [PATCH 1/2] test_runner: print coverage report with dot reporter --- lib/internal/test_runner/reporter/dot.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/internal/test_runner/reporter/dot.js b/lib/internal/test_runner/reporter/dot.js index 45ff047bc4e5a0..15645695f1597b 100644 --- a/lib/internal/test_runner/reporter/dot.js +++ b/lib/internal/test_runner/reporter/dot.js @@ -4,6 +4,7 @@ const { MathMax, } = primordials; const colors = require('internal/util/colors'); +const { getCoverageReport } = require('internal/test_runner/utils'); const { formatTestReport } = require('internal/test_runner/reporter/utils'); module.exports = async function* dot(source) { @@ -18,6 +19,9 @@ module.exports = async function* dot(source) { yield `${colors.red}X${colors.reset}`; ArrayPrototypePush(failedTests, data); } + if (type === 'test:coverage') { + yield getCoverageReport('', data.summary, '', '', true); + } if ((type === 'test:fail' || type === 'test:pass') && ++count === columns) { yield '\n'; From e38e30151649c0455aebcbbd0903e7ac091296bb Mon Sep 17 00:00:00 2001 From: Codebuff Contributor Date: Wed, 20 May 2026 08:50:03 +0600 Subject: [PATCH 2/2] test_runner: fix branch count when ignore comment present --- lib/internal/test_runner/coverage.js | 6 ++--- .../test-runner-coverage-thresholds.js | 6 ++--- test/parallel/test-runner-coverage.js | 26 +++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index 8fa9c872568d1e..48ee23085ac683 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -196,11 +196,11 @@ class TestCoverage { ArrayPrototypePush(branchReports, { __proto__: null, line: range.lines[0]?.line, - count: range.count, + count: range.count !== 0 ? range.count : + range.ignoredLines > 0 ? 1 : 0, }); - if (range.count !== 0 || - range.ignoredLines === range.lines.length) { + if (range.count !== 0 || range.ignoredLines > 0) { branchesCovered++; } diff --git a/test/parallel/test-runner-coverage-thresholds.js b/test/parallel/test-runner-coverage-thresholds.js index e45e1191299ca7..7bb6029fa96b97 100644 --- a/test/parallel/test-runner-coverage-thresholds.js +++ b/test/parallel/test-runner-coverage-thresholds.js @@ -29,12 +29,12 @@ function getTapCoverageFixtureReport() { '# test | | | | ', '# fixtures | | | | ', '# test-runner | | | | ', - '# coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', + '# coverage.js | 78.65 | 46.15 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', '# invalid-tap.js | 100.00 | 100.00 | 100.00 | ', '# v8-coverage | | | | ', '# throw.js | 71.43 | 50.00 | 100.00 | 5-6', '# --------------------------------------------------------------------------------------------', - '# all files | 78.35 | 43.75 | 60.00 | ', + '# all files | 78.35 | 50.00 | 60.00 | ', '# --------------------------------------------------------------------------------------------', '# end of coverage report', ].join('\n'); @@ -53,7 +53,7 @@ const reporter = fixtures.fileURL('test-runner/custom_reporters/coverage.mjs'); const coverages = [ { flag: '--test-coverage-lines', name: 'line', actual: 78.35 }, { flag: '--test-coverage-functions', name: 'function', actual: 60.00 }, - { flag: '--test-coverage-branches', name: 'branch', actual: 43.75 }, + { flag: '--test-coverage-branches', name: 'branch', actual: 50.00 }, ]; for (const coverage of coverages) { diff --git a/test/parallel/test-runner-coverage.js b/test/parallel/test-runner-coverage.js index 5a8f3d743538cb..e8f65bf826d27d 100644 --- a/test/parallel/test-runner-coverage.js +++ b/test/parallel/test-runner-coverage.js @@ -31,12 +31,12 @@ function getTapCoverageFixtureReport() { '# test | | | | ', '# fixtures | | | | ', '# test-runner | | | | ', - '# coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', + '# coverage.js | 78.65 | 46.15 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', '# invalid-tap.js | 100.00 | 100.00 | 100.00 | ', '# v8-coverage | | | | ', '# throw.js | 71.43 | 50.00 | 100.00 | 5-6', '# --------------------------------------------------------------------------------------------', - '# all files | 78.35 | 43.75 | 60.00 | ', + '# all files | 78.35 | 50.00 | 60.00 | ', '# --------------------------------------------------------------------------------------------', '# end of coverage report', ].join('\n'); @@ -59,12 +59,12 @@ function getSpecCoverageFixtureReport() { '\u2139 test | | | | ', '\u2139 fixtures | | | | ', '\u2139 test-runner | | | | ', - '\u2139 coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', + '\u2139 coverage.js | 78.65 | 46.15 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', '\u2139 invalid-tap.js | 100.00 | 100.00 | 100.00 | ', '\u2139 v8-coverage | | | | ', '\u2139 throw.js | 71.43 | 50.00 | 100.00 | 5-6', '\u2139 --------------------------------------------------------------------------------------------', - '\u2139 all files | 78.35 | 43.75 | 60.00 | ', + '\u2139 all files | 78.35 | 50.00 | 60.00 | ', '\u2139 --------------------------------------------------------------------------------------------', '\u2139 end of coverage report', ].join('\n'); @@ -309,7 +309,7 @@ test('coverage reports on lines, functions, and branches', skipIfNoInspector, as await t.test('reports on branch coverage', () => { const uncalledBranch = file.branches.find((b) => b.line === 6); - assert.strictEqual(uncalledBranch.count, 0); + assert.strictEqual(uncalledBranch.count, 1); const calledTwice = file.branches.find((b) => b.line === 35); assert.strictEqual(calledTwice.count, 2); @@ -421,11 +421,11 @@ test('coverage with excluded files', skipIfNoInspector, () => { '# test | | | | ', '# fixtures | | | | ', '# test-runner | | | | ', - '# coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', + '# coverage.js | 78.65 | 46.15 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', '# v8-coverage | | | | ', '# throw.js | 71.43 | 50.00 | 100.00 | 5-6', '# -----------------------------------------------------------------------------------------', - '# all files | 78.13 | 40.00 | 60.00 | ', + '# all files | 78.13 | 46.67 | 60.00 | ', '# -----------------------------------------------------------------------------------------', '# end of coverage report', ].join('\n'); @@ -458,11 +458,11 @@ test('coverage with included files', skipIfNoInspector, () => { '# test | | | | ', '# fixtures | | | | ', '# test-runner | | | | ', - '# coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', + '# coverage.js | 78.65 | 46.15 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', '# v8-coverage | | | | ', '# throw.js | 71.43 | 50.00 | 100.00 | 5-6', '# -----------------------------------------------------------------------------------------', - '# all files | 78.13 | 40.00 | 60.00 | ', + '# all files | 78.13 | 46.67 | 60.00 | ', '# -----------------------------------------------------------------------------------------', '# end of coverage report', ].join('\n'); @@ -494,9 +494,9 @@ test('coverage with included and excluded files', skipIfNoInspector, () => { '# test | | | | ', '# fixtures | | | | ', '# test-runner | | | | ', - '# coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', + '# coverage.js | 78.65 | 46.15 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', '# -----------------------------------------------------------------------------------------', - '# all files | 78.65 | 38.46 | 60.00 | ', + '# all files | 78.65 | 46.15 | 60.00 | ', '# -----------------------------------------------------------------------------------------', '# end of coverage report', ].join('\n'); @@ -518,13 +518,13 @@ test('correctly prints the coverage report of files contained in parent director '# file | line % | branch % | funcs % | uncovered lines', '# --------------------------------------------------------------------------------------------', '# .. | | | | ', - '# coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', + '# coverage.js | 78.65 | 46.15 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', '# invalid-tap.js | 100.00 | 100.00 | 100.00 | ', '# .. | | | | ', '# v8-coverage | | | | ', '# throw.js | 71.43 | 50.00 | 100.00 | 5-6', '# --------------------------------------------------------------------------------------------', - '# all files | 78.35 | 43.75 | 60.00 | ', + '# all files | 78.35 | 50.00 | 60.00 | ', '# --------------------------------------------------------------------------------------------', '# end of coverage report', ].join('\n');