testdouble / jasmine-rails

A Jasmine runner for rails projects that's got you covered in both the terminal and the browser
http://rubygems.org/gems/jasmine-rails
MIT License
378 stars 154 forks source link

PhantomJS / Jasmine-Rails doesn't exit when run from command line with bundle exec rake spec:javascript #155

Closed JackWCollins closed 8 years ago

JackWCollins commented 9 years ago

If I run bundle exec rake spec:javascript RAILS_ENV=test from my command line, phantomJS will never exit if all of the tests pass. The last thing that is printed to the console is "ConsoleReporter finished" from assets\javascripts\jasmine-console-reporter.js. From the code comments, it looks like that was printed as a hook of some sort for PhantomJS to see and subsequently exit.

    /* Print something that signals that testing is over so that headless browsers
     like PhantomJs know when to terminate. */
    this.log("");
    this.log("ConsoleReporter finished");

However, I couldn't find any code that would actually cause PhantomJS to exit. I saw this piece of code in assets\javascripts\jasmine-runner.js that looks like it is waiting for a Phantom call:

  // listen for event from parent page
    page.onCallback = function(data) {
      if (data.event === 'exit') {
        phantom.exit(data.exitCode);
      } else if (data.event === 'writeFile') {
        var fs = require("fs");
        fs.write(data.filename, data.text, 'w');
      } else {
        console.log('unknown event callback: ' + data);
      }
    };

My workaround will be to add this piece of code in the jasmine-console-reporter.js. It seems to work. I will also make a pull request for this, unless you identify something I'm overlooking.

    /* Print something that signals that testing is over so that headless browsers
       like PhantomJs know when to terminate. */
    this.log("");
    this.log("ConsoleReporter finished");
    if (this.status == "success") {
      window.callPhantom({
        event: 'exit',
        exitCode: 0
      });
    } else if (this.status == "fail") {
      window.callPhantom({
        event: 'exit',
        exitCode: 1
      });
    };
searls commented 9 years ago

Make sure you run as RAILS_ENV=test bundle exec rake spec:javascript. Does that work?

JackWCollins commented 9 years ago

I couldn't run it with RAILS_ENV=test as the first argument so I put it after spec:javascript, but besides that yes that is what I was running. I updated my original post to reflect what I was actually entering at the command line.

searls commented 8 years ago

What version of phantomjs are you on?

phansch commented 8 years ago

I had the same issue after upgrading to phantomjs >2. I fixed it to 1.9.8 for now. Unfortunately I don't have time right now to check what exact version of phantomjs 2 introduces this problem.

JackWCollins commented 8 years ago

Sorry for the late reply. I am currently on 2.0.0, but I was on 1.9.7 when I first saw this issue. However, for me, this was due to a spec error. Please see #156 for my issue description and 'fix'.

This can probably be closed @searls. I didn't realize it was still open - sorry about that.