FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test_runner: print coverage and diagnostic info with dot reporter · nodejs/node@79c39c2 · GitHub

/ node Public

Commit 79c39c2

Browse files
authored andcommitted
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: #60884 Signed-off-by: mag123c <diehreo@gmail.com> PR-URL: #61423 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent c4dbe14 commit 79c39c2

5 files changed

Lines changed: 95 additions & 1 deletion

File tree

‎lib/internal/test_runner/reporter/dot.js‎

Lines changed: 24 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,8 +32,24 @@ module.exports = async function* dot(source) {
2532
columns = getLineLength();
2633
count = 0;
2734
}
35+
if (type === 'test:diagnostic' && data.level === 'error') {
36+
ArrayPrototypePush(diagnostics, data);
37+
}
38+
if (type === 'test:coverage') {
39+
coverage = data;
40+
}
2841
}
2942
yield '\n';
43+
if (diagnostics.length > 0) {
44+
for (const diagnostic of diagnostics) {
45+
const color = reporterColorMap[diagnostic.level] || reporterColorMap['test:diagnostic'];
46+
yield `${color}${reporterUnicodeSymbolMap['test:diagnostic']}${diagnostic.message}${colors.white}\n`;
47+
}
48+
if (coverage) {
49+
yield getCoverageReport('', coverage.summary,
50+
reporterUnicodeSymbolMap['test:coverage'], colors.blue, true);
51+
}
52+
}
3053
if (failedTests.length > 0) {
3154
yield `\n${colors.red}Failed tests:${colors.white}\n\n`;
3255
for (const test of failedTests) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
require('../../../common');
3+
const fixtures = require('../../../common/fixtures');
4+
const spawn = require('node:child_process').spawn;
5+
6+
spawn(
7+
process.execPath,
8+
[
9+
'--no-warnings',
10+
'--experimental-test-coverage',
11+
'--test-coverage-exclude=!test/**',
12+
'--test-coverage-lines=99',
13+
'--test-reporter', 'dot',
14+
fixtures.path('test-runner/coverage.js'),
15+
],
16+
{ stdio: 'inherit' },
17+
);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
invalid tap output
2+
.
3+
ℹ Error: 78.35% line coverage does not meet threshold of 99%.
4+
ℹ start of coverage report
5+
ℹ --------------------------------------------------------------------------------------------
6+
ℹ file | line % | branch % | funcs % | uncovered lines
7+
ℹ --------------------------------------------------------------------------------------------
8+
ℹ test | | | |
9+
ℹ fixtures | | | |
10+
ℹ test-runner | | | |
11+
ℹ coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72
12+
ℹ invalid-tap.js | 100.00 | 100.00 | 100.00 |
13+
ℹ v8-coverage | | | |
14+
ℹ throw.js | 71.43 | 50.00 | 100.00 | 5-6
15+
ℹ --------------------------------------------------------------------------------------------
16+
ℹ all files | 78.35 | 43.75 | 60.00 |
17+
ℹ --------------------------------------------------------------------------------------------
18+
ℹ end of coverage report

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,25 @@ for (const coverage of coverages) {
170170
assert.strictEqual(result.status, 1);
171171
assert(!findCoverageFileForPid(result.pid));
172172
});
173+
174+
test(`test failing ${coverage.flag} with dot reporter`, () => {
175+
const result = spawnSync(process.execPath, [
176+
'--test',
177+
'--experimental-test-coverage',
178+
'--test-coverage-exclude=!test/**',
179+
`${coverage.flag}=99`,
180+
'--test-reporter', 'dot',
181+
fixture,
182+
]);
183+
184+
const stdout = result.stdout.toString();
185+
assert.match(
186+
stdout,
187+
RegExp(`Error: ${coverage.actual.toFixed(2)}% ${coverage.name} coverage does not meet threshold of 99%`)
188+
);
189+
assert.match(stdout, /start of coverage report/);
190+
assert.match(stdout, /end of coverage report/);
191+
assert.strictEqual(result.status, 1);
192+
assert(!findCoverageFileForPid(result.pid));
193+
});
173194
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Test that the output of test-runner/output/dot_reporter_coverage_threshold.js matches
2+
// test-runner/output/dot_reporter_coverage_threshold.snapshot
3+
import * as common from '../common/index.mjs';
4+
import * as fixtures from '../common/fixtures.mjs';
5+
import { spawnAndAssert, specTransform, ensureCwdIsProjectRoot } from '../common/assertSnapshot.js';
6+
7+
if (!process.features.inspector) {
8+
common.skip('inspector support required');
9+
}
10+
11+
ensureCwdIsProjectRoot();
12+
await spawnAndAssert(
13+
fixtures.path('test-runner/output/dot_reporter_coverage_threshold.js'),
14+
specTransform,
15+
);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL