Skip to content

fix: prevent duplicate bench result table for top-level bench() calls#9968

Open
restareaByWeezy wants to merge 2 commits intovitest-dev:mainfrom
restareaByWeezy:fix/top-level-bench-duplicate-output
Open

fix: prevent duplicate bench result table for top-level bench() calls#9968
restareaByWeezy wants to merge 2 commits intovitest-dev:mainfrom
restareaByWeezy:fix/top-level-bench-duplicate-output

Conversation

@restareaByWeezy
Copy link
Copy Markdown

Fixes #9718

Root Cause

When bench() is used at the top level of a file (outside any describe()), the result table was printed twice.

The benchmark runner (runBenchmarkSuite) emits a suite-finished event for the file itself when it contains direct benchmark tasks. After that call returns, the general runSuite wrapper also unconditionally emits suite-finished for the same file. This results in two suite-finished events for the file → two onTestModuleEnd calls → two printSuiteTable invocations.

Fix

Skip emitting suite-finished in runBenchmarkSuite when the suite is the file root (suite.file === suite). The general runSuite wrapper already handles this event for the file level. For describe-level suites, suite.file !== suite, so they continue to emit normally as before.

Test

  • test/cli/fixtures/benchmarking/reporter/multiple.bench.ts directly demonstrates the fix: running it before the fix produces the result table twice; after the fix, once.
  • All existing benchmarking.test.ts tests pass.

Fixes vitest-dev#9718

When bench() is used at the top level of a file (outside any describe()),
runBenchmarkSuite emitted suite-finished for the file root after running
its benchmark tasks. The general runSuite wrapper that calls runner.runSuite()
also unconditionally emits suite-finished for the file after returning,
resulting in two suite-finished events → two onTestModuleEnd calls →
two printSuiteTable invocations.

Skip emitting suite-finished in runBenchmarkSuite when suite.file === suite
(i.e. the suite is the file root). The general wrapper already handles
this event at the file level. For describe-level suites, suite.file !== suite,
so they continue to emit normally.
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 25, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9d15ec8
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69c38cbfb6f9580008f844d8
😎 Deploy Preview https://deploy-preview-9968--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@restareaByWeezy restareaByWeezy force-pushed the fix/top-level-bench-duplicate-output branch from 9171140 to 9d15ec8 Compare March 25, 2026 09:35
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.

top level bench prints result twice

1 participant