memlab icon indicating copy to clipboard operation
memlab copied to clipboard

Discussion: How to run memlab on a test suite.

Open SimonGodefroid opened this issue 2 years ago • 3 comments

It's all in the title, we are running tests with Testing Library + MSW on Jest and with some legacy jest mocks. The pipeline looks a bit flaky on the CI and we'd like to rule out memory leaks by running memlab on the existing test suite as opposed to creating a scenario and re-write all the test base.

Is there any chance to achieve this with the current implementation? The get started doc seemed that you need to boot up the app and run scenario to find leaks by headlessly browsing the app as opposed to running existing tests.

SimonGodefroid avatar Sep 15 '22 05:09 SimonGodefroid

@SimonGodefroid Can you share an example of what your current test looks like, does your test create its own Puppeteer page object and interact with it?

JacksonGL avatar Sep 15 '22 21:09 JacksonGL

Hey @JacksonGL so I don't have an example to share unfortunately because our company's code is closed source but essentially we run tests with Jest + React Testing Library. I guess my question is outside of the current working principles of Memlab essentially I'm asking whether there'll be a way to for instance:

$ memlab "yarn test" 

Where yarn test is your test script command e.g. react-scripts test and then Memlab would be able to track down leaks by relying on the test suite rendering the app as opposed to going through Puppeteer.

Essentially finding a memory leak on a repo would be something that you run against an existing test base (if possible) as opposed to having to setup a new tool. Then it might not be doable. I kinda thought Memlab would do what --detectOpenHandles does but super charged and without having to setup anything new.

SimonGodefroid avatar Sep 16 '22 06:09 SimonGodefroid

@SimonGodefroid --detectOpenHandles in Jest was using async_hooks from node.js. E2E test framework like puppeteer doesn't seem to provide a callback to instrument navigation in SPA (let me know if there is one). Navigation and interaction in SPA is often application specific, MemLab doesn't know when and how to take heap snapshots without the puppeteer page object. Curious to hear if there is any ideas.

JacksonGL avatar Sep 17 '22 04:09 JacksonGL