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 <moshe@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
This commit is contained in:
Sungwon 2025-08-13 17:50:42 +09:00 committed by GitHub
parent ff11b59569
commit f7a2ba7e83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -58,7 +58,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) {

View file

@ -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, /<testsuite .*name="nested".*tests="2".*failures="1".*skipped="0".*>/);
assert.match(fileContents, /<testcase .*name="failing".*>\s*<failure .*type="testCodeFailure".*message="error".*>/);
assert.match(fileContents, /<testcase .*name="ok".*classname="test".*\/>/);
assert.match(fileContents, /<testcase .*name="top level".*classname="test".*\/>/);
});
});