Version
v24.15.0
Platform
Microsoft Windows NT 10.0.26200.0 x64
Subsystem
test_runner
What steps will reproduce the bug?
-
Create any test file, like junit.test.mjs:
import { fail } from 'node:assert/strict';
import { test } from 'node:test';
await test('testName', (context) => {
context.diagnostic('');
fail();
});
-
Run the test via console
node --test --test-reporter=junit ".\junit.test.mjs"
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior? Why is that the expected behavior?
The JUnit reporter should gracefully handle empty diagnostic messages (e.g., context.diagnostic('')). It should format them as empty XML comments (<!-- -->) without throwing errors, aligning with the default spec reporter which successfully prints empty lines for empty diagnostic events. The generated XML report must remain valid and fully closed with the </testsuites> tag.
What do you see instead?
When a failed test contains an empty diagnostic call, the internal XML formatter (treeToXML) evaluates the falsy empty string if (comment) as false and mistakenly tries to read ObjectEntries(attrs) from an undefined object. This causes an unhandled TypeError inside the stream generator, silently destroying the stream and leaving the JUnit XML report truncated and broken.
Stack trace:
TypeError: Cannot convert undefined or null to object
at entries (<anonymous>)
at treeToXML (node:internal/test_runner/reporter/junit:46:7)
at junitReporter (node:internal/test_runner/reporter/junit:160:11)
Additional information
No response
Version
v24.15.0
Platform
Subsystem
test_runner
What steps will reproduce the bug?
Create any test file, like
junit.test.mjs:Run the test via console
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior? Why is that the expected behavior?
The JUnit reporter should gracefully handle empty diagnostic messages (e.g.,
context.diagnostic('')). It should format them as empty XML comments (<!-- -->) without throwing errors, aligning with the defaultspecreporter which successfully prints empty lines for empty diagnostic events. The generated XML report must remain valid and fully closed with the</testsuites>tag.What do you see instead?
When a failed test contains an empty diagnostic call, the internal XML formatter (
treeToXML) evaluates the falsy empty stringif (comment)as false and mistakenly tries to readObjectEntries(attrs)from an undefined object. This causes an unhandledTypeErrorinside the stream generator, silently destroying the stream and leaving the JUnit XML report truncated and broken.Stack trace:
Additional information
No response