-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(vitest): support hooks in bench runner #5076
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for fastidious-cascaron-4ded94 canceled.
|
@@ -90,7 +94,12 @@ async function runBenchmarkSuite(suite: Suite, runner: NodeBenchmarkRunner) { | |||
await task.warmup() | |||
tasks.push([ | |||
await new Promise<BenchTask>(resolve => setTimeout(async () => { | |||
resolve(await task.run()) | |||
let beforeEachCleanups: HookCleanupCallback[] = [] | |||
beforeEachCleanups = await callSuiteHook(benchmark.suite, benchmark, 'beforeEach', runner, [benchmark.context, benchmark.suite]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use tinybench's hooks? I don't have any issues with this, but just asking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting idea!
I think we might need to refine what each hook does, since in benchmarking there is one more level of hooks.
At the moment, with my implementation, this is what would happen (I added some comment at the end to see the execution order):
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
bench,
describe,
} from 'vitest'
describe('hooks', () => {
beforeAll(() => {
console.log('beforeAll')
})
beforeEach(() => {
console.log('beforeEach')
})
afterEach(() => {
console.log('afterEach')
})
afterAll(() => {
console.log('afterAll')
})
bench('one', () => {
console.log('bench one')
}, {
setup: () => {
console.log('setup')
},
teardown: () => {
console.log('tearDown')
},
iterations: 10,
time: 1,
})
})
// when the bench is executed, the following should be logged
// beforeAll
// beforeEach
// setup x10
// bench one x10
// tearDown x10
// afterEach
// beforeAll
Do you think it is what should be expected?
As far as using the hooks from tinybench, I can map the *Each
hooks from vitest to the Task
*All
hooks from tinybench.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting edge case, nice, I think let's keep it as is and this should be documented somewhere.
After all, @sheremet-va might have some interesting ideas and insights around this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes more sense to use Vitest's hooks. They are shown in the reporter for example if they take too long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will go and try to add a test that verify the order of execution of the hooks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will switch the PR to draft for the moment, and mark it as ready when I will have added the tests
Fix #5075