Skip to content

Commit

Permalink
fix: reset runningPromise after finally in case there is an error t…
Browse files Browse the repository at this point in the history
…o avoid it getting stuck (#6951)
  • Loading branch information
sheremet-va authored Nov 22, 2024
1 parent dac813a commit 021944c
Showing 1 changed file with 30 additions and 27 deletions.
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

0 comments on commit 021944c

Please sign in to comment.