Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: make sure tap subtest is reported in order #45220

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class TestContext {
class Test extends AsyncResource {
#abortController;
#outerSignal;
#reportedSubtest;

constructor(options) {
super('Test');
Expand Down Expand Up @@ -308,7 +309,7 @@ class Test extends AsyncResource {
}

if (i === 1 && this.parent !== null) {
this.reporter.subtest(this.indent, this.name);
this.reportSubtest();
}

// Report the subtest's results and remove it from the ready map.
Expand Down Expand Up @@ -631,12 +632,6 @@ class Test extends AsyncResource {
this.processReadySubtestRange(true);

// Output this test's results and update the parent's waiting counter.
if (this.subtests.length > 0) {
this.reporter.plan(this.subtests[0].indent, this.subtests.length);
} else {
this.reporter.subtest(this.indent, this.name);
}

this.report();
this.parent.waitingOn++;
this.finished = true;
Expand All @@ -648,6 +643,11 @@ class Test extends AsyncResource {
}

report() {
if (this.subtests.length > 0) {
this.reporter.plan(this.subtests[0].indent, this.subtests.length);
} else {
this.reportSubtest();
}
let directive;

if (this.skipped) {
Expand All @@ -666,6 +666,15 @@ class Test extends AsyncResource {
this.reporter.diagnostic(this.indent, this.diagnostics[i]);
}
}

reportSubtest() {
if (this.#reportedSubtest || this.parent === null) {
return;
}
this.#reportedSubtest = true;
this.parent.reportSubtest();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the actual fix.

this.reporter.subtest(this.indent, this.name);
}
}

class TestHook extends Test {
Expand Down
10 changes: 10 additions & 0 deletions test/message/test_runner_describe_nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Flags: --no-warnings
'use strict';
require('../common');
const { describe, it } = require('node:test');

describe('nested - no tests', () => {
describe('nested', () => {
it('nested', () => {});
});
});
26 changes: 26 additions & 0 deletions test/message/test_runner_describe_nested.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
TAP version 13
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prior to the fix, output was

TAP version 13
    # Subtest: nested
        # Subtest: nested
        ok 1 - nested
          ---
          duration_ms: 0.132417
          ...
# Subtest: nested - no tests
        1..1
    ok 1 - nested
      ---
      duration_ms: 0.740375
      ...
    1..1
ok 1 - nested - no tests
  ---
  duration_ms: 1.359792
  ...
1..1
# tests 1
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 2.906166

# Subtest: nested - no tests
# Subtest: nested
# Subtest: nested
ok 1 - nested
---
duration_ms: *
...
1..1
ok 1 - nested
---
duration_ms: *
...
1..1
ok 1 - nested - no tests
---
duration_ms: *
...
1..1
# tests 1
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms *