Why are my AngularJS, Karma / Jasmine tests so slow?

I have some simple karma / jasmine unit tests that work against the angularjs application. I use the latest version of Chrome and run my tests from the WebStorm environment.

Sometimes the test suite is very fast (0.24 seconds)

Sometimes the exact same set of tests against the same code runs very slowly (120 seconds)

I have tried every sound decision. I browsed the web to try and figure out what I was doing wrong.

Why are my tests running so slow?

+45
angularjs karma-runner jasmine
Oct 30 '13 at 13:38 on
source share
2 answers

The answer is very simple.

I use Chrome to start the karma server. When you first start the karma server, the Chrome instance starts as a maximized window. So naturally, you minimize this so that you can verify that your tests are running.

The problem is that Chrome stores any minimized or secondary tabs (switchable tabs) of CPU cycles.

Therefore, if you minimize the browser instance on which the karma server is running, or simply switch to another tab, then the karma server is very hungry from the processor, and the tests take a lot of time.

The solution is to keep the karma tab active. The browser window can be hidden behind other windows, but the karma tab should be the selected tab, and the browser should not be minimized.

Following these simple rules, you will always work at full speed.

+115
Oct 30 '13 at 13:38 on
source share

Biofractal answered your question, and you could do it. You can also configure your tests to run in PhantomJS or Chrome Headless, which basically allows you to test unit tests only on your command line, thereby eliminating the effect on actual browsers.

0
May 23 '16 at 1:35
source share



All Articles