From d18d92f700aa09934348e5f0f1794b179f5d1d71 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Fri, 28 Oct 2022 10:28:21 +0300 Subject: [PATCH] fix: report tap subtest in order PR-URL: https://github.com/nodejs/node/pull/45220 Reviewed-By: Colin Ihrig Reviewed-By: Benjamin Gruenbaum (cherry picked from commit 3e57891ee2fde0971e18fc383c25acf8f90def05) --- lib/internal/test_runner/test.js | 25 +++++++++++++------ test/message/test_runner_describe_nested.js | 11 +++++++++ test/message/test_runner_describe_nested.out | 26 ++++++++++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 test/message/test_runner_describe_nested.js create mode 100644 test/message/test_runner_describe_nested.out diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index ce1ae08..166053f 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -1,4 +1,4 @@ -// https://github.com/nodejs/node/blob/a69a30016cf3395b0bd775c1340ab6ecbac58296/lib/internal/test_runner/test.js +// https://github.com/nodejs/node/blob/3e57891ee2fde0971e18fc383c25acf8f90def05/lib/internal/test_runner/test.js 'use strict' @@ -146,6 +146,7 @@ class TestContext { class Test extends AsyncResource { #abortController #outerSignal + #reportedSubtest constructor (options) { super('Test') @@ -312,7 +313,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. @@ -635,12 +636,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 @@ -652,6 +647,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) { @@ -670,6 +670,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() + this.reporter.subtest(this.indent, this.name) + } } class TestHook extends Test { diff --git a/test/message/test_runner_describe_nested.js b/test/message/test_runner_describe_nested.js new file mode 100644 index 0000000..e60ebf6 --- /dev/null +++ b/test/message/test_runner_describe_nested.js @@ -0,0 +1,11 @@ +// https://github.com/nodejs/node/blob/3e57891ee2fde0971e18fc383c25acf8f90def05/test/message/test_runner_describe_nested.js +// Flags: --no-warnings +'use strict' +require('../common') +const { describe, it } = require('#node:test') + +describe('nested - no tests', () => { + describe('nested', () => { + it('nested', () => {}) + }) +}) diff --git a/test/message/test_runner_describe_nested.out b/test/message/test_runner_describe_nested.out new file mode 100644 index 0000000..1d3fe31 --- /dev/null +++ b/test/message/test_runner_describe_nested.out @@ -0,0 +1,26 @@ +TAP version 13 +# 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 *