memlab icon indicating copy to clipboard operation
memlab copied to clipboard

Support for cypress

Open phalgunv opened this issue 3 years ago • 4 comments

Hello,

I would like to know if memlab can work with Cypress. We have a large test suite of Cypress based tests, it would be nice to use memlabs with those tests rather than creating new ones with pupeteer.

phalgunv avatar Sep 13 '22 06:09 phalgunv

MemLab can analyze heap snapshots taken from V8. In your case, write scripts to take heap snapshots from Cypress (if Cypress supports taking heap snapshots from browser) and put them into disk in the format that can be processed by MemLab.

Here is what the MemLab output files look like (only run-meta.json, snap-seq.json and all .heapsnapshot files are necessary): https://facebook.github.io/memlab/docs/guides/integration-and-file-structure/#collect-results

To get examples of those meta files, run a random MemLab test scenario and view those files under this directory: $(memlab get-default-work-dir)/data/cur.

When the files are ready, create a result reader:

const reader = BrowserInteractionResultReader.from(directory);

Then find memory leaks with the reader and this MemLab API: https://facebook.github.io/memlab/docs/api/modules/api_src#findleaksrunresult

JacksonGL avatar Sep 13 '22 06:09 JacksonGL

Can't find a way for cypress to take heap snapshots, embarrassing.

Levix avatar Sep 22 '22 07:09 Levix

@Levix I've never used Cypress before, but it seems Cypress supports Chrome DevTools Protocol, which could be used to get JS heap snapshots from Chromium.

Here is the code pointer of how memlab uses puppeteer to collect the heap snapshots from Chromium.

JacksonGL avatar Sep 29 '22 02:09 JacksonGL

@Levix I've never used Cypress before, but it seems Cypress supports Chrome DevTools Protocol, which could be used to get JS heap snapshots from Chromium.

Here is the code pointer of how memlab uses puppeteer to collect the heap snapshots from Chromium.

Here is an article written in Chinese on how to take heap snapshots. https://github.com/Levix/weekly/blob/feat-docs-cypress-heap/article/2022/%E4%BD%BF%E7%94%A8%20Cypress%20%E6%8B%8D%E6%91%84%E5%A0%86%E5%BF%AB%E7%85%A7%EF%BC%88Take%20snapshot%EF%BC%89/%E4%BD%BF%E7%94%A8%20Cypress%20%E6%8B%8D%E6%91%84%E5%A0%86%E5%BF%AB%E7%85%A7%EF%BC%88Take%20snapshot%EF%BC%89.md

Levix avatar Nov 10 '22 01:11 Levix