Jest-preset-angular: Memory leak when running tests

Created on 19 Aug 2018  路  7Comments  路  Source: thymikee/jest-preset-angular

Somewhere within the jest preset angular setup it causes memory leaks on every test.

REPL: https://github.com/chris5287/repl-jest-preset-angular-leak

When removing import "jest-preset-angular"; from setupJest.ts, no memory leaks are detected.

image

Help Wanted

All 7 comments

Thanks! That's interesting, would be nice to have some more findings about that. Maybe it's related to https://github.com/facebook/jest/issues/6814

@thymikee not sure how to investigate this further, any ideas?

We experience the same issue. For us it is zone.js that causes the problem.
require('zone.js/dist/zone.js');

We were experimenting same memory leak problems during testing in our codebase (with 1K tests more or less). As @me-12 has mentioned, the problems seems to be related with zone.js.

I have been checking this PR https://github.com/angular/zone.js/pull/1106 that seems to fix the problem. It is merged in zone.js but the current deployed version of the library (0.8.26) still does not include these PR so we are waiting for the official release of a new zone.js version.

Meanwhile, we are using an updated repo (thank you @JiaLiPassion) in our package.json:

{
  "zone.js": "git://github.com/JiaLiPassion/zone.js#20181005-dist"
}

It is not the perfect solution but temporally solves the problem.

Anyway, jest --detectLeaks still fails us but the --logHeapUsage option shows a correct manage of memory by jest.

@ricveal thank you very much for keeping us updated information. I'm looking forward to the fix from zone.js too.

@thymikee do you have any information regarding to the issue with detectLeaks ?

--detectLeaks may be connected with something different, e.g. listener or server/db connection not being released. Cool they fixed the leak!

Zonejs released 0.8.27 which includes the fix for memory leak with jsdom.

Was this page helpful?
0 / 5 - 0 ratings