Jest hangs due to open handles in MemoryMapCache
Closed this issue · 0 comments
When doing unit testing with Jest, MemoryMapCache
causes a Jest has detected the following 1 open handle potentially keeping Jest from exiting
error. This is caused by how MemoryMapCache handles expiry, using an interval that runs on a fixed time. For now I've found a temporary workaround, which is to override setInterval
in a jest setup script (global.setInterval = () => {};
) but that feels hacky and breaks expiry which is important in some tests. I think it would be nicer to automatically handle it in kas.
As a solution I think checking process.env.NODE_ENV
and if it equals testing
switching to a setTimeout
for each key would work, instead of the setInterval loop that will keep the app running even if its not doing anything. This could even be a configurable option passed to the constructor, as some applications may want to disable that loop (for example, clis that want to exit once they're done).
The only issue I can see with that approach would be that it's extra code that is only relevant to testing environments, unless it were a constructor option that defaults to true
based on the NODE_ENV
check, which I think would actually be a nice option to have.