3

I am doing testing in angular 4 in my test cases i need large amount of data. I dynamically require the json which is needed in my spec files. These files are approximately 4 to 5 MB.

Here is some reference ...

  it('Multiple JSON:', () => {
    rdocList.forEach(element => {
      if (element.rdoc_id) {
        service.rdoc = require('../mock/' +
          element.rdoc_id +
          '.json');
        service.rdoc = new RDoc(service.rdoc);
        const storage = service.rdoc.descendants.filter({
          class_id: STORAGE_CLASS_IDS.ID
        });
        const clusterNode = storage[0].descendants.filter({
          class_id: STORAGE_CLASS_IDS.CLUSTERID
        });
        component.id = clusterNode[0].id;
        fixture.detectChanges();
      }
    });
  });

i have cleared the json in after each..

  afterEach(() => {
    service.rdoc = null;
    service = null;
  });

i get this issue

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

3 Answers 3

6

For me, instead of a simple ng test, this worked:
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test
where 8192 is your disered memory to allocate

Sign up to request clarification or add additional context in comments.

Comments

1

You can also first increase the memory usage of the node globally by running export NODE_OPTIONS=--max_old_space_size=8192 followed by the ng test command.

Comments

0

Move to npm location in this path - C:\Users*UserName*\AppData\Roaming\npm

try to changing ng.cmd to this:

@IF EXIST "%~dp0\node.exe" (
   "%~dp0\node.exe" --max_old_space_size=8192 "%~dp0\..\@angular\cli\bin\ng" %*
) ELSE (
   @SETLOCAL
   @SET PATHEXT=%PATHEXT:;.JS;=;%
   node --max_old_space_size=8192 "%~dp0\..\@angular\cli\bin\ng" %*
)

change in ngc.cmd to:

@IF EXIST "%~dp0\node.exe" (
       "%~dp0\node.exe" --max_old_space_size=8192 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
 ) ELSE (
       @SETLOCAL
       @SET PATHEXT=%PATHEXT:;.JS;=;%
       node --max_old_space_size=8192 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
 )

1 Comment

I have done it still failed My system has 32 GB RAM. My question is how to manage GC while running testing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.