Skip to content

Commit

Permalink
test: failing test case for benchmark's duplicate test reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Dec 13, 2024
1 parent 81be53c commit d4223fd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/benchmark/fixtures/reporter/multiple.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { bench, describe } from 'vitest'
import { setTimeout } from 'node:timers/promises'

const options = { iterations: 1, warmupIterations: 1 }

bench('first', async () => {
await setTimeout(500)
}, options)

bench('second', async () => {
await setTimeout(500)
}, options)
26 changes: 26 additions & 0 deletions test/benchmark/test/reporter.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { RunnerTestCase } from 'vitest'
import * as pathe from 'pathe'
import { assert, expect, it } from 'vitest'
import { TaskParser } from 'vitest/src/node/reporters/task-parser.js'
import { runVitest } from '../../test-utils'

it('summary', async () => {
Expand Down Expand Up @@ -33,6 +35,30 @@ it('non-tty', async () => {
}
})

it('reports passed tasks just once', async () => {
const passed: string[] = []

class CustomReporter extends TaskParser {
onTestFinished(_test: RunnerTestCase): void {
passed.push(_test.name)
}
}

await runVitest({
root: pathe.join(import.meta.dirname, '../fixtures/reporter'),
benchmark: {
reporters: new CustomReporter(),
},
}, ['multiple.bench.ts'], 'benchmark')

expect(passed).toMatchInlineSnapshot(`
[
"first",
"second",
]
`)
})

it.for([true, false])('includeSamples %s', async (includeSamples) => {
const result = await runVitest(
{
Expand Down

0 comments on commit d4223fd

Please sign in to comment.