Skip to content

Commit

Permalink
fix: make takeCoverage call optional (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
Demivan committed Feb 3, 2022
1 parent 07fa187 commit dfa494d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/vitest/src/integrations/coverage.ts
@@ -1,5 +1,4 @@
import { existsSync, promises as fs } from 'fs'
import { takeCoverage } from 'v8'
import { createRequire } from 'module'
import { pathToFileURL } from 'url'
import type { Profiler } from 'inspector'
Expand Down Expand Up @@ -57,7 +56,11 @@ const require = createRequire(import.meta.url)

export async function reportCoverage(ctx: Vitest) {
// Flush coverage to disk
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()

// eslint-disable-next-line @typescript-eslint/no-var-requires
const createReport = require('c8/lib/report')
Expand Down

0 comments on commit dfa494d

Please sign in to comment.