Enzyme: Compared to enzyme v2, initializing v3 is slow and runs out of memory

Created on 18 Oct 2017  路  4Comments  路  Source: enzymejs/enzyme

For context, I'm working on a large project with ~700 test suites. As part of upgrading to enzyme v2 to v3 I configured jest to initialize the enzyme adapter before each test suite. This works (in the sense that the test cases pass) but causes two problems:

  1. The test cases take 10x longer to run.
  2. Eventually the node process runs out of memory and dies.

The root of the problem here, I think, is that now enzyme is being initialized ~700 times. Only ~15 of the test suites actually use enzyme, so previously it was only imported a handful of times. Now, because of the way jest's test setup works, enzyme gets imported and initialized before every test suite. Obviously that's outside the scope of enzyme itself, but it doesn't seem like importing and calling configure should be so heavy. (Based on my experimentation it's importing enzyme that's taking a long time, not calling configure.)

For now I've worked around this by forgoing the jest config option and explicitly configuring enzyme for each test suite that needs it. But it would be great if enzyme itself could make the configuration process more lightweight.

Need More Information Need To Reproduce question v3 bugs

Most helpful comment

We definitely aren't transpiling node_modules -- or at least not intentionally -- but it sounds like there must be something else factoring into the issue. If I have a chance I'll try to profile the scenario and see what's making it so slow. If I find anything out I'll update this issue.

All 4 comments

Hmm - Airbnb has thousands of test suites, using jest, and this doesn't seem to be an issue for us.

Are you by chance transpiling node_modules?

We definitely aren't transpiling node_modules -- or at least not intentionally -- but it sounds like there must be something else factoring into the issue. If I have a chance I'll try to profile the scenario and see what's making it so slow. If I find anything out I'll update this issue.

Hi, I'm having similar issue I believe after updating to the newest versions of React, Jest and Enzyme plus adding new Adapter setup. I've added explicitly transformIgnorePatterns: ["/node_modules/"],, but still cant run all my tests. It is usually hangs after 20th test and then I get the error Allocation failed - JavaScript heap out of memory. Any help highly appreciated!

I'm not sure if this is still an issue, but it hasn't been one at airbnb.

I'm going to close this, but if anyone has a repro case, I'm happy to reopen.

Was this page helpful?
0 / 5 - 0 ratings