test_runner: do not error when getting fullName of root context

PR-URL: https://github.com/nodejs/node/pull/59377
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
René 2025-08-23 20:40:58 +01:00 committed by GitHub
parent 589ef79bf8
commit 52f616d42f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -1533,6 +1533,8 @@ class Suite extends Test {
} }
function getFullName(test) { function getFullName(test) {
if (test === test.root) return test.name;
let fullName = test.name; let fullName = test.name;
for (let t = test.parent; t !== t.root; t = t.parent) { for (let t = test.parent; t !== t.root; t = t.parent) {

View File

@ -1,7 +1,11 @@
'use strict'; 'use strict';
require('../common'); require('../common');
const { strictEqual } = require('node:assert'); const { strictEqual } = require('node:assert');
const { suite, test } = require('node:test'); const { before, suite, test } = require('node:test');
before((t) => {
strictEqual(t.fullName, '<root>');
});
suite('suite', (t) => { suite('suite', (t) => {
strictEqual(t.fullName, 'suite'); strictEqual(t.fullName, 'suite');