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
6 changes: 3 additions & 3 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function configureCoverage(rootTest, globalOptions) {
} catch (err) {
const msg = `Warning: Code coverage could not be enabled. ${err}`;

rootTest.diagnostic(msg);
rootTest.diagnostic(msg, 'warn');
rootTest.harness.success = false;
process.exitCode = kGenericUserError;
}
Expand All @@ -194,15 +194,15 @@ function collectCoverage(rootTest, coverage) {
try {
summary = coverage.summary();
} catch (err) {
rootTest.diagnostic(`Warning: Could not report code coverage. ${err}`);
rootTest.diagnostic(`Warning: Could not report code coverage. ${err}`, 'warn');
rootTest.harness.success = false;
process.exitCode = kGenericUserError;
}

try {
coverage.cleanup();
} catch (err) {
rootTest.diagnostic(`Warning: Could not clean up code coverage. ${err}`);
rootTest.diagnostic(`Warning: Could not clean up code coverage. ${err}`, 'warn');
rootTest.harness.success = false;
process.exitCode = kGenericUserError;
}
Expand Down
16 changes: 15 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,17 @@ const {
MathMax,
} = primordials;
const colors = require('internal/util/colors');
const { formatTestReport } = require('internal/test_runner/reporter/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 diagnosticWarnings = [];
for await (const { type, data } of source) {
if (type === 'test:pass') {
yield `${colors.green}.${colors.reset}`;
Expand All @@ -18,6 +23,9 @@ module.exports = async function* dot(source) {
yield `${colors.red}X${colors.reset}`;
ArrayPrototypePush(failedTests, data);
}
if (type === 'test:diagnostic' && (data.level === 'warn' || data.level === 'error')) {
ArrayPrototypePush(diagnosticWarnings, data);
}
if ((type === 'test:fail' || type === 'test:pass') && ++count === columns) {
yield '\n';

Expand All @@ -27,6 +35,12 @@ module.exports = async function* dot(source) {
}
}
yield '\n';
if (diagnosticWarnings.length > 0) {
for (const diagnostic of diagnosticWarnings) {
const diagnosticColor = reporterColorMap[diagnostic.level] || reporterColorMap['test:diagnostic'];
yield `${diagnosticColor}${reporterUnicodeSymbolMap['test:diagnostic']}${diagnostic.message}${colors.white}\n`;
}
}
if (failedTests.length > 0) {
yield `\n${colors.red}Failed tests:${colors.white}\n\n`;
for (const test of failedTests) {
Expand Down
17 changes: 9 additions & 8 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ class TestContext {
return Number(envWorkerId) || undefined;
}

diagnostic(message) {
this.#test.diagnostic(message);
diagnostic(message, level = 'info') {
this.#test.diagnostic(message, level);
}

log(message, data) {
Expand Down Expand Up @@ -525,8 +525,8 @@ class SuiteContext {
return this.#suite.attempt ?? 0;
}

diagnostic(message) {
this.#suite.diagnostic(message);
diagnostic(message, level = 'info') {
this.#suite.diagnostic(message, level);
}

log(message, data) {
Expand Down Expand Up @@ -1203,8 +1203,8 @@ class Test extends AsyncResource {
this.message = message;
}

diagnostic(message) {
ArrayPrototypePush(this.diagnostics, message);
diagnostic(message, level = 'info') {
ArrayPrototypePush(this.diagnostics, { __proto__: null, message, level });
}

log(message, data) {
Expand Down Expand Up @@ -1551,7 +1551,7 @@ class Test extends AsyncResource {
const coverage = harness.coverage();
harness.snapshotManager?.writeSnapshotFiles();
for (let i = 0; i < diagnostics.length; i++) {
reporter.diagnostic(nesting, loc, diagnostics[i]);
reporter.diagnostic(nesting, loc, diagnostics[i].message, diagnostics[i].level);
}

const duration = this.duration();
Expand Down Expand Up @@ -1693,7 +1693,8 @@ class Test extends AsyncResource {
}

for (let i = 0; i < this.diagnostics.length; i++) {
this.reporter.diagnostic(this.nesting, this.loc, this.diagnostics[i]);
const { message, level } = this.diagnostics[i];
this.reporter.diagnostic(this.nesting, this.loc, message, level);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.
ℹ Warning: Could not report code coverage. Error: Failed to collect coverage
16 changes: 16 additions & 0 deletions test/test-runner/test-output-dot-coverage-failure.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Test that the output of test-runner/output/coverage_failure.js matches
// test-runner/output/dot_coverage_failure.snapshot when using the dot reporter
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/coverage_failure.js'),
defaultTransform,
{ flags: ['--test-reporter=dot', '--test-coverage-exclude=!test/**'] },
);
Loading