From 0898145e3735fd2c4500b69952ea8b40e948d870 Mon Sep 17 00:00:00 2001 From: Richie McColl Date: Sat, 18 Feb 2023 22:36:08 +0000 Subject: [PATCH] test_runner: display skipped tests in spec reporter output PR-URL: https://github.com/nodejs/node/pull/46651 Backport-PR-URL: https://github.com/nodejs/node/pull/46839 Reviewed-By: Colin Ihrig Reviewed-By: Moshe Atlow --- lib/internal/test_runner/reporter/spec.js | 14 +++++++++---- .../test_runner_output_spec_reporter.out | 20 +++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/internal/test_runner/reporter/spec.js b/lib/internal/test_runner/reporter/spec.js index c19d5568d1c5ca..3637c74111c4b7 100644 --- a/lib/internal/test_runner/reporter/spec.js +++ b/lib/internal/test_runner/reporter/spec.js @@ -30,6 +30,7 @@ const symbols = { 'test:pass': '\u2714 ', 'test:diagnostic': '\u2139 ', 'arrow:right': '\u25B6 ', + 'hyphen:minus': '\uFE63 ', }; class SpecReporter extends Transform { #stack = []; @@ -60,8 +61,8 @@ class SpecReporter extends Transform { return `\n${indent} ${message}\n`; } #handleEvent({ type, data }) { - const color = colors[type] ?? white; - const symbol = symbols[type] ?? ' '; + let color = colors[type] ?? white; + let symbol = symbols[type] ?? ' '; switch (type) { case 'test:fail': @@ -81,15 +82,20 @@ class SpecReporter extends Transform { ArrayPrototypeUnshift(this.#reported, msg); prefix += `${this.#indent(msg.nesting)}${symbols['arrow:right']}${msg.name}\n`; } + const skippedSubtest = subtest && data.skip && data.skip !== undefined; const indent = this.#indent(data.nesting); const duration_ms = data.details?.duration_ms ? ` ${gray}(${data.details.duration_ms}ms)${white}` : ''; - const title = `${data.name}${duration_ms}`; + const title = `${data.name}${duration_ms}${skippedSubtest ? ' # SKIP' : ''}`; if (this.#reported[0] && this.#reported[0].nesting === data.nesting && this.#reported[0].name === data.name) { - // If this test has had children - it was already reporter, so slightly modify the output + // If this test has had children - it was already reported, so slightly modify the output ArrayPrototypeShift(this.#reported); return `${prefix}${indent}${color}${symbols['arrow:right']}${white}${title}\n\n`; } const error = this.#formatError(data.details?.error, indent); + if (skippedSubtest) { + color = gray; + symbol = symbols['hyphen:minus']; + } return `${prefix}${indent}${color}${symbol}${title}${error}${white}\n`; } case 'test:start': diff --git a/test/message/test_runner_output_spec_reporter.out b/test/message/test_runner_output_spec_reporter.out index cf47c7ac7e33ff..88ce796a783eeb 100644 --- a/test/message/test_runner_output_spec_reporter.out +++ b/test/message/test_runner_output_spec_reporter.out @@ -20,8 +20,8 @@ * * - sync skip pass (*ms) - sync skip pass with message (*ms) + sync skip pass (*ms) # SKIP + sync skip pass with message (*ms) # SKIP sync pass (*ms) this test should pass sync throw fail (*ms) @@ -34,7 +34,7 @@ * * - async skip pass (*ms) + async skip pass (*ms) # SKIP async pass (*ms) async throw fail (*ms) Error: thrown from async throw fail @@ -46,7 +46,7 @@ * * - async skip fail (*ms) + async skip fail (*ms) # SKIP Error: thrown from async throw fail * * @@ -129,8 +129,8 @@ top level (*ms) invalid subtest - pass but subtest fails (*ms) - sync skip option (*ms) - sync skip option with message (*ms) + sync skip option (*ms) # SKIP + sync skip option with message (*ms) # SKIP sync skip option is false fail (*ms) Error: this should be executed * @@ -146,13 +146,13 @@ (*ms) test with only a name provided (*ms) (*ms) - (*ms) - test with a name and options provided (*ms) - functionAndOptions (*ms) + (*ms) # SKIP + test with a name and options provided (*ms) # SKIP + functionAndOptions (*ms) # SKIP escaped description \ # * * (*ms) - escaped skip message (*ms) + escaped skip message (*ms) # SKIP escaped todo message (*ms) escaped diagnostic (*ms) #diagnostic