From 79c39c217d9cae91c21047c96017eb2cf89f3306 Mon Sep 17 00:00:00 2001 From: mag123c Date: Sun, 18 Jan 2026 14:48:44 +0900 Subject: [PATCH] test_runner: print coverage and diagnostic info with dot reporter When using the dot reporter with coverage enabled, coverage threshold failures and coverage reports were not printed, only an exit code was returned. This made it impossible to know why the test run failed. This change adds handling for test:diagnostic and test:coverage events to the dot reporter, matching the behavior of the spec reporter. Fixes: https://github.com/nodejs/node/issues/60884 Signed-off-by: mag123c PR-URL: https://github.com/nodejs/node/pull/61423 Reviewed-By: Chemi Atlow Reviewed-By: Xuguang Mei Reviewed-By: Aviv Keller --- lib/internal/test_runner/reporter/dot.js | 25 ++++++++++++++++++- .../output/dot_reporter_coverage_threshold.js | 17 +++++++++++++ .../dot_reporter_coverage_threshold.snapshot | 18 +++++++++++++ .../test-runner-coverage-thresholds.js | 21 ++++++++++++++++ ...output-dot-reporter-coverage-threshold.mjs | 15 +++++++++++ 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/test-runner/output/dot_reporter_coverage_threshold.js create mode 100644 test/fixtures/test-runner/output/dot_reporter_coverage_threshold.snapshot create mode 100644 test/test-runner/test-output-dot-reporter-coverage-threshold.mjs diff --git a/lib/internal/test_runner/reporter/dot.js b/lib/internal/test_runner/reporter/dot.js index 45ff047bc4e..1d73523f3c3 100644 --- a/lib/internal/test_runner/reporter/dot.js +++ b/lib/internal/test_runner/reporter/dot.js @@ -4,12 +4,19 @@ const { MathMax, } = primordials; const colors = require('internal/util/colors'); -const { formatTestReport } = require('internal/test_runner/reporter/utils'); +const { getCoverageReport } = require('internal/test_runner/utils'); +const { + formatTestReport, + reporterColorMap, + reporterUnicodeSymbolMap, +} = require('internal/test_runner/reporter/utils'); module.exports = async function* dot(source) { let count = 0; let columns = getLineLength(); const failedTests = []; + const diagnostics = []; + let coverage; for await (const { type, data } of source) { if (type === 'test:pass') { yield `${colors.green}.${colors.reset}`; @@ -25,8 +32,24 @@ module.exports = async function* dot(source) { columns = getLineLength(); count = 0; } + if (type === 'test:diagnostic' && data.level === 'error') { + ArrayPrototypePush(diagnostics, data); + } + if (type === 'test:coverage') { + coverage = data; + } } yield '\n'; + if (diagnostics.length > 0) { + for (const diagnostic of diagnostics) { + const color = reporterColorMap[diagnostic.level] || reporterColorMap['test:diagnostic']; + yield `${color}${reporterUnicodeSymbolMap['test:diagnostic']}${diagnostic.message}${colors.white}\n`; + } + if (coverage) { + yield getCoverageReport('', coverage.summary, + reporterUnicodeSymbolMap['test:coverage'], colors.blue, true); + } + } if (failedTests.length > 0) { yield `\n${colors.red}Failed tests:${colors.white}\n\n`; for (const test of failedTests) { diff --git a/test/fixtures/test-runner/output/dot_reporter_coverage_threshold.js b/test/fixtures/test-runner/output/dot_reporter_coverage_threshold.js new file mode 100644 index 00000000000..b49dd148815 --- /dev/null +++ b/test/fixtures/test-runner/output/dot_reporter_coverage_threshold.js @@ -0,0 +1,17 @@ +'use strict'; +require('../../../common'); +const fixtures = require('../../../common/fixtures'); +const spawn = require('node:child_process').spawn; + +spawn( + process.execPath, + [ + '--no-warnings', + '--experimental-test-coverage', + '--test-coverage-exclude=!test/**', + '--test-coverage-lines=99', + '--test-reporter', 'dot', + fixtures.path('test-runner/coverage.js'), + ], + { stdio: 'inherit' }, +); diff --git a/test/fixtures/test-runner/output/dot_reporter_coverage_threshold.snapshot b/test/fixtures/test-runner/output/dot_reporter_coverage_threshold.snapshot new file mode 100644 index 00000000000..0645329f1a8 --- /dev/null +++ b/test/fixtures/test-runner/output/dot_reporter_coverage_threshold.snapshot @@ -0,0 +1,18 @@ +invalid tap output +. +ℹ Error: 78.35% line coverage does not meet threshold of 99%. +ℹ start of coverage report +ℹ -------------------------------------------------------------------------------------------- +ℹ file | line % | branch % | funcs % | uncovered lines +ℹ -------------------------------------------------------------------------------------------- +ℹ 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 +ℹ 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 | +ℹ -------------------------------------------------------------------------------------------- +ℹ end of coverage report diff --git a/test/parallel/test-runner-coverage-thresholds.js b/test/parallel/test-runner-coverage-thresholds.js index e45e1191299..2742464adf6 100644 --- a/test/parallel/test-runner-coverage-thresholds.js +++ b/test/parallel/test-runner-coverage-thresholds.js @@ -170,4 +170,25 @@ for (const coverage of coverages) { assert.strictEqual(result.status, 1); assert(!findCoverageFileForPid(result.pid)); }); + + test(`test failing ${coverage.flag} with dot reporter`, () => { + const result = spawnSync(process.execPath, [ + '--test', + '--experimental-test-coverage', + '--test-coverage-exclude=!test/**', + `${coverage.flag}=99`, + '--test-reporter', 'dot', + fixture, + ]); + + const stdout = result.stdout.toString(); + assert.match( + stdout, + RegExp(`Error: ${coverage.actual.toFixed(2)}% ${coverage.name} coverage does not meet threshold of 99%`) + ); + assert.match(stdout, /start of coverage report/); + assert.match(stdout, /end of coverage report/); + assert.strictEqual(result.status, 1); + assert(!findCoverageFileForPid(result.pid)); + }); } diff --git a/test/test-runner/test-output-dot-reporter-coverage-threshold.mjs b/test/test-runner/test-output-dot-reporter-coverage-threshold.mjs new file mode 100644 index 00000000000..e764863a6b0 --- /dev/null +++ b/test/test-runner/test-output-dot-reporter-coverage-threshold.mjs @@ -0,0 +1,15 @@ +// Test that the output of test-runner/output/dot_reporter_coverage_threshold.js matches +// test-runner/output/dot_reporter_coverage_threshold.snapshot +import * as common from '../common/index.mjs'; +import * as fixtures from '../common/fixtures.mjs'; +import { spawnAndAssert, specTransform, ensureCwdIsProjectRoot } from '../common/assertSnapshot.js'; + +if (!process.features.inspector) { + common.skip('inspector support required'); +} + +ensureCwdIsProjectRoot(); +await spawnAndAssert( + fixtures.path('test-runner/output/dot_reporter_coverage_threshold.js'), + specTransform, +);