Karma tests are repeated over and over in an endless loop

I ran into this problem since I created a bunch of new directory tests (in the JHipster project). Karma block tests are performed by a grunt task. I would like to clearly emphasize that my problem is different from these two (and several others that I am not allowed to publish) that I found on GitHub:

https://github.com/karma-runner/karma/issues/1077

https://github.com/karma-runner/karma/issues/393

The difference is that karma is never executed when tests are executed, but it continues to run in a loop, as if there were an infinite number of tests in this tuned place. This can be seen at the command prompt:

Firefox 45.0.0 (Windows 7 0.0.0): Executed 321 of 192 (skipped 7) SUCCESS (0 secs / 1 min 3.757 secs) Chrome 51.0.2704 (Windows 7 0.0.0): Executed 399 of 192 (skipped 11) SUCCESS (0 secs / 1 min 2.239 secs) PhantomJS 2.1.1 (Windows 7 0.0.0): Executed 444 of 192 (skipped 11) SUCCESS (0 secs / 1 min 0.515 secs) 

And it goes on forever. After almost an hour of execution, this is the result:

 Chrome 51.0.2704 (Windows 7 0.0.0): Executed 20171 of 192 (skipped 472) SUCCESS (0 secs / 50 mins 7.281 secs) Firefox 45.0.0 (Windows 7 0.0.0): Executed 3186 of 192 (skipped 72) DISCONNECTED (14 mins 48.503 secs / 12 mins 16.547 secs) PhantomJS 2.1.1 (Windows 7 0.0.0): Executed 27054 of 192 (skipped 611) DISCONNECTED (48 mins 25.253 secs / 47 mins 34.776 secs) 

It does not matter if the tests pass or fail, or why they fail ( TypeError, ReferenceError... ), the tests are executed forever independently (all tests pass here, as you can see). Execution stops only if I stop the grunt task on the command line.

Karma's configuration and grunt tasks have not changed over the past few months. The settings for Singlerun and autowatch (like any others) do not matter.

Testing the code does not seem to matter. Some changes, they made the problem go away for a while, but when I write new tests, it always comes back. Of course, at first I thought that my code was guilty, but the following will show why this is not a logical conclusion.

Strange behavior always starts when a new test is created, but the test code itself seems irrelevant, since new tests never use any special operations or close components that are not in other tests. Moreover, even if the new test is a completely empty function body, it still leads to strange behavior, which suggests that this is not a new solution path in the program that causes a problem when lighting up with tests. That is why I do not believe that the code is to blame. I also managed to stop the endless execution by disabling random tests (which we have been using for a long time, without any problems), but the problem always returned when I added new tests.

The environment does not matter. Tests run endlessly on my Windows machine and in CI on a Linux server.

I also thought that maybe this is a memory limitation problem, because for some time browsers crashed with a certain test, which has nothing to do with a new function or new tests (and works fine for several months). When I turned off this test, the problem stopped for a while, but later came back again (as I continued to write tests).

I updated all NPM packages and Bower components to the latest version, but this did not change the endless loop.

By now, I'm completely out of ideas. Has anyone encountered such strange behavior and console output?

+8
angularjs karma-runner
source share
1 answer

We just fixed this exact problem. The problem was that we have a logout function in our application that performs various tasks until the browser redirects to another page . One of our tests, which we added around our logout function, did not scoff at calling window.redirect, and when it was done from the karma test, it caused a loop behavior.

After bullying / spying on this call, the behavior of the cycle ceased.

Not sure if this is the same as what you have, but hopefully this information will help you!

+5
source share

All Articles