Jest unit test works locally but fail on circleci docker image cimg/node:16.13


What I did so far :

  • I made sure that my circleci config.yml contains the right image version image: cimg/node:16.13
  • I sshd into the circleci container

The error I get is the following

/project/scripts/ line 3:   634 Killed                  TZ=UTC NODE_ENV=test SYSTEM_UNDER_TEST=client JEST_JUNIT_OUTPUT=reports/junit/junit_client.xml jest --ci --reporters=default --reporters=jest-junit --coverageDirectory=reports/coverage/client --coverage --maxWorkers=2 --logHeapUsage
scripty ERR! script failed: '/project/scripts/'
scripty ERR! exit status: 137
  • I also run my test locally within a container with image cimg/node:16.13 and I reproduce the same error

I don’t know what to do at this point, what could be different between my local environment and the circleci image container

Basically in circle the unit test are hanging forever and exit eventually with 137

I did 2 test within circleci

  • First test with Jest26 => Test run
  • Second with Jest 27 => Test hang forever

However they both work on my local

I’ve also tried --runInBand and --clearCache does not work

Hello @jaybe78,

Welcome to the CircleCI community, and thanks for the post!

This error (exit status: 137) is typically caused by memory exhaustion.

This can happen when the script looks at the number of CPUs available on the physical machine, which can be 32+ cores, rather than the number vCPUs the Docker container has been allocated.

The number of workers/threads your test suites uses will need to be configured to not exceed the number of vCPUs allocated to the resource class in use.

In the case of jest you can limit the number of workers with the --maxWorkers= command line option.

Let me know if this helps.

Do not use Jest with Node >= 16.11.0