Skip to content

Commit

Permalink
fix: always use same coverage output filename
Browse files Browse the repository at this point in the history
  • Loading branch information
BenShelton committed Sep 30, 2024
1 parent dc06060 commit bb7d9b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export const setupFilePath = resolve(__dirname, 'setupFile.mjs')

export const configGlob = '**/*{vite,vitest}*.config*.{ts,js,mjs,cjs,cts,mts}'
export const workspaceGlob = '**/*vitest.{workspace,projects}*.{ts,js,mjs,cjs,cts,mts,json}'

export const finalCoverageFileName = 'coverage-final.json'
5 changes: 2 additions & 3 deletions src/coverage.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { readFileSync } from 'node:fs'
import { IstanbulCoverageContext, IstanbulMissingCoverageError } from 'istanbul-to-vscode'
import { join } from 'pathe'
import { finalCoverageFileName } from './constants'

export const coverageContext = new IstanbulCoverageContext()

const FINAL_COVERAGE_FILE_NAME = 'coverage-final.json'

export function readCoverageReport(reportsDirectory: string) {
try {
return JSON.parse(readFileSync(join(reportsDirectory, FINAL_COVERAGE_FILE_NAME), 'utf8'))
return JSON.parse(readFileSync(join(reportsDirectory, finalCoverageFileName), 'utf8'))
}
catch (err: any) {
throw new IstanbulMissingCoverageError(reportsDirectory, err)
Expand Down
8 changes: 7 additions & 1 deletion src/worker/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'pathe'
import type { CoverageProvider, ResolvedCoverageOptions, Vitest as VitestCore } from 'vitest/node'
import { finalCoverageFileName } from '../constants'
import type { Vitest } from './vitest'

export class VitestCoverage {
Expand Down Expand Up @@ -60,7 +61,12 @@ export class VitestCoverage {
this._enabled = true

const jsonReporter = this._config.reporter.find(([name]) => name === 'json')
this._config.reporter = [jsonReporter || ['json', {}]]
this._config.reporter = [
['json', {
...jsonReporter?.[1],
file: finalCoverageFileName,
}],
]
this._config.reportOnFailure = true
this._config.reportsDirectory = join(tmpdir(), `vitest-coverage-${randomUUID()}`)

Expand Down

0 comments on commit bb7d9b8

Please sign in to comment.