5

Stack: System: OS: macOS High Sierra 10.13.4 CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz Binaries: Node: 8.1.4 - ~/.nvm/versions/node/v8.1.4/bin/node npm: 6.0.0 - ~/.nvm/versions/node/v8.1.4/bin/npm npmPackages: jest: ^23.0.1 => 23.0.1 sequelize: ^4.37.10 pg: ^7.4.3 koa: ^2.3.0 babel-jest: ^22.4.3

1. Preface

We recently switched all our API's test from Mocha to Jest. We have around 90 tests, half of them require to run synchronously due to them using our testing database (running seeds between them), so we have to use --runInBand.

I unfortunately can't share my code as it is private.

2. The problem

Running tests one by one was fine, I then tried to run all of them at once and things went bad. With the --logHeapUsage, it seems context memory isn't GC'd resulting in a Javascript heap out of memory.

I tried using the new option --detectOpenHandles to see what could prevent the GC to work but this is what came out: ● PROMISE at Promise.catch (<anonymous>) at node_modules/core-js/library/modules/es6.promise.js:244:30 at Object.<anonymous>.module.exports (node_modules/core-js/library/modules/_iter-detect.js:19:5) at Object.<anonymous> (node_modules/core-js/library/modules/es6.promise.js:243:74) at Object.<anonymous> (node_modules/core-js/library/fn/promise.js:4:1) I have around 6-8 of these, and no clue whatsoever of where to look.

I searched around and found out it was most likely the database connection so I added these as a global teardown:

afterAll(async () => {
    await db.close(); // Sequelize instance
    server.close(); // Koa server instance used with supertest (when needed)
});

This didn't change much, memory still goes up very quickly (30-40 MB per test). In the end, I wrote a small file launching jest multiple times to avoid memory problems and stitching coverage report together but this isn't ideal.

xavier
  • 1,860
  • 4
  • 18
  • 46
  • I have the same problem with jest, restify, sequelize and supertest :( – Philipp Kyeck Jun 07 '18 at 09:16
  • @pkyeck here is the issue related to my problem: https://github.com/facebook/jest/issues/6399. TL;DR: I ended up replacing a file from graceful-fs before running my tests as the memory leaks comes from its interaction with Jest – Raphaël RIcard Jun 27 '18 at 10:16

0 Answers0