How to get around memory error with karma & phantomjs

karma-jasmine, karma-runner, phantomjs

Solution

Thanks to the StackOverflow phenomenon of posting a question and quickly discovering an answer, we solved this by adding `gulp` tasks. Before we were just running `karma start` at the command line. This spun up a single instance of phantomjs that crashed when 750MB was reached.

Now we have a gulp command for each one of our sections of tests, e.g. `gulp common-tests` and `gulp admin-tests` and `gulp customer-tests`

Then a single `gulp karma` that runs each of those groupings. This allows each gulp command to have its own instance of phantom, and therefore stay underneath that threshold.

Problem

We're running tests using `karma` and `phantomjs` Last week, our tests mysteriously started crashing phantomJS with an error of -1073741819. Based on this thread for `Chutzpah` it appears that code indicates a native memory failure with PhantomJS. Upon further investigation, we are consistently seeing phantom crash around 750MB of memory. Is there a way to configure Karma so that it does not run up against this limit? Or a way to tell it to flush phantom? We only have around 1200 tests so far. We're about 1/4 of the way through our project, so 5000 UI tests doesn't seem out of the question.

Original source