You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
onTestRunEnd receives reason: 'passed' when a forks worker is killed and its test file never completes #11464
When a forks worker dies before its test file finishes, onTestRunEnd still receives reason: 'passed'. The dead file is left in pending state and the summary reads Test Files 1 passed (2). The run exits 1 only because of the unhandled pool error — a reporter that looks at reason, or a config with dangerouslyIgnoreUnhandledErrors: true, sees a passed run in which a planned file never executed.
Reproduction
Two test files and a config (npm i vitest@5.0.3, npx vitest run):
// passing.test.tsimport{test,expect}from'vitest'test('passes',()=>{expect(1).toBe(1)})// self-kill.test.ts — stands in for an OOM kill or a host signalimport{test}from'vitest'test('kills its own forks worker',()=>{process.kill(process.pid,'SIGKILL')})// vitest.config.tsimport{defineConfig}from'vitest/config'exportdefaultdefineConfig({test: {pool: 'forks',reporters: ['default',{onTestRunEnd(modules,errors,reason){console.log(`reason=${reason} errors=${errors.length} `+modules.map(m=>`${m.moduleId.split('/').pop()}:${m.state()}`).join(' '))},}],},})
Output (vitest 5.0.3, Node 24.14.0, Linux x64; same on 4.1.10):
Caused by: Error: Worker exited unexpectedly with signal SIGKILL during started state while running test file .../self-kill.test.ts
Test Files 1 passed (2)
reason=passed errors=1 passing.test.ts:passed self-kill.test.ts:pending
Expected
A run in which a test module never completed is not reported to onTestRunEnd as 'passed' — either a distinct reason (e.g. 'failed', or a new value), or the unexecuted module ending in a non-pending failure state. Either lets a reporter or CI gate tell "all files ran" from "a worker died".
Workaround
A custom reporter that diffs the planned module list against those that reached a terminal state and fails the run itself.
Not covered by
#8766/#8767 (RPC torn down too soon, fixed 4.0.1), #8861/#8967 (Windows Defender, fixed 4.0.8), #9762 (bun/glibc). The exit-signal reporting (with signal SIGKILL … while running test file) is already present in 5.x; this is only about the run-end reason.
I reproduced this. Two test files with pool: 'forks' and a reporter that prints what onTestRunEnd receives; one of them calls process.kill(process.pid, 'SIGKILL'):
The crashed file stays pending, it never ran a test, so ok() reports no failure. The error
was in unhandledErrors the whole time, the reason just never looked there. end() computed
it with hasFailed(modules) only, which is why a run that fails with an unhandled error is
still reported as passed, contradicting both the documented TestRunEndReason values
(passed: "there are no errors") and the exit code.
I have a tested fix. The reason now comes from the same rule that decides whether the run
fails, so it cannot disagree with the exit code, and dangerouslyIgnoreUnhandledErrors is
honored. test/e2e/test/pool-worker-exit.test.ts has a case that fails without the change
(expected 'passed' to be 'failed') and passes with it. It is in #11498, which the pull
request policy closed automatically.
Activity
ezefernandezyf commentedon Oct 5, 2026
I reproduced this. Two test files with
pool: 'forks'and a reporter that prints whatonTestRunEndreceives; one of them callsprocess.kill(process.pid, 'SIGKILL'):The crashed file stays
pending, it never ran a test, sook()reports no failure. The errorwas in
unhandledErrorsthe whole time, the reason just never looked there.end()computedit with
hasFailed(modules)only, which is why a run that fails with an unhandled error isstill reported as
passed, contradicting both the documentedTestRunEndReasonvalues(
passed: "there are no errors") and the exit code.I have a tested fix. The reason now comes from the same rule that decides whether the run
fails, so it cannot disagree with the exit code, and
dangerouslyIgnoreUnhandledErrorsishonored.
test/e2e/test/pool-worker-exit.test.tshas a case that fails without the change(
expected 'passed' to be 'failed') and passes with it. It is in #11498, which the pullrequest policy closed automatically.