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

PhantomJS timeout in Ubuntu #4

Open
kcz opened this issue May 16, 2012 · 31 comments
Open

PhantomJS timeout in Ubuntu #4

kcz opened this issue May 16, 2012 · 31 comments

Comments

@kcz
Copy link

kcz commented May 16, 2012

When I try to run grunt jasmine, it failed, due to a timeout, in Ubuntu 10.04 with PhantomJS 1.5.
But the same project worked well in my Mac 10.7.3.

The error message is as follows:

Running "jasmine:all" (jasmine) task
Running specs for index.html

<WARN> PhantomJS timed out, possibly due to an unfinished async spec. Use --force to continue. </WARN>

Aborted due to warnings.

In order to debug, I replaced my project with jasmine demo from official site. The same phenomenon happened again.
Here is the minimized project to indicate problem:
http://kcz.me/test/grunt-jasmine.zip

Maybe the reason comes from phantomJS version. Is there anyone know where I can download PhantomJS 1.3 since that there is no download link in googlecode.

Thanks.

@creynders
Copy link
Member

I have no problems running your test on Mac.
There are some issues with phantomJS v1.5 on windows too.
I have no idea what we can do about it, though.

@Jontyy
Copy link

Jontyy commented May 17, 2012

I'm getting the same error, I'm on 12.04 with PhantomJS 1.5.
I can run the qunit task fine though.

@axelhzf
Copy link

axelhzf commented May 26, 2012

Same error on OS X with phantomjs 1.5

@creynders
Copy link
Member

@axelhzf could you provide me with a barebones setup that fails? I'm on OS X as well and have so far not encountered any problems.

@axelhzf
Copy link

axelhzf commented May 27, 2012

It was a problem of my test runner configuration, I was using a HtmlReporter. When I delete this reporter it worked. My final configuration is:

<script type="text/javascript">
    jasmine.getEnv().execute();
</script>

@mattd
Copy link

mattd commented Jun 9, 2012

I ran kcz's test project on OSX Lion, and I get the same error. A project I've been working on is showing the same results.

@creynders
Copy link
Member

@mattd what version of PhantomJS are you using? 1.5? I'm still on v1.4.1 and have no problems.
This is a really unfortunate situation. Something changed from v1.4.x to v1.5, but I have no idea what. Could be PhantomJS is WAI and my code simply benefits from a previous PhantomJS bug - or a new bug was introduced in PhantomJS. It's however very hard to find out what is going wrong since there's a whole stack of tech involved: grunt, phantomjs, jasmine, my plugin, and a bunch of other node modules.

@ariya is there some way we could join forces on this and find out what's going wrong? I can mail you more specifics about how my grunt plugin uses phantomjs

@Aaronius
Copy link

Aaronius commented Jun 9, 2012

Hey creynders, thanks for your work on this and it's good to see you on the interwebs again. I noticed on my setup with Windows 7 that Phantom 1.4 and 1.5 both time out but 1.3 works. Using grunt-mocha all three time out. The tasks are so similar I don't know why I see different results. Sorry, I don't have an answer yet either.

@mattd
Copy link

mattd commented Jun 9, 2012

@creynders Yeah, the size of the stack is what had me scratching my head.

So I finally got my setup working after many hours. My notes:

  • @kcz 's test project is definitely broken on 1.5. I downgraded to 1.4.1 and it works flawlessly.
  • After downgrading to 1.4.1, I went back and tried running my project's test suite. While it didn't work, I did finally get some helpful error reporting - specifically, a missing variable. So 1.5 was swallowing the error, 1.4.1 was not.
  • I'm using backbone-boilerplate, which includes a skeleton for jasmine tests. It uses upwards-climbing relative paths for scripts, which apparently angers PhantomJS. I symlinked my application directories into my testing root, and everything works flawlessly. I assume that's a bug in PhantomJS and not intentional, so I'll file a bug report for @ariya to weigh in on.

Thanks so much for writing this task - I initially thought I'd have to write it myself. ;)

@mattd
Copy link

mattd commented Jun 9, 2012

For reference, the bug report. http://code.google.com/p/phantomjs/issues/detail?id=583

@creynders
Copy link
Member

@mattd wow, thanks a lot for the hard work! I'll keep an eye on your bug report and see if there is something I do have to do.

@creynders
Copy link
Member

@kcz @mattd @axelhzf @Aaronius @Jontyy Have you guys tried PhantomJS v1.6 ? With the Grunt Qunit plugin there were similar problems and I just had confirmation from someone that they were solved by updating.

@kcz
Copy link
Author

kcz commented Jun 25, 2012

@creynders , thanks for your reminder. But i've got the same error with PhantomJS v1.6 in Ubuntu 10.04. How about other guys?

@PhillyWebGuy
Copy link

Same problem here, PhantomJS 1.5.1, Ubuntu 12.04. Would love to figure this out.

@papachan
Copy link

papachan commented Jul 4, 2012

I have the same problem here in ubuntu. My project work fine in Mac OS but when i run the grunt-jasmine task it always shows me a time out error. :0

@chchrist
Copy link

I get timeout with phantomjs 1.6 on mac os

Running "jasmine:all" (jasmine) task
Running specs for runner.html

PhantomJS timed out, possibly due to an unfinished async spec. Use --force to continue.

Aborted due to warnings.

@nhunzaker
Copy link

I had this same issue with both Jasmine and Mocha Grunt tasks using PhantomJS 1.6.1.

