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, +);