Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vitest): include coverageMap in json report #6606

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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