test_runner: add passed, attempt, and diagnostic to SuiteContext

PR-URL: https://github.com/nodejs/node/pull/62504
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
This commit is contained in:
Moshe Atlow authored and Antoine du Hamel committed 2026-05-07 15:41:31 +02:00
1 parent 40ccfdecf9
commit dd43efffa6
3 files changed
+71

No files matched your search

+39
View File
@@ -4222,6 +4222,45 @@ added:
Can be used to abort test subtasks when the test has been aborted.
### `context.passed`
<!-- YAML
added: REPLACEME
-->
* Type: {boolean}
Indicates whether the suite and all of its subtests have passed.
### `context.attempt`
<!-- YAML
added: REPLACEME
-->
* Type: {number}
The current attempt number of the suite. Used in conjunction with the
`--test-rerun-failures` option to determine the attempt number of the current
run.
### `context.diagnostic(message)`
<!-- YAML
added: REPLACEME
-->
* `message` {string} A diagnostic message to output.
Output a diagnostic message. This is typically used for logging information
about the current suite or its tests.
```js
test.describe('my suite', (suite) => {
suite.diagnostic('Suite diagnostic message');
});
```
[TAP]: https://testanything.org/
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
[`--experimental-test-module-mocks`]: cli.md#--experimental-test-module-mocks
+12
View File
@@ -494,6 +494,18 @@ class SuiteContext {
get fullName() {
return getFullName(this.#suite);
}
get passed() {
return this.#suite.passed;
}
get attempt() {
return this.#suite.attempt ?? 0;
}
diagnostic(message) {
this.#suite.diagnostic(message);
}
}
function parseExpectFailure(expectFailure) {
@@ -9,6 +9,11 @@ before(common.mustCall((t) => {
suite('suite', common.mustCall((t) => {
assert.strictEqual(t.fullName, 'suite');
// Test new SuiteContext properties
assert.strictEqual(typeof t.passed, 'boolean');
assert.strictEqual(t.attempt, 0);
// diagnostic() can be called to add diagnostic output
t.diagnostic('Suite diagnostic message');
test('test', (t) => {
assert.strictEqual(t.fullName, 'suite > test');
@@ -26,3 +31,18 @@ suite('suite', common.mustCall((t) => {
test((t) => {
assert.strictEqual(t.fullName, '<anonymous>');
});
// Test SuiteContext passed, attempt, and diagnostic properties
suite('suite with context checks', common.mustCall((ctx) => {
assert.strictEqual(ctx.fullName, 'suite with context checks');
assert.strictEqual(typeof ctx.passed, 'boolean');
assert.strictEqual(ctx.attempt, 0);
// Verify diagnostic method is callable
ctx.diagnostic('Test diagnostic message in suite');
test('child test', () => {
// Verify properties are accessible in nested test
assert.strictEqual(typeof ctx.passed, 'boolean');
assert.strictEqual(ctx.attempt, 0);
});
}));