I'm facing this problem since I created a bunch of new directive tests (in a JHipster project). The karma unit tests are executed by a grunt task. I would like to clearly highlight that my problem is different from these two (and a few others I am not allowed to post) 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 done executing the tests, but keeps running them in a loop as if there were an infinite number of tests in the configured location. It can be clearly seen on the command line output:
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 whether tests pass or fail, or why they fail (TypeError, ReferenceError...
), tests run forever regardless (all tests pass here, as you can see). The execution stops only if I stop the grunt task in the command line.
Karma configuration and the grunt tasks have not changed in the past few months. Singlerun and autowatch settings (as well as any other) are irrelevant.
The code under test seems to be irrelevant. Some changes, they made the problem go away for a while, but as I write new tests, it always comes back. Of course I thought at first that my code was the blame, but the followings will show why it is not a logical conclusion.
The strange behavior always starts when creating a new test, but the test code itself seems to be irrelevant, as the new tests never use any special operations or cover components that other tests don't. Moreover, even if the new test is a completely empty function body, it still results the strange behavior which suggests that it is not a new decision path in the program that causes the problem when covered by tests. That is why I don't believe the code is the blame. I also managed to stop the infinite execution by turning off random tests (that we use long ago without any issues), but the problem always came back when I added new tests.
The environment is irrelevant. Tests run infinitely on my Windows machine and in CI on a Linux server.
I also thought that maybe it is a memory limitation problem, because for a while, the browsers crashed at a certain test that has nothing to do with the new feature or the new tests (and has been working fine for months). When I turned off that test, the issue ceased for a while but later on came back again (as I kept on writing tests).
I updated all NPM packages and Bower components to the latest version, but that has not changed the infinite looping.
By now I am totally out of ideas. Did anyone ever encountered such strange behavior and console output?
We've just fixed this exact problem. The issue was that we have a logout function in our application that performs various tasks before redirecting the browser to another page. One of our tests that we added around our logout function was not mocking the window.redirect call, and when this was executed from a karma test run it caused the looping behaviour.
After mocking/spying this call out, the looping behaviour stopped.
Not sure if this is the same issue you are having, but hopefully this information will help you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With