Debugging and Fixing Local Karma PhantomJS Issue
Using Karma for a client AngularJS project. Technically there is only one Karma test (a stub success test) since we haven’t gotten around to using that yet. But it is set up and part of our test build chain. Using Mocha for Node tests (controllers, models) and Protractor for end-to-end testing.
So I am running Karma locally, and all of a sudden getting some PhantomJS issues. The results look something like:
$ grunt test:karma --debug Running "env:test" (env) task [D] Task source: myproject/node_modules/grunt-env/tasks/env.js Running "karma:unit" (karma) task [D] Task source: myproject/node_modules/grunt-karma/tasks/grunt-karma.js INFO [karma]: Karma v0.12.23 server started at http://localhost:9876/ INFO [launcher]: Starting browser PhantomJS WARN [launcher]: PhantomJS have not captured in 60000 ms, killing. INFO [launcher]: Trying to start PhantomJS again (1/2). WARN [launcher]: PhantomJS have not captured in 60000 ms, killing. INFO [launcher]: Trying to start PhantomJS again (2/2). WARN [launcher]: PhantomJS have not captured in 60000 ms, killing. ERROR [launcher]: PhantomJS failed 2 times (timeout). Giving up. Warning: Task "karma:unit" failed. Use --force to continue. Aborted due to warnings.
It would try again after a bit and continually fail. The continuous integration server and other developers’ machines are working just fine. Usually you hear “works on my machine”. Well in this case, it didn’t work on my machine, but worked everywhere else.
Strangely enough, I could access http://localhost:9876 through a browser even without the grunt task running (it said “Not Found” instead of the typical Chrome server not running message.) So I figured maybe something else was listening on that port. I killed all node and grunt and karma and phantomjs-like things, but it was still not working.
So on my Mac:
$ lsof -n -i4TCP:9876 | grep LISTEN Emacs-10. 30723 anthonypanozzo 9u IPv4 0x866a47118fd21843 0t0 TCP 127.0.0.1:sd (LISTEN)
I have been dipping my toes into Emacs again after realizing the unparalleled power of org-mode. Turns out it was a plugin I recently added to Emacs called org-trello that listens on the same port. Specifically org-trello uses elnode which listes on that port. So I disabled org-trello for now (just trialing it currently anyway) until I have time to figure out how to change the port that org-trello listens on. The bottom of the org-trello migrations page is promising, but my Emacs-fu is not up to snuff.
This took me longer than I expected to take on it. I think one of the issues is that Karma does not complain if something else is listening on the same port. I figured it was a problem with PhantomJS instead.
After this change, Karma was back and working again. Hope this shows how I think about debugging problems like this.