This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Description
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.
Repository to reproduce this issue:
https://github.com/ahayes91/TestTimeouts
- 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:
// mockAxiosCache.js
/* eslint-disable no-undef */
jest.mock('axios-cache-adapter', () => {
return {
setupCache: jest.fn().mockReturnValue({ adapter: 'mockAdapter' }),
};
});
// jest.config.js
...
setupFilesAfterEnv: [
'@testing-library/jest-dom/extend-expect',
'./mockAxiosCache.js',
],
...