From e57992ffb2e30834fbd7c3521ecf6d2df28a35fd Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Wed, 3 Apr 2024 02:03:13 +0300 Subject: [PATCH] test_runner: hide new line when no error in spec reporter PR-URL: https://github.com/nodejs/node/pull/52297 Reviewed-By: Colin Ihrig Reviewed-By: Benjamin Gruenbaum Reviewed-By: Chemi Atlow --- lib/internal/test_runner/reporter/spec.js | 4 ++-- .../test-runner/output/default_output.snapshot | 1 - .../output/hooks_spec_reporter.snapshot | 14 -------------- .../test-runner/output/spec_reporter.snapshot | 6 ------ .../test-runner/output/spec_reporter_cli.snapshot | 6 ------ .../test-runner/output/suite-skip-hooks.snapshot | 1 - 6 files changed, 2 insertions(+), 30 deletions(-) diff --git a/lib/internal/test_runner/reporter/spec.js b/lib/internal/test_runner/reporter/spec.js index b1f071d567ed32..fd4313ae19b615 100644 --- a/lib/internal/test_runner/reporter/spec.js +++ b/lib/internal/test_runner/reporter/spec.js @@ -83,8 +83,8 @@ class SpecReporter extends Transform { const error = this.#formatError(data.details?.error, indent); if (hasChildren) { // If this test has had children - it was already reported, so slightly modify the output - const err = data.details?.error?.failureType === 'subtestsFailed' ? '' : error; - return `${prefix}${indent}${color}${symbols['arrow:right']}${colors.white}${title}\n${err}`; + const err = !error || data.details?.error?.failureType === 'subtestsFailed' ? '' : `\n${error}`; + return `${prefix}${indent}${color}${symbols['arrow:right']}${colors.white}${title}${err}`; } if (skip !== undefined) { color = colors.gray; diff --git a/test/fixtures/test-runner/output/default_output.snapshot b/test/fixtures/test-runner/output/default_output.snapshot index d91db3bd9e54fe..96450b05bc7ec8 100644 --- a/test/fixtures/test-runner/output/default_output.snapshot +++ b/test/fixtures/test-runner/output/default_output.snapshot @@ -28,7 +28,6 @@ [32m'test did not finish before its parent and was cancelled'[39m [31m▶ [39mparent [90m(*ms)[39m - [34mℹ tests 6[39m [34mℹ suites 0[39m [34mℹ pass 1[39m diff --git a/test/fixtures/test-runner/output/hooks_spec_reporter.snapshot b/test/fixtures/test-runner/output/hooks_spec_reporter.snapshot index 4158335409aba1..ce748bba437050 100644 --- a/test/fixtures/test-runner/output/hooks_spec_reporter.snapshot +++ b/test/fixtures/test-runner/output/hooks_spec_reporter.snapshot @@ -6,9 +6,7 @@ nested 1 (*ms) nested 2 (*ms) nested (*ms) - describe hooks (*ms) - describe hooks - no subtests (*ms) before throws 1 @@ -96,7 +94,6 @@ * beforeEach throws (*ms) - afterEach throws 1 (*ms) Error: afterEach @@ -124,7 +121,6 @@ * afterEach throws (*ms) - afterEach when test fails 1 (*ms) Error: test @@ -141,7 +137,6 @@ 2 (*ms) afterEach when test fails (*ms) - afterEach throws and test fails 1 (*ms) Error: test @@ -169,7 +164,6 @@ * afterEach throws and test fails (*ms) - test hooks 1 (*ms) 2 (*ms) @@ -177,9 +171,7 @@ nested 1 (*ms) nested 2 (*ms) nested (*ms) - test hooks (*ms) - test hooks - no subtests (*ms) t.before throws 1 (*ms) @@ -293,7 +285,6 @@ * t.beforeEach throws (*ms) - t.afterEach throws 1 (*ms) Error: afterEach @@ -322,7 +313,6 @@ * t.afterEach throws (*ms) - afterEach when test fails 1 (*ms) Error: test @@ -338,11 +328,9 @@ 2 (*ms) afterEach when test fails (*ms) - afterEach context when test passes 1 (*ms) afterEach context when test passes (*ms) - afterEach context when test fails 1 (*ms) Error: test @@ -352,7 +340,6 @@ * afterEach context when test fails (*ms) - afterEach throws and test fails 1 (*ms) Error: test @@ -380,7 +367,6 @@ * afterEach throws and test fails (*ms) - t.after() is called if test body throws (*ms) Error: bye * diff --git a/test/fixtures/test-runner/output/spec_reporter.snapshot b/test/fixtures/test-runner/output/spec_reporter.snapshot index a15ce8261bfc65..8162dafcdc0350 100644 --- a/test/fixtures/test-runner/output/spec_reporter.snapshot +++ b/test/fixtures/test-runner/output/spec_reporter.snapshot @@ -107,7 +107,6 @@ this subtest should make its parent test fail subtest sync throw fail (*ms) - sync throw non-error fail (*ms) Symbol(thrown symbol from sync throw non-error fail) @@ -117,7 +116,6 @@ level 1c (*ms) level 1d (*ms) level 0a (*ms) - top level +long running (*ms) 'test did not finish before its parent and was cancelled' @@ -125,9 +123,7 @@ +short running ++short running (*ms) +short running (*ms) - top level (*ms) - invalid subtest - pass but subtest fails (*ms) sync skip option (*ms) # SKIP sync skip option with message (*ms) # this is skipped @@ -197,7 +193,6 @@ 'only' and 'runOnly' require the --test-only command-line option. running subtest 4 (*ms) only is set but not in only mode (*ms) - 'only' and 'runOnly' require the --test-only command-line option. custom inspect symbol fail (*ms) customized @@ -231,7 +226,6 @@ * subtest sync throw fails (*ms) - timed out async test (*ms) 'test timed out after *ms' diff --git a/test/fixtures/test-runner/output/spec_reporter_cli.snapshot b/test/fixtures/test-runner/output/spec_reporter_cli.snapshot index 79e7ecbd61d88f..9386a6db82753f 100644 --- a/test/fixtures/test-runner/output/spec_reporter_cli.snapshot +++ b/test/fixtures/test-runner/output/spec_reporter_cli.snapshot @@ -107,7 +107,6 @@ this subtest should make its parent test fail subtest sync throw fail (*ms) - sync throw non-error fail (*ms) Symbol(thrown symbol from sync throw non-error fail) @@ -117,7 +116,6 @@ level 1c (*ms) level 1d (*ms) level 0a (*ms) - top level +long running (*ms) 'test did not finish before its parent and was cancelled' @@ -125,9 +123,7 @@ +short running ++short running (*ms) +short running (*ms) - top level (*ms) - invalid subtest - pass but subtest fails (*ms) sync skip option (*ms) # SKIP sync skip option with message (*ms) # this is skipped @@ -197,7 +193,6 @@ 'only' and 'runOnly' require the --test-only command-line option. running subtest 4 (*ms) only is set but not in only mode (*ms) - 'only' and 'runOnly' require the --test-only command-line option. custom inspect symbol fail (*ms) customized @@ -231,7 +226,6 @@ * subtest sync throw fails (*ms) - timed out async test (*ms) 'test timed out after *ms' diff --git a/test/fixtures/test-runner/output/suite-skip-hooks.snapshot b/test/fixtures/test-runner/output/suite-skip-hooks.snapshot index 610b1d984530d9..b7fc826426eaf9 100644 --- a/test/fixtures/test-runner/output/suite-skip-hooks.snapshot +++ b/test/fixtures/test-runner/output/suite-skip-hooks.snapshot @@ -13,7 +13,6 @@ AFTER 2 ﹣ should not run (*ms) # SKIP ✔ should run 2 (*ms) ▶ suite runs with mixture of skipped tests (*ms) - ℹ tests 4 ℹ suites 2 ℹ pass 2