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

feat: show error, when process.exit is called #2643

Merged
merged 2 commits into from Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/vitest/src/node/pool.ts
Expand Up @@ -138,7 +138,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