मुख्य सामग्री पर जाएँ
Skillpedia
टेस्टिंग5.1k · #15058

memlab-memory-tests

यह क्या करती है

यह दिखाती है कि यूनिट टेस्ट कैसे लिखें जो जाँचें कि dispose के बाद ऑब्जेक्ट सचमुच हट गया है, और memlab परिदृश्यों को ऐसे टेस्ट जॉब में कैसे चलाएँ जो लीक मिलने पर विफल हो। यह उन डेवलपर्स के लिए है जो लीक जाँच को अपने टेस्ट सूट में रखना चाहते हैं।

कब इस्तेमाल करें

  • ✓जब आप ऐसा टेस्ट चाहते हैं जो dispose के बाद ऑब्जेक्ट रिलीज़ न होने पर विफल हो।
  • ✓जब आप चाहते हैं कि ब्राउज़र की लीक जाँच continuous integration में चले।
  • ✓जब आपके पास Playwright, Cypress या Puppeteer टेस्ट हैं और आप उनकी मेमोरी जाँचना चाहते हैं।

Skill का लिंक

https://github.com/meta/memlab/blob/main/plugins/memlab/skills/memlab-memory-tests/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/meta/memlab/blob/main/plugins/memlab/skills/memlab-memory-tests/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“Jest टेस्ट जोड़िए जो विफल हो जाए, अगर dispose कॉल होने के बाद भी मेरी Widget क्लास मेमोरी में बची रहे।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

आपका एजेंट ऑब्जेक्ट को टैग करता है, उसे रिलीज़ करता है, heap snapshot लेता है, और जाँचता है कि टैग किया गया ऑब्जेक्ट हट गया है। ब्राउज़र फ़्लो के लिए वह memlab परिदृश्य चलाता है जो लीक मिलने पर बिल्ड विफल कर देता है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Memory leak tests with memlab

Pick the kind of test from what has to stay leak-free:

Code under test Test
A Node.js module, class or server code Heap assertion in a unit test
A web UI interaction memlab scenario run from the test job
An existing Playwright, Cypress or Puppeteer test Snapshots from the existing test

Node.js heap assertions

takeNodeMinimalHeap() from @memlab/core snapshots the current process and returns a queryable heap. Assert that the object you released is gone:

// widget.memory.test.js (Jest; node:test and Mocha work the same way)
const {config, takeNodeMinimalHeap, tagObject} = require('@memlab/core');
const {Widget} = require('./widget');

test('Widget is released after dispose()', async () => {
  config.muteConsole = true;

  let widget = new Widget();
  tagObject(widget, 'widget-under-test'); // marks it without changing it
  widget.dispose();
  widget = null;

  const heap = await takeNodeMinimalHeap();
  expect(heap.hasObjectWithTag('widget-under-test')).toBe(false);
}, 30000);
npm install --save-dev @memlab/core
  • tagObject(obj, tag) + heap.hasObjectWithTag(tag) checks one specific instance. heap.hasObjectWithClassName('Widget') checks that no instance of the class is left; heap.getAnyObjectWithClassName('Widget') returns one to inspect. heap.hasObjectWithPropertyName(name) checks for any object with that property.
  • Drop every reference the test holds (set variables to null) before taking the heap, or the test itself keeps the object alive.
  • Taking and parsing a snapshot takes from under a second to many seconds, depending on heap size. Give the test a generous timeout, and keep these tests in their own file so the rest of the suite stays fast.
  • For retained sizes, use takeNodeFullHeap() from @memlab/heap-analysis. The minimal heap skips that computation to parse faster.
  • When the assertion fails, find out what still holds the object: save a snapshot with dumpNodeHeapSnapshot() from @memlab/core and inspect it (see the memlab-analyze-heap-snapshot skill).

Browser leak tests in CI

Write a scenario for the interaction (see the memlab-find-web-leaks skill), then run it from the test job with @memlab/api and fail on leaks:

// settings-dialog.memory.test.js
const {run} = require('@memlab/api');
const scenario = require('./scenarios/settings-dialog');

test('settings dialog does not leak', async () => {
  const {leaks} = await run({
    scenario,
    skipWarmup: true, // skip the server warm-up visits
    consoleMode: 'CONTINUOUS_TEST', // no progress animation in CI logs
    workDir: '/tmp/memlab/settings-dialog', // must exist; keep it as a CI artifact
  });
  expect(leaks.length).toBe(0);
}, 10 * 60 * 1000);
npm install --save-dev @memlab/api
  • run returns {leaks, runResult}. leaks is the list of clustered leak traces; an empty list means no leaks were found. The work directory has the snapshots and browser console output (data/cur/) and the readable traces (data/out/leaks.txt). Upload it from CI so a failure can be investigated.
  • CONTINUOUS_TEST mode skips screenshots and waits an extra 10 seconds after the initial page load. Leave consoleMode out when you want screenshots of each step.
  • Create workDir before calling run (for example with fs.mkdirSync(dir, {recursive: true})).
  • run launches headless Chromium through Puppeteer. On Linux CI images, install Chromium's shared libraries, or set chromiumBinary to a browser the image already has.
  • The CLI equivalent is memlab run --scenario <file> --work-dir <dir> --sc, where --sc is the continuous-test console mode. Assert on the result in a script with BrowserInteractionResultReader and findLeaks from @memlab/api.
  • Keep one interaction per scenario, so a failure points at one feature.

Snapshots from an existing E2E test

Take three Chromium heap snapshots in the existing test: baseline (before the interaction), target (after it) and final (after undoing it). The memlab-capture-heap-snapshots skill has a CDP helper for Puppeteer and Playwright. Then:

const {findLeaksBySnapshotFilePaths} = require('@memlab/api');

test('the flow under test does not leak', async () => {
  // ...drive the flow and write the 
अक्सर पूछे जाने वाले सवाल

कौन-से टेस्ट टूल समर्थित हैं?

Node.js का उदाहरण Jest इस्तेमाल करता है, और स्किल बताती है कि node:test और Mocha भी उसी तरह काम करते हैं।

Node.js जाँच के लिए कौन-सा पैकेज चाहिए?

@memlab/core पैकेज, जो development dependency के रूप में इंस्टॉल होता है।

क्या मौजूदा end-to-end टेस्ट भी जाँचे जा सकते हैं?

हाँ। स्किल बताती है कि मौजूदा Playwright, Cypress या Puppeteer टेस्ट से snapshots कैसे लिए जाएँ।

जानकारी

लेखक का मूल विवरण

Write automated memory leak tests with memlab. Use it for Node.js unit tests that assert an object was garbage collected (takeNodeMinimalHeap, tagObject, hasObjectWithClassName), for browser leak tests in CI that run a memlab scenario through @memlab/api and fail when leaks are found, and for checking heap snapshots from Playwright, Cypress or Puppeteer tests. Use when the user wants a regression test for a memory leak, asks how to assert that memory is released, or wants memory leak checks in Jest, Mocha, node:test or a CI pipeline.

repo: meta/memlab

लोकप्रियता

GitHub स्टार
5.1k
रैंकिंग में स्थान
#15058
लाइसेंस
MIT
अपडेट की गई
31/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills