Skip to content

Commit d71eee3

Browse files
author
AZ & QZ
committed
test_runner: print failed coverage reports with dot runner
When running tests with both the dot reporter and coverage reports, if the coverage report fails there was no output (other than the dots) but the program exits with a failure status code. This change adds coverage failure output to the dot reporter, similar to how the spec reporter handles coverage events. Now users can see why the command failed without needing to check F12 console. Fixes #60884 Signed-off-by: AZ & QZ <dev@local>
1 parent 78e56fa commit d71eee3

File tree

1 file changed

+18
-1
lines changed
  • lib/internal/test_runner/reporter

1 file changed

+18
-1
lines changed

lib/internal/test_runner/reporter/dot.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ const {
44
MathMax,
55
} = primordials;
66
const colors = require('internal/util/colors');
7-
const { formatTestReport } = require('internal/test_runner/reporter/utils');
7+
const { formatTestReport, getCoverageReport } = require('internal/test_runner/reporter/utils');
88

99
module.exports = async function* dot(source) {
1010
let count = 0;
1111
let columns = getLineLength();
1212
const failedTests = [];
13+
const coverageFailures = [];
1314
for await (const { type, data } of source) {
1415
if (type === 'test:pass') {
1516
yield `${colors.green}.${colors.reset}`;
@@ -18,6 +19,16 @@ module.exports = async function* dot(source) {
1819
yield `${colors.red}X${colors.reset}`;
1920
ArrayPrototypePush(failedTests, data);
2021
}
22+
if (type === 'test:coverage') {
23+
// Check if coverage failed (threshold not met)
24+
if (data.summary && (
25+
(data.summary.lines && data.summary.lines.pct < 100) ||
26+
(data.summary.functions && data.summary.functions.pct < 100) ||
27+
(data.summary.branches && data.summary.branches.pct < 100)
28+
)) {
29+
ArrayPrototypePush(coverageFailures, data);
30+
}
31+
}
2132
if ((type === 'test:fail' || type === 'test:pass') && ++count === columns) {
2233
yield '\n';
2334

@@ -33,6 +44,12 @@ module.exports = async function* dot(source) {
3344
yield formatTestReport('test:fail', test);
3445
}
3546
}
47+
if (coverageFailures.length > 0) {
48+
yield `\n${colors.red}Coverage report failed:${colors.white}\n\n`;
49+
for (const coverage of coverageFailures) {
50+
yield getCoverageReport('', coverage.summary, 'ℹ ', colors.blue, true);
51+
}
52+
}
3653
};
3754

3855
function getLineLength() {

0 commit comments

Comments
 (0)