title: Karma unit tests run over and over again in an infinite loop
body: <p>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:</p>
  
  <p><a href="https://github.com/karma-runner/karma/issues/1077">https://github.com/karma-runner/karma/issues/1077</a></p>
  
  <p><a href="https://github.com/karma-runner/karma/issues/393">https://github.com/karma-runner/karma/issues/393</a></p>
  
  <p>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:</p>
  
  <pre><code>
  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)
  </code></pre>
  
  <p>And it goes on forever. After almost an hour of execution, this is the result:</p>
  
  <pre><code>
  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)
  </code></pre>
  
  <p>It does not matter whether tests pass or fail, or why they fail (<code>TypeError, ReferenceError...</code>), 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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>The environment is irrelevant. Tests run infinitely on my Windows machine and in CI on a Linux server.</p>
  
  <p>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).</p>
  
  <p>I updated all NPM packages and Bower components to the latest version, but that has not changed the infinite looping.</p>
  
  <p>By now I am totally out of ideas. Did anyone ever encountered such strange behavior and console output?</p>