test_runner: fix junit report on empty diagnostic

Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65357
Fixes: https://github.com/nodejs/node/issues/65355
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
Lazizbek Ergashev authored and Antoine du Hamel committed 2026-09-07 11:53:52 +02:00
1 parent 2ba8661e23
commit 6a248acefe
4 files changed
+43 -1

No files matched your search

+1 -1
View File
@@ -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}<!-- ${escapeComment(comment)} -->\n`;
}
const attrsString = ArrayPrototypeJoin(
@@ -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');
});
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testcase name="failing" time="*" classname="test" file="*" failure="error">
<failure type="testCodeFailure" message="error">
[Error [ERR_TEST_FAILURE]: error] {
code: 'ERR_TEST_FAILURE',
failureType: 'testCodeFailure',
cause: Error: error
at TestContext.&lt;anonymous> (<project-root>/test/fixtures/test-runner/output/junit_empty_diagnostic.js:7:9)
at <node-internal-frames>
}
</failure>
</testcase>
<!-- -->
<!-- tests 1 -->
<!-- suites 0 -->
<!-- pass 0 -->
<!-- fail 1 -->
<!-- cancelled 0 -->
<!-- skipped 0 -->
<!-- todo 0 -->
<!-- duration_ms * -->
</testsuites>
@@ -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,
);