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: reset runningPromise after finally in case there is an error to avoid it getting stuck #6951

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,38 +592,39 @@ export class Vitest {

// schedule the new run
this.runningPromise = (async () => {
if (!this.pool) {
this.pool = createPool(this)
}
try {
if (!this.pool) {
this.pool = createPool(this)
}

const invalidates = Array.from(this.invalidates)
this.invalidates.clear()
this.snapshot.clear()
this.state.clearErrors()
const invalidates = Array.from(this.invalidates)
this.invalidates.clear()
this.snapshot.clear()
this.state.clearErrors()

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

await this.initializeGlobalSetup(specs)
await this.initializeGlobalSetup(specs)

try {
await this.pool.runTests(specs as WorkspaceSpec[], invalidates)
}
catch (err) {
this.state.catchError(err, 'Unhandled Error')
}
try {
await this.pool.runTests(specs as WorkspaceSpec[], invalidates)
}
catch (err) {
this.state.catchError(err, 'Unhandled Error')
}

const files = this.state.getFiles()
const files = this.state.getFiles()

if (hasFailed(files)) {
process.exitCode = 1
}
if (hasFailed(files)) {
process.exitCode = 1
}

this.cache.results.updateResults(files)
await this.cache.results.writeToCache()
})()
.finally(async () => {
this.cache.results.updateResults(files)
await this.cache.results.writeToCache()
}
finally {
// can be duplicate files if different projects are using the same file
const files = Array.from(new Set(specs.map(spec => spec.moduleId)))
const errors = this.state.getUnhandledErrors()
Expand All @@ -632,7 +633,9 @@ export class Vitest {
this.checkUnhandledErrors(errors)
await this.report('onFinished', this.state.getFiles(files), errors, coverage)
await this.reportCoverage(coverage, allTestsRun)

}
})()
.finally(() => {
this.runningPromise = undefined
this.isFirstRun = false

Expand Down Expand Up @@ -681,7 +684,7 @@ export class Vitest {
process.exitCode = 1
}
})()
.finally(async () => {
.finally(() => {
this.runningPromise = undefined

// all subsequent runs will treat this as a fresh run
Expand Down
Loading