salesforce / sfdx-lwc-jest

Run Jest against LWC components in SFDX workspace environment
MIT License
164 stars 81 forks source link

Enable Jest 29 to fix `FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory` errors #301

Closed AllanOricil closed 1 year ago

AllanOricil commented 1 year ago

Description

I'm running Jest tests in my ci pipelines, and it started failing because it is consuming too much heap memory. You can learn more about it in this github issue https://github.com/facebook/jest/issues/11956

image

I have already tried lots of different things and none worked. I would like to try setting workerIdleMemoryLimit but it is only available in Jest 29. I can't use this setting with Jest v27 or v28, as shown in the image below

image

Configuring Jest with the following additional flags could solve my problem:

-w 2 --workerIdleMemoryLimit 1000
AllanOricil commented 1 year ago

using Node 16.10 reduced the amount of memory usage, but It was still not enough to let my tests run on a vm with 4gb of ram. I had to alocate 8gb just for running unit tests, which is extremelly overkill and expensive.

nolanlawson commented 1 year ago

Thanks for letting us know! Based on the 200+ comments in the Jest bug (https://github.com/facebook/jest/issues/11956), this is affecting more than just sfdx-lwc-jest. Based on my cursory reading of the issue, downgrading to Node 16.10 seems like the prudent option until this is figured out.

nolanlawson commented 1 year ago

Ah, I misread your comment. Supporting Jest 29 would be possible, but may cause compatibility issues, so it would have to be done carefully.

AllanOricil commented 1 year ago

Because this would introduce breaking changes, and Jest is provided by this package, I believe this is the time for creating v2 in order to support Jest 29. Then you can deprecate v1.

AllanOricil commented 1 year ago

So you already tried to upgrade Jest to v29 https://github.com/salesforce/sfdx-lwc-jest/releases/tag/v1.1.3

But it was removed in v1.1.4

It is better if you maintain one major version for each jest major version instead of releasing patches, because sfdx-lwc-jest is usually added to sfdx projects using ~/^ (i believe sfdx cli is adding it with ^). If u release a "patch" that changes a "major" version of jest, people's tests will certainly break.

Please, try again but release as v2.