jest icon indicating copy to clipboard operation
jest copied to clipboard

[Feature]: Configure jest to fail (non-zero exit) if test suite does not cleanly exit

Open davidmfoley opened this issue 6 months ago • 2 comments

🚀 Feature Proposal

Add a cli flag/config setting that causes jest to fail (exit with non-zero exit code), rather than printing the message: Jest did not exit one second after the test run has completed.

Motivation

We would like to catch any instance of "open handles" in a test in our automated checks, since it is always the result of a programming mistake.

Example

jest --failOnOpenHandles or perhaps jest --failOnForceExit

...plus commensurate config file syntax

I don't have a strong opinion about the exact wording; "handles" is used in the detectOpenHandlessetting, "forcedExit" is used in the runner source code.

Pitch

The code that needs changed is here: https://github.com/jestjs/jest/blob/91e80829a08b03ed7c0166e59543cd2a6b20d08b/packages/jest-runner/src/index.ts#L186

This is in the runner, and it doesn't currently provide an obvious extensibility point.

NOTE! I've only looked at the jest codebase for under an hour -- I could definitely be missing some other way to accomplish this.

davidmfoley avatar Aug 19 '24 23:08 davidmfoley