🐛 Memory leak testing for node.

Overview

Leakage - Memory Leak Testing for Node

Build Status NPM Version JavaScript Style Guide

Write leakage tests using Mocha or another test runner of your choice.

Does not only support spotting and fixing memory leaks, but writing tests also enables you to prevent regressions and show that the code does not leak.

Screencast

Table of Contents

Installation

npm install --save-dev leakage
# or
yarn --dev leakage

Usage

In theory you could use any testing framework to run leakage tests. In practice, though, you want to use one that generates a minimal memory overhead itself. We suggest using Mocha or Tape, since they are quite simple and don't produce much noise in the captured data.

Usage with Mocha

import myLib from 'my-lib'
import { iterate } from 'leakage'

describe('myLib', () => {
  it('does not leak when doing stuff', () => {
    iterate(() => {
      const instance = myLib.createInstance()
      instance.doStuff('foo', 'bar')
    })
  })
})

iterate() will run the function several times, create a heap snapshot and repeat that process until there is a set of heap diffs. If a memory leak has been detected an error with some debugging information will be thrown.

Make sure you run all tests serially in order to get clean heap diffs. Mocha should run them sequentially by default.

Use iterate.async() for asynchronous test code. See Asynchronous Tests and API for details.

Usage with tape

import test from 'tape'
import myLib from 'my-lib'
import { iterate } from 'leakage'

test('myLib does not leak when doing stuff', () => {
  iterate(() => {
    const instance = myLib.createInstance()
    instance.doStuff('foo', 'bar')
  })
})

Asynchronous Tests

Use iterate.async() to test asynchronous code. The iterator function is supposed to return a promise and iterate.async() will return a promise itself. In case of a memory leak that returned promise will be rejected instead of iterate failing synchronously.

Do not forget to return the promise in your test or use async functions and await iterate.async().

import fetch from 'isomorphic-fetch'
import { iterate } from 'leakage'

describe('isomorphic-fetch', () => {
  it('does not leak when requesting data and parsing JSON', async () => {
    await iterate.async(async () => {
      const response = await fetch()
      await response.json()
    })
  })
})

Memory Management in JS?

Since every JavaScript runtime comes with a garbage collector you should not have to care about memory allocation / freeing memory at all, right? Sadly not.

Memory leaks are a common problem in most programming languages. Memory gets allocated, but is not freed again, leading to a steadily increasing usage of memory. Since the memory you use is finite your application will eventually crash or become so slow it is rendered useless.

As soon as you still have a reference to an object, array, arrow function, ... you do not use anymore you might have already created a memory leak. Creating an object (incl. arrays and closures) means allocating heap memory that will be freed by the next automatic garbage collection only if all references to this object have vanished.

API

iterate(syncIterator: Function, options: ?Object): Result

Test for memory leaks. Will throw an error when a leak is recognized.

syncIterator can be any synchronous function. Let it perform your operations you want to test for memory leaks.

options.iterations is the number the iterator function is run for each heap diff / garbage collection. Defaults to 30.

options.gcollections is the number of heap snapshots to create. Defaults to 60.

iterate.async(asyncIterator: Function, options: ?Object): Promise

Test for memory leaks. Will return a rejecting promise when a leak is recognized.

asyncIterator can be any asynchronous function. Let it perform your operations you want to test for memory leaks.

options.iterations is the number the iterator function is run for each heap diff / garbage collection. Defaults to 30.

options.gcollections is the number of heap snapshots to create. Defaults to 60.

Result object

Properties:

  • heapDiffs - An array of heap diffs as created by node-memwatch
  • iterations - The number of iterator runs per heap diff
  • gcollections - The number of garbage collections / heap diffs performed

Methods:

  • printSummary(title: ?String, log: ?Function) - Prints a short summary. Can pass a title to print. log is the function used to output the summary line by line. Defaults to console.log.

MemoryLeakError

Memory leak errors are instances of this custom error. You can use it to check if an error is really a memory leak error or just a generic kind of problem (like a broken reference).

Import it as const { MemoryLeakError } = require('leakage').

CLI Parameters

You can pass special CLI parameters for leakage to your test runner:

mocha test/sample.test.js --heap-file heap-diff.json

--heap-file