Here's how I solved it:

In your specrunner.html (or whatever you have it named), include this javascript fle:
https://github.com/creynders/grunt-jasmine-task/blob/master/tasks/jasmine/jasmine-helper.js

Example:

<head>

<!-- Beginning of specrunner.html etc.... -->

<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine-html.js"></script>
<script type="text/javascript" src="../node_modules/grunt-jasmine-task/tasks/jasmine/jasmine-helper.js"></script>

<!-- Now include spec files here... -->  

</head>

<!-- The rest of the document.... -->

It completely eliminated all issues for me!

@papachan
Copy link

OMG, you right, this absolutely solved my problem in ubuntu 12.04 ! thank you so much !

@kcz
Copy link
Author

kcz commented Jul 20, 2012

Sorry, it doesn't work to me in ubuntu 10.04, using nodejs 0.6.15 and phantomjs 1.6.0 !

@kcz
Copy link
Author

kcz commented Jul 26, 2012

@nhunzaker , thanks so much. You are right. "jasmine-helper.js" is the final solution.
It seems to me phantomjs 1.6.0 is buggy. When I upgraded to 1.6.1, it works on both mac and ubuntu 10.04.
In the file "jasmine-helper.js", "alert" of function sendMessage is the key point.

@kcz
Copy link
Author

kcz commented Jul 26, 2012

@chchrist , Timeout error using requireJS doesn't matter with grunt-jasmine-task. It comes from the same reason discussed above.

There is a demo with requireJS working well on mac lion and ubuntu 10.04.
http://kcz.me/test/grunt-jasmine-requirejs.zip

Don't forget to upgrade phantomjs to 1.6.1 !

@kcz kcz closed this as completed Jul 27, 2012
@creynders creynders reopened this Jul 27, 2012
@creynders
Copy link
Member

I'm re-opening this, since I'm not convinced this is the definite solution. I'm afraid i won't be able to fix this 100% until this comes through: http://code.google.com/p/phantomjs/issues/detail?id=539

Maybe I should add @nhunzaker 's solution (thanks for that BTW !!!) to the README though.

@nhunzaker
Copy link

@creynders I think that would be very helpful! It definitely needs to be way more prominent than the line in the docs for grunt-mocha!

@creynders
Copy link
Member

Hmmm, unfortunately this cripples manually run spec runner files. Since the task uses alerts to relay the events from the sandboxed specrunner to grunt, all these alerts are thrown when it's run manually. I suppose it's the same with the grunt-mocha task.
Damn, at the moment I don't have the time to think this through to make this less hackish.

@dosu
Copy link

dosu commented Aug 10, 2012

any update on this issue?

I got the same error
Running "jasmine:all" (jasmine) task
Running specs for index.html

PhantomJS timed out, possibly due to an unfinished async spec. Use --force to continue.

Aborted due to warnings.

Using Mac OS X 10.6.8 + phantomjs-1.6.1 + nhunzaker's solution.

@cburgmer
Copy link

cburgmer commented Sep 5, 2012

I have a bug that I believe to be similar to this. My SpecRunner.html references a reporter in addition to the helper. When it does, the tests are run before grunt-jasmine-task's reporter is able to pick them up. If I omit my own Reporter, everything works fine.

I found a way to solve this, by injecting the helper on the DOMContentLoaded event. Here's a nice workaround to make phantomjs support it: https://gist.github.com/2475509

@creynders
Copy link
Member

@cburgmer that seems like a really clever solution! One thing I don't understand however is why you use an eval to run the function, wouldn't this work with a direct call to a function too, since the onConsoleMessage handler isn't sandboxed?

@cburgmer
Copy link

cburgmer commented Sep 6, 2012

Hi, I didn't look at the code for too long. However the idea is neat and it does work. I could get the task's own reporter to be added before the tests would actually start.

My issue is/was that grunt-jasmine-task would only run about half of my tests, as the test run was already underway when the reporter was added. You might want to open another bug report for that.

@creynders
Copy link
Member

Could you guys checkout the code in the WIP branch?
It should solve the timeout problems. I have a hard time testing it, since I haven't encountered the problem myself yet. But I feel quite confident this is the solution.
If it is, thank you so much @cburgmer !!! My solution is based on yours, although - as I wrote - there's no need to use eval you can call the injecting code directly.

@svperfecta
Copy link

Hi folks - I'm having the problem as well. I'm unclear if you fixed it. Could you post your specrunner file?

@charlievaughan-zz
Copy link

I've been working to fix a similar problem related to the Warning: PhantomJS timed out, possibly due to an unfinished async spec. Use --force to continue error.

I'd thought this was due the Jasmine async tests we had been using combined with PhantomJS / Grunt / grunt-contrib-jasmine. But after a LOT of time and investigation I found it was related to the way some of our tests were being cleaned up:

afterEach(function () {
    $body.empty();
});

In this instance we were emptying all the elements injected into the DOM for the test. But this doesn't unbind all the JS code which lingers in the background and causes PhantomJS to eventually timeout. This blocked further Grunt tasks from running reports.

This is the better technique:

afterEach(function () {
    $element.remove();
    $nav.remove();
});

Elements added to the DOM should be removed individually to ensure all the JS associated with them is properly removed and cleaned up, ready for the next spec.

This meant we could have a large stack of 77 specs complete without PhantomJS timing out.

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

No branches or pull requests