Skip to content

Commit 866f449

Browse files
authoredJan 11, 2023
feat: show error, when process.exit is called (#2643)
* feat: throw error, when process.exit is called * chore: show exit error, but still exit process
1 parent ece434a commit 866f449

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed
 

‎packages/vitest/src/node/pool.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ function createChannel(ctx: Vitest) {
140140

141141
createBirpc<{}, WorkerRPC>(
142142
{
143-
onWorkerExit(code) {
143+
async onWorkerExit(error, code) {
144+
await ctx.logger.printError(error, false, 'Unexpected Exit')
144145
process.exit(code || 1)
145146
},
146147
snapshotSaved(snapshot) {

‎packages/vitest/src/runtime/worker.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ async function startViteNode(ctx: WorkerContext) {
2323

2424
const processExit = process.exit
2525

26-
process.on('beforeExit', (code) => {
27-
rpc().onWorkerExit(code)
28-
})
29-
3026
process.exit = (code = process.exitCode || 0): never => {
31-
rpc().onWorkerExit(code)
27+
const error = new Error(`process.exit called with "${code}"`)
28+
rpc().onWorkerExit(error, code)
3229
return processExit(code)
3330
}
3431

‎packages/vitest/src/types/worker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface WorkerRPC {
2727
getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>
2828

2929
onFinished: (files: File[], errors?: unknown[]) => void
30-
onWorkerExit: (code?: number) => void
30+
onWorkerExit: (error: unknown, code?: number) => void
3131
onPathsCollected: (paths: string[]) => void
3232
onUserConsoleLog: (log: UserConsoleLog) => void
3333
onUnhandledRejection: (err: unknown) => void

0 commit comments

Comments
 (0)
Please sign in to comment.