Jest offers a CLI flag called --forceExit Forces Jest to exit after all tests have completed running even if there are resources that have not yet been cleaned up. This is useful when resources set up by test code cannot be adequately cleaned up.
There is also a CLI flag called --detectOpenHandles Which attempts to collect and print open handles preventing Jest from exiting cleanly.
It would be great if we could set these two flags on the invoke test Serverless call.
The mocha-serverless-plugin allows something very similar see this issue