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

Commit 79c39c2

Browse files
mag123caduh95
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
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

0 commit comments

Comments
 (0)