vitest-dev / vitest-dev/vitest

top level `bench` prints result twice

Open
#9,718 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p3-minor-bug
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Describe the bug

When bench is invoked at the top of the module his results are displayed twice.

Wrapping the bench call in a describe doesn't duplicate the results.

sum-without-describe.bench.ts
import { bench } from "vitest";

bench("sum", () => {
  1 + 1;
});

sum-with-describe.bench.ts
import { bench, describe } from "vitest";

describe("sum", () => {
  bench("a", () => {
    1 + 1;
  });
});

Result
 ✓ tests/sum-with-describe.bench.ts > sum 5789ms
     name             hz     min     max    mean     p75     p99    p995    p999     rme   samples
   · a     48,128,806.17  0.0000  0.0327  0.0000  0.0000  0.0000  0.0000  0.0001  ±0.05%  24064404

 ✓ tests/sum-without-describe.bench.ts 5748ms
     name             hz     min     max    mean     p75     p99    p995    p999     rme   samples
   · sum   48,075,917.04  0.0000  0.0334  0.0000  0.0000  0.0000  0.0000  0.0001  ±0.05%  24037959

 ✓ tests/sum-without-describe.bench.ts 5748ms
     name             hz     min     max    mean     p75     p99    p995    p999     rme   samples
   · sum   48,075,917.04  0.0000  0.0334  0.0000  0.0000  0.0000  0.0000  0.0001  ±0.05%  24037959
Reproduction

Code: https://github.com/marcalexiei/vitest-bench-playground
GitHub actions: https://github.com/marcalexiei/vitest-bench-playground/actions/runs/22277251116/job/64441360076

System Info
System:
    OS: macOS 26.3
    CPU: (8) arm64 Apple M3
    Memory: 139.19 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.12.0 - /.nvm/versions/node/v24.12.0/bin/node
    npm: 11.6.2 - /.nvm/versions/node/v24.12.0/bin/npm
    pnpm: 10.28.2 - /.nvm/versions/node/v24.12.0/bin/pnpm
  Browsers:
    Chrome: 144.0.7559.133
    Safari: 26.3
  npmPackages:
    vitest: 4.0.18 => 4.0.18
Used Package Manager

pnpm

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked reproduction with sum-without-describe.bench.ts and compare its output with sum-with-describe.bench.ts. Trace how the top-level bench call is collected and reported, then verify that each benchmark result appears only once while the describe-wrapped case remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.