Skip to content

Commit

Permalink
chore(jest-runner): Add info regarding timers to forcedExit message
Browse files Browse the repository at this point in the history
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
  • Loading branch information
silverwind committed Nov 24, 2021
1 parent 9947a2a commit 9d9f6d6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

### Chore & Maintenance

- `[jest-runner]` Add info regarding timers to forcedExit message([#12083](https://github.com/facebook/jest/pull/12083))
- `[*]` Replaced `substr` method with `substring` ([#12066](https://github.com/facebook/jest/pull/12066))

### Performance
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
),
);
}
Expand Down

0 comments on commit 9d9f6d6

Please sign in to comment.