Skip to content

Commit

Permalink
fix(coverage): prevent crash when cleanOnRerun is disabled (#5540)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Apr 17, 2024
1 parent df6a432 commit ea3c16e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/coverage-istanbul/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,13 @@ export class IstanbulCoverageProvider extends BaseCoverageProvider implements Co
}
}

await fs.rm(this.coverageFilesDirectory, { recursive: true })
this.coverageFiles = new Map()
// In watch mode we need to preserve the previous results if cleanOnRerun is disabled
const keepResults = !this.options.cleanOnRerun && this.ctx.config.watch

if (!keepResults) {
this.coverageFiles = new Map()
await fs.rm(this.coverageFilesDirectory, { recursive: true })
}
}

async getCoverageMapForUncoveredFiles(coveredFiles: string[]) {
Expand Down
9 changes: 7 additions & 2 deletions packages/coverage-v8/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,13 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
}
}

this.coverageFiles = new Map()
await fs.rm(this.coverageFilesDirectory, { recursive: true })
// In watch mode we need to preserve the previous results if cleanOnRerun is disabled
const keepResults = !this.options.cleanOnRerun && this.ctx.config.watch

if (!keepResults) {
this.coverageFiles = new Map()
await fs.rm(this.coverageFilesDirectory, { recursive: true })
}
}

private async getUntestedFiles(testedFiles: string[]): Promise<RawCoverage> {
Expand Down

0 comments on commit ea3c16e

Please sign in to comment.