Skip to content

Commit

Permalink
chore: close
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Oct 17, 2023
1 parent 630281f commit a78777a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ export class Vitest {
}

async start(filters?: string[]) {
this._onClose = []

try {
await this.initCoverageProvider()
await this.coverageProvider?.clean(this.config.coverage.clean)
Expand Down
8 changes: 6 additions & 2 deletions packages/vitest/src/node/reporters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export abstract class BaseReporter implements Reporter {
private _lastRunTimer: NodeJS.Timer | undefined
private _lastRunCount = 0
private _timeStart = new Date()
private _offUnhandledRejection?: () => void

constructor() {
this.registerUnhandledRejection()
Expand All @@ -41,6 +42,9 @@ export abstract class BaseReporter implements Reporter {

onInit(ctx: Vitest) {
this.ctx = ctx
ctx.onClose(() => {
this._offUnhandledRejection?.()
})
ctx.logger.printBanner()
this.start = performance.now()
}
Expand Down Expand Up @@ -377,8 +381,8 @@ export abstract class BaseReporter implements Reporter {
process.exit(1)
}
process.on('unhandledRejection', onUnhandledRejection)
this.ctx.onClose(() => {
this._offUnhandledRejection = () => {
process.off('unhandledRejection', onUnhandledRejection)
})
}
}
}

0 comments on commit a78777a

Please sign in to comment.