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

fix: flush coverage after every test file (fix #771) #776

Merged
merged 1 commit into from Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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