Will make the library write a detailed heap diff JSON to the file system. Make sure you only run a single test using it.only. Otherwise you will only find the heap diff of the last test in the file. Useful for debugging.

Under the Hood

Leakage uses node-memwatch to trigger the garbage collector and create heap diffs.

You just specify an iterator function. It will be run 30 times by default then a garbage collection will be performed and a heap snapshot will be made. This process is iterated 6 times by default to collect several heap diffs, since especially in async tests there is always a bit of background noise.

If the heap size increased over more than [heapDiffCount * 2 / 3] subsequent garbage collections an error is thrown.

Travis CI

You might want your leakage tests to be run by your CI service. There is an issue with Travis CI's linux containers, g++ and a transitive dependency of node-memwatch (nan).

Fortunately there is a fix: You need to install and use version 4.8 of g++ in order to compile the dependency.

Have a look at leakage's .travis.yml file to see how it can be done or find further details by @btmills in this issue.

FAQ

I encountered a timeout error

If you see an error like Error: Timeout of 2000ms exceeded. (...) it means that your test took so long that the test runner cancelled it.

You can easily increase the timeout. Have a look at your test runner's documentation for that. When using Mocha, for instance, you can run it with --timeout 10000 to increase the timeout to 10000ms (10s).

Why are my tests slow anyway?

Leakage tests are rather slow compared to usual unit tests, since heap snapshotting and diffing takes some time and has to be done several times per test.

You can try to reduce the number of heap diffs created, but beware that fewer heap diffs can result in less accurate results. See API for details.

Contribute

Got any feedback, suggestions, ...? Feel free to open an issue and share your thoughts!

Used it successfully or were unable to use it? Let us know!

Have an improvement? Open a pull request any time.

License

Released under the terms of the MIT license. See LICENSE for details.

