Skip to content

Only print failing assertion once with spec reporter #56316

Closed
@legendecas

Description

@legendecas

What is the problem this feature will solve?

The default test runner reporter spec prints an error twice. For example, with the following simple test:

const test = require('node:test');

test('foo', () => {
  throw new Error('foo');
});

The command node --test test.js, or node test.js prints:

✖ foo (0.308375ms)
  Error: foo
      at TestContext.<anonymous> (/Users/cwu631/Developer/nodejs/node/test.js:4:9)
      at Test.runInAsyncScope (node:async_hooks:211:14)
      at Test.run (node:internal/test_runner/test:931:25)
      at Test.start (node:internal/test_runner/test:829:17)
      at startSubtestAfterBootstrap (node:internal/test_runner/harness:297:17)

ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 50.714375

✖ failing tests:

test at t.js:3:1
✖ foo (0.308375ms)
  Error: foo
      at TestContext.<anonymous> (/Users/cwu631/Developer/nodejs/node/test.js:4:9)
      at Test.runInAsyncScope (node:async_hooks:211:14)
      at Test.run (node:internal/test_runner/test:931:25)
      at Test.start (node:internal/test_runner/test:829:17)
      at startSubtestAfterBootstrap (node:internal/test_runner/harness:297:17

A single test caused two identical errors in the output.

When there are 2 or more test failures, the output is really verbose to be inspected by a human -- are these the same failures?

This hurts the experience with node:test in node core development. A change can fail many cases in the test, and every test failure is printed twice, causing super long outputs.

What is the feature you are proposing to solve the problem?

Only print a single test identical failure detail exactly once. This reduces the length of the output on failure and allow people to focus, rather than been distracted by the verbose long output.

✖ foo (0.308375ms)
  Error: foo
      at TestContext.<anonymous> (/Users/cwu631/Developer/nodejs/node/test.js:4:9)
      at Test.runInAsyncScope (node:async_hooks:211:14)
      at Test.run (node:internal/test_runner/test:931:25)
      at Test.start (node:internal/test_runner/test:829:17)
      at startSubtestAfterBootstrap (node:internal/test_runner/harness:297:17)

ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 50.714375

✖ failing tests:

test at t.js:3:1
✖ foo (0.308375ms)

What alternatives have you considered?

Don't change the status quo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions