memlab
分析 JavaScript 堆,并查找浏览器和 node.js 中的内存泄漏
定义你的测试
定义浏览器交互的 E2E 测试场景
// test.jsfunction url() {return 'https://www.google.com/maps/place/Silicon+Valley,+CA/';}async function action(page) {await page.click('text/Hotels');}async function back(page) {await page.click('[aria-label="Close"]');}module.exports = {action, back, url};
在 CLI 中运行 memlab
使用自定义 E2E 测试场景查找内存泄漏
支持之前浏览器测试的内存分析$ memlab run --scenario test.js
# Analyze duplicated string in heap$ memlab analyze string# Check unbound object growth$ memlab analyze unbound-object# Get shapes with unbound growth$ memlab analyze unbound-shape# Discover more memory analyses$ memlab analyze -h
编程 API
用于 JavaScript 堆快照的内存分析
const {findLeaks, takeSnapshots} = require('@memlab/api');async function test() {const scenario = {url: () => 'https://#',};const result = await takeSnapshots({scenario});const leaks = findLeaks(result);// ...}