Skip to content

Commit

Permalink
fix: flush coverage after every test file (fix #771) (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
Demivan committed Feb 18, 2022
1 parent c98355a commit 7611178
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/vitest/src/integrations/coverage.ts
Expand Up @@ -32,13 +32,17 @@ export async function cleanCoverage(options: ResolvedC8Options, clean = true) {

const require = createRequire(import.meta.url)

export async function reportCoverage(ctx: Vitest) {
// Flush coverage to disk
// Flush coverage to disk
export function takeCoverage() {
const v8 = require('v8')
if (v8.takeCoverage == null)
console.warn('[Vitest] takeCoverage is not available in this NodeJs version.\nCoverage could be incomplete. Update to NodeJs 14.18.')
else
v8.takeCoverage()
}

export async function reportCoverage(ctx: Vitest) {
takeCoverage()

// eslint-disable-next-line @typescript-eslint/no-var-requires
const createReport = require('c8/lib/report')
Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/runtime/run.ts
Expand Up @@ -4,6 +4,7 @@ import { vi } from '../integrations/vi'
import { getSnapshotClient } from '../integrations/snapshot/chai'
import { getFullName, hasFailed, hasTests, partitionSuiteChildren } from '../utils'
import { getState, setState } from '../integrations/chai/jest-expect'
import { takeCoverage } from '../integrations/coverage'
import { getFn, getHooks } from './map'
import { rpc } from './rpc'
import { collectTests } from './collect'
Expand Down Expand Up @@ -207,6 +208,8 @@ export async function startTests(paths: string[], config: ResolvedConfig) {

await runSuites(files)

takeCoverage()

await getSnapshotClient().saveSnap()

await sendTasksUpdate()
Expand Down

0 comments on commit 7611178

Please sign in to comment.