From bc3ffbd713ae4363c5f75de496f5ed2590a00a10 Mon Sep 17 00:00:00 2001 From: Sungwon <63222221+mete0rfish@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:50:42 +0900 Subject: [PATCH] test_runner: fix isSkipped check in junit The `isSkipped` function in the JUnit reporter was incorrectly checking for `node?.attrs.failures` instead of `node?.attrs.skipped`. PR-URL: https://github.com/nodejs/node/pull/59414 Reviewed-By: Moshe Atlow Reviewed-By: Pietro Marchini --- lib/internal/test_runner/reporter/junit.js | 2 +- test/parallel/test-runner-reporters.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/internal/test_runner/reporter/junit.js b/lib/internal/test_runner/reporter/junit.js index b45c233861c..b7a7d33c56d 100644 --- a/lib/internal/test_runner/reporter/junit.js +++ b/lib/internal/test_runner/reporter/junit.js @@ -56,7 +56,7 @@ function isFailure(node) { } function isSkipped(node) { - return (node?.children && ArrayPrototypeSome(node.children, (c) => c.tag === 'skipped')) || node?.attrs?.failures; + return (node?.children && ArrayPrototypeSome(node.children, (c) => c.tag === 'skipped')) || node?.attrs?.skipped; } module.exports = async function* junitReporter(source) { diff --git a/test/parallel/test-runner-reporters.js b/test/parallel/test-runner-reporters.js index a412bd099ec..28fbfa481c4 100644 --- a/test/parallel/test-runner-reporters.js +++ b/test/parallel/test-runner-reporters.js @@ -191,4 +191,17 @@ describe('node:test reporters', { concurrency: true }, () => { assert.match(fileConent, /ℹ skipped 0/); assert.match(fileConent, /ℹ todo 0/); }); + + it('should correctly report pass/fail for junit reporter using reporters.js', async () => { + const file = tmpdir.resolve(`${tmpFiles++}.xml`); + const child = spawnSync(process.execPath, + ['--test', '--test-reporter', 'junit', '--test-reporter-destination', file, testFile]); + assert.strictEqual(child.stderr.toString(), ''); + assert.strictEqual(child.stdout.toString(), ''); + const fileContents = fs.readFileSync(file, 'utf8'); + assert.match(fileContents, //); + assert.match(fileContents, /\s*/); + assert.match(fileContents, //); + assert.match(fileContents, //); + }); });