facebook / memlab

A framework for finding JavaScript memory leaks and analyzing heap snapshots
https://facebook.github.io/memlab/
MIT License
4.36k stars 119 forks source link

Possibility to analyze memory leaks/usage in Jest #14

Open tmkasun opened 2 years ago

tmkasun commented 2 years ago

Hi Team,

First of all, Thank you very much for making this project open source, AFAIK there are very few opensource tools like memlab to analyze memory leaks in SPA apps, Hope this will be an excellent help for frontend developers to identify memory leaks in the Single Page Apps.

My question is, Is it possible to analyze the memory usage or leaks in tests written using the Jest framework?

JacksonGL commented 2 years ago

MemLab tests its APIs with Jest. Please check out the src/__test__ folder of each memlab packages for more examples.

To find memory leaks in SPA using Jest, here is one example: https://github.com/facebookincubator/memlab/blob/main/packages/api/src/__tests__/API/E2EFindMemoryLeaks.test.ts (more examples under the packages/api/src/__tests__ folder)

If you would like to analyze memory in node.js, MemLab provides the following APIs:

Here is an example of using MemLab with Jest: https://facebookincubator.github.io/memlab/docs/api/interfaces/core_src.IHeapSnapshot/#hasobjectwithtagtag

tmkasun commented 2 years ago

Thank you very much @JacksonGL for the quick response, I will have a look at the MemLab tests and other materials.

derN3rd commented 2 years ago

I think the question was more like "Is there any way/functionality already that allows us to throw this tool onto our jest tests to find memory leaks in it".

At least thats my question, but after reading through the code, docs and examples I couldn't find anything.