From 50712ec3b8a71f8106bf5861e45836022edab2ee Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 24 Nov 2021 17:52:03 +0100 Subject: [PATCH] Add info regarding timers to forcedExit message. When a test finishes while a Node.js timer is still active, the worker process will have to be force-killed by jest because the active timer will keep the event loop alive. It is often not immediately clear that such timers are the issue for this message and the suggested method of `--detectOpenHandles` will never detect them. Add a helpful message to point the user to this potential issue. Ref: https://nodejs.org/api/timers.html#timeoutunref --- packages/jest-runner/src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/jest-runner/src/index.ts b/packages/jest-runner/src/index.ts index cd297c3696c5..5f6e17eeb615 100644 --- a/packages/jest-runner/src/index.ts +++ b/packages/jest-runner/src/index.ts @@ -273,7 +273,8 @@ export default class TestRunner { chalk.yellow( 'A worker process has failed to exit gracefully and has been force exited. ' + 'This is likely caused by tests leaking due to improper teardown. ' + - 'Try running with --detectOpenHandles to find leaks.', + 'Try running with --detectOpenHandles to find leaks. ' + + 'Active timers can also cause this, ensure that .unref() was called on them.', ), ); }