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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose getBenchFn to be able to access benchmarks functions in a custom runner #4170

Closed
4 tasks done
adriencaccia opened this issue Sep 23, 2023 · 0 comments · Fixed by #4208
Closed
4 tasks done

Expose getBenchFn to be able to access benchmarks functions in a custom runner #4170

adriencaccia opened this issue Sep 23, 2023 · 0 comments · Fixed by #4208
Labels
enhancement New feature or request pr welcome

Comments

@adriencaccia
Copy link
Contributor

adriencaccia commented Sep 23, 2023

Clear and concise description of the problem

I am writing a custom runner for benchmarks. I used https://github.com/vitest-dev/vitest/tree/main/packages/vitest/src/runtime/runners/benchmark.ts as a reference and got blocked when I needed to access the registered functions through bench.
In NodeBenchmarkRunner's implementation, they are retrieved thanks to the following line

const benchmarkFn = getBenchFn(benchmark)

However, getBenchFn is not exposed, so I cannot access it in my custom runner.

Suggested solution

Export getBenchFn from a new vitest/bench namespace, or somewhere else.

Alternative

No response

Additional context

The equivalent getFn function to retrieve test functions is already exported from vitest/suite:

export { setFn, getFn } from './map'

So I think that it would make sense to export getBenchFn, and maybe getBenchOptions too.

I would be more than happy to submit a pull request if you accept this proposal!

For context, the custom runner would be to support vitest on https://codspeed.io/, I already talked about it on discord with @Aslemammad

P.S. Thank you for such an amazing project!

Validations

@sheremet-va sheremet-va added enhancement New feature or request pr welcome labels Oct 1, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants