diff --git a/packages/coverage-v8/src/provider.ts b/packages/coverage-v8/src/provider.ts index e0e34b40bea8..e393ddc7abc1 100644 --- a/packages/coverage-v8/src/provider.ts +++ b/packages/coverage-v8/src/provider.ts @@ -235,10 +235,10 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage }, }) } - - this.coverageFiles = new Map() - await fs.rm(this.coverageFilesDirectory, { recursive: true }) } + + this.coverageFiles = new Map() + await fs.rm(this.coverageFilesDirectory, { recursive: true }) } private async getUntestedFiles(testedFiles: string[]): Promise { diff --git a/test/coverage-test/coverage-report-tests/generic.report.test.ts b/test/coverage-test/coverage-report-tests/generic.report.test.ts index cbff56cc9ee0..42147822a541 100644 --- a/test/coverage-test/coverage-report-tests/generic.report.test.ts +++ b/test/coverage-test/coverage-report-tests/generic.report.test.ts @@ -184,3 +184,10 @@ test('multi environment coverage is merged correctly', async () => { // Condition covered by both tests expect(lineCoverage[30]).toBe(2) }) + +test('temporary files are removed after test', async () => { + const coveragePath = resolve('./coverage') + const files = fs.readdirSync(coveragePath) + + expect(files).not.toContain('.tmp') +})