Skip to content

Commit

Permalink
chore: benchmark word error change (#5886)
Browse files Browse the repository at this point in the history
  • Loading branch information
minsgy committed Jun 16, 2024
1 parent 8800601 commit 84a4fdb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions packages/vitest/src/node/reporters/benchmark/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class TableReporter extends BaseReporter {
if (this.ctx.config.benchmark?.compare) {
const compareFile = pathe.resolve(this.ctx.config.root, this.ctx.config.benchmark?.compare)
try {
this.rendererOptions.compare = flattenFormattedBenchamrkReport(
this.rendererOptions.compare = flattenFormattedBenchmarkReport(
JSON.parse(
await fs.promises.readFile(compareFile, 'utf-8'),
),
Expand Down Expand Up @@ -80,7 +80,7 @@ export class TableReporter extends BaseReporter {
const outputDirectory = pathe.dirname(outputFile)
if (!fs.existsSync(outputDirectory))
await fs.promises.mkdir(outputDirectory, { recursive: true })
const output = createFormattedBenchamrkReport(files)
const output = createFormattedBenchmarkReport(files)
await fs.promises.writeFile(outputFile, JSON.stringify(output, null, 2))
this.ctx.logger.log(`Benchmark report written to ${outputFile}`)
}
Expand Down Expand Up @@ -109,7 +109,7 @@ export class TableReporter extends BaseReporter {
}
}

export interface FormattedBenchamrkReport {
export interface FormattedBenchmarkReport {
files: {
filepath: string
groups: FormattedBenchmarkGroup[]
Expand All @@ -132,8 +132,8 @@ export type FormattedBenchmarkResult = Omit<BenchmarkResult, 'samples'> & {
median: number
}

function createFormattedBenchamrkReport(files: File[]) {
const report: FormattedBenchamrkReport = { files: [] }
function createFormattedBenchmarkReport(files: File[]) {
const report: FormattedBenchmarkReport = { files: [] }
for (const file of files) {
const groups: FormattedBenchmarkGroup[] = []
for (const task of getTasks(file)) {
Expand Down Expand Up @@ -169,7 +169,7 @@ function createFormattedBenchamrkReport(files: File[]) {
return report
}

function flattenFormattedBenchamrkReport(report: FormattedBenchamrkReport): FlatBenchmarkReport {
function flattenFormattedBenchmarkReport(report: FormattedBenchmarkReport): FlatBenchmarkReport {
const flat: FlatBenchmarkReport = {}
for (const file of report.files) {
for (const group of file.groups) {
Expand Down
4 changes: 2 additions & 2 deletions test/benchmark/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs'
import { expect, it } from 'vitest'
import * as pathe from 'pathe'
import type { FormattedBenchamrkReport } from 'vitest/src/node/reporters/benchmark/table/index.js'
import type { FormattedBenchmarkReport } from 'vitest/src/node/reporters/benchmark/table/index.js'
import { runVitest } from '../../test-utils'

it('basic', { timeout: 60_000 }, async () => {
Expand All @@ -17,7 +17,7 @@ it('basic', { timeout: 60_000 }, async () => {
expect(result.exitCode).toBe(0)

const benchResult = await fs.promises.readFile(benchFile, 'utf-8')
const resultJson: FormattedBenchamrkReport = JSON.parse(benchResult)
const resultJson: FormattedBenchmarkReport = JSON.parse(benchResult)
const names = resultJson.files.map(f => f.groups.map(g => [g.fullName, g.benchmarks.map(b => b.name)]))
expect(names).toMatchInlineSnapshot(`
[
Expand Down

0 comments on commit 84a4fdb

Please sign in to comment.