Comments
  • Promise support

    Promise support

    I can use your module for a database related module Do you see any drawback adding support for Promises, let me know what you think!

    I'm already working on it, it should be ready by the end of the day

    enhancement 
    opened by mastilver 33
  • Document best practices: console.log

    Document best practices: console.log

    Thoughts on adding a few best practices around garbage collection. Adding a console.log for instance...

    describe.only('test()', () => {
      it('does not leak when doing stuff', () => {
        iterate(6, () => { const test = new Person(); console.log(test); });
      });
    });
    
    function Person() {
      this.age = 1;
      this.name = 'mike';
    }
    

    vs

    describe.only('test()', () => {
      it('does not leak when doing stuff', () => {
        iterate(6, () => { const test = new Person();  });
      });
    });
    
    function Person() {
      this.age = 1;
      this.name = 'mike';
    }
    
    improve documentation 
    opened by mjhea0 9
  • cannot install on node 10

    cannot install on node 10

    memwatch-next, an upstream dependence, doesn't support v8 6.6 and therefore preventing leakage to be installed on node 10. See https://github.com/marcominetti/node-memwatch/issues/39

    Should we swap memwatch-next with node-memwatch to solve the problem?

    bug 
    opened by alvis 6
  • Updated README.md and added mocha to run the existing test.

    Updated README.md and added mocha to run the existing test.

    When I imported 'iterate' from the package, the value was undefined. I realized that the README.md was misleading, so this PR adjusts it to reflect what the package exports ('iteration').

    I'm having another issue with the library, which might end up in another PR, so I wanted to run the test suite to see what happens and realized that it didn't come with mocha and needed an improved test command (both using mocha and not relying on any local PATH modifications).

    opened by tydira 6
  • Cannot install on node 10.15.1

    Cannot install on node 10.15.1

    ../src/heapdiff.cc:95:20: warning: 'Utf8Value' is deprecated [-Wdeprecated-declarations]
            String::Utf8Value utfString(str->ToString());
                              ^
    /Users/krzysztofszostak/.node-gyp/10.15.1/include/node/v8.h:2891:5: note: 'Utf8Value' has been explicitly marked deprecated here
        V8_DEPRECATED("Use Isolate version",
        ^
    /Users/krzysztofszostak/.node-gyp/10.15.1/include/node/v8config.h:327:29: note: expanded from macro 'V8_DEPRECATED'
      declarator __attribute__((deprecated))
                                ^
    1 warning generated.
      CXX(target) Release/obj.target/memwatch/src/init.o
    ../src/init.cc:20:9: error: no type named 'AddGCEpilogueCallback' in 'v8::V8'; did you mean 'Nan::GCEpilogueCallback'?
            v8::V8::AddGCEpilogueCallback(memwatch::after_gc);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Nan::GCEpilogueCallback
    ../../nan/nan.h:745:35: note: 'Nan::GCEpilogueCallback' declared here
      typedef v8::Isolate::GCCallback GCEpilogueCallback;
                                      ^
    ../src/init.cc:20:49: error: definition or redeclaration of 'after_gc' not allowed inside a function
            v8::V8::AddGCEpilogueCallback(memwatch::after_gc);
                                          ~~~~~~~~~~^
    2 errors generated.
    make: *** [Release/obj.target/memwatch/src/init.o] Error 1
    gyp ERR! build error 
    
    opened by hejkerooo 5
  • Failed to install on Windows

    Failed to install on Windows

    I am trying to installing the package on Win10 and it does not have sys/time.h for @airbnb\node-memwatch to be built.

    d:\<...>\node_modules\@airbnb\node-memwatch\src\memwatch.cc(19): fatal error C1083: 無法開啟包含檔案: 'sys/time.h': No such file or directory [D:\<...>\node_modules\@airbnb\node-memwatch\bui
    ld\memwatch.vcxproj]
    

    Any alternatives or solution I can try for this? Throw Windows away and embrace Ubuntu? 😂 (OMG

    Thanks for the nice project anyway!

    opened by momocow 5
  • Testing / CI

    Testing / CI

    There must be at least some integration test showing that the whole thing works and works for different node versions.

    Correlates with #3 and will be successor of a proposed change in #1.

    enhancement 
    opened by andywer 5
  • Node 10 Support

    Node 10 Support

    The original memwatch-next is out of date and fails to be installed under node 10. This PR addresses this issue by swapping a drop-in replacement @airbnb/node-memwatch, which is constantly maintained by the folks at AirBnb.

    Note: With this PR, we have to drop support for Node 6 as the new node-memwatch doesn't support it. We should leave 0.3.0 for Node 6, and bump to 0.4.0 for Node 7+.

    @andywer: would you mind clearing the cache for the test under Node 8 and retrigger the test. There was a problem with npm I suppose?

    opened by alvis 4
  • Testing code with promises

    Testing code with promises

    Hey, I'm trying to test code that uses promises and always getting the MemoryLeakError. Is there anything I'm doing wrong, or is that just how promises work?

    here's my code:

    const Leakage =  require('leakage');
    
    it('leak test', async() => {
        let i = 0;
        jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000;
        expect.hasAssertions();
    
         await Leakage.iterate.async(async () => {
            let dummyPromise = new Promise((resolve) => {
               setTimeout(() => resolve('ok ' + ++i), 1);
            });
            
            try {
                const result = await dummyPromise;
                expect(result).toBeTruthy();
            } catch (e) {
                throw 'this should not happen ' + e;
            }
        });
    })
    

    and very minimalistic package.json

    {
      "name": "promise-leak",
      "version": "1.0.0",
      "main": "index.js",
      "scripts": {
          "test": "jest --runInBand"
      },
      "license": "MIT",
      "dependencies": {
        "jest": "^23.6.0",
        "leakage": "^0.4.0"
      }
    }
    
    question 
    opened by karpikpl 3
  • How to catch a probable false alarm

    How to catch a probable false alarm

    This is actually a really nice module. Thanks!

    I have set up a small experiment here: https://github.com/diorahman/send However, I'm not sure if the http.Agent with keepAlive: true is supposed to be leaking all the time.

    If I set the keepAlive as https://github.com/diorahman/send/blob/master/fetch.js#L12 it leaks, however if I set it false it doesn't.

    What do you think?

    Thanks!

    opened by diorahman 3
  • How many iterations to do?

    How many iterations to do?

    Hello Maintainers, Please accept a hat-tip, love what I see thus far in the project. I have a question/comment regarding the wording here:

    Nevertheless you can try to reduce the iteration count (the first parameter passed to iterate()). If you use 100 iterations as in the sample, try 30 iterations instead.

    From past experience, generally profiling tests encourage having a sufficiently large iteration count, so this suggestion sounds a tad counter-intuitive. A lower iteration count may produce false-positives (unless there is a glaringly obvious leak that is caught easily). I believe this phrase should be removed. What are your thoughts?

    help wanted improve documentation discussion 
    opened by mishrsud 3
  • Repoint node-memwatch to fork which supports node 18

    Repoint node-memwatch to fork which supports node 18

    This change repoints the node-memwatch package dependency to a different fork (@airbnb/node-memwatch) which supports node 18.

    Also in this change is a slight implicit change in development tooling to suggest the use of asdf (https://asdf-vm.com/), as well as a quick sweep of security vulnerabilities using npm audit fix --force.

    In particular this proposed alteration should address https://github.com/andywer/leakage/issues/34.

    opened by token-cjg 0
  • Varying results for same test

    Varying results for same test

    I am running the following test multiple times in a row:

    describe('leaks', function() {
      it('leak test', function() {
        this.timeout(100000)
    
        return Leakage.iterate.async(async () => {
          return myFunction()
        })
      })
    })
    

    Sometimes it passes and other times I get something like this:

    MemoryLeakError: Heap grew on 6 subsequent garbage collections (180 of 180 iterations) by 175 kB.
    
      Iterations between GCs: 30
    
      Final GC details:
      [   19.4 kB] [+ 123x] [-  84x] Array
      [     14 kB] [+   5x] [-   1x] Code
      [       0 B] [+   1x] [-   1x] Immediate
      [       0 B] [+   2x] [-   2x] Native
      ... (15 more)
    

    Should it consistently pass or fail rather than be intermittent? Thanks.

    question 
    opened by byumark 1
  • Package not working with NodeJS 12

    Package not working with NodeJS 12

    This could possibly also be due to VS 2019, but I doubt it

    > @airbnb/[email protected] install C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch
    > node-gyp rebuild
    
    
    C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch>if not defined npm_config_node_gyp (node "C:\Users\<User>\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\<User>\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild ) 
    Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
      heapdiff.cc
      init.cc
      memwatch.cc
      util.cc
      win_delay_load_hook.cc
    c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan_object_wrap.h(24): error C2039: 'IsNearDeath': is not a member of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>' [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwat
    ch\build\memwatch.vcxproj]
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\memwatch.cc)
      c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan.h(1920): note: see declaration of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>'
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\memwatch.cc)
    c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan_object_wrap.h(127): error C2039: 'IsNearDeath': is not a member of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>' [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwa
    tch\build\memwatch.vcxproj]
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\memwatch.cc)
      c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan.h(1920): note: see declaration of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>'
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\memwatch.cc)
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.hh(18): error C2039: 'Handle': is not a member of 'v8' (compiling source file ..\src\memwatch.cc) [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\bui
    ld\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8-profiler.h(48): note: see declaration of 'v8' (compiling source file ..\src\memwatch.cc)
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.hh(18): error C2061: syntax error: identifier 'Handle' (compiling source file ..\src\memwatch.cc) [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\bui
    ld\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\memwatch.cc(19): fatal error C1083: Cannot open include file: 'sys/time.h': No such file or directory [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\me
    mwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan_object_wrap.h(24): error C2039: 'IsNearDeath': is not a member of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>' [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwat
    ch\build\memwatch.vcxproj]
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\heapdiff.cc)
      c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan.h(1920): note: see declaration of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>'
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\heapdiff.cc)
    c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan_object_wrap.h(127): error C2039: 'IsNearDeath': is not a member of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>' [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwa
    tch\build\memwatch.vcxproj]
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\heapdiff.cc)
      c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan.h(1920): note: see declaration of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>'
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\heapdiff.cc)
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.hh(18): error C2039: 'Handle': is not a member of 'v8' (compiling source file ..\src\heapdiff.cc) [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\bui
    ld\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8-platform.h(16): note: see declaration of 'v8' (compiling source file ..\src\heapdiff.cc)
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.hh(18): error C2061: syntax error: identifier 'Handle' (compiling source file ..\src\heapdiff.cc) [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\bui
    ld\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(46): error C2039: 'Handle': is not a member of 'v8' [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8-platform.h(16): note: see declaration of 'v8'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(46): error C2065: 'Handle': undeclared identifier [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(46): error C2275: 'v8::Object': illegal use of this type as an expression [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]  
      c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(46): note: see declaration of 'v8::Object'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(46): error C2065: 'target': undeclared identifier [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(46): error C2761: 'void heapdiff::HeapDiff::Initialize(void)': redeclaration of member is not allowed [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwa 
    tch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(47): error C2448: 'heapdiff::HeapDiff::Initialize': function-style initializer appears to be a function definition [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airb 
    nb\node-memwatch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan_object_wrap.h(24): error C2039: 'IsNearDeath': is not a member of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>' [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwat
    ch\build\memwatch.vcxproj]
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\init.cc)
      c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan.h(1920): note: see declaration of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>'
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\init.cc)
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(93): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\bui 
    ld\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan_object_wrap.h(127): error C2039: 'IsNearDeath': is not a member of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>' [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwa 
    tch\build\memwatch.vcxproj]
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\init.cc)c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(93): error C2143: syntax error: missing ',' before '<'
      
      c:\users\<User>\desktop\programming\rest.js\node_modules\nan\nan.h(1920): note: see declaration of 'Nan::Persistent<v8::Object,v8::NonCopyablePersistentTraits<T>>'
              with
              [
                  T=v8::Object
              ] (compiling source file ..\src\init.cc)
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(95): error C2065: 'str': undeclared identifier [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(95): error C2512: 'v8::String::Utf8Value::Utf8Value': no appropriate default constructor available [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch
    \build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.hh(18): error C2039: 'Handle': is not a member of 'v8' (compiling source file ..\src\init.cc) [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\m
    emwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8-profiler.h(48): note: see declaration of 'v8' (compiling source file ..\src\init.cc)c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(110): error C2664: 'std::string handleToStr
      (const int)': cannot convert argument 1 from 'v8::Local<v8::String>' to 'const int'
    
      c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(110): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.hh(18): error C2061: syntax error: identifier 'Handle' (compiling source file ..\src\init.cc) [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\m 
    emwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\init.cc(12): error C2039: 'Handle': is not a member of 'v8' [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8-profiler.h(48): note: see declaration of 'v8'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\init.cc(12): error C2065: 'Handle': undeclared identifier [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\init.cc(12): error C2275: 'v8::Object': illegal use of this type as an expression [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\init.cc(12): note: see declaration of 'v8::Object'c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(182): error C2664: 'std::string handleToStr 
      (const int)': cannot convert argument 1 from 'v8::Local<v8::String>' to 'const int'
      
      c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(182): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\init.cc(12): error C2065: 'target': undeclared identifier [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\init.cc(12): error C2182: 'init': illegal use of type 'void' [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\init.cc(13): error C2448: 'init': function-style initializer appears to be a function definition [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatc 
    h.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\init.cc(24): warning C4312: 'type cast': conversion from 'int' to 'node::addon_register_func' of greater size [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\
    build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(223): error C2143: syntax error: missing ';' before '<' [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(223): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\bu 
    ild\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(224): error C2143: syntax error: missing ';' before '{' [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(224): error C2447: '{': missing function header (old-style formal list?) [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(307): error C3861: 'changesetToObject': identifier not found [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(252): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(254): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(257): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(259): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(265): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(266): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(271): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(272): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(277): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(278): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(279): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(284): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    c:\users\<User>\desktop\programming\rest.js\node_modules\@airbnb\node-memwatch\src\heapdiff.cc(300): warning C4996: 'v8::Object::Set': was declared deprecated [C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch\build\memwatch.vcxproj]
      c:\users\<User>\.node-gyp\12.2.0\include\node\v8.h(3358): note: see declaration of 'v8::Object::Set'
    gyp ERR! build error 
    gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
    gyp ERR! stack     at ChildProcess.onExit (C:\Users\<User>\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:262:23)
    gyp ERR! stack     at ChildProcess.emit (events.js:196:13)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:257:12)
    gyp ERR! System Windows_NT 10.0.18362
    gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\<User>\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
    gyp ERR! cwd C:\Users\<User>\Desktop\Programming\rest.js\node_modules\@airbnb\node-memwatch
    gyp ERR! node -v v12.2.0
    gyp ERR! node-gyp -v v3.8.0
    gyp ERR! not ok
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
    
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! @airbnb/[email protected] install: `node-gyp rebuild`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the @airbnb/[email protected] install script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\<User>\AppData\Roaming\npm-cache\_logs\2019-05-25T23_11_48_315Z-debug.log
    
    bug 
    opened by wolfy1339 18
  • Extremely low performance on node.js 11

    Extremely low performance on node.js 11

    Leakage is incredibly slow on my system (with an Intel(R) Core(TM) i7-3610QM CPU).

    Take the following minimal example:

    $ cat leakage.js
    const sinon = require('sinon');
    const leakage = require('leakage');
    
    it(`test`, function(){
            this.timeout( 1000000 );
            leakage.iterate( ()=>{} );
    });
    
    $ npx mocha leakage.js
    (node:7249) ExperimentalWarning: queueMicrotask() is experimental.
      ✓ test (26544ms)
    
      1 passing (27s)
    

    The test time decreases from 26s to ~4.6s if I avoid including sinon. In my real tests, where I require a bunch of other modules besides sinon, testing a no-op function for leaks takes minutes.

    Is this the expected behavior? I don't think so, unless it's due to recent fixes for the latest v8, since several issues mention a suggested timeout of 5000ms.

    I'm running node v11.10.0 and mocha 5.2.0 on a Linux 4.20.7 system.

    bug 
    opened by peoro 3
  • Document best practices

    Document best practices

    Here is a draft for what the best practices should contain. Follow-up of #18.

    Topics

    No console.log() on non-primitive values in tests

    As @mjhea0 pointed out, the console.* methods will keep a reference to any object/array/function you pass them, thus artificially introducing a memory leak. See http://stackoverflow.com/a/28859493/1799408.

    Leakage tests are quite slow

    ... so think twice before running it together with your other tests everytime. Point out why they are quite slow (as in the FAQ/Timeouts). Ideally present alternatives.

    Make test fail first, then fix it

    Similar to other kinds of test it is also best practice to first check that your leakage test actually works, by purposely introducing a leak and watching the test fail. Remove the initial leak again and make sure the test passes.

    (to be filled with additional content)

    help wanted improve documentation discussion 
    opened by andywer 6
Releases(v0.5.0)
  • v0.5.0(Sep 25, 2019)

    A very small maintenance release, shipping support for node 10. Node 12 is still not working, due to incompatibilities in the native V8 bindings.

    Features

    • Support for node 10 (#36 - kudos to @brandonros)
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(May 16, 2017)

    Hallelujah!

    It took almost half a year and four tries of rewriting the library. It is safe to say that this baby was born out of sweat and tears!

    But here it is: Asynchronous memory leak testing for node.

    There is also a slightly changed API that shall bring us joy in the future and there are extra heap footprint tests to make sure leakage itself won't impact heap snapshotting much.

    Enjoy!

    Changelog

    • Support for asynchronous tests: iterate.async(iterator: Function, options: ?Object): Promise<Result> (#7)
    • Changed API: iterate(iterations: number, iterator: Function) => iterate(iterator: Function, options: ?Object)
    • Pretty much a complete rewrite of the library
    • Added heap footprint tests checking the library's own footprint
    • Result object contains heap diffs and test metadata
    • Requires node 6+
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Dec 28, 2016)

    v0.2.0 fixes a rather critical issue and comes with a bunch of improvements.

    Fixes

    • Renamed iteration() method to iterate() as described in the docs (kept iteration for backwards compatibility, though)

    New features

    • Added simple integration test and Travis CI config
    • Support for node 4+ (was node 6+ before)
    • Faster installation, since only lib/ is published now (the screenshot in the docs/ made it pretty big before)

    Happy hacking!

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Dec 28, 2016)

    Initial release. Working iterate() method, detailed error, but no support for async functions and no unit tests.

    Edit: iterate() was documented, but the method was actually called iteration() in v0.1.0.

    bildschirmfoto 2016-12-27 um 14 20 30

    Source code(tar.gz)
    Source code(zip)
Owner
Andy Wermke
Engineer and part-time product manager. Node.js since 2011, React since 2014, C/C++/Java/Assembler earlier. Into #blockchain and #cryptography.
Andy Wermke
A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers

debug A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers. Installation $ npm ins

Sloth 10.5k Dec 30, 2022
Node is running but you don't know why? why-is-node-running is here to help you.

why-is-node-running Node is running but you don't know why? why-is-node-running is here to help you. Installation Node 8 and above: npm i why-is-node-

Mathias Buus 1.5k Dec 30, 2022
An lldb plugin for Node.js and V8, which enables inspection of JavaScript states for insights into Node.js processes and their core dumps.

Node.js v10.x+ C++ plugin for the LLDB debugger. The llnode plugin adds the ability to inspect JavaScript stack frames, objects, source code and more

Node.js 1k Dec 14, 2022
Node.js debugger based on Blink Developer Tools

Node Inspector Overview Node Inspector is a debugger interface for Node.js applications that uses the Blink Developer Tools (formerly WebKit Web Inspe

null 12.6k Dec 29, 2022
ndb is an improved debugging experience for Node.js, enabled by Chrome DevTools

ndb ndb is an improved debugging experience for Node.js, enabled by Chrome DevTools Installation Compatibility: ndb requires Node >=8.0.0. It works be

null 10.8k Dec 28, 2022
[OBSOLETE] runs Node.js programs through Chromium DevTools

devtool ⚠️ Update: This tool is mostly obsolete as much of the philosophy has been brought into Node/DevTool core, see here for details. If you wish t

Jam3 3.8k Dec 20, 2022
Debug Node.js code with Chrome Developer Tools.

Debug Node.js code with Chrome Developer Tools on Linux, Windows and OS X. This software aims to make things easier ?? . With ironNode you have the fu

Stephan Ahlf 2.3k Dec 30, 2022
Long stack traces for node.js inspired by https://github.com/tlrobinson/long-stack-traces

longjohn Long stack traces for node.js with configurable call trace length Inspiration I wrote this while trying to add long-stack-traces to my server

Matt Insler 815 Dec 23, 2022
API Observability. Trace API calls and Monitor API performance, health and usage statistics in Node.js Microservices.

swagger-stats | API Observability https://swaggerstats.io | Guide Trace API calls and Monitor API performance, health and usage statistics in Node.js

slana.tech 773 Jan 4, 2023
A Node.js tracing and instrumentation utility

njsTrace - Instrumentation and Tracing njstrace lets you easily instrument and trace you code, see all function calls, arguments, return values, as we

Yuval 354 Dec 29, 2022
Locus is a debugging module for node.js

ʆ Locus Locus is a debugging module which allows you to execute commands at runtime via a REPL. Installing npm install locus --save-dev Using require(

Ali Davut 300 Nov 13, 2022
He is like Batman, but for Node.js stack traces

Stackman Give Stackman an error and he will give an array of stack frames with extremely detailed information for each frame in the stack trace. With

Thomas Watson 242 Jan 1, 2023
Streamline Your Node.js Debugging Workflow with Chromium (Chrome, Edge, More) DevTools.

NiM (Node.js --inspector Manager) Streamlines your development process Google Chrome Web Store (works with any Chromium browsers: Google's Chrome, Mic

Will 188 Dec 28, 2022
Infinity bot list source code leak

This is not DMCAable!!! The repo was listed under MIT. Check package.json. "No weapon formed against me shall prosper" - Toxic Dev (510065483693817867

null 6 Feb 14, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A testing focused Remix Stack, that integrates E2E & Unit testing with Playwright, Vitest, MSW and Testing Library. Driven by Prisma ORM. Deploys to Fly.io

Live Demo · Twitter A testing focused Remix Stack, that integrates E2E & Unit testing with Playwright, Vitest, MSW and Testing Library. Driven by Pris

Remix Stacks 18 Oct 31, 2022
🐐 Simple and complete React DOM testing utilities that encourage good testing practices.

React Testing Library Simple and complete React DOM testing utilities that encourage good testing practices. Read The Docs | Edit the docs Table of Co

Testing Library 17.3k Jan 4, 2023
🐐 Simple and complete React DOM testing utilities that encourage good testing practices.

React Testing Library Simple and complete React DOM testing utilities that encourage good testing practices. Read The Docs | Edit the docs Table of Co

Testing Library 17.3k Jan 4, 2023