Skip to content

Commit

Permalink
feat: show error, when process.exit is called (#2643)
Browse files Browse the repository at this point in the history
* feat: throw error, when process.exit is called

* chore: show exit error, but still exit process
  • Loading branch information
sheremet-va committed Jan 11, 2023
1 parent ece434a commit 866f449
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/vitest/src/node/pool.ts
Expand Up @@ -140,7 +140,8 @@ function createChannel(ctx: Vitest) {

createBirpc<{}, WorkerRPC>(
{
onWorkerExit(code) {
async onWorkerExit(error, code) {
await ctx.logger.printError(error, false, 'Unexpected Exit')
process.exit(code || 1)
},
snapshotSaved(snapshot) {
Expand Down
7 changes: 2 additions & 5 deletions packages/vitest/src/runtime/worker.ts
Expand Up @@ -23,12 +23,9 @@ async function startViteNode(ctx: WorkerContext) {

const processExit = process.exit

process.on('beforeExit', (code) => {
rpc().onWorkerExit(code)
})

process.exit = (code = process.exitCode || 0): never => {
rpc().onWorkerExit(code)
const error = new Error(`process.exit called with "${code}"`)
rpc().onWorkerExit(error, code)
return processExit(code)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/types/worker.ts
Expand Up @@ -27,7 +27,7 @@ export interface WorkerRPC {
getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>

onFinished: (files: File[], errors?: unknown[]) => void
onWorkerExit: (code?: number) => void
onWorkerExit: (error: unknown, code?: number) => void
onPathsCollected: (paths: string[]) => void
onUserConsoleLog: (log: UserConsoleLog) => void
onUnhandledRejection: (err: unknown) => void
Expand Down

0 comments on commit 866f449

Please sign in to comment.