fix(ngMock): prevent memory leak due to data attached to $rootElement#14098
fix(ngMock): prevent memory leak due to data attached to $rootElement#14098gkalpak wants to merge 4 commits intoangular:masterfrom
$rootElement#14098Conversation
test/ngMock/angular-mocksSpec.js
Outdated
| }); | ||
|
|
||
|
|
||
| describe('don\'t leak memory between tests', function() { |
There was a problem hiding this comment.
I prefer describe block descriptions to be nouns of things that are being tested...
But I see you are following the pattern above :-(
There was a problem hiding this comment.
I don't like the descriptions either. I'll tweak them.
|
So the idea of the tests is that you have to run a test beforehand that sets up the spies so that you can check to see that the root element was in fact cleaned up? |
test/ngMock/angular-mocksSpec.js
Outdated
| }); | ||
| }); | ||
|
|
||
| describe('don\'t leak memory between tests with mocked `$rootScope`', function() { |
There was a problem hiding this comment.
should this be "with mocked $rootElement"?
44684c9 to
393f68b
Compare
Starting with 88bb551, `ngMock` will attach the `$injector` to the `$rootElement`, but will never clean it up, resulting in a memory leak. Since a new `$rootElement` is created for every test, this leak causes Karma to crash on large test-suites. The problem was not detected by our internal tests, because we do our own clean-up in `testabilityPatch.js`. This commit prevents the memory leak, by cleaning up all data attached to `$rootElement` after each test. Fixes angular#14094
393f68b to
739d4c6
Compare
|
I has to rebase this on top of master (because the commit this is supposed to fix was reverted). I incorporated the original commit (attaching I added a 2nd commit, that addressed your feedback (except for #14098 (comment) - I'll play with that next). |
fd1891d to
a33e753
Compare
a33e753 to
b972a12
Compare
|
I added a 3rd commit that uses |
9e62160 to
d8fca15
Compare
|
And a 4th commit (fixup 3) that fixes a couple of corner cases. |
339468f to
352e2a9
Compare
- Reset `originalRootElement` for each test to avoid. - Fix clean-up break, if `$rootElement` was never initialized. - Fix clean-up break, if decorated `$rootElement` was falsy (e.g. `null`). - (Rename `cleanUpElems` to `cleanUpNodes` - since it's "raw" nodes, not jq-wrapped elements.)
223fb52 to
db92324
Compare
|
LGTM - please squash and merge. |
Starting with 88bb551, `ngMock` will attach the `$injector` to the `$rootElement`, but will never clean it up, resulting in a memory leak. Since a new `$rootElement` is created for every test, this leak causes Karma to crash on large test-suites. The problem was not detected by our internal tests, because we do our own clean-up in `testabilityPatch.js`. 88bb551 was revert with 1b8590a. This commit incorporates the changes from 88bb551 and prevents the memory leak, by cleaning up all data attached to `$rootElement` after each test. Fixes #14094 Closes #14098
Starting with 88bb551, `ngMock` will attach the `$injector` to the `$rootElement`, but will never clean it up, resulting in a memory leak. Since a new `$rootElement` is created for every test, this leak causes Karma to crash on large test-suites. The problem was not detected by our internal tests, because we do our own clean-up in `testabilityPatch.js`. 88bb551 was revert with 1b8590a. This commit incorporates the changes from 88bb551 and prevents the memory leak, by cleaning up all data attached to `$rootElement` after each test. Fixes #14094 Closes #14098
Starting with 88bb551,
ngMockwill attach the$injectorto the$rootElement, but will never clean it up, resulting in a memory leak. Since a new$rootElementis created for every test, this leak causes Karma to crash on large test-suites.The problem was not detected by our internal tests, because we do our own clean-up in
testabilityPatch.js.This commit prevents the memory leak, by cleaning up all data attached to
$rootElementafter each test.Fixes #14094