Skip to content

Commit

Permalink
feat(vitest): include coverageMap in json report
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Oct 1, 2024
1 parent 3de00ab commit 7172409
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/vitest/src/node/reporters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { existsSync, promises as fs } from 'node:fs'
import { dirname, resolve } from 'pathe'
import type { File, Suite, TaskMeta, TaskState } from '@vitest/runner'
import type { SnapshotSummary } from '@vitest/snapshot'
import type { CoverageMap } from 'istanbul-lib-coverage'
import { getSuites, getTests } from '../../utils'
import { getOutputFile } from '../../utils/config-helpers'
import type { Reporter } from '../types/reporter'
Expand Down Expand Up @@ -63,7 +64,7 @@ export interface JsonTestResults {
success: boolean
testResults: Array<JsonTestResult>
snapshot: SnapshotSummary
// coverageMap?: CoverageMap | null | undefined
coverageMap?: CoverageMap | null | undefined
// numRuntimeErrorTestSuites: number
// wasInterrupted: boolean
}
Expand All @@ -86,7 +87,7 @@ export class JsonReporter implements Reporter {
this.start = Date.now()
}

protected async logTasks(files: File[]) {
protected async logTasks(files: File[], coverageMap?: CoverageMap | null) {
const suites = getSuites(files)
const numTotalTestSuites = suites.length
const tests = getTests(files)
Expand Down Expand Up @@ -188,13 +189,14 @@ export class JsonReporter implements Reporter {
startTime: this.start,
success,
testResults,
coverageMap,
}

await this.writeReport(JSON.stringify(result))
}

async onFinished(files = this.ctx.state.getFiles()) {
await this.logTasks(files)
async onFinished(files = this.ctx.state.getFiles(), _errors: unknown[] = [], coverageMap?: unknown) {
await this.logTasks(files, coverageMap as CoverageMap)
}

/**
Expand Down

0 comments on commit 7172409

Please sign in to comment.