Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some of your tests did a full page reload! #2373

Closed
maruthi1255 opened this issue Sep 23, 2016 · 12 comments
Closed

Some of your tests did a full page reload! #2373

maruthi1255 opened this issue Sep 23, 2016 · 12 comments
Labels

Comments

@maruthi1255
Copy link

Getting the following error while running karma test

Command: gulp test:unit "--browsers=Chrome"

This is happing most of the time.
There is no proper stack trace to find the root cause of the issue.

Using the following karma versions

Karma "version": "0.13.22"
karma-coverage: "version": "0.2.6"
karma-jasmine: "version": "0.3.8"

Error Log (Log):
1.Chrome 53.0.2785 (Mac OS X 10.11.6) ERROR
Some of your tests did a full page reload!
Chrome 53.0.2785 (Mac OS X 10.11.6): Executed 0 of 0 ERROR (3.638 secs / 0 secs)
2. Also getting the code coverage as
=============================== Coverage summary ===============================
Statements : 100% ( 0/0 )
Branches : 100% ( 0/0 )
Functions : 100% ( 0/0 )
Lines : 100% ( 0/0 )

Would you please suggest the versions in which the issue got resolved.

@vivganes
Copy link
Contributor

@maruthi1255 Please try to do what is suggested in this comment: #1101 (comment)

Running with the above suggestion can help you to find out which part is doing a page reload

@wesleycho
Copy link
Member

wesleycho commented Dec 4, 2016

Usually this type of error can occur when one is doing something like window.location.href = 'http://example.com'; - this is something a user must work around karma to test, changing the location compromises the test environment.

@rawbin-
Copy link

rawbin- commented Jul 11, 2017

@wesleycho Is there any idea to work around?

@sarathcs
Copy link

This issue seems to be happening in the Chrome. Try configuring the headless browser, like PhantomJS in karma configuration and tests run. Yes, its hard to debug. But, that seems to be workaround. ( I have tried)

Or as many pointed, that seems to be an issue with the window location, probably jasmine Spy objects can help to hook the fake listeners to events. I haven't tried this.

@rawbin-
Copy link

rawbin- commented Jul 24, 2017

@SarathChandraSVM I am using the headless chrome, wanting to navigate to a page and do some check, with the same problem

@ORESoftware
Copy link

ORESoftware commented Dec 18, 2017

I solved this like so:
https://stackoverflow.com/questions/47876604/stubbing-window-location-reload-for-unit-tests-some-of-your-tests-did-a-ful

  beforeEach(function(){
    angular.mock.module('app', function ($provide) {
      let $window = {location: {reload: sinon.spy()}};
      $provide.value('$window', $window);
      $window.onbeforeunload = sinon.spy();
    });
  });

the above just stubs it out. You have to inject $window into your codebase, so use:

$window.location.reload()

instead of

window.location.reload()

@ashawley
Copy link

I experienced this on Travis CI, despite the following:

  1. Disabling auto-watch with karma start --no-auto-watch
  2. My code wasn't modifying window.location, however mocking $window.location in Angularjs did fix it:
'use strict';

jasmine.getEnv().topSuite().beforeEach({
  fn: function() {
    angular.mock.module('app', function ($provide) {
      var $window = {location: { reload: jasmine.createSpy('reload') }};
      $provide.value('$window', $window);
    });
  }
});

However, that didn't really help determine the root cause. What ended up fixing it as well was disabling concurrency in my karma.conf.js:

concurrency: 1,

It's sad to disable concurrency. Maybe I'll just go back to using the Jasmine hack?

Here's a minimal reproduction of the issue:

https://github.com/ashawley/karma-issue-2373

@albertodonato
Copy link

I see this error as well, but only when running with more than one browser at a time (I'm using chromium + phantomjs).
Oddly seting concurrency: 1 doesn't affect it, and the error only happens with the chromium run.
Running tests with just chromium (or just phantomjs) never fails.

@ashawley
Copy link

ashawley commented Apr 18, 2018

What platform are you on? Did you try the minimal example in the repo I posted? Do either of the "Jasmine before each" / "Angular mock" hacks change anything?

@sdebanik
Copy link

It will solve this Karma redirect error!

var html = '<script type="text/javascript">';
html += 'window.location = "' + urlToRedirect +'"';
html += '</script>';
$( '.wrapper' ).append( html );

@rooby
Copy link

rooby commented Feb 26, 2021

This is potentially resolved by #3560

@devoto13
Copy link
Collaborator

@rooby Thanks for the heads up!

The race condition causing the false positive errors was indeed resolved in the latest release of Karma. It worths noting that you may still see this error if your tests trigger navigation. If it is the case, you should update your test code to prevent it (by for example mocking window.location.href or other calls, which may cause navigation. Navigations during the test will break Karma test execution and that's why Karma reports this error.

Please open a new issue providing minimal reproduction if you still believe that there is a Karma bug involved here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests