Skip to content

Commit

Permalink
fix: clean coverage-c8 tmp before reporting (fix vitest-dev#1917)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan committed Aug 27, 2022
1 parent 88d5764 commit efd3f79
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/coverage-c8/src/provider.ts
@@ -1,4 +1,4 @@
import { existsSync, promises as fs } from 'fs'
import { existsSync, promises as fs, mkdirSync, rmSync } from 'fs'
import _url from 'url'
import type { Profiler } from 'inspector'
import { takeCoverage } from 'v8'
Expand Down Expand Up @@ -29,6 +29,18 @@ export class C8CoverageProvider implements CoverageProvider {
}

onBeforeFilesRun() {
let tmpExist = existsSync(this.options.tempDirectory)

// clean tmp dir before run
if (tmpExist) {
rmSync(this.options.tempDirectory, { recursive: true, force: true })
tmpExist = false
}

// make sure tmp dir exist before run
if (!tmpExist)
mkdirSync(this.options.tempDirectory, { recursive: true })

process.env.NODE_V8_COVERAGE ||= this.options.tempDirectory
}

Expand Down

0 comments on commit efd3f79

Please sign in to comment.