Skip to content

feat: record hooks and fixtures in trace timeline - #11755

Draft
hi-ogawa wants to merge 1 commit into
mainfrom
feat/trace-timeline-hooks
Draft

hi-ogawa wants to merge 1 commit into
mainfrom
feat/trace-timeline-hooks

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

WIP 🤖

Slow setup is a common cause of a timeout that gets blamed on the test body, but a timeline that only shows polls and waits has nothing to say about it. With this PR, experimental.traceTimeline also records the hooks and fixtures that run for each test attempt, so the timeline shows where the time went before and during the test body.

Trace:
  step                       start  duration  location
  aroundEach                  +0ms      21ms  basic.test.ts:13:1
  beforeEach                 +21ms     134ms  basic.test.ts:18:1
  ├── fixture server         +22ms      32ms  basic.test.ts:5:19
  │   └── vi.waitFor()       +22ms      31ms  basic.test.ts:7:14
  └── expect.poll().toBe()  +155ms       0ms  basic.test.ts:20:35
  expect.poll().toBe()      +155ms     102ms  basic.test.ts:26:53

The recorded steps are beforeEach and its returned cleanup, afterEach, aroundEach setup and teardown, onTestFinished, onTestFailed, and fixture setup and teardown. Each step points at where the hook or test.extend was called, and a poll, wait, or fixture that runs inside a hook nests under it. Hooks know their test exactly, so they are attributed correctly under test.concurrent too. The attempt now starts before aroundEach and ends after its fixtures are torn down, so the whole attempt is covered.

Steps after the test body, such as afterEach, fixture teardown, and onTestFinished, are printed in the terminal only when they fail or don't finish. They can't cause a test timeout and rarely explain the failure, but they would push the setup and poll steps out of the 10-step limit. The recorded trace still keeps them, with a vitest:onTaskFinished entry that marks where the test body ended, so a trace viewer can show them all.

beforeAll and afterAll are not recorded, because they run once per suite rather than per attempt, and a failure there is reported on the suite, which has no timeline. Browser mode is unchanged, because the option has no effect there and browser.traceView does not record hooks either.

The option still adds no measurable cost to passing tests. On 20,000 passing tests that each run aroundEach, beforeEach with cleanup, afterEach, a fixture, and onTestFinished (one worker, 8 interleaved runs), the run took 2.31s on average with the option off and 2.32s with it on, which is within run-to-run noise.

@hi-ogawa
hi-ogawa changed the base branch from feat/node-trace-timeline to feat/trace-timeline-wait-message October 27, 2026 07:06
@hi-ogawa
hi-ogawa added this pull request to stack #11758 October 27, 2026 07:06
@netlify

netlify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 846cae0
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6ae836e70075c2d2093613dc
😎 Deploy Preview https://deploy-preview-11755--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Base automatically changed from feat/trace-timeline-wait-message to main November 2, 2026 06:56
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@hi-ogawa
hi-ogawa force-pushed the feat/trace-timeline-hooks branch from c0ac9d4 to 846cae0 Compare November 2, 2026 07:08
@flakiness-io

flakiness-io Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Test Results Summary

This comment shows the latest test results for this pull request.

Commit Status Test Results CI Runs
846cae0 ✅ Passed 31317 passed · 234 flaky · 1179 skipped 27 runs
⚠️ 234 flaky

⚠️ Ubuntu 24.04 · threads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ win 10.0.26100 · vmThreads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ win 10.0.26100 · threads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · threads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · vmThreads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · forks test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ win 10.0.26100 · forks test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · vmThreads test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · forks test/unit/test/retry.test.ts:55 › describe object add(1, 1) › returned value not be greater than 2
⚠️ Ubuntu 24.04 · threads test/unit/test/retry.test.ts:61 › describe object add(1, 1) › returned value not be less than 2
…and 224 more

View full report

ℹ️ About Flakiness.io in GitHub

Your team has set up Flakiness.io pull request comments. This comment is updated when

  • The first test results arrive for this pull request
  • A later run reports more results for the same commit
  • A new commit is pushed and tested

Flakiness.io rewrites the comment in place, so it always reflects the most recently tested commit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Record hooks and fixtures in the trace timeline

1 participant