This took a while to track down - we're seeing issues with the performance of tests in our monorepo when running in the CI, and after some investigation using the --detect-leaks flag in jest, I've identified that the leaks are occurring in our use of the axios-cache-adapter package.
https://github.com/ahayes91/TestTimeouts/pull/2 shows that the leak is removed when running yarn workspace @test/parentApp test --detect-leaks if the cache functionality is commented from the functional code
https://github.com/ahayes91/TestTimeouts/pull/3 shows that the leak is removed for the App.integration.test.js file if the axios-cache-adapter module is mocked in the test file (you can run yarn jest PATH_TO_FILE --detect-leaks to test this one individually)
Can we find out what code in the module is causing the leakage & fix it / have you seen this before?
Can you advise on how best to mock the module globally for unit tests without having to put jest.mock in every test file? https://jestjs.io/docs/en/manual-mocks didn't seem to work for me, even when I put the manual mocking file in a __mocks__ directory beside the root level node_modules and in a __mocks__ directory beside the package level node_modules.
Edit: I've updated our jest config to load the mock in the setupFilesAfterEnv step:
This took a while to track down - we're seeing issues with the performance of tests in our monorepo when running in the CI, and after some investigation using the
--detect-leaks
flag in jest, I've identified that the leaks are occurring in our use of theaxios-cache-adapter
package.Repository to reproduce this issue: https://github.com/ahayes91/TestTimeouts
yarn workspace @test/parentApp test --detect-leaks
if the cache functionality is commented from the functional codeaxios-cache-adapter
module is mocked in the test file (you can runyarn jest PATH_TO_FILE --detect-leaks
to test this one individually)jest.mock
in every test file? https://jestjs.io/docs/en/manual-mocks didn't seem to work for me, even when I put the manual mocking file in a__mocks__
directory beside the root level node_modules and in a__mocks__
directory beside the package level node_modules.Edit: I've updated our jest config to load the mock in the setupFilesAfterEnv step: