GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test_runner: print coverage and diagnostic info with dot reporter · nodejs/node@2df1681

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/test_runner/reporter
    • dot.js
  • test
    • fixtures/test-runner/output
      • dot_reporter_coverage_threshold.js
      • dot_reporter_coverage_threshold.snapshot
    • parallel
      • test-runner-coverage-thresholds.js
    • test-runner
      • test-output-dot-reporter-coverage-threshold.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/test_runner/reporter/dot.js
+24-1Lines 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) {
Collapse file

‎test/fixtures/test-runner/output/dot_reporter_coverage_threshold.js‎

Copy file name to clipboard
+17Lines 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+
);
Collapse file

‎test/fixtures/test-runner/output/dot_reporter_coverage_threshold.snapshot‎

Copy file name to clipboard
+18Lines 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
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-runner-coverage-thresholds.js
+21Lines 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
}
Collapse file

‎test/test-runner/test-output-dot-reporter-coverage-threshold.mjs‎

Copy file name to clipboard
+15Lines 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 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.