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(coverage): don't crash when re-run removes earlier run's reports #5022

Merged
Merged
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
27 changes: 11 additions & 16 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,9 @@ export class Vitest {
// populate once, update cache on watch
await this.cache.stats.populateStats(this.config.root, files)

await this.runFiles(files)
await this.runFiles(files, true)
}

await this.reportCoverage(true)

if (this.config.watch)
await this.report('onWatcherStart')
}
Expand Down Expand Up @@ -472,7 +470,7 @@ export class Vitest {
await project.initializeGlobalSetup()
}

async runFiles(paths: WorkspaceSpec[]) {
async runFiles(paths: WorkspaceSpec[], allTestsRun: boolean) {
const filepaths = paths.map(([, file]) => file)
this.state.collectPaths(filepaths)

Expand All @@ -492,6 +490,10 @@ export class Vitest {
this.invalidates.clear()
this.snapshot.clear()
this.state.clearErrors()

if (!this.isFirstRun && this.config.coverage.cleanOnRerun)
await this.coverageProvider?.clean()

await this.initializeGlobalSetup(paths)

try {
Expand All @@ -513,7 +515,10 @@ export class Vitest {
// can be duplicate files if different projects are using the same file
const specs = Array.from(new Set(paths.map(([, p]) => p)))
await this.report('onFinished', this.state.getFiles(specs), this.state.getUnhandledErrors())
await this.reportCoverage(allTestsRun)

this.runningPromise = undefined
this.isFirstRun = false
})

return await this.runningPromise
Expand All @@ -530,13 +535,8 @@ export class Vitest {
files = files.filter(file => filteredFiles.some(f => f[1] === file))
}

if (this.coverageProvider && this.config.coverage.cleanOnRerun)
await this.coverageProvider.clean()

await this.report('onWatcherRerun', files, trigger)
await this.runFiles(files.flatMap(file => this.getProjectsByTestFile(file)))

await this.reportCoverage(!trigger)
await this.runFiles(files.flatMap(file => this.getProjectsByTestFile(file)), !trigger)

await this.report('onWatcherStart', this.state.getFiles(files))
}
Expand Down Expand Up @@ -632,16 +632,11 @@ export class Vitest {

this.changedTests.clear()

if (this.coverageProvider && this.config.coverage.cleanOnRerun)
await this.coverageProvider.clean()

const triggerIds = new Set(triggerId.map(id => relative(this.config.root, id)))
const triggerLabel = Array.from(triggerIds).join(', ')
await this.report('onWatcherRerun', files, triggerLabel)

await this.runFiles(files.flatMap(file => this.getProjectsByTestFile(file)))

await this.reportCoverage(false)
await this.runFiles(files.flatMap(file => this.getProjectsByTestFile(file)), false)

await this.report('onWatcherStart', this.state.getFiles(files))
}, WATCHER_DEBOUNCE)
Expand Down