From 0a00f2828d883ee34e31f92b7b8ce6b238b5d320 Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Tue, 18 Aug 2026 00:43:36 +0500 Subject: [PATCH] test_runner: fix junit report on empty diagnostic Signed-off-by: Lazizbek Ergashev --- lib/internal/test_runner/reporter/junit.js | 2 +- .../output/junit_empty_diagnostic.js | 8 +++++++ .../output/junit_empty_diagnostic.snapshot | 23 +++++++++++++++++++ .../test-output-junit-empty-diagnostic.mjs | 11 +++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/test-runner/output/junit_empty_diagnostic.js create mode 100644 test/fixtures/test-runner/output/junit_empty_diagnostic.snapshot create mode 100644 test/test-runner/test-output-junit-empty-diagnostic.mjs diff --git a/lib/internal/test_runner/reporter/junit.js b/lib/internal/test_runner/reporter/junit.js index ed25a4bd5fbd..5052f5444c0d 100644 --- a/lib/internal/test_runner/reporter/junit.js +++ b/lib/internal/test_runner/reporter/junit.js @@ -41,7 +41,7 @@ function treeToXML(tree) { tag, attrs, nesting, children, comment, } = tree; const indent = StringPrototypeRepeat('\t', nesting + 1); - if (comment) { + if (comment != null) { return `${indent}\n`; } const attrsString = ArrayPrototypeJoin( diff --git a/test/fixtures/test-runner/output/junit_empty_diagnostic.js b/test/fixtures/test-runner/output/junit_empty_diagnostic.js new file mode 100644 index 000000000000..491c2f230d98 --- /dev/null +++ b/test/fixtures/test-runner/output/junit_empty_diagnostic.js @@ -0,0 +1,8 @@ +// Flags: --test --test-reporter=junit +'use strict'; +const test = require('node:test'); + +test('failing', (t) => { + t.diagnostic(''); + throw new Error('error'); +}); diff --git a/test/fixtures/test-runner/output/junit_empty_diagnostic.snapshot b/test/fixtures/test-runner/output/junit_empty_diagnostic.snapshot new file mode 100644 index 000000000000..666c5c3523a7 --- /dev/null +++ b/test/fixtures/test-runner/output/junit_empty_diagnostic.snapshot @@ -0,0 +1,23 @@ + + + + +[Error [ERR_TEST_FAILURE]: error] { + code: 'ERR_TEST_FAILURE', + failureType: 'testCodeFailure', + cause: Error: error + at TestContext.<anonymous> (/test/fixtures/test-runner/output/junit_empty_diagnostic.js:7:9) + at +} + + + + + + + + + + + + diff --git a/test/test-runner/test-output-junit-empty-diagnostic.mjs b/test/test-runner/test-output-junit-empty-diagnostic.mjs new file mode 100644 index 000000000000..5c1cf4a2b382 --- /dev/null +++ b/test/test-runner/test-output-junit-empty-diagnostic.mjs @@ -0,0 +1,11 @@ +// Test that the output of test-runner/output/junit_empty_diagnostic.js matches +// test-runner/output/junit_empty_diagnostic.snapshot +import '../common/index.mjs'; +import * as fixtures from '../common/fixtures.mjs'; +import { spawnAndAssert, junitTransform, ensureCwdIsProjectRoot } from '../common/assertSnapshot.js'; + +ensureCwdIsProjectRoot(); +await spawnAndAssert( + fixtures.path('test-runner/output/junit_empty_diagnostic.js'), + junitTransform, +);