Skip to content

Commit b7cd703

Browse files
committed
test_runner: print coverage and
diagnostics with dot reporter
1 parent 5a8f845 commit b7cd703

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/internal/test_runner/reporter/dot.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ const {
44
MathMax,
55
} = primordials;
66
const colors = require('internal/util/colors');
7-
const { formatTestReport } = require('internal/test_runner/reporter/utils');
7+
const { getCoverageReport } = require('internal/test_runner/utils');
8+
const {
9+
formatTestReport,
10+
reporterColorMap,
11+
reporterUnicodeSymbolMap,
12+
} = require('internal/test_runner/reporter/utils');
813

914
module.exports = async function* dot(source) {
1015
let count = 0;
1116
let columns = getLineLength();
1217
const failedTests = [];
18+
const diagnostics = [];
19+
let coverage;
1320
for await (const { type, data } of source) {
1421
if (type === 'test:pass') {
1522
yield `${colors.green}.${colors.reset}`;
@@ -25,6 +32,12 @@ module.exports = async function* dot(source) {
2532
columns = getLineLength();
2633
count = 0;
2734
}
35+
if (type === 'test:diagnostic') {
36+
ArrayPrototypePush(diagnostics, data);
37+
}
38+
if (type === 'test:coverage') {
39+
coverage = data;
40+
}
2841
}
2942
yield '\n';
3043
if (failedTests.length > 0) {
@@ -33,6 +46,13 @@ module.exports = async function* dot(source) {
3346
yield formatTestReport('test:fail', test);
3447
}
3548
}
49+
for (const diagnostic of diagnostics) {
50+
const color = reporterColorMap[diagnostic.level] || reporterColorMap['test:diagnostic'];
51+
yield `${color}${reporterUnicodeSymbolMap['test:diagnostic']}${diagnostic.message}${colors.white}\n`;
52+
}
53+
if (coverage) {
54+
yield getCoverageReport('', coverage.summary, reporterUnicodeSymbolMap['test:coverage'], colors.blue, true);
55+
}
3656
};
3757

3858
function getLineLength() {

test/parallel/test-runner-coverage-thresholds.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,23 @@ for (const coverage of coverages) {
143143
assert(!findCoverageFileForPid(result.pid));
144144
});
145145

146+
test(`test failing ${coverage.flag} with dot reporter`, () => {
147+
const result = spawnSync(process.execPath, [
148+
'--test',
149+
'--experimental-test-coverage',
150+
'--test-coverage-exclude=!test/**',
151+
`${coverage.flag}=99`,
152+
'--test-reporter', 'dot',
153+
fixture,
154+
]);
155+
156+
const stdout = result.stdout.toString();
157+
assert.match(stdout, RegExp(`Error: ${coverage.actual.toFixed(2)}% ${coverage.name} coverage does not meet threshold of 99%`));
158+
assert.match(stdout, /start of coverage report/);
159+
assert.strictEqual(result.status, 1);
160+
assert(!findCoverageFileForPid(result.pid));
161+
});
162+
146163
test(`test out-of-range ${coverage.flag} (too high)`, () => {
147164
const result = spawnSync(process.execPath, [
148165
'--test',

0 commit comments

Comments
 (0)