diff --git a/packages/vitest/src/runtime/runners/benchmark.ts b/packages/vitest/src/runtime/runners/benchmark.ts index 8166c166424f..d64f556b2014 100644 --- a/packages/vitest/src/runtime/runners/benchmark.ts +++ b/packages/vitest/src/runtime/runners/benchmark.ts @@ -88,30 +88,31 @@ async function runBenchmarkSuite(suite: Suite, runner: VitestRunner) { }) }) - Promise.all(benchmarkGroup.map(async (benchmark) => { + const tasks: BenchTask[] = [] + for (const benchmark of benchmarkGroup) { await benchmark.meta.task!.warmup() const { setTimeout } = getSafeTimers() - return await new Promise(resolve => setTimeout(async () => { + tasks.push(await new Promise(resolve => setTimeout(async () => { resolve(await benchmark.meta.task!.run()) - })) - })).then((tasks) => { - suite.result!.duration = performance.now() - start - suite.result!.state = 'pass' - - tasks - .sort((a, b) => a.result!.mean - b.result!.mean) - .forEach((cycle, idx) => { - const benchmark = benchmarkMap[cycle.name || ''] - benchmark.result!.state = 'pass' - if (benchmark) { - const result = benchmark.result!.benchmark! - result.rank = Number(idx) + 1 - updateTask(benchmark) - } - }) - updateTask(suite) - defer.resolve(null) - }) + }))) + } + + suite.result!.duration = performance.now() - start + suite.result!.state = 'pass' + + tasks + .sort((a, b) => a.result!.mean - b.result!.mean) + .forEach((cycle, idx) => { + const benchmark = benchmarkMap[cycle.name || ''] + benchmark.result!.state = 'pass' + if (benchmark) { + const result = benchmark.result!.benchmark! + result.rank = Number(idx) + 1 + updateTask(benchmark) + } + }) + updateTask(suite) + defer.resolve(null) await defer }