karma-runner / karma-ng-scenario

A Karma plugin. Adapter for Angular's Scenario Runner.
MIT License
25 stars 16 forks source link

browser().navigateTo() hangs #6

Closed chiefy closed 11 years ago

chiefy commented 11 years ago

I'm really not sure if this is a Karma or a Karma-ng-scenario issue, but it's weird.

I simply do a browser().navigateTo('/app/') and the URL loads but then everything just stops. I don't get any feedback w/ DEBUG level output. My app is running proxied at http://localhost:8282/.

Here's a gist

Thanks for any help.

chiefy commented 11 years ago

Seems to occur in Karma 0.8.5 and 0.9.x

vojtajina commented 11 years ago

Is the app you are testing using AngularJS ? Because I don't think the angular scenario runner works without angular.

vojtajina commented 11 years ago

I don't see anything wrong in your config...

chiefy commented 11 years ago

Yup - AngularJS app. My unit tests w/Karma-mocha & chai run fine. I'm kind of stumped, I can look more into it at work this week.

vojtajina commented 11 years ago

Try opening http://localhost:9876/debug.html and see what's going on in the browser...

On Sat, May 11, 2013 at 6:14 PM, Christopher Najewicz < notifications@github.com> wrote:

Yup - AngularJS app. My unit tests w/Karma-mocha & chai run fine. I'm kind of stumped, I can look more into it at work this week.

— Reply to this email directly or view it on GitHubhttps://github.com/karma-runner/karma-ng-scenario/issues/6#issuecomment-17770585 .

chiefy commented 11 years ago

edit OK confirmed it's something to do with the ng-bootstrap-transition / animation. If I mouseover the slideshow (which stops the animation), the test runs succesfully.

Ok, I did a bunch of digging around today, and it's kind of over my head, but I think the issue has to do with the fact that I am using the ng-bootstrap Carousel which includes animations, and I think it loads the slide images with ng-src async. Perhaps it's screwing the runner up? I noticed this piece of code around line 26287 in navigateTo:

 if ($window.angular) {
          // Disable animations

          // TODO(i): this doesn't disable javascript animations
          //          we don't need that for our tests, but it should be done
          $window.angular.resumeBootstrap([['$provide', function($provide) {
            $provide.decorator('$sniffer', function($delegate) {
              $delegate.supportsTransitions = false;
              return $delegate;
            });
          }]]);
        }

I also set a breakpoint in this function and outstandingRequestCount decreases to 1, but never gets into the conditional where it === 0:

 /**
   * Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks`
   * counter. If the counter reaches 0, all the `outstandingRequestCallbacks` are executed.
   */
  function completeOutstandingRequest(fn) {
    try {
      fn.apply(null, sliceArgs(arguments, 1));
    } finally {
      outstandingRequestCount--;
      if (outstandingRequestCount === 0) {
        while(outstandingRequestCallbacks.length) {
          try {
            outstandingRequestCallbacks.pop()();
          } catch (e) {
            $log.error(e);
          }
        }
      }
    }
  }
facultymatt commented 11 years ago

following. Getting the same issue

shanestillwell commented 11 years ago

I'm seeing the same issue when using AngularUI-Bootstrap Carousel.

Karma: 0.8.5 AngularJS: 1.0.6 AngularUI-Bootstrap: 0.3.0

It hangs when I include the Carousel, performs flawlessly when I remove the code for the Carousel.

chiefy commented 11 years ago

@shanestillwell nice to see I'm not going crazy. As a quick fix, if you actually hover your mouse over the slideshow, it will halt the animations and the tests will continue.

shanestillwell commented 11 years ago

Yes, I noticed that, but kind of defeats the purpose of automated testing right :P

Have you figured out if this is a fix that ng-scenario needs to address or maybe something that can be changed in the Carousel module?

Shane A. Stillwell @shanestillwell 218.499.9205

On Wednesday, May 22, 2013 at 2:37 PM, Christopher Najewicz wrote:

