mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test_runner: add context.fullName
This commit adds a fullName getter to the TestContext and SuiteContext classes. This is similar to the existing name getter, but also includes the name of all ancestor tests/suites. PR-URL: https://github.com/nodejs/node/pull/53169 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Co-authored-by: Jacob Smith <jacob@frende.me>
This commit is contained in:
parent
063afa85fe
commit
90e81aaad7
@ -3044,6 +3044,14 @@ test('top level test', (t) => {
|
||||
});
|
||||
```
|
||||
|
||||
### `context.fullName`
|
||||
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
The name of the test and each of its ancestors, separated by `>`.
|
||||
|
||||
### `context.name`
|
||||
|
||||
<!-- YAML
|
||||
|
@ -218,6 +218,10 @@ class TestContext {
|
||||
return this.#test.name;
|
||||
}
|
||||
|
||||
get fullName() {
|
||||
return getFullName(this.#test);
|
||||
}
|
||||
|
||||
get error() {
|
||||
return this.#test.error;
|
||||
}
|
||||
@ -331,6 +335,10 @@ class SuiteContext {
|
||||
get name() {
|
||||
return this.#suite.name;
|
||||
}
|
||||
|
||||
get fullName() {
|
||||
return getFullName(this.#suite);
|
||||
}
|
||||
}
|
||||
|
||||
class Test extends AsyncResource {
|
||||
@ -1216,6 +1224,16 @@ class Suite extends Test {
|
||||
}
|
||||
}
|
||||
|
||||
function getFullName(test) {
|
||||
let fullName = test.name;
|
||||
|
||||
for (let t = test.parent; t !== t.root; t = t.parent) {
|
||||
fullName = `${t.name} > ${fullName}`;
|
||||
}
|
||||
|
||||
return fullName;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
kCancelledByParent,
|
||||
kSubtestsFailed,
|
||||
|
24
test/parallel/test-runner-test-fullname.js
Normal file
24
test/parallel/test-runner-test-fullname.js
Normal file
@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const { strictEqual } = require('node:assert');
|
||||
const { suite, test } = require('node:test');
|
||||
|
||||
suite('suite', (t) => {
|
||||
strictEqual(t.fullName, 'suite');
|
||||
|
||||
test('test', (t) => {
|
||||
strictEqual(t.fullName, 'suite > test');
|
||||
|
||||
t.test('subtest', (t) => {
|
||||
strictEqual(t.fullName, 'suite > test > subtest');
|
||||
|
||||
t.test('subsubtest', (t) => {
|
||||
strictEqual(t.fullName, 'suite > test > subtest > subsubtest');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test((t) => {
|
||||
strictEqual(t.fullName, '<anonymous>');
|
||||
});
|
Loading…
Reference in New Issue
Block a user