diff --git a/test/benchmark/fixtures/reporter/multiple.bench.ts b/test/benchmark/fixtures/reporter/multiple.bench.ts new file mode 100644 index 000000000000..1b204ffa7a96 --- /dev/null +++ b/test/benchmark/fixtures/reporter/multiple.bench.ts @@ -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) diff --git a/test/benchmark/test/reporter.test.ts b/test/benchmark/test/reporter.test.ts index f5c89d52b878..4e3895ede04e 100644 --- a/test/benchmark/test/reporter.test.ts +++ b/test/benchmark/test/reporter.test.ts @@ -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 () => { @@ -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( {