fix: prevent duplicate bench result table for top-level bench() calls#9968
Open
restareaByWeezy wants to merge 2 commits intovitest-dev:mainfrom
Open
fix: prevent duplicate bench result table for top-level bench() calls#9968restareaByWeezy wants to merge 2 commits intovitest-dev:mainfrom
restareaByWeezy wants to merge 2 commits intovitest-dev:mainfrom
Conversation
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.
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
9171140 to
9d15ec8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9718
Root Cause
When
bench()is used at the top level of a file (outside anydescribe()), the result table was printed twice.The benchmark runner (
runBenchmarkSuite) emits asuite-finishedevent for the file itself when it contains direct benchmark tasks. After that call returns, the generalrunSuitewrapper also unconditionally emitssuite-finishedfor the same file. This results in twosuite-finishedevents for the file → twoonTestModuleEndcalls → twoprintSuiteTableinvocations.Fix
Skip emitting
suite-finishedinrunBenchmarkSuitewhen the suite is the file root (suite.file === suite). The generalrunSuitewrapper already handles this event for the file level. Fordescribe-level suites,suite.file !== suite, so they continue to emit normally as before.Test
test/cli/fixtures/benchmarking/reporter/multiple.bench.tsdirectly demonstrates the fix: running it before the fix produces the result table twice; after the fix, once.benchmarking.test.tstests pass.