Skip to content

Show the trace timeline in test failure output outside browser mode #11701

Description

@hi-ogawa

Clear and concise description of the problem

#11592 prints a browser test's trace steps under its error. Node tests that wait on something could use the same. When expect.poll or vi.waitFor times out, the error shows what didn't match, but not what ran before it or how long each step took. That can help with flaky integration tests, which currently need console.log calls to get the same information.

Suggested solution

Record async steps in Node tests and print the same timeline under the error when a test fails, behind experimental.traceTimeline. For example:

import { expect, test, vi } from 'vitest'
import { api, db, search } from './helpers'

test('finds new user in search', async () => {
  await vi.waitFor(() => search.ping())
  await api.post('/users', { name: 'alice' })
  await vi.waitUntil(() => db.users.findByName('alice'))
  await expect.poll(() => search.query('alice')).toHaveLength(1)
})
 FAIL  search.test.ts > finds new user in search
AssertionError: expected [] to have a length of 1 but got +0
...

Trace:
  step                           start  duration  location
  vi.waitFor()                    +2ms     120ms  search.test.ts:5:12
  vi.waitUntil()                +171ms      42ms  search.test.ts:7:12
  expect.poll().toHaveLength()  +214ms    1001ms  search.test.ts:8:50
  • Steps are the async waits Vitest already knows about: expect.poll, then vi.waitFor and vi.waitUntil. expect(...).resolves/.rejects and toMatchFileSnapshot are candidates too.
  • Only failed attempts keep their steps, like 'failure-only' in Trace View: Failure-Only Trace Recording #10310. A passing test keeps a few entries in memory and sends nothing, so the option costs about nothing on passing tests. That leaves room to enable it by default later.
  • Locations resolve like error stacks, so a step inside a helper file points at the helper, and a step inside vi.defineHelper points at the line that called the helper.
  • The data is the same trace artifact browser mode records, so Vitest UI and the HTML reporter can show it once the trace viewer handles steps without a DOM snapshot, which feat(browser): add failure-only trace view mode #11612 does for failure-only browser traces.

vi.waitFor and a global expect.poll have no test of their own, so they're attributed to the test that's currently running. That's exact for sequential tests. Under test.concurrent the current test is ambiguous, so steps are skipped when more than one test is running. A test that times out but keeps running in the background can still leave a step in the next test's timeline. Vitest has the same limitation for console output and the global expect, and an AsyncLocalStorage-based test context would remove it, which #9751 needs for per-test timeouts as well.

Alternative

experimental.openTelemetry can export the same kind of timing, but reading it means setting up an SDK and a trace viewer and finding the test's spans there. The timeline shows the steps under the error, with no setup.

Additional context

Possible follow-ups:

  • A way for tests and helpers to name their own steps, like page.mark in browser mode. This also covers most of what Add bail option to describe block (support test.step) #7787 asks for under the name test.step. Custom matchers could record steps through the matcher context.
  • A message option on vi.waitFor and vi.waitUntil that names the step and goes into the timeout error, such as vi.waitUntil(() => db.users.findByName('alice'), { message: 'user saved' }). expect.poll already takes message, which could name its step the same way.
  • An 'on' mode that also records passing attempts, so the UI can show their steps, as browser mode has.
  • Hooks and fixtures as steps, since slow setup is a common cause of a timeout blamed on the test body.
  • A per-test async context with AsyncLocalStorage, shared with Unify and simplify timeout configuration #9751.

Activity

  1. added theissue type on Oct 22, 2026
  2. added
    p2-to-be-discussed
    on Oct 22, 2026
  3. moved this to P2 - 3 in Team Boardon Oct 22, 2026
  4. moved this from P2 - 3 to Approved in Team Boardon Oct 23, 2026
  5. removed
    p2-to-be-discussed
    on Oct 23, 2026
  6. locked and limited conversation to collaborators on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions