Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion lib/internal/test_runner/reporter/dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ const {
MathMax,
} = primordials;
const colors = require('internal/util/colors');
const { formatTestReport } = require('internal/test_runner/reporter/utils');
const { getCoverageReport } = require('internal/test_runner/utils');
const {
formatTestReport,
reporterColorMap,
reporterUnicodeSymbolMap,
} = require('internal/test_runner/reporter/utils');

module.exports = async function* dot(source) {
let count = 0;
let columns = getLineLength();
const failedTests = [];
const diagnostics = [];
let coverage;
for await (const { type, data } of source) {
if (type === 'test:pass') {
yield `${colors.green}.${colors.reset}`;
Expand All @@ -25,6 +32,12 @@ module.exports = async function* dot(source) {
columns = getLineLength();
count = 0;
}
if (type === 'test:diagnostic') {
ArrayPrototypePush(diagnostics, data);
}
if (type === 'test:coverage') {
coverage = data;
}
}
yield '\n';
if (failedTests.length > 0) {
Expand All @@ -33,6 +46,13 @@ module.exports = async function* dot(source) {
yield formatTestReport('test:fail', test);
}
}
for (const diagnostic of diagnostics) {
const color = reporterColorMap[diagnostic.level] || reporterColorMap['test:diagnostic'];
yield `${color}${reporterUnicodeSymbolMap['test:diagnostic']}${diagnostic.message}${colors.white}\n`;
}
if (coverage) {
yield getCoverageReport('', coverage.summary, reporterUnicodeSymbolMap['test:coverage'], colors.blue, true);
}
};

function getLineLength() {
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/test-runner/output/dot_reporter_coverage.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Flags: --experimental-test-coverage --test-coverage-lines=99
// here we can't import common module as the coverage will be different based on the system
// Unused imports are here in order to populate the coverage report
// eslint-disable-next-line no-unused-vars
import * as a from '../coverage-snap/b.js';
// eslint-disable-next-line no-unused-vars
import * as b from '../coverage-snap/a.js';

import { test } from 'node:test';

process.stdout.columns = 80;

test('passing test for dot coverage report');
19 changes: 19 additions & 0 deletions test/fixtures/test-runner/output/dot_reporter_coverage.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.

ℹ Error: *% line coverage does not meet threshold of 99%.
ℹ start of coverage report
ℹ ------------------------------------------------------------------------------
ℹ file | line % | branch % | funcs % | uncovered lines
ℹ ------------------------------------------------------------------------------
ℹ test | | | |
ℹ fixtures | | | |
ℹ test-runner | | | |
ℹ coverage-snap | | | |
ℹ a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-…
ℹ b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
ℹ output | | | |
ℹ dot_reporter_cove….mjs | 100.00 | 100.00 | 100.00 |
ℹ ------------------------------------------------------------------------------
ℹ all files | 61.84 | 100.00 | 0.00 |
ℹ ------------------------------------------------------------------------------
ℹ end of coverage report
17 changes: 17 additions & 0 deletions test/parallel/test-runner-coverage-thresholds.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,23 @@ for (const coverage of coverages) {
assert(!findCoverageFileForPid(result.pid));
});

test(`test failing ${coverage.flag} with dot reporter`, () => {
const result = spawnSync(process.execPath, [
'--test',
'--experimental-test-coverage',
'--test-coverage-exclude=!test/**',
`${coverage.flag}=99`,
'--test-reporter', 'dot',
fixture,
]);

const stdout = result.stdout.toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a snapshot test too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch, thank you, added in this commit.
let me know if this could be improved!

assert.match(stdout, RegExp(`Error: ${coverage.actual.toFixed(2)}% ${coverage.name} coverage does not meet threshold of 99%`));
assert.match(stdout, /start of coverage report/);
assert.strictEqual(result.status, 1);
assert(!findCoverageFileForPid(result.pid));
});

test(`test out-of-range ${coverage.flag} (too high)`, () => {
const result = spawnSync(process.execPath, [
'--test',
Expand Down
16 changes: 16 additions & 0 deletions test/test-runner/test-output-dot-reporter-coverage.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Test that the output of test-runner/output/dot_reporter_coverage.mjs matches
// test-runner/output/dot_reporter_coverage.snapshot
import * as common from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { spawnAndAssert, defaultTransform, ensureCwdIsProjectRoot } from '../common/assertSnapshot.js';

if (!process.features.inspector) {
common.skip('inspector support required');
}

ensureCwdIsProjectRoot();
await spawnAndAssert(
fixtures.path('test-runner/output/dot_reporter_coverage.mjs'),
defaultTransform,
{ flags: ['--test-reporter=dot', '--test-coverage-exclude=!test/**'] },
);