14.8.2023

Node/Jest Memory Leaks

describe('Classname', () => {
  it('should test 1 equals 1', function () {
    expect(1).toBe(1);
  });
});

Referencing the class and calling the name as a name for the describe block causes memory leaks in jest

describe(Classname.name, () => {
  it('should test 1 equals 1', function () {
    expect(1).toBe(1);
  });
});

here is a repo for an actual reproduction: https://github.com/adrian-goe/prisma-nestjs-memory-leak-repoduction/

use node --expose-gc to run jest and add --detectLeaks as jest parameter. For example: node --expose-gc ./node_modules/.bin/jest --config=apps/prisma-memeory-leak/jest.config.ts --verbose --no-compilation-cache --detectLeaks --runTestsByPath ./apps/prisma-memeory-leak/src/app/app-prisma.controller.spec.ts

Adrian

Softwareentwickler

Zur Übersicht

Standort Hannover

newcubator GmbH
Bödekerstraße 22
30161 Hannover

Standort Dortmund

newcubator GmbH
Westenhellweg 85-89
44137 Dortmund