@shanestillwell (https://github.com/shanestillwell) nice to see I'm not going crazy. As a quick fix, if you actually hover your mouse over the slideshow, it will halt the animations and the tests will continue.

— Reply to this email directly or view it on GitHub (https://github.com/karma-runner/karma-ng-scenario/issues/6#issuecomment-18302502).

chiefy commented 11 years ago

@shanestillwell I have to find some time to look through the code, but there's actually a comment in ng-scenario that says something like "we should stop any animations here in the future..." so I think it was just an oversight? I might see if I can fix it this weekend, but I am no expert on <JS internals.

chiefy commented 11 years ago

Ok, I spent the holiday weekend spending some time on this, trying to figure out what the issue is and it has to do with the way angular-bootstrap queues up $timeouts - unfortunately they never seem to resolve in ng-scenario-land if they happen inside the angular bootstrap window. I modified angular-bootstrap's $transition service such that it checks if the $sniffer service's transitions or supportsTransitions property is set to false (which Karma v0.8.5 sets to false [see here], $transition will promptly resolve the promise and return without invoking any $timeouts, thus temporarily solving this issue at least with the mentioned versions of Karma and my fork of angular-bootstrap.

It's important to note that (my solution) is very hacky and breaks in the latest version of Karma. I'm not familiar with the internals of angular / ng-scenario, but it seems like they're going to need to make some adjustments to somehow flag any timeouts that are set in external modules/services?

any ideas @vojtajina ?

DURK commented 11 years ago

I'm having (what appears to be) the same issue. However, I'm not using anything Bootstrap-related like @chiefy . I am using jquery-mobile accompanied with a jquery-mobile-angular-adapter, but disabling these libs doesn't solve the issue.

In short: navigateTo gets executed -> all proxying requests are shown in debug -> page is shown -> no errors -> nothing happens -> sad face.

I've tried combinations of both Angular 1.0.7/1.1.5 and Karma 0.8.5/0.9.2.

Here's my gist

pauldijou commented 11 years ago

Following, having the same problem with AngularUI carousel. So frustrating...

@DURK Try to add urlRoot = '/__karma/'; in your conf, so your proxy doesn't clash with the root url of the karma runner (or something like that). See how @chiefy did in its gist if necessary.

DURK commented 11 years ago

Thanks for your response @pauldijou, but I had tried that already and it had no effect. I've just found the solution to be a missing 'ng-app' definition in my html. Adding the urlRoot was still necessary though.

vojtajina commented 11 years ago

cc @IgorMinar who did this on angular build (he disabled animations, we only use the css) and knows about this better.

@chiefy your work around makes sense - it disables the JS animation. However, why do we need to disable animation? I don't understand that. In theory, the angular scenario runner would just wait for the JS animation to finish, which would make it a bit slower, but it should work. Obviously I'm missing something here.

IgorMinar commented 11 years ago

The scenario runner contains code that disables animation by default. AFAIK animations currently don't increment the outstanding request counter.

To get this to work, you'll need angular 1.0.7.

I don't think that you'll need to do anything, it should just work. Just make sure that karma scenario plugin ships with the right scenario runner version - it should be 1.1.5.

AngularUI-Bootstrap was mentioned here as well but, that project doesn't use our animations yet (they have their own $transition service), so I don't know how that fits into this picture.

chiefy commented 11 years ago

@IgorMinar I have made a sample project using ng-1.0.7, Karma 0.8.6 and ui.bootstrap 0.4.0, and the test still hangs with use of a carousel component. I'm curious if they're planning on moving over to ng-animation?

IgorMinar commented 11 years ago

this is an issue in ui.bootstrap. They should either use the core animation framework or skip animations when they are not supported by browser.

cc: @pkozlowski-opensource @ajoslin

pkozlowski-opensource commented 11 years ago

@chiefy Please open an issue in https://github.com/angular-ui/bootstrap so I don't miss this one. We are planning to migrate to ng-animate as soon as it stabilizes a bit and supports animations with custom class names.