Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ benchmark ] unable to use the json reporter #5953

Open
6 tasks done
mouhannad-sh opened this issue Jun 22, 2024 · 2 comments
Open
6 tasks done

[ benchmark ] unable to use the json reporter #5953

mouhannad-sh opened this issue Jun 22, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@mouhannad-sh
Copy link

Describe the bug

Hi 馃憢馃徎
Thank you for adding the ability to run benchmarking inside of Vitest, it's 馃敟

In the documentation for benchmark outputfile the json reporter was mentioned as the only way to output benchmark results and compare against previous results via the compare option However, when I follow the instructions to configure my vitest benchmarks I get this error

Error: Failed to load custom Reporter from json

Additionally, I noticed that the BenchmarkBuiltinReporters only include "default" and "verbose" and both don't seem to allow us to output benchmark results into a file.

I would like to be able to export the benchmark results and compare them to a previous run if possible

Reproduction

run npm run bench

https://stackblitz.com/edit/vitest-dev-vitest-1qwwb1?file=vite.config.ts

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitest/ui: latest => 1.6.0 
    vite: latest => 5.3.1 
    vitest: latest => 1.6.0

Used Package Manager

npm

Validations

@hi-ogawa
Copy link
Contributor

It looks like the documentation of benchmark.outputFile is a little outdated. For comparison, you need to use benchmark.outputJson and benchmark.compare combo as shown in https://vitest.dev/config/#benchmark-outputJson

# save main branch's result
git checkout main
vitest bench --outputJson main.json

# change a branch and compare against main
git checkout feature
vitest bench --compare main.json

Technically, you can put a same file to both options like below, but this will always overwrite bench.json, so that's a bit different from the intended usage.

export default defineConfig({
  test: {
    benchmark: {
      outputJson: './bench.json',
      compare: './bench.json'
    },
  },
});

@hi-ogawa hi-ogawa added documentation Improvements or additions to documentation and removed pending triage labels Jun 22, 2024
@mouhannad-sh
Copy link
Author

Thanks @hi-ogawa this works with a small gotcha

It will fail at the first runtime if there's no bench.json file present. might be worth adding this detail to the docs too

I updated the Stackblitz link to reflect this
thanks a bunch !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants