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
2 changes: 1 addition & 1 deletion lib/internal/test_runner/reporter/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/test-runner/output/junit_empty_diagnostic.js
Original file line number Diff line number Diff line change
@@ -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');
});
23 changes: 23 additions & 0 deletions test/fixtures/test-runner/output/junit_empty_diagnostic.snapshot
Original file line number Diff line number Diff line change
@@ -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>
11 changes: 11 additions & 0 deletions test/test-runner/test-output-junit-empty-diagnostic.mjs
Original file line number Diff line number Diff line change
@@ -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,
);
